/** * Execute extension. * @param object the object instance found */ private void executeExtension(final Object object) { ISafeRunnable runnable = new ISafeRunnable() { @Override public void handleException(Throwable e) { System.out.println("Exception in client"); } @Override public void run() throws Exception { System.err.println(object.toString()); } }; SafeRunner.run(runnable); }
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 (); }
@Override protected void fireValueChanged ( final String property, final Object oldValue, final Object newValue ) { if ( VALUE.equals ( property ) ) { if ( this.callback != null ) { SafeRunner.run ( new SafeRunnable () { @Override public void run () throws Exception { ComboFieldEditor2.this.callback.valueChange ( newValue ); } } ); } } super.fireValueChanged ( property, oldValue, newValue ); }
/** * Fire visibility change * <p> * The change will only be fired if the state really changed. * </p> * * @param state * the new state */ protected void fireChange ( final boolean state ) { if ( this.state == state ) { return; } this.state = state; for ( final Listener listener : this.listeners ) { SafeRunner.run ( new SafeRunnable () { @Override public void run () throws Exception { listener.visibilityChanged ( state ); } } ); } }
/** * <p> * Restores the code folding state from a XML file in the state location. * </p> * * @param uriString the key to determine the file to load the state from */ public void restoreCodeFoldingStateFromFile(String uriString) { final File stateFile = getCodeFoldingStateFile(uriString); if (stateFile == null || !stateFile.exists()) { calculatePositions(); return; } SafeRunner.run(new SafeRunnable("Unable to read code folding state. The state will be reset.") { public void run() throws Exception { FileInputStream input = new FileInputStream(stateFile); BufferedReader reader = new BufferedReader(new InputStreamReader(input, "utf-8")); IMemento memento = XMLMemento.createReadRoot(reader); reader.close(); String sourceText = sourceViewer.getDocument().get(); if (memento.getString(VERIFY_KEY).equals(makeMD5(sourceText))) { restoreCodeFolding(memento); } else { calculatePositions(); } } }); }
/** * 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); } }
/** * This method is called by FileModificationManager when some resources have * changed */ public static void broadcastModificationStateChanges( final IResource[] resources) { 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.resourceModified(resources); } public void handleException(Throwable e) { // don't log the exception....it is already being logged in // Platform#run } }; SafeRunner.run(code); } }
/** * This method is called by SVNTeamProvider.configureProject which is * invoked when a project is mapped */ protected static void broadcastProjectConfigured(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.projectConfigured(project); } public void handleException(Throwable e) { // don't log the exception....it is already being logged in // Platform#run } }; SafeRunner.run(code); } }
/** * 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); } }
private void preferencesChanged(Preferences oldPreferences, Preferences newPreferences) { for (final IPreferencesChangeListener listener : preferencesChangeListeners) { ISafeRunnable job = new ISafeRunnable() { @Override public void handleException(Throwable e) { JavaLanguageServerPlugin.log(new CoreException(StatusFactory.newErrorStatus(e.getMessage(), e))); } @Override public void run() throws Exception { listener.preferencesChange(oldPreferences, newPreferences); } }; SafeRunner.run(job); } }
private String getBundleExtensionResult() { IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSIONPOINT_ID); assertEquals("Expect one extension point", 1, elements.length); final String[] resultValues = new String[] { "" }; for (IConfigurationElement e : elements) { if ("java".equals(e.getAttribute("type"))) { SafeRunner.run(new ISafeRunnable() { @Override public void run() throws Exception { final Object extInstance = e.createExecutableExtension("class"); resultValues[0] = extInstance.toString(); } @Override public void handleException(Throwable ex) { IStatus status = new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, IStatus.OK, "Error in JDT Core during launching debug server", ex); //$NON-NLS-1$ JavaLanguageServerPlugin.log(status); } }); } } return resultValues[0]; }
private void fireMappingAdded(BookmarkId bookmarkFolderId) { Object[] listeners = listenerList.getListeners(); for (int i = 0; i < listeners.length; i++) { final IBookmarkMappingsListener listener = (IBookmarkMappingsListener) listeners[i]; SafeRunner.run(new ISafeRunnable() { public void run() throws Exception { listener.mappingAdded(bookmarkFolderId); } public void handleException(Throwable exception) { StatusHelper.logError("Error when mapping added", exception); } }); } }
@Override 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() { @Override public void run() { l.selectionChanged(e); } }); } }
protected void fire() { IElementChangedListener[] listeners; synchronized (elementChangedListeners) { listeners = new IElementChangedListener[elementChangedListeners.size()]; elementChangedListeners.toArray(listeners); } int offset = editor.getCursorOffset(); IElement part = partAtOffset(offset); final ElementChangedEvent event = new ElementChangedEvent(this, part, ElementChangedEvent.POST_CHANGE); for (IElementChangedListener listener : listeners) { SafeRunner.run(new ISafeRunnable() { @Override public void run() throws Exception { listener.elementChanged(event); } @Override public void handleException(Throwable exception) { Log.error("Exception during change notification", exception); } }); } }
public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) { // important: create intermediate array to protect against listeners // being added/removed during the notification final Object[] list = getListeners(); if (list.length == 0) { return; } final PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue); for (int i = 0; i < list.length; i++) { final IPropertyChangeListener listener = (IPropertyChangeListener) list[i]; SafeRunner.run(new SafeRunnable(JFaceResources .getString("PreferenceStore.changeError")) { //$NON-NLS-1$ public void run() { listener.propertyChange(event); } }); } }
@Override public void firePropertyChangeEvent(String name, Object oldValue, Object newValue) { // important: create intermediate array to protect against listeners // being added/removed during the notification final Object[] list = getListeners(); if (list.length == 0) { return; } final PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue); for (int i = 0; i < list.length; i++) { final IPropertyChangeListener listener = (IPropertyChangeListener) list[i]; SafeRunner.run(new SafeRunnable(JFaceResources .getString("PreferenceStore.changeError")) { //$NON-NLS-1$ @Override public void run() { listener.propertyChange(event); } }); } }
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); } }); } }
private void notifyTypeHierarchies(IElementChangedListener[] listeners, int listenerCount) { for (int i = 0; i < listenerCount; i++) { final IElementChangedListener listener = listeners[i]; if (!(listener instanceof TypeHierarchy)) continue; // wrap callbacks with Safe runnable for subsequent listeners to be called when some are // causing grief SafeRunner.run( new ISafeRunnable() { public void handleException(Throwable exception) { Util.log( exception, "Exception occurred in listener of Java element change notification"); // $NON-NLS-1$ } public void run() throws Exception { TypeHierarchy typeHierarchy = (TypeHierarchy) listener; if (typeHierarchy.hasFineGrainChanges()) { // case of changes in primary working copies typeHierarchy.needsRefresh = true; typeHierarchy.fireChange(); } } }); } }
private void fireAboutToPerformChange(final Change change) { if (fListeners == null) return; Object[] listeners = fListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final IUndoManagerListener listener = (IUndoManagerListener) listeners[i]; SafeRunner.run( new ISafeRunnable() { public void run() throws Exception { listener.aboutToPerformChange(UndoManager2.this, change); } public void handleException(Throwable exception) { RefactoringCorePlugin.log(exception); } }); } }
private void fireChangePerformed(final Change change) { if (fListeners == null) return; Object[] listeners = fListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final IUndoManagerListener listener = (IUndoManagerListener) listeners[i]; SafeRunner.run( new ISafeRunnable() { public void run() throws Exception { listener.changePerformed(UndoManager2.this, change); } public void handleException(Throwable exception) { RefactoringCorePlugin.log(exception); } }); } }
private void fireUndoStackChanged() { if (fListeners == null) return; Object[] listeners = fListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final IUndoManagerListener listener = (IUndoManagerListener) listeners[i]; SafeRunner.run( new ISafeRunnable() { public void run() throws Exception { listener.undoStackChanged(UndoManager2.this); } public void handleException(Throwable exception) { RefactoringCorePlugin.log(exception); } }); } }
private void fireRedoStackChanged() { if (fListeners == null) return; Object[] listeners = fListeners.getListeners(); for (int i = 0; i < listeners.length; i++) { final IUndoManagerListener listener = (IUndoManagerListener) listeners[i]; SafeRunner.run( new ISafeRunnable() { public void run() throws Exception { listener.redoStackChanged(UndoManager2.this); } public void handleException(Throwable exception) { RefactoringCorePlugin.log(exception); } }); } }
private void fireRefactoringExecutionEvent( final RefactoringDescriptorProxy proxy, final int eventType) { Assert.isNotNull(proxy); final Object[] listeners = fExecutionListeners.getListeners(); for (int index = 0; index < listeners.length; index++) { final IRefactoringExecutionListener listener = (IRefactoringExecutionListener) listeners[index]; SafeRunner.run( new ISafeRunnable() { public void handleException(final Throwable throwable) { RefactoringCorePlugin.log(throwable); } public void run() throws Exception { listener.executionNotification( new RefactoringExecutionEvent(RefactoringHistoryService.this, eventType, proxy)); } }); } }
private void fireRefactoringHistoryEvent( final RefactoringDescriptorProxy proxy, final int eventType) { Assert.isNotNull(proxy); final Object[] listeners = fHistoryListeners.getListeners(); for (int index = 0; index < listeners.length; index++) { final IRefactoringHistoryListener listener = (IRefactoringHistoryListener) listeners[index]; SafeRunner.run( new ISafeRunnable() { public void handleException(final Throwable throwable) { RefactoringCorePlugin.log(throwable); } public void run() throws Exception { listener.historyNotification( new RefactoringHistoryEvent(RefactoringHistoryService.this, eventType, proxy)); } }); } }
/** * {@inheritDoc} * * <p>The composite change sends <code>dispose</code> to all its children. It is guaranteed that * all children receive the <code>dispose</code> call. */ public void dispose() { for (Iterator iter = fChanges.iterator(); iter.hasNext(); ) { final Change change = (Change) iter.next(); SafeRunner.run( new ISafeRunnable() { public void run() throws Exception { change.dispose(); } public void handleException(Throwable exception) { RefactoringCorePlugin.log(exception); } }); } }
private void invokeExportMarshaller(final ExportMarshaller exportMarshaller, final Diagram diagram, final IProgressMonitor monitor) { ISafeRunnable runnable = new ISafeRunnable() { @Override public void handleException(Throwable exception) { System.out.println("An exception occurred while running ExportMarshaller " + exportMarshaller.getMarshallerName() + ": " + exception.getMessage()); } @Override public void run() throws Exception { exportMarshaller.marshallDiagram(diagram, monitor); } }; SafeRunner.run(runnable); }
private static void executeExtension(final Object o) { ISafeRunnable runnable = new ISafeRunnable() { @Override public void handleException(Throwable e) { //TODO logging // System.out.println("Exception in extension"); } @Override public void run() throws Exception { ISuggestionProvider provider = ((ISuggestionProvider) o); SuggestionProviderUtils.addSuggestionProvider(provider); } }; SafeRunner.run(runnable); }
/** * Disposes the given part and its site. * * @param part * The part to dispose; must not be <code>null</code>. */ private void disposePart(final IWorkbenchPart part) { SafeRunner.run(new ISafeRunnable() { public void run() { IWorkbenchPartSite partSite = part.getSite(); part.dispose(); if (partSite instanceof MultiPageToolbarEditorSite) { ((MultiPageToolbarEditorSite) partSite).dispose(); } } public void handleException(Throwable e) { // Exception has already being logged by Core. Do nothing. } }); }
/** * 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); }
/** * Notify a status change to the registered listeners. * * @param oldStatus * @param newStatus */ private void notifyChange(final IStatus oldStatus, final IStatus newStatus) { IStatusCollectorListener[] notifyTo = listeners.toArray(new IStatusCollectorListener[listeners.size()]); for (final IStatusCollectorListener listener : notifyTo) { SafeRunner.run(new ISafeRunnable() { public void run() throws Exception { listener.statusChanged(oldStatus, newStatus); } public void handleException(Throwable exception) { IdeLog.logError(CorePlugin.getDefault(), "StatusCollector: Error while notifying a staus change event.", exception); //$NON-NLS-1$ } }); } }
private void notifyListeners(Kind kind, IServer serverConfiguration) { final ServerChangeEvent event = new ServerChangeEvent(kind, serverConfiguration); for (Object i : listeners.getListeners()) { final IServerChangeListener listener = (IServerChangeListener) i; SafeRunner.run(new ISafeRunnable() { public void run() { listener.configurationChanged(event); } public void handleException(Throwable exception) { IdeLog.logError(WebServerCorePlugin.getDefault(), exception); } }); } }