Java Code Examples for org.eclipse.core.runtime.SafeRunner#run()

The following examples show how to use org.eclipse.core.runtime.SafeRunner#run() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemoryEclipsePreferences.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
protected void firePreferenceEvent(String key, Object oldValue, Object newValue) {
    if (preferenceChangeListeners == null) {
        return;
    }
    final PreferenceChangeEvent event = new PreferenceChangeEvent(this, key, oldValue, newValue);
    for (final IPreferenceChangeListener listener : preferenceChangeListeners) {
        ISafeRunnable job = new ISafeRunnable() {
            @Override
            public void handleException(Throwable exception) {
                // already logged in Platform#run()
            }

            @Override
            public void run() throws Exception {
                listener.preferenceChange(event);
            }
        };
        SafeRunner.run(job);
    }
}
 
Example 2
Source File: SVNProviderPlugin.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method is called by SyncFileChangeListener when metafiles have
 * changed
 */
public static void broadcastSyncInfoChanges(final IResource[] resources, final boolean initializeListeners) {
	IResourceStateChangeListener[] toNotify;
	synchronized(listeners) {
		toNotify = (IResourceStateChangeListener[])listeners.toArray(new IResourceStateChangeListener[listeners.size()]);
	}

	for (int i = 0; i < toNotify.length; ++i) {
		final IResourceStateChangeListener listener = toNotify[i];
		ISafeRunnable code = new ISafeRunnable() {
			public void run() throws Exception {
				if (initializeListeners) listener.initialize();
				listener.resourceSyncInfoChanged(resources);
			}
			public void handleException(Throwable e) {
				// don't log the exception....it is already being logged in
				// Platform#run
			}
		};
		SafeRunner.run(code);
	}
}
 
Example 3
Source File: SimpleMatcherFactory.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 加载记忆库匹配实现 ;
 */
private void runExtension() {
	IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
	try {
		for (IConfigurationElement e : config) {
			final Object o = e.createExecutableExtension("class");
			if (o instanceof ISimpleMatcher) {
				ISafeRunnable runnable = new ISafeRunnable() {

					public void handleException(Throwable exception) {
						logger.error(Messages.getString("simpleMatch.SimpleMatcherFactory.logger1"), exception);
					}

					public void run() throws Exception {
						ISimpleMatcher simpleMatcher = (ISimpleMatcher) o;							
						matchers.add(simpleMatcher);
					}
				};
				SafeRunner.run(runnable);
			}
		}
	} catch (CoreException ex) {
		logger.error(Messages.getString("simpleMatch.SimpleMatcherFactory.logger1"), ex);
	}
}
 
Example 4
Source File: SVNProviderPlugin.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method is called by SVNTeamProvider.deconfigured which is invoked
 * after a provider has been unmaped
 */
protected static void broadcastProjectDeconfigured(final IProject project) {
	IResourceStateChangeListener[] toNotify;
	synchronized(listeners) {
		toNotify = (IResourceStateChangeListener[])listeners.toArray(new IResourceStateChangeListener[listeners.size()]);
	}

	for (int i = 0; i < toNotify.length; ++i) {
		final IResourceStateChangeListener listener = toNotify[i];
		ISafeRunnable code = new ISafeRunnable() {
			public void run() throws Exception {
				listener.projectDeconfigured(project);
			}
			public void handleException(Throwable e) {
				// don't log the exception....it is already being logged in
				// Platform#run
			}
		};
		SafeRunner.run(code);
	}
}
 
Example 5
Source File: DynamicValidationStateChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void workspaceChanged() {
	long currentTime= System.currentTimeMillis();
	if (currentTime - fTimeStamp < LIFE_TIME)
		return;
	fValidationState= RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.DynamicValidationStateChange_workspace_changed);
	// remove listener from workspace tracker
	WorkspaceTracker.INSTANCE.removeListener(this);
	fListenerRegistered= false;
	// clear up the children to not hang onto too much memory
	Change[] children= clear();
	for (int i= 0; i < children.length; i++) {
		final Change change= children[i];
		SafeRunner.run(new ISafeRunnable() {
			public void run() throws Exception {
				change.dispose();
			}
			public void handleException(Throwable exception) {
				JavaPlugin.log(exception);
			}
		});
	}
}
 
Example 6
Source File: CloseResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tries to find opened editors matching given resource roots. The editors will be closed without confirmation and
 * only if the editor resource does not exists anymore.
 *
 * @param resourceRoots
 *            non null array with deleted resource tree roots
 * @param deletedOnly
 *            true to close only editors on resources which do not exist
 */
static void closeMatchingEditors(final List<? extends IResource> resourceRoots, final boolean deletedOnly) {
	if (resourceRoots.isEmpty()) { return; }
	final Runnable runnable = () -> SafeRunner.run(new SafeRunnable(IDEWorkbenchMessages.ErrorOnCloseEditors) {
		@Override
		public void run() {
			final IWorkbenchWindow w = getActiveWindow();
			if (w != null) {
				final List<IEditorReference> toClose = getMatchingEditors(resourceRoots, w, deletedOnly);
				if (toClose.isEmpty()) { return; }
				closeEditors(toClose, w);
			}
		}
	});
	BusyIndicator.showWhile(PlatformUI.getWorkbench().getDisplay(), runnable);
}
 
Example 7
Source File: DisplayBlinkServiceImpl.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void processTick ()
{
    this.scheduled = false;

    this.globalCounter++;
    for ( final BlinkCallback tc : this.callbacks )
    {
        SafeRunner.run ( new SafeRunnable () {

            @Override
            public void run () throws Exception
            {
                tc.toggle ( DisplayBlinkServiceImpl.this.globalCounter );
            }
        } );
    }

    schedule ();
}
 
Example 8
Source File: TmImporter.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 加载记忆库匹配实现 ;
 */
private void runExtension() {
	IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(
			TMIMPORTER_EXTENSION_ID);
	try {
		for (IConfigurationElement e : config) {
			final Object o = e.createExecutableExtension("class");
			if (o instanceof ITmImporter) {
				ISafeRunnable runnable = new ISafeRunnable() {

					public void handleException(Throwable exception) {
						logger.error(Messages.getString("importer.TmImporter.logger1"), exception);
					}

					public void run() throws Exception {
						tmImporter = (ITmImporter) o;
					}
				};
				SafeRunner.run(runnable);
			}
		}
	} catch (CoreException ex) {
		logger.error(Messages.getString("importer.TmImporter.logger1"), ex);
	}
}
 
Example 9
Source File: CasEditorViewPage.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Selection changed.
 *
 * @param event the event
 */
public void selectionChanged(final SelectionChangedEvent event) {
  
  for (Object listener : selectionChangedListeners.getListeners()) {
    
    final ISelectionChangedListener selectionChangedListener = 
            (ISelectionChangedListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        selectionChangedListener.selectionChanged(event);
      }
    });
  }
}
 
Example 10
Source File: TbImporter.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 加载记忆库匹配实现 ;
 */
private void runExtension() {
	IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(
			TERMIMPORT_EXTENSION_ID);
	try {
		for (IConfigurationElement e : config) {
			final Object o = e.createExecutableExtension("class");
			if (o instanceof ITbImporter) {
				ISafeRunnable runnable = new ISafeRunnable() {

					public void handleException(Throwable exception) {
						logger.error(Messages.getString("importer.TbImporter.logger1"), exception);
					}

					public void run() throws Exception {
						tbImporter = (ITbImporter) o;
					}
				};
				SafeRunner.run(runnable);
			}
		}
	} catch (CoreException ex) {
		logger.error(Messages.getString("importer.TbImporter.logger1"), ex);
	}
}
 
Example 11
Source File: InterpreterInfo.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Collection<String> getAdditionalLibraries() {
    final Collection<String> additions = new ArrayList<String>();
    for (final IInterpreterNewCustomEntries newEntriesProvider : fParticipants) {
        SafeRunner.run(() -> {
            additions.addAll(newEntriesProvider.getAdditionalLibraries());
        });
    }
    return additions;
}
 
Example 12
Source File: EvaluateExtentionHandler.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
private void executeExtension(final Object o) {
	ISafeRunnable runnable = new ISafeRunnable() {
		@Override
		public void handleException(Throwable e) {
			log.error("Error in the " + ExtentionPoint_ID, e);
		}

		@Override
		public void run() throws Exception {
			setType(((IResourceManager) o).getIDeveloperStudioResourceProviders(true));
		}
	};
	SafeRunner.run(runnable);
}
 
Example 13
Source File: XmlUtils.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private static synchronized @NonNull List<@NonNull URL> getUrlsFromConfiguration(String extensionName, String elementName, String attribName) {
    /* Get the XSD files advertised through the extension point */
    IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(extensionName);
    List<@NonNull URL> list = new ArrayList<>();
    for (IConfigurationElement element : elements) {
        if (element.getName().equals(elementName)) {
            final String filename = element.getAttribute(attribName);
            final String name = element.getContributor().getName();
            // Run this in a safe runner in case there is an exception
            // (IOException, FileNotFoundException, NPE, etc).
            // This makes sure other extensions are not prevented from
            // working if one is faulty.
            SafeRunner.run(new ISafeRunnable() {

                @Override
                public void run() throws IOException {
                    if (name != null) {
                        Bundle bundle = Platform.getBundle(name);
                        if (bundle != null) {
                            URL xmlUrl = bundle.getResource(filename);
                            if (xmlUrl == null) {
                                throw new FileNotFoundException(filename);
                            }
                            URL locatedURL = FileLocator.toFileURL(xmlUrl);
                            list.add(NonNullUtils.checkNotNull(locatedURL));
                        }
                    }
                }

                @Override
                public void handleException(Throwable exception) {
                    // Handled sufficiently in SafeRunner
                }
            });
        }
    }
    return list;
}
 
Example 14
Source File: JavaUILabelProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Fires a label provider changed event to all registered listeners
 * Only listeners registered at the time this method is called are notified.
 *
 * @param event a label provider changed event
 *
 * @see ILabelProviderListener#labelProviderChanged
 */
protected void fireLabelProviderChanged(final LabelProviderChangedEvent event) {
    Object[] listeners = fListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final ILabelProviderListener l = (ILabelProviderListener) listeners[i];
        SafeRunner.run(new SafeRunnable() {
            public void run() {
                l.labelProviderChanged(event);
            }
        });
    }
}
 
Example 15
Source File: ProblemManager.java    From typescript.java with MIT License 5 votes vote down vote up
private void notifyListeners(Set<IResource> changedResources) {
	for (IProblemChangeListener listener : listeners) {
		SafeRunner.run(new ISafeRunnable() {
			@Override
			public void run() throws Exception {
				listener.problemsChanged(changedResources);
			}

			@Override
			public void handleException(Throwable exception) {
				// logged by SafeRunner
			}
		});
	}
}
 
Example 16
Source File: SelectionProviderAdapter.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 设置被选中对象,并用安全线程通知监听器。
 * @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);
			}
		});
	}
}
 
Example 17
Source File: AbstractDocument.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Sends an added message to registered listeners.
 *
 * @param annotation the annotation
 */
protected void fireAddedFeatureStructure(final FeatureStructure annotation) {
  
  for (Object listener : mListener.getListeners()) {
    final ICasDocumentListener documentListener = (ICasDocumentListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        documentListener.added(annotation);
      }
    });
  }
}
 
Example 18
Source File: AbstractDocument.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Fire view changed.
 *
 * @param oldViewName the old view name
 * @param newViewName the new view name
 */
protected void fireViewChanged(final String oldViewName, final String newViewName) {
  for (Object listener : mListener.getListeners()) {
    
    final ICasDocumentListener documentListener = (ICasDocumentListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        documentListener.viewChanged(oldViewName, newViewName);
      }
    });
  }
}
 
Example 19
Source File: ContributedCleanUpTabPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String getPreview() {
	final String[] result= new String[] { "" }; //$NON-NLS-1$
	SafeRunner.run(new ISafeRunnable() {
		public void handleException(Throwable exception) {
			ContributedCleanUpTabPage.this.handleException(exception);
		}

		public void run() throws Exception {
			result[0]= fContribution.getPreview();
		}
	});
	return result[0];
}
 
Example 20
Source File: KeyInstanceManager.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void fireUpdate ( final KeyInformation key, final Date validUntil )
{
    for ( final StatusListener listener : this.statusListeners )
    {
        SafeRunner.run ( new SafeRunnable () {

            @Override
            public void run () throws Exception
            {
                listener.defaultKeyChanged ( key, validUntil );
            }
        } );
    }
}