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

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

Introduction

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

Prototype

public static void run(ISafeRunnable runnable) 

Source Link

Document

Runs the given safe runnable using the safe runnable runner.

Usage

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
 *//*www.j  av  a  2  s.  c  o m*/
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.ga.earthsci.common.ui.preferences.LazyPreferenceDialog.java

License:Apache License

@Override
protected void okPressed() {
    SafeRunnable.run(new SafeRunnable() {
        private boolean errorOccurred;

        /*//w  ww  .  j ava 2 s  .co  m
         * (non-Javadoc)
         * 
         * @see org.eclipse.core.runtime.ISafeRunnable#run()
         */
        @Override
        public void run() {
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            errorOccurred = false;
            boolean hasFailedOK = false;
            try {
                // Notify all the pages and give them a chance to abort
                Iterator<?> nodes = getPreferenceManager().getElements(PreferenceManager.PRE_ORDER).iterator();
                while (nodes.hasNext()) {
                    IPreferenceNode node = (IPreferenceNode) nodes.next();
                    IPreferencePage page = node.getPage();
                    if (page != null && pagesWithCreatedControls.contains(page)) {
                        if (!page.performOk()) {
                            hasFailedOK = true;
                            return;
                        }
                    }
                }
            } catch (Exception e) {
                handleException(e);
            } finally {
                //Don't bother closing if the OK failed
                if (hasFailedOK) {
                    setReturnCode(FAILED);
                    getButton(IDialogConstants.OK_ID).setEnabled(true);
                    return;
                }

                if (!errorOccurred) {
                    //Give subclasses the choice to save the state of the
                    //preference pages.
                    handleSave();
                }
                setReturnCode(OK);
                close();
            }
        }

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
         */
        @Override
        public void handleException(Throwable e) {
            errorOccurred = true;

            Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e));

            setSelectedNodePreference(null);
            String message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$

            Policy.getStatusHandler().show(new Status(IStatus.ERROR, Policy.JFACE, message, e),
                    JFaceResources.getString("Error")); //$NON-NLS-1$

        }
    });

    if (getReturnCode() == FAILED) {
        return;
    }

    if (workingCopyManager != null) {
        try {
            workingCopyManager.applyChanges();
        } catch (BackingStoreException e) {
            String msg = e.getMessage();
            if (msg == null) {
                msg = WorkbenchMessages.FilteredPreferenceDialog_PreferenceSaveFailed;
            }
            StatusUtil.handleStatus(WorkbenchMessages.PreferencesExportDialog_ErrorDialogTitle + ": " + msg, e, //$NON-NLS-1$
                    StatusManager.SHOW, getShell());
        }
    }

    // Run the update jobs
    Iterator<Job> updateIterator = updateJobs.iterator();
    while (updateIterator.hasNext()) {
        updateIterator.next().schedule();
    }
}

From source file:au.gov.ga.earthsci.common.ui.preferences.LazyPreferenceDialog.java

License:Apache License

@Override
protected void cancelPressed() {
    // Inform all pages that we are cancelling
    Iterator<?> nodes = getPreferenceManager().getElements(PreferenceManager.PRE_ORDER).iterator();
    final boolean[] cancelOK = new boolean[] { true };
    while (nodes.hasNext()) {
        final IPreferenceNode node = (IPreferenceNode) nodes.next();
        final IPreferencePage page = getPage(node);
        if (page != null && pagesWithCreatedControls.contains(page)) {
            SafeRunnable.run(new SafeRunnable() {
                @Override//  www .  j a  v  a2  s. com
                public void run() {
                    if (!page.performCancel()) {
                        cancelOK[0] = false;
                    }
                }
            });
            if (!cancelOK[0]) {
                return;
            }
        }
    }

    // Give subclasses the choice to save the state of the preference pages if needed
    handleSave();

    setReturnCode(CANCEL);
    close();
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.LayoutCanvasViewer.java

License:Open Source License

protected void firePostSelectionChanged(final SelectionChangedEvent event) {
    Object[] listeners = mPostChangedListeners.getListeners();
    for (int i = 0; i < listeners.length; i++) {
        final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {
            @Override//from www  .j  ava 2s.c  o  m
            public void run() {
                l.selectionChanged(event);
            }
        });
    }
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.SelectionManager.java

License:Open Source License

/**
 * Notifies listeners that the selection has changed.
 *//*from  www .  ja  v a 2  s . co m*/
private void fireSelectionChanged() {
    if (mInsideUpdateSelection) {
        return;
    }
    try {
        mInsideUpdateSelection = true;

        final SelectionChangedEvent event = new SelectionChangedEvent(this, getSelection());

        SafeRunnable.run(new SafeRunnable() {
            @Override
            public void run() {
                for (Object listener : mSelectionListeners.getListeners()) {
                    ((ISelectionChangedListener) listener).selectionChanged(event);
                }
            }
        });

        updateActionsFromSelection();
    } finally {
        mInsideUpdateSelection = false;
    }
}

From source file:com.aptana.ide.editors.unified.UnifiedEditor.java

License:Open Source License

/**
 * Updates the file service listeners with the new service
 *//*from w w w. jav  a2 s. c  om*/
private void fireNewFileServiceEvent() {
    if (this._fileContextWrapper != null && this._fileContextWrapper.getFileContext() != null) {
        final IFileService newService = this._fileContextWrapper.getFileContext();
        // Notify file service listeners
        Object[] listeners = fileServiceChangeListeners.getListeners();
        for (int i = 0; i < listeners.length; ++i) {
            final IFileServiceChangeListener l = (IFileServiceChangeListener) listeners[i];
            SafeRunnable.run(new SafeRunnable() {
                public void run() {
                    l.fileServiceChanged(newService);
                }
            });
        }
    }
}

From source file:com.aptana.ide.server.ui.decorators.StartPageDecorator.java

License:Open Source License

/**
 * Fires a label provider changed event to all registered listeners Only listeners registered at the time this
 * method is called are notified./*from   ww w  .  j  av  a 2 s.c  o m*/
 * 
 * @param event
 *            a label provider changed event
 * @see ILabelProviderListener#labelProviderChanged
 */
protected void fireLabelProviderChanged(final LabelProviderChangedEvent event) {
    Object[] listeners = this.listeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final ILabelProviderListener l = (ILabelProviderListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {
            public void run() {
                l.labelProviderChanged(event);
            }
        });

    }
}

From source file:com.codesourcery.internal.installer.ui.WizardDialog.java

License:Open Source License

/**
 * Notifies any selection changed listeners that the selected page has
 * changed. Only listeners registered at the time this method is called are
 * notified./*  w w  w  . j a  v  a2 s  .c om*/
 * 
 * @param event
 *            a selection changed event
 * 
 * @see IPageChangedListener#pageChanged
 * 
 * @since 3.1
 */
protected void firePageChanged(final PageChangedEvent event) {
    Object[] listeners = pageChangedListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final IPageChangedListener l = (IPageChangedListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {
            public void run() {
                l.pageChanged(event);
            }
        });
    }
}

From source file:com.codesourcery.internal.installer.ui.WizardDialog.java

License:Open Source License

/**
 * Notifies any page changing listeners that the currently selected dialog
 * page is changing. Only listeners registered at the time this method is
 * called are notified.//from   w  ww  .jav a2  s  .  c  o  m
 * 
 * @param event
 *            a selection changing event
 * 
 * @see IPageChangingListener#handlePageChanging(PageChangingEvent)
 * @since 3.3
 */
protected void firePageChanging(final PageChangingEvent event) {
    Object[] listeners = pageChangingListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final IPageChangingListener l = (IPageChangingListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {
            public void run() {
                l.handlePageChanging(event);
            }
        });
    }
}

From source file:com.github.jennybrown8.wicketsourceopener.preferences.SecurePreferenceStore.java

License:GNU General Public License

@Override
public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) {
    final Object[] finalListeners = getListeners();
    // Do we need to fire an event.
    if (finalListeners.length > 0 && (oldValue == null || !oldValue.equals(newValue))) {
        final PropertyChangeEvent pe = new PropertyChangeEvent(this, name, oldValue, newValue);
        for (int i = 0; i < finalListeners.length; ++i) {
            final IPropertyChangeListener l = (IPropertyChangeListener) finalListeners[i];
            SafeRunnable.run(new SafeRunnable(JFaceResources.getString("PreferenceStore.changeError")) { //$NON-NLS-1$
                public void run() {
                    l.propertyChange(pe);
                }// w w  w .  ja v  a 2 s  . com
            });
        }
    }
}