Search in sources :

Example 1 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable in project translationstudio8 by heartsome.

the class KeyController2 method exportCSV.

public void exportCSV(Shell shell) {
    final FileDialog fileDialog = new FileDialog(shell, SWT.SAVE | SWT.SHEET);
    //$NON-NLS-1$
    fileDialog.setFilterExtensions(new String[] { "*.csv" });
    //$NON-NLS-1$
    fileDialog.setFilterNames(new String[] { Util.translateString(RESOURCE_BUNDLE, "csvFilterName") });
    fileDialog.setOverwrite(true);
    final String filePath = fileDialog.open();
    if (filePath == null) {
        return;
    }
    final SafeRunnable runnable = new SafeRunnable() {

        public final void run() throws IOException {
            Writer fileWriter = null;
            try {
                //$NON-NLS-1$
                fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath), "UTF-8"));
                final Object[] bindingElements = bindingModel.getBindings().toArray();
                for (int i = 0; i < bindingElements.length; i++) {
                    final BindingElement be = (BindingElement) bindingElements[i];
                    if (be.getTrigger() == null || be.getTrigger().isEmpty() || be.getContext() == null || be.getContext().getName() == null) {
                        continue;
                    }
                    StringBuffer buffer = new StringBuffer();
                    buffer.append(ESCAPED_QUOTE + Util.replaceAll(be.getCategory(), ESCAPED_QUOTE, REPLACEMENT) + ESCAPED_QUOTE + DELIMITER);
                    buffer.append(ESCAPED_QUOTE + be.getName() + ESCAPED_QUOTE + DELIMITER);
                    buffer.append(ESCAPED_QUOTE + be.getTrigger().format() + ESCAPED_QUOTE + DELIMITER);
                    buffer.append(ESCAPED_QUOTE + be.getContext().getName() + ESCAPED_QUOTE);
                    //$NON-NLS-1$
                    buffer.append(System.getProperty("line.separator"));
                    fileWriter.write(buffer.toString());
                }
            } finally {
                if (fileWriter != null) {
                    try {
                        fileWriter.close();
                    } catch (final IOException e) {
                    // At least I tried.
                    }
                }
            }
        }
    };
    SafeRunner.run(runnable);
}
Also used : BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) SafeRunnable(org.eclipse.jface.util.SafeRunnable) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) FileDialog(org.eclipse.swt.widgets.FileDialog) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) BufferedWriter(java.io.BufferedWriter)

Example 2 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable in project translationstudio8 by heartsome.

the class SelectionProviderAdapter method setSelection.

/**
	 * 设置被选中对象,并用安全线程通知监听器。
	 * @param selection
	 *            the selection
	 * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
	 */
public void setSelection(ISelection selection) {
    theSelection = selection;
    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);
            }
        });
    }
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SafeRunnable(org.eclipse.jface.util.SafeRunnable) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent)

Example 3 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable in project archi by archimatetool.

the class ComponentSelectionManager method fireSelectionEvent.

public void fireSelectionEvent(final Object source, final Object selection) {
    if (selection == null) {
        return;
    }
    Object[] listenersArray = listeners.toArray();
    for (int i = 0; i < listenersArray.length; i++) {
        final IComponentSelectionListener l = (IComponentSelectionListener) listenersArray[i];
        SafeRunner.run(new SafeRunnable() {

            public void run() {
                l.componentSelectionChanged(source, selection);
            }
        });
    }
}
Also used : SafeRunnable(org.eclipse.jface.util.SafeRunnable)

Example 4 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable in project eclipse.platform.text by eclipse.

the class TextSearchEngineRegistry method createFromExtension.

private TextSearchEngine createFromExtension(final String id) {
    final TextSearchEngine[] res = new TextSearchEngine[] { null };
    SafeRunnable safe = new SafeRunnable() {

        @Override
        public void run() throws Exception {
            IConfigurationElement[] extensions = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_POINT_ID);
            for (IConfigurationElement curr : extensions) {
                if (ENGINE_NODE_NAME.equals(curr.getName()) && id.equals(curr.getAttribute(ATTRIB_ID))) {
                    res[0] = (TextSearchEngine) curr.createExecutableExtension(ATTRIB_CLASS);
                    return;
                }
            }
        }

        @Override
        public void handleException(Throwable e) {
            SearchPlugin.log(e);
        }
    };
    SafeRunnable.run(safe);
    return res[0];
}
Also used : SafeRunnable(org.eclipse.jface.util.SafeRunnable) TextSearchEngine(org.eclipse.search.core.text.TextSearchEngine) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 5 with SafeRunnable

use of org.eclipse.jface.util.SafeRunnable in project eclipse.platform.text by eclipse.

the class SearchPageRegistry method getSearchResultPage.

private ISearchResultPage getSearchResultPage(final IConfigurationElement configElement, boolean create) {
    ISearchResultPage instance = fExtensionToInstance.get(configElement);
    if (instance == null && create) {
        final Object[] result = new Object[1];
        ISafeRunnable safeRunnable = new SafeRunnable(SearchMessages.SearchPageRegistry_error_creating_extensionpoint) {

            @Override
            public void run() throws Exception {
                // $NON-NLS-1$
                result[0] = configElement.createExecutableExtension("class");
            }

            @Override
            public void handleException(Throwable e) {
                // invalid contribution
                SearchPlugin.log(e);
            }
        };
        SafeRunner.run(safeRunnable);
        if (result[0] instanceof ISearchResultPage) {
            instance = (ISearchResultPage) result[0];
            instance.setID(configElement.getAttribute(ATTRIB_ID));
            fExtensionToInstance.put(configElement, instance);
        }
    }
    return instance;
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SafeRunnable(org.eclipse.jface.util.SafeRunnable) ISearchResultPage(org.eclipse.search.ui.ISearchResultPage) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable)

Aggregations

SafeRunnable (org.eclipse.jface.util.SafeRunnable)30 ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)6 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)5 Point (org.eclipse.swt.graphics.Point)5 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)4 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)3 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 DropTargetEvent (org.eclipse.swt.dnd.DropTargetEvent)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Control (org.eclipse.swt.widgets.Control)3 TableItem (org.eclipse.swt.widgets.TableItem)3 TreeItem (org.eclipse.swt.widgets.TreeItem)3 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)2 LocalSelectionTransfer (org.eclipse.jface.util.LocalSelectionTransfer)2 TransferDropTargetListener (org.eclipse.jface.util.TransferDropTargetListener)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 Transfer (org.eclipse.swt.dnd.Transfer)2 DragNodeCommand (org.eclipse.wst.xml.ui.internal.dnd.DragNodeCommand)2