コード例 #1
0
  /**
   * Creates the filter descriptors.
   *
   * @param elements the configuration elements
   * @param extensionPointID
   * @return new filter descriptors
   */
  private static Collection<FilterDescriptor> createFilterDescriptors(
      final IConfigurationElement[] elements, final String extensionPointID) {
    final List<FilterDescriptor> result = Lists.newArrayList();
    final Set<String> descIds = Sets.newHashSet();
    for (final IConfigurationElement element : elements) {
      if (FILTER_TAG.equals(element.getName())) {

        final FilterDescriptor[] desc = new FilterDescriptor[1];
        SafeRunner.run(
            new SafeRunnable(
                " One of the extensions for extension-point "
                    + extensionPointID
                    + " is incorrect.") {
              @Override
              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;
  }
コード例 #2
0
  public Object createGui(final MUIElement element) {
    final Object[] gui = {null};
    // wrap the handling in a SafeRunner so that exceptions do not prevent
    // the renderer from processing other elements
    SafeRunner.run(
        new ISafeRunnable() {
          public void handleException(Throwable e) {
            if (e instanceof Error) {
              // errors are deadly, we shouldn't ignore these
              throw (Error) e;
            } else {
              // log exceptions otherwise
              if (logger != null) {
                String message = "Exception occurred while rendering: {0}"; // $NON-NLS-1$
                logger.error(e, NLS.bind(message, element));
              }
            }
          }

          public void run() throws Exception {
            gui[0] = safeCreateGui(element);
          }
        });
    return gui[0];
  }
コード例 #3
0
  /**
   * Implements IPersistableElement. Persist the working set name and working set contents. The
   * contents has to be either IPersistableElements or provide adapters for it to be persistent.
   *
   * @see org.eclipse.ui.IPersistableElement#saveState(IMemento)
   */
  public void saveState(IMemento memento) {
    if (workingSetMemento != null) {
      // just re-save the previous memento if the working set has
      // not been restored
      memento.putMemento(workingSetMemento);
    } else {
      memento.putString(IWorkbenchConstants.TAG_NAME, getName());
      memento.putString(IWorkbenchConstants.TAG_LABEL, getLabel());
      memento.putString(IWorkbenchConstants.TAG_ID, getUniqueId());
      memento.putString(IWorkbenchConstants.TAG_EDIT_PAGE_ID, editPageId);
      Iterator iterator = elements.iterator();
      while (iterator.hasNext()) {
        IAdaptable adaptable = (IAdaptable) iterator.next();
        final IPersistableElement persistable =
            (IPersistableElement) Util.getAdapter(adaptable, IPersistableElement.class);
        if (persistable != null) {
          final IMemento itemMemento = memento.createChild(IWorkbenchConstants.TAG_ITEM);

          itemMemento.putString(IWorkbenchConstants.TAG_FACTORY_ID, persistable.getFactoryId());
          SafeRunner.run(
              new SafeRunnable(
                  "Problems occurred while saving persistable item state") { //$NON-NLS-1$

                public void run() throws Exception {
                  persistable.saveState(itemMemento);
                }
              });
        }
      }
    }
  }
コード例 #4
0
  @Override
  public boolean close() {

    // Do this is in a SafeRunnable as it may run client code
    SafeRunnable runnable =
        new SafeRunnable() {
          @Override
          public void run() throws Exception {
            List<IPreferenceNode> nodes =
                preferenceManager.getElements(PreferenceManager.PRE_ORDER);
            for (int i = 0; i < nodes.size(); i++) {
              IPreferenceNode node = nodes.get(i);
              node.disposeResources();
            }
          }

          @Override
          public void handleException(Throwable e) {
            super.handleException(e);
            clearSelectedNode(); // Do not cache a node with problems
          }
        };

    SafeRunner.run(runnable);

    return super.close();
  }
コード例 #5
0
  /**
   * Creates trackers from the extension point.
   *
   * @return A list of tracker objects.
   */
  private ImmutableSet<ITracker<?>> createTrackers() {

    IConfigurationElement[] elements =
        Platform.getExtensionRegistry().getConfigurationElementsFor(TRACKER_EXTENSION_ID);

    final ImmutableSet.Builder<ITracker<?>> builder = ImmutableSet.builder();
    for (final IConfigurationElement e : elements) {

      SafeRunner.run(
          new ISafeRunnable() {
            @Override
            public void handleException(Throwable e) {
              getLog().log(new Status(IStatus.ERROR, PLUGIN_ID, e.getMessage(), e));
              e.printStackTrace();
            }

            @Override
            public void run() throws Exception {
              Object o = e.createExecutableExtension("class");
              if (o instanceof ITracker<?>) {
                builder.add((ITracker<?>) o);
              } else {
                System.err.println("Object is not a tracker: " + o);
              }
            }
          });
    }
    return builder.build();
  }
  /**
   * Take the values from element and execute the class for path.
   *
   * @param elem
   * @param path
   * @return IStatus the result of the settings transfer.
   */
  private IStatus transferSettings(final IConfigurationElement element, final IPath path) {

    final IStatus[] exceptions = new IStatus[1];

    SafeRunner.run(
        new ISafeRunnable() {
          @Override
          public void run() throws Exception {

            try {
              SettingsTransfer transfer =
                  (SettingsTransfer) WorkbenchPlugin.createExtension(element, ATT_CLASS);
              transfer.transferSettings(path);
            } catch (CoreException exception) {
              exceptions[0] = exception.getStatus();
            }
          }

          @Override
          public void handleException(Throwable exception) {
            exceptions[0] =
                StatusUtil.newStatus(
                    IStatus.ERROR,
                    NLS.bind(
                        IDEWorkbenchMessages.ChooseWorkspaceWithSettingsDialog_ClassCreationFailed,
                        element.getAttribute(ATT_CLASS)),
                    exception);
          }
        });

    if (exceptions[0] != null) return exceptions[0];

    return Status.OK_STATUS;
  }
コード例 #7
0
ファイル: TmImporter.java プロジェクト: heartsome/tmxeditor8
  /** 加载记忆库匹配实现 ; */
  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);
    }
  }
コード例 #8
0
  /**
   * If the specified configuration element is activated under the current input.
   *
   * @param input The input object.
   * @param configuration The configuration element that defines the activation element.
   * @return true if it is activated.
   */
  private boolean isElementActivated(Object input, final IConfigurationElement configuration) {
    IConfigurationElement[] children = configuration.getChildren("activation"); // $NON-NLS-1$
    if (children == null || children.length == 0) return true;
    children = children[0].getChildren();
    if (children == null || children.length == 0) return true;
    final IConfigurationElement config = children[0];
    final EvaluationContext context = new EvaluationContext(null, input);
    context.addVariable("input", input); // $NON-NLS-1$
    context.setAllowPluginActivation(true);
    final boolean[] result = new boolean[1];
    SafeRunner.run(
        new SafeRunnable() {
          @Override
          public void handleException(Throwable e) {
            // Ignore exception
          }

          @Override
          public void run() throws Exception {
            Expression expression = ExpressionConverter.getDefault().perform(config);
            EvaluationResult evaluate = expression.evaluate(context);
            if (evaluate == EvaluationResult.TRUE) {
              result[0] = true;
            }
          }
        });
    return result[0];
  }
コード例 #9
0
  /**
   * Creates a new <code>ViewerFilter</code>. This method is only valid for viewer filters.
   *
   * @return a new <code>ViewerFilter</code>
   */
  public ViewerFilter getViewerFilter() {
    if (!isClassFilter()) {
      return null;
    }

    if (fCachedInstance == null) {

      final ViewerFilter[] result = new ViewerFilter[1];
      final String message =
          String.format(
              "The org.erlide.ui.erlangElementFilters plug-in extension \"%s\" specifies a viewer filter class which does not exist.",
              getId());
      final ISafeRunnable code =
          new SafeRunnable(message) {
            /*
             * @see org.eclipse.core.runtime.ISafeRunnable#run()
             */
            @Override
            public void run() throws Exception {
              result[0] = (ViewerFilter) fElement.createExecutableExtension(CLASS_ATTRIBUTE);
            }
          };
      SafeRunner.run(code);
      fCachedInstance = result[0];
    }
    return fCachedInstance;
  }
コード例 #10
0
  /*
   * @see org.eclipse.jdt.internal.ui.preferences.cleanup.CleanUpTabPage#setWorkingValues(java.util.Map)
   */
  public void setWorkingValues(Map workingValues) {
    super.setWorkingValues(workingValues);

    final CleanUpOptions options =
        new CleanUpOptions(workingValues) {
          /*
           * @see org.eclipse.jdt.internal.ui.fix.CleanUpOptions#setOption(java.lang.String, java.lang.String)
           */
          public void setOption(String key, String value) {
            super.setOption(key, value);

            doUpdatePreview();
            notifyValuesModified();
          }
        };
    SafeRunner.run(
        new ISafeRunnable() {
          public void handleException(Throwable exception) {
            ContributedCleanUpTabPage.this.handleException(exception);
          }

          public void run() throws Exception {
            fContribution.setOptions(options);
          }
        });
  }
コード例 #11
0
ファイル: Activator.java プロジェクト: cschneider/ecf
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
   */
  public void start(final BundleContext context) throws Exception {
    bundleContext = context;

    SafeRunner.run(
        new ExtensionRegistryRunnable(context) {
          protected void runWithoutRegistry() throws Exception {
            context.registerService(Namespace.class, new JSLPNamespace(), null);
            context.registerService(
                ContainerTypeDescription.class,
                new ContainerTypeDescription(
                    "ecf.discovery.jslp",
                    new ContainerInstantiator(),
                    "JSLP Discovery Container",
                    true,
                    false),
                null); //$NON-NLS-1$//$NON-NLS-2$
            context.registerService(
                ContainerTypeDescription.class,
                new ContainerTypeDescription(
                    "ecf.discovery.jslp.locator",
                    new ContainerInstantiator(),
                    "JSLP Discovery Locator Container",
                    true,
                    false),
                null); //$NON-NLS-1$//$NON-NLS-2$
            context.registerService(
                ContainerTypeDescription.class,
                new ContainerTypeDescription(
                    "ecf.discovery.jslp.advertiser",
                    new ContainerInstantiator(),
                    "JSLP Discovery Advertiser Container",
                    true,
                    false),
                null); //$NON-NLS-1$//$NON-NLS-2$
          }
        });

    // initially get the locator and add a life cycle listener
    locatorSt = new ServiceTracker(context, Locator.class.getName(), null);

    // initially get the advertiser and add a life cycle listener
    advertiserSt = new ServiceTracker(context, Advertiser.class.getName(), null);

    // register ourself as an OSGi service
    final Properties props = new Properties();
    props.put(IDiscoveryService.CONTAINER_NAME, JSLPDiscoveryContainer.NAME);
    props.put(Constants.SERVICE_RANKING, new Integer(500));

    String[] clazzes =
        new String[] {
          IDiscoveryService.class.getName(),
          IDiscoveryLocator.class.getName(),
          IDiscoveryAdvertiser.class.getName()
        };
    serviceRegistration = context.registerService(clazzes, serviceFactory, props);
  }
コード例 #12
0
ファイル: EditorHistory.java プロジェクト: Bluelich/xmind
 private void fireChanged() {
   for (final Object listener : listeners.getListeners()) {
     SafeRunner.run(
         new SafeRunnable() {
           public void run() throws Exception {
             ((IEditorHistoryListener) listener).editorHistoryChanged();
           }
         });
   }
 }
コード例 #13
0
  /*
   * Notify listeners of an operation event.
   */
  private void notifyListeners(final OperationHistoryEvent event) {
    if (event.getOperation() instanceof IAdvancedUndoableOperation) {
      final IAdvancedUndoableOperation advancedOp =
          (IAdvancedUndoableOperation) event.getOperation();
      SafeRunner.run(
          new ISafeRunnable() {
            @Override
            public void handleException(Throwable exception) {
              if (DEBUG_OPERATION_HISTORY_UNEXPECTED) {
                Tracing.printTrace(
                    "OPERATIONHISTORY", //$NON-NLS-1$
                    "Exception during notification callback " + exception); // $NON-NLS-1$
              }
            }

            @Override
            public void run() throws Exception {
              advancedOp.aboutToNotify(event);
            }
          });
    }
    final Object[] listenerArray = listeners.getListeners();
    for (int i = 0; i < listenerArray.length; i++) {
      final IOperationHistoryListener listener = (IOperationHistoryListener) listenerArray[i];
      SafeRunner.run(
          new ISafeRunnable() {
            @Override
            public void handleException(Throwable exception) {
              if (DEBUG_OPERATION_HISTORY_UNEXPECTED) {
                Tracing.printTrace(
                    "OPERATIONHISTORY", //$NON-NLS-1$
                    "Exception during notification callback " + exception); // $NON-NLS-1$
              }
            }

            @Override
            public void run() throws Exception {
              listener.historyNotification(event);
            }
          });
    }
  }
コード例 #14
0
ファイル: MButton.java プロジェクト: koson/xmind3
 protected void fireOpen(final OpenEvent event) {
   if (openListeners == null) return;
   for (final Object l : openListeners.toArray()) {
     SafeRunner.run(
         new SafeRunnable() {
           public void run() throws Exception {
             ((IOpenListener) l).open(event);
           }
         });
   }
 }
コード例 #15
0
ファイル: SliderViewer.java プロジェクト: gedaofeng/xmind3
 protected void firePostSelectionChanged(final SelectionChangedEvent event) {
   if (postSelectionChangedListeners == null) return;
   for (final Object l : postSelectionChangedListeners.toArray()) {
     SafeRunner.run(
         new SafeRunnable() {
           public void run() throws Exception {
             ((ISelectionChangedListener) l).selectionChanged(event);
           }
         });
   }
 }
コード例 #16
0
  /*
   * (non-Javadoc)
   *
   * @see org.talend.core.utils.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement)
   */
  @Override
  protected boolean readElement(final IConfigurationElement element) {
    final String bundleName = element.getContributor().getName();
    if ("TemplateManager".equals(element.getName())) {
      SafeRunner.run(
          new RegistryReader.RegistrySafeRunnable() {

            @Override
            public void run() throws Exception {
              AbstractMavenTemplateManager templateManager =
                  (AbstractMavenTemplateManager) element.createExecutableExtension(CLASS_ATTRIBUTE);
              if (templateManager == null) {
                log.error("Can't create the template manager in " + bundleName);
              } else {
                // FIXME, means, for each bundle, should impl only one template manager.
                templateManagerBundleMap.put(bundleName, templateManager);
              }
            }
          });
      return true;
    } else if ("ProjectSettingManager".equals(element.getName())) {
      SafeRunner.run(
          new RegistryReader.RegistrySafeRunnable() {

            @Override
            public void run() throws Exception {
              IProjectSettingManagerProvider settingManager =
                  (IProjectSettingManagerProvider)
                      element.createExecutableExtension(CLASS_ATTRIBUTE);
              if (settingManager == null) {
                log.error("Can't create the project setting manager in " + bundleName);
              } else {
                // FIXME, means, for each bundle, should impl only one project setting manager.
                projectSettingManagerBundleMap.put(bundleName, settingManager);
              }
            }
          });
      return true;
    }
    return false;
  }
コード例 #17
0
 protected void fireInstanceAboutToTransition(final InstanceEvent event) {
   Object list[] = getListeners();
   for (int i = 0; i < list.length; i++) {
     final IInstanceListener l = (IInstanceListener) list[i];
     SafeRunner.run(
         new SafeRunnable() {
           public void run() {
             l.instanceAboutToTransition(event);
           }
         });
   }
 }
コード例 #18
0
 /**
  * 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);
           }
         });
   }
 }
コード例 #19
0
 private void fireDoubleClickEvent(final DoubleClickEvent event) {
   IDoubleClickListener[] firingListeners = listeners;
   for (int i = 0; i < firingListeners.length; ++i) {
     final IDoubleClickListener l = firingListeners[i];
     SafeRunner.run(
         new SafeRunnable() {
           public void run() {
             l.doubleClick(event);
           }
         });
   }
 }
コード例 #20
0
  public void validate(IRegion dirtyRegion, IValidationContext helper, IReporter reporter) {

    // install editors
    if (fEditor == null) {
      install(helper);
      if (fEditor == null) {
        return;
      }
    }

    if (!(fEditor instanceof PHPStructuredEditor)) {
      return;
    }

    final IModelElement modelElement = ((PHPStructuredEditor) fEditor).getModelElement();
    if (modelElement instanceof ISourceModule) {

      final Program ast[] = new Program[1];
      try {
        SafeRunner.run(
            new ISafeRunnable() {
              public void run() throws ModelException {
                ast[0] = reconcile((ISourceModule) modelElement, true);
              }

              public void handleException(Throwable ex) {
                IStatus status =
                    new Status(
                        IStatus.ERROR,
                        PHPUiPlugin.ID,
                        IStatus.OK,
                        "Error in php Core during reconcile",
                        ex); //$NON-NLS-1$
                PHPCorePlugin.getDefault().getLog().log(status);
              }
            });
      } finally {
        // Always notify listeners, see
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=55969 for the
        // final solution
        try {
          if (fIsScriptReconcilingListener) {
            IProgressMonitor pm = fProgressMonitor;
            if (pm == null) pm = new NullProgressMonitor();
            fJavaReconcilingListener.reconciled(ast[0], !fNotify, pm);
          }
        } finally {
          fNotify = true;
        }
      }
    }
  }
コード例 #21
0
 private String getBranchNameSuggestionFromProvider() {
   final AtomicReference<String> ref = new AtomicReference<String>();
   final IBranchNameProvider branchNameProvider = getBranchNameProvider();
   if (branchNameProvider != null)
     SafeRunner.run(
         new SafeRunnable() {
           @Override
           public void run() throws Exception {
             ref.set(branchNameProvider.getBranchNameSuggestion());
           }
         });
   return ref.get();
 }
コード例 #22
0
 private void notifyTestRunStarted(final int count) {
   if (JUnitCorePlugin.isStopped()) return;
   for (int i = 0; i < fListeners.length; i++) {
     final ITestRunListener2 listener = fListeners[i];
     SafeRunner.run(
         new ListenerSafeRunnable() {
           @Override
           public void run() {
             listener.testRunStarted(count);
           }
         });
   }
 }
コード例 #23
0
 private void testRunEnded(final long elapsedTime) {
   if (JUnitCorePlugin.isStopped()) return;
   for (int i = 0; i < fListeners.length; i++) {
     final ITestRunListener2 listener = fListeners[i];
     SafeRunner.run(
         new ListenerSafeRunnable() {
           @Override
           public void run() {
             listener.testRunEnded(elapsedTime);
           }
         });
   }
 }
コード例 #24
0
ファイル: CheckSpellingAction.java プロジェクト: koson/xmind3
  public void run(IAction action) {
    if (window == null) return;

    SafeRunner.run(
        new SafeRunnable() {
          public void run() throws Exception {
            IViewPart view = window.getActivePage().showView(SpellingPlugin.SPELLING_CHECK_VIEW_ID);
            if (view instanceof SpellingCheckView) {
              ((SpellingCheckView) view).scanWorkbook();
            }
          }
        });
  }
コード例 #25
0
 private void fireDelta(final IModelElementDelta delta) {
   final ISourceUnit su = LTKUtil.getSourceUnit(delta.getModelElement());
   if (su == null) {
     return;
   }
   final WorkingContext context = su.getWorkingContext();
   final ElementChangedEvent event = new ElementChangedEvent(delta, context);
   final SafeRunnable runnable = new SafeRunnable(event);
   final IElementChangedListener[] listeners = fModelManager.getElementChangedListeners(context);
   for (int i = 0; i < listeners.length; i++) {
     runnable.fListener = listeners[i];
     SafeRunner.run(runnable);
   }
 }
コード例 #26
0
 private void notifyTestRunTerminated() {
   // fix for 77771 RemoteTestRunnerClient doing work after junit shutdown [JUnit]
   if (JUnitCorePlugin.isStopped()) return;
   for (int i = 0; i < fListeners.length; i++) {
     final ITestRunListener2 listener = fListeners[i];
     SafeRunner.run(
         new ListenerSafeRunnable() {
           @Override
           public void run() {
             listener.testRunTerminated();
           }
         });
   }
 }
コード例 #27
0
  /**
   * Fires a property changed event.
   *
   * @param propertyId the id of the property that changed
   */
  protected void firePropertyChange(final int propertyId) {
    Object[] array = getListeners();
    for (int nX = 0; nX < array.length; nX++) {
      final IPropertyListener l = (IPropertyListener) array[nX];
      SafeRunner.run(
          new SafeRunnable() {

            @Override
            public void run() {
              l.propertyChanged(this, propertyId);
            }
          });
    }
  }
コード例 #28
0
 public IStatus runInUIThread(IProgressMonitor monitor) {
   SafeRunner.run(
       new NavigatorSafeRunnable() {
         public void run() throws Exception {
           if (commonNavigator.getCommonViewer().getInput() != null) {
             IStructuredSelection selection =
                 new StructuredSelection(commonNavigator.getCommonViewer().getInput());
             actionService.setContext(new ActionContext(selection));
             actionService.fillActionBars(commonNavigator.getViewSite().getActionBars());
           }
         }
       });
   return Status.OK_STATUS;
 }
コード例 #29
0
 private void fireSelectionChangedEvent(
     final SelectionChangedEvent event, List<ISelectionChangedListener> listeners) {
   if (listeners == null) return;
   Object[] ls = listeners.toArray();
   for (int i = 0; i < ls.length; ++i) {
     final ISelectionChangedListener l = (ISelectionChangedListener) ls[i];
     SafeRunner.run(
         new SafeRunnable() {
           public void run() {
             l.selectionChanged(event);
           }
         });
   }
 }
コード例 #30
0
 private void notifyTestStarted(final String test) {
   if (JUnitCorePlugin.isStopped()) return;
   for (int i = 0; i < fListeners.length; i++) {
     final ITestRunListener2 listener = fListeners[i];
     SafeRunner.run(
         new ListenerSafeRunnable() {
           @Override
           public void run() {
             String s[] = extractTestId(test);
             listener.testStarted(s[0], s[1]);
           }
         });
   }
 }