Example usage for org.eclipse.jface.util SafeRunnable SafeRunnable

List of usage examples for org.eclipse.jface.util SafeRunnable SafeRunnable

Introduction

In this page you can find the example usage for org.eclipse.jface.util SafeRunnable SafeRunnable.

Prototype

public SafeRunnable() 

Source Link

Document

Creates a new instance of SafeRunnable with a default error message.

Usage

From source file:au.com.langdale.ui.util.SelectionProvider.java

License:Open Source License

public void setSelection(ISelection selection) {
    theSelection = selection;/* w w  w.  j  a va2  s  . c o  m*/
    final SelectionChangedEvent e = new SelectionChangedEvent(this, selection);
    Object[] listenersArray = listeners.toArray();

    for (int i = 0; i < listenersArray.length; i++) {
        final ISelectionChangedListener l = (ISelectionChangedListener) listenersArray[i];
        SafeRunner.run(new SafeRunnable() {
            public void run() {
                l.selectionChanged(e);
            }
        });
    }
}

From source file:au.gov.ansto.bragg.echidna.ui.views.EchidnaAnalysisControlView.java

License:Open Source License

@Override
public void createPartControl(Composite composite) {
    super.createPartControl(composite);

    progressBar = new ProgressBar(parameterEditorsHolderComposite, SWT.HORIZONTAL | SWT.NULL);
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    progressBar.setLayoutData(data);//w w  w  .java  2 s  . c  om
    progressBar.setForeground(composite.getDisplay().getSystemColor(SWT.COLOR_DARK_RED));
    progressBar.setEnabled(false);

    //      progressBar.moveAbove(parameterGroupButtonsComposite);
    defaultParametersButton.dispose();
    revertParametersButton.dispose();
    configurationButton.dispose();
    applyParametersButton.setText("Apply");
    data = new GridData();
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    applyParametersButton.setLayoutData(data);

    exportAllButton = new Button(parameterGroupButtonsComposite, SWT.PUSH);
    exportAllButton.setText("Export Selected ...");
    exportAllButton.setImage(Activator
            .imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/file-export-16x16.png").createImage());
    exportAllButton.setToolTipText("Export reduction results of all opened nexus files into 3-column files");
    //      exportAllButton.setEnabled(isDataSourceAvailable());
    stripChoiceMenu = new Menu(composite.getShell(), SWT.POP_UP);
    data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.verticalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    data.grabExcessVerticalSpace = true;
    exportAllButton.setLayoutData(data);

    initListener();
    //      parameterGroupButtonsComposite.layout();
    //      parameterGroupButtonsComposite.update();
    //      parameterGroupButtonsComposite.redraw();
    //      parameterGroupButtonsComposite.getParent().update();
    //      parameterGroupButtonsComposite.getParent().redraw();
    AlgorithmTask task = getAlgorithmTask();
    final Operation operation = task.getOperationManager(0).getOperation(NAVIGATION_PROCESSOR_NAME);
    //      final OperationParameter parameter = operation.getOperationParameter(SCAN_VARIABLE_NAME);
    //      final Operation plotOperation = task.getOperationManager(0).getOperation(ONEDPLOT_PROCESSOR_NAME);
    //      final Operation geometryOperation = task.getOperationManager(0).getOperation(CORRECTED_HISTOGRAM_PROCESSOR_NAME);
    //      final Operation integrationOperation = task.getOperationManager(0).getOperation(INTEGRATION_PROCESSOR_NAME);

    //      final IPointLocatorListener mouseListener = new IPointLocatorListener(){
    //
    //         public void locationUpdated(double x, double y, double val) {
    //            List<OperationParameterEditor> editors = parameterEditorsMap.get(operation.getName());
    //            for (OperationParameterEditor editor : editors){
    //               if (editor.getOperationParameter() == parameter){
    ////                  parameter.setValue(new Double(x));
    ////                  editor.loadData();
    //                  if (editor instanceof OptionOperationParameterEditor)
    //                     ((OptionOperationParameterEditor) editor).setSelection(new Double(x));
    //               }
    //            }
    //            
    //            applyParameters();
    //         }
    //      };
    //      loadPreference();

    statusListener = new AlgorithmTaskStatusListener() {

        public void onChange(final AlgorithmStatus status) {
            DisplayManager.getDefault().asyncExec(new Runnable() {

                public void run() {
                    if (currentStatus != AlgorithmStatus.Running && status == AlgorithmStatus.Running) {

                        progressBar.setEnabled(true);
                        progressBar.setMinimum(0);
                        progressBar.setMaximum(algorithmTask.getOperationManager(0).getOperations().size());
                        //                     progressBar.setMaximum(6);
                    } else if (status == AlgorithmStatus.End) { //AlgorithmStatus.Running && status != AlgorithmStatus.Running){
                        progressBar.setSelection(0);
                        progressBar.setEnabled(false);
                    }
                    currentStatus = status;
                }
            });
        }

        public void setStage(final int operationIndex, final AlgorithmStatus status) {
            DisplayManager.getDefault().asyncExec(new Runnable() {

                public void run() {
                    if (progressBar.isEnabled()) {
                        if (progressBar.isEnabled() && progressBar.getMaximum() > operationIndex + 1
                                && operationIndex + 1 > progressBar.getSelection()) {
                            progressBar.setSelection(operationIndex + 1);
                        } else if (progressBar.getMaximum() == operationIndex + 1) {
                            progressBar.setSelection(0);
                            progressBar.setMaximum(0);
                            progressBar.setEnabled(false);
                        }
                    }
                }
            });
        }
    };

    algorithmTask.addStatusListener(statusListener);
    loadPreference();

    SafeUIRunner.asyncExec(new SafeRunnable() {

        @Override
        public void run() throws Exception {
            try {
                au.gov.ansto.bragg.kakadu.ui.plot.Plot plot3 = PlotManager.openPlot(PlotType.OverlayPlot,
                        getViewSite().getWorkbenchWindow(), 3);
                plot3.setQuickRemoveEnabled(true);
                plot3.getMultiPlotDataManager().setStartColorIndex(1);
                //               plot3.setDataViewSelection(true);
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    });

}

From source file:au.gov.ansto.bragg.kakadu.ui.widget.CheckboxTableTreeViewer.java

License:Open Source License

/**
 * Notifies any check state listeners that a check state changed  has been received.
 * Only listeners registered at the time this method is called are notified.
 *
 * @param event a check state changed event
 *
 * @see ICheckStateListener#checkStateChanged
 *//*from  w  w w.java  2  s.c om*/
private void fireCheckStateChanged(final CheckStateChangedEvent event) {
    Object[] array = checkStateListeners.getListeners();
    for (int i = 0; i < array.length; i++) {
        final ICheckStateListener l = (ICheckStateListener) array[i];
        SafeRunnable.run(new SafeRunnable() {
            public void run() {
                l.checkStateChanged(event);
            }
        });
    }
}

From source file:au.gov.ansto.bragg.nbi.ui.tasks.PythonScriptingTask.java

License:Open Source License

private void createNewScriptConsoleAndRun(final IScriptExecutor executor, final IScriptBlock block) {
    if (consoleHolder == null || consoleHolder.isDisposed()) {
        return;//from ww  w .  j av a 2 s. co  m
    }
    SafeUIRunner.asyncExec(new SafeRunnable() {
        public void run() throws Exception {
            /*************************************************************
             * Refresh UI
             *************************************************************/
            for (Control child : consoleHolder.getChildren()) {
                child.dispose();
            }
            if (consoleHolder.getMenu() == null || consoleHolder.getMenu().isDisposed()) {
                consoleHolder.setMenu(new Menu(consoleHolder));
            }

            /*************************************************************
             * Creates new viewer
             *************************************************************/
            ICommandLineViewer console = new CommandLineViewer();
            Composite composite = toolkit.createComposite(consoleHolder, SWT.NONE);
            composite.setLayout(new FillLayout());
            console.createPartControl(composite,
                    ICommandLineViewer.NO_INPUT_TEXT | ICommandLineViewer.NO_UTIL_AREA);
            console.setScriptExecutor(executor);
            consoleHolder.layout(true, true);

            /*************************************************************
             * Run script
             *************************************************************/
            executor.runScript(block);
            executor.runTask(new Runnable() {
                public void run() {
                    result = executor.getEngine().get("__workflow_output__");
                    resultReady = true;
                }
            });
        }
    });
}

From source file:au.gov.ansto.bragg.nbi.ui.widgets.HMControlWidget.java

License:Open Source License

private void bindProxy() {
    // Get command controller
    Job job = new Job("Get command controller") {
        protected IStatus run(IProgressMonitor monitor) {
            // Check if SICS is ready
            if (SicsCore.getSicsController() == null) {
                schedule(500);/* ww  w  .  ja v  a2  s  . c  o  m*/
                return Status.OK_STATUS;
            }
            // Get controller
            commandController = (ICommandController) SicsCore.getSicsController()
                    .findComponentController(PATH_HISTMEM);
            // Create UI
            SafeUIRunner.asyncExec(new SafeRunnable() {
                public void run() throws Exception {
                    createUI();
                }
            });
            return Status.OK_STATUS;
        }
    };
    job.schedule();
}

From source file:au.gov.ansto.bragg.nbi.ui.widgets.HMControlWidget.java

License:Open Source License

private void unbindProxy() {
    commandController = null;// ww w  .  j a  v a  2  s.co m
    // Disable UI
    SafeUIRunner.asyncExec(new SafeRunnable() {
        public void run() throws Exception {
            HMControlWidget.this.setEnabled(false);
        }
    });
}

From source file:au.gov.ansto.bragg.nbi.ui.widgets.HMControlWidget.java

License:Open Source License

private void updateData(final Object control, final Object data) {
    SafeUIRunner.asyncExec(new SafeRunnable() {
        public void run() throws Exception {
            if (control instanceof ComboViewer) {
                // Update Mode
                ((ComboViewer) control).setSelection(new StructuredSelection(data));
            } else if (control instanceof Text) {
                // Update preset
                ((Text) control).setText(data.toString());
            } else if (control instanceof Button) {
                // Command status
                if (CommandStatus.valueOf((String) data).equals(CommandStatus.IDLE)) {
                    ((Button) control).setImage(InternalImage.START_32.getImage());
                    ((Button) control).setData("status", "idle");
                } else {
                    ((Button) control).setImage(InternalImage.STOP_32.getImage());
                    ((Button) control).setData("status", "running");
                }/*from w  ww. ja v a 2s . co  m*/
            }
        }
    });
}

From source file:au.gov.ansto.bragg.nbi.ui.widgets.ShutterStatusWidget.java

License:Open Source License

public void renderWidget() {
    setBackgroundMode(SWT.INHERIT_FORCE);
    GridLayoutFactory.swtDefaults().applyTo(this);

    Label label = getToolkit().createLabel(this, "Secondary\n--", SWT.CENTER | SWT.WRAP | SWT.BORDER);
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(label);
    Context context = new Context();
    context.path = "/instrument/status/secondary";
    context.label = label;/*from   ww  w. j a va2  s .c o m*/
    context.originalForeground = label.getForeground();
    context.handler = new HdbEventHandler(context).activate();
    contexts.add(context);

    label = getToolkit().createLabel(this, "Sample\n--", SWT.CENTER | SWT.WRAP | SWT.BORDER);
    label.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(label);
    context = new Context();
    context.path = "/instrument/status/tertiary";
    context.label = label;
    context.originalForeground = label.getForeground();
    context.handler = new HdbEventHandler(context).activate();
    contexts.add(context);

    // TODO: test this code
    // [GUMTREE-141] Blinking
    eventHandler = new EventHandler(IDirectoryService.EVENT_TOPIC_BIND) {
        @Override
        public void handleEvent(Event event) {
            // TODO: use topic to filter
            if (event.getProperty(IDirectoryService.EVENT_PROP_NAME).equals("shutterStatusCheckFailed")) {
                if ((Boolean) event.getProperty(IDirectoryService.EVENT_PROP_OBJECT)) {
                    final int[] counter = new int[] { 0 };
                    final Map<Label, Color> originalColourMap = new HashMap<Label, Color>();
                    Job job = new Job("") {
                        protected IStatus run(IProgressMonitor monitor) {
                            // Over 5 times ... exit
                            if (isDisposed() || counter[0] > 5) {
                                return Status.OK_STATUS;
                            }
                            SafeUIRunner.asyncExec(new SafeRunnable() {
                                public void run() throws Exception {
                                    for (Context context : contexts) {
                                        if (!context.isActivated) {
                                            continue;
                                        }
                                        // Initialise and finalise
                                        if (counter[0] == 0) {
                                            originalColourMap.put(context.label, context.label.getBackground());
                                        } else if (counter[0] >= 5) {
                                            context.label.setBackground(originalColourMap.get(context.label));
                                        }
                                        // Blinking
                                        if (counter[0] % 2 == 0) {
                                            context.label.setBackground(null);
                                        } else {
                                            context.label.setBackground(originalColourMap.get(context.label));
                                        }
                                    }
                                    counter[0]++;
                                }
                            });
                            // Repeat every 0.5 sec
                            schedule(500);
                            return Status.OK_STATUS;
                        }
                    };
                    // Run now
                    job.schedule();
                }
            }

        }
    };
}

From source file:au.gov.ansto.bragg.nbi.ui.widgets.ShutterStatusWidget.java

License:Open Source License

protected void disableWidget() {
    if (contexts == null) {
        return;/*from  ww  w . ja  v a  2  s.  c o  m*/
    }
    if (eventHandler != null) {
        eventHandler.deactivate();
    }
    SafeUIRunner.asyncExec(new SafeRunnable() {
        @Override
        public void run() throws Exception {
            for (final Context context : contexts) {
                // Set label text
                StringBuilder builder = new StringBuilder();
                if (context.path.endsWith("secondary")) {
                    builder.append("Secondary\n");
                } else if (context.path.endsWith("tertiary")) {
                    builder.append("Sample\n");
                }
                builder.append("--");
                context.label.setText(builder.toString());
                context.label.setBackground(null);
                context.label.setForeground(context.originalForeground);
                context.isActivated = false;
            }
        }
    });
}

From source file:au.gov.ansto.bragg.nbi.ui.widgets.ShutterStatusWidget.java

License:Open Source License

private void updateLabel(final Context context, final String data) {
    SafeUIRunner.asyncExec(new SafeRunnable() {
        public void run() throws Exception {
            if (isDisposed()) {
                return;
            }// w  w w . j  av a 2 s .  co  m
            // Set label text
            StringBuilder builder = new StringBuilder();
            if (context.path.endsWith("secondary")) {
                builder.append("Secondary\n");
            } else if (context.path.endsWith("tertiary")) {
                builder.append("Sample\n");
            }
            builder.append(data);
            context.label.setText(builder.toString());
            // Set colour based on status
            if (data.equalsIgnoreCase("Opened") | data.equalsIgnoreCase("OPEN")) {
                context.label.setBackground(getDisplay().getSystemColor(SWT.COLOR_GREEN));
                context.label.setForeground(getDisplay().getSystemColor(SWT.COLOR_BLACK));
                context.isActivated = true;
            } else if (data.equalsIgnoreCase("Closed") | data.equalsIgnoreCase("CLOSE")) {
                context.label.setBackground(getDisplay().getSystemColor(SWT.COLOR_RED));
                context.label.setForeground(getDisplay().getSystemColor(SWT.COLOR_WHITE));
                context.isActivated = true;
            } else {
                context.label.setBackground(null);
                context.label.setForeground(context.originalForeground);
                context.isActivated = false;
            }
        }
    });
}