org.eclipse.jface.util.SafeRunnable Java Examples

The following examples show how to use org.eclipse.jface.util.SafeRunnable. 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: 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 #2
Source File: LibraryExplorerViewPage.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Fires a selection changed event.
 * 
 * @param selection
 *            the new selection
 */
private void fireSelectionChanged( ISelection selection )
{
	final SelectionChangedEvent event = new SelectionChangedEvent( this,
			selection );

	// create an event
	// fire the event
	Object[] listeners = selectionChangedListeners.getListeners( );
	for ( int i = 0; i < listeners.length; ++i )
	{
		final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
		SafeRunner.run( new SafeRunnable( ) {

			public void run( )
			{
				l.selectionChanged( event );
			}
		} );
	}
}
 
Example #3
Source File: AbstractPropertyDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param event
 */
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 );
			}
		} );
	}
}
 
Example #4
Source File: PreferenceWrapper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public void firePreferenceChangeEvent( 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 PreferenceChangeEvent pe = new PreferenceChangeEvent( this,
				name,
				oldValue,
				newValue );
		for ( int i = 0; i < finalListeners.length; ++i )
		{
			final IPreferenceChangeListener l = (IPreferenceChangeListener) finalListeners[i];
			SafeRunnable.run( new SafeRunnable( JFaceResources.getString( "PreferenceStore.changeError" ) ) { //$NON-NLS-1$

				public void run( )
				{
					l.preferenceChange( pe );
				}
			} );
		}
	}
}
 
Example #5
Source File: ReportResourceSynchronizer.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected void notifyListeners( final IReportResourceChangeEvent event )
{
	log.log( Level.FINE, event.toString( ) );
	
	//Object[] list = listeners.getListeners( );
	List<IReportResourceChangeListener> list = listeners.get( event.getType( ) );
	if (list == null)
	{
		return;
	}

	for ( int i = 0; i < list.size( ); i++ )
	{
		final IReportResourceChangeListener rcl = list.get( i );

		SafeRunner.run( new SafeRunnable( ) {

			public void run( ) throws Exception
			{
				rcl.resourceChanged( event );
			}
		} );
	}

}
 
Example #6
Source File: TableLayout.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
void reselect( )
{
	final List list = new ArrayList( ( (StructuredSelection) getOwner( ).getViewer( )
			.getSelection( ) ).toList( ) );

	boolean hasCell = false;
	for ( int i = 0; i < list.size( ); i++ )
	{
		if ( list.get( i ) instanceof ITableLayoutCell
				|| list.get( i ) instanceof ITableLayoutOwner )
		{
			hasCell = true;
			break;
		}
	}
	if ( hasCell )
	{
		Platform.run( new SafeRunnable( ) {

			public void run( )
			{
				UIUtil.resetViewSelection( getOwner( ).getViewer( ), false );
			}
		} );
	}
}
 
Example #7
Source File: WizardBaseDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Notifies any selection changed listeners that the selected page has
 * changed. Only listeners registered at the time this method is called
 * are notified.
 * 
 * @param event
 *            a selection changed event
 * 
 * @see IPageChangedListener#pageChanged
 * 
 * @since 2.1
 */
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 );
			}
		} );
	}
}
 
Example #8
Source File: FilterDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates the filter descriptors.
 * @param elements the configuration elements
 * @return new filter descriptors
 */
private static FilterDescriptor[] createFilterDescriptors(IConfigurationElement[] elements) {
	List<FilterDescriptor> result= new ArrayList<FilterDescriptor>(5);
	Set<String> descIds= new HashSet<String>(5);
	for (int i= 0; i < elements.length; i++) {
		final IConfigurationElement element= elements[i];
		if (FILTER_TAG.equals(element.getName())) {

			final FilterDescriptor[] desc= new FilterDescriptor[1];
			SafeRunner.run(new SafeRunnable(FilterMessages.FilterDescriptor_filterDescriptionCreationError_message) {
				public void run() throws Exception {
					desc[0]= new FilterDescriptor(element);
				}
			});

			if (desc[0] != null && !descIds.contains(desc[0].getId())) {
				result.add(desc[0]);
				descIds.add(desc[0].getId());
			}
		}
	}
	return result.toArray(new FilterDescriptor[result.size()]);
}
 
Example #9
Source File: FilterDescriptor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new <code>ViewerFilter</code>.
 * This method is only valid for viewer filters.
 * @return a new <code>ViewerFilter</code>
 */
public ViewerFilter createViewerFilter() {
	if (!isCustomFilter())
		return null;

	final ViewerFilter[] result= new ViewerFilter[1];
	String message= Messages.format(FilterMessages.FilterDescriptor_filterCreationError_message, getId());
	ISafeRunnable code= new SafeRunnable(message) {
		/*
		 * @see org.eclipse.core.runtime.ISafeRunnable#run()
		 */
		public void run() throws Exception {
			result[0]= (ViewerFilter)fElement.createExecutableExtension(CLASS_ATTRIBUTE);
		}

	};
	SafeRunner.run(code);
	return result[0];
}
 
Example #10
Source File: ScopedPreferenceStore.java    From e4Preferences with Eclipse Public License 1.0 6 votes vote down vote up
@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[] listeners = getListeners();
	if (listeners.length == 0) {
		return;
	}
	final PropertyChangeEvent event = new PropertyChangeEvent(this, name, oldValue, newValue);
	for (Object listener : listeners) {
		final IPropertyChangeListener propertyChangeListener = (IPropertyChangeListener) listener;
		SafeRunner.run(new SafeRunnable(JFaceResources.getString("PreferenceStore.changeError")) { //$NON-NLS-1$
			@Override
			public void run() {
				propertyChangeListener.propertyChange(event);
			}
		});
	}
}
 
Example #11
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 #12
Source File: DeleteResourceAction.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 = WorkbenchHelper.getWindow();
			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 #13
Source File: AutoConfigMaker.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
private List<IInterpreterProvider> getAllProviders() {
    final List<IInterpreterProvider> providers = new ArrayList<IInterpreterProvider>();
    @SuppressWarnings("unchecked")
    List<IInterpreterProviderFactory> participants = ExtensionHelper
            .getParticipants(ExtensionHelper.PYDEV_INTERPRETER_PROVIDER);
    for (final IInterpreterProviderFactory providerFactory : participants) {
        SafeRunner.run(new SafeRunnable() {
            @Override
            public void run() throws Exception {
                IInterpreterProvider[] ips = providerFactory.getInterpreterProviders(interpreterType);
                if (ips != null) {
                    providers.addAll(Arrays.asList(ips));
                }
            }
        });
    }
    return providers;
}
 
Example #14
Source File: FixedScopedPreferenceStore.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@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);
					}
				});
	}
}
 
Example #15
Source File: AbstractVisibilityProvider.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 );
            }
        } );
    }
}
 
Example #16
Source File: ComboFieldEditor2.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
@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 );
}
 
Example #17
Source File: ChartRenderer.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
public void dispose ()
{
    checkWidget ();

    if ( this.disposed )
    {
        return;
    }

    this.disposed = true;

    for ( final DisposeListener listener : this.disposeListeners )
    {
        SafeRunnable.getRunner ().run ( new SafeRunnable () {
            @Override
            public void run () throws Exception
            {
                listener.onDispose ();
            };
        } );
    }

    this.resourceManager.dispose ();
}
 
Example #18
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 #19
Source File: TabContents.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * If controls have been created, refresh all sections on the page.
 */
public void refresh() {
    if (controlsCreated) {
        for (final ISection section : sections) {
            ISafeRunnable runnable = new SafeRunnable() {

                @Override
	public void run()
                    throws Exception {
                    section.refresh();
                }
            };
            SafeRunnable.run(runnable);
        }
    }
}
 
Example #20
Source File: CDateTimeSelectionProvider.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Notifies any selection changed listeners that the viewer's selection has changed.
 * Only listeners registered at the time this method is called are notified.
 *
 * @param event a selection changed event
 *
 * @see ISelectionChangedListener#selectionChanged
 */
private void fireSelectionChanged(final SelectionChangedEvent event) {
    Object[] listeners = selectionChangedListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
        SafeRunnable.run(new SafeRunnable() {
            public void run() {
                l.selectionChanged(event);
            }
        });
    }
}
 
Example #21
Source File: TabContents.java    From bonita-studio with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sends the lifecycle event to the page's sections.
 */
public void aboutToBeHidden() {
    for (final ISection section : sections) {
        ISafeRunnable runnable = new SafeRunnable() {

            @Override
public void run()
                throws Exception {
                section.aboutToBeHidden();
            }
        };
        SafeRunnable.run(runnable);
    }
}
 
Example #22
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 #23
Source File: AbstractDocument.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Fire changed.
 */
protected void fireChanged() {
  for (Object listener : mListener.getListeners()) {
    
    final ICasDocumentListener documentListener = (ICasDocumentListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        documentListener.changed();
      }
    });
  }
}
 
Example #24
Source File: AbstractDocument.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Sends an updated message to registered listeners.
 *
 * @param annotations the annotations
 */
protected void fireUpdatedFeatureStructure(final Collection<? extends FeatureStructure> annotations) {
  for (Object listener : mListener.getListeners()) {
    
    final ICasDocumentListener documentListener = (ICasDocumentListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        documentListener.updated(Collections.unmodifiableCollection(annotations));
      }
    });
  }
}
 
Example #25
Source File: AbstractDocument.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Sends an updated message to registered listeners.
 *
 * @param annotation the annotation
 */
protected void fireUpdatedFeatureStructure(final FeatureStructure annotation) {
  for (Object listener : mListener.getListeners()) {
    
    final ICasDocumentListener documentListener = (ICasDocumentListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        documentListener.updated(annotation);
      }
    });
  }
}
 
Example #26
Source File: AbstractDocument.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a removed message to registered listeners.
 *
 * @param annotations the annotations
 */
protected void fireRemovedFeatureStructure(final Collection<? extends FeatureStructure> annotations) {
  for (Object listener : mListener.getListeners()) {
    
    final ICasDocumentListener documentListener = (ICasDocumentListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        documentListener.removed(Collections.unmodifiableCollection(annotations));
      }
    });
  }
}
 
Example #27
Source File: AbstractDocument.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Sends a removed message to registered listeners.
 *
 * @param annotation the annotation
 */
protected void fireRemovedFeatureStructure(final FeatureStructure annotation) {
  for (Object listener : mListener.getListeners()) {
    
    final ICasDocumentListener documentListener = (ICasDocumentListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        documentListener.removed(annotation);
      }
    });
  }
}
 
Example #28
Source File: ContentOutlinePageWithFilter.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
protected void fireSelectionChanged(ISelection selection) {
    final SelectionChangedEvent event = new SelectionChangedEvent(this, selection);

    Object[] listeners = selectionChangedListeners.getListeners();
    for (int i = 0; i < listeners.length; ++i) {
        final ISelectionChangedListener l = (ISelectionChangedListener) listeners[i];
        SafeRunner.run(new SafeRunnable() {
            @Override
            public void run() {
                l.selectionChanged(event);
            }
        });
    }
}
 
Example #29
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 annotations the annotations
 */
protected void fireAddedFeatureStructure(final Collection<? extends FeatureStructure> annotations) {
  for (Object listener : mListener.getListeners()) {
    
    final ICasDocumentListener documentListener = (ICasDocumentListener) listener;
    
    SafeRunner.run(new SafeRunnable() {
      @Override
      public void run() {
        documentListener.added(Collections.unmodifiableCollection(annotations));
      }
    });
  }
}
 
Example #30
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);
      }
    });
  }
}