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);
}
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);
}
});
}
}
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);
}
});
}
}
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];
}
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;
}
Aggregations