Esempio n. 1
0
  private void createMenu() {
    MenuManager menuMgr = new MenuManager("Events", CONTEXT_MENU_ID);

    ActionContributionItem aItem =
        new ActionContributionItem(
            new AddColumnAsFilterCriteriaAction(site.getWorkbenchWindow(), this));
    aItem.setId("lighthouse.events.actions.filterCriteria");
    menuMgr.add(aItem);
    ActionContributionItem bItem =
        new ActionContributionItem(
            new CreateFilterFromCriteriaAction(site.getWorkbenchWindow(), lighthouseDomain));
    bItem.setId("lighthouse.events.actions.eventToFilter");
    menuMgr.add(bItem);
    menuMgr.add(new Separator());
    ActionContributionItem cItem =
        new ActionContributionItem(new CopyEventXmlAction(site.getWorkbenchWindow()));
    cItem.setId(CopyEventXmlAction.ID);
    menuMgr.add(cItem);
    ActionContributionItem dItem =
        new ActionContributionItem(new CopyEventAsCsvAction(site.getWorkbenchWindow(), this));
    dItem.setId(CopyEventAsCsvAction.ID);
    menuMgr.add(dItem);
    menuMgr.add(new Separator(EVENT_TABLE_ADDITIONS));
    tableMenu = menuMgr.createContextMenu(site.getShell());

    tableViewer.getControl().setMenu(menuMgr.getMenu());
    site.registerContextMenu(CONTEXT_MENU_ID, menuMgr, tableViewer);
  }
  /**
   * Adds this as element state listener in the UI thread as it can otherwise conflict with other
   * listener additions, since DocumentProvider is not thread-safe.
   *
   * @param editor the editor to get the display from
   * @param provider the document provider to register as element state listener
   */
  private void addElementStateListener(ITextEditor editor, final IDocumentProvider provider) {
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=66686 and
    // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=56871

    Runnable runnable =
        new Runnable() {
          public void run() {
            synchronized (fLock) {
              if (fDocumentProvider == provider)
                // addElementStateListener adds at most once - no problem to call repeatedly
                provider.addElementStateListener(LastSaveReferenceProvider.this);
            }
          }
        };

    Display display = null;
    if (editor != null) {
      IWorkbenchPartSite site = editor.getSite();
      if (site != null) {
        IWorkbenchWindow window = site.getWorkbenchWindow();
        if (window != null) {
          Shell shell = window.getShell();
          if (shell != null) display = shell.getDisplay();
        }
      }
    }

    if (display != null && !display.isDisposed()) {
      display.asyncExec(runnable);
    } else {
      runnable.run();
    }
  }
Esempio n. 3
0
  public void activate() {
    // just check we're alive - just in case we've been called before
    // the init is complete
    final IWorkbenchPartSite site = getSite();
    final IWorkbenchWindow window = site.getWorkbenchWindow();
    final IWorkbenchPage page = window.getActivePage();

    if (page != null) {
      page.activate(site.getPart());
    }
  }
Esempio n. 4
0
  public void uninstall() {
    IWorkbenchPartSite site = fEditor.getSite();
    IWorkbenchWindow window = site.getWorkbenchWindow();
    window.getPartService().removePartListener(fPartListener);
    fPartListener = null;

    fViewer.removeTextInputListener(fModelListener);
    fModelListener = null;

    IWorkspace workspace = EDTUIPlugin.getWorkspace();
    workspace.removeResourceChangeListener(fResourceChangeListener);
    fResourceChangeListener = null;

    EDTUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPropertyListener);
    fPropertyListener = null;

    synchronized (this) {
      BackgroundThread bt = fThread;
      fThread = null;
      bt.cancel();
    }
  }
Esempio n. 5
0
  public void install(ITextViewer textViewer) {
    fViewer = textViewer;

    synchronized (this) {
      if (fThread != null) return;
      fThread = new BackgroundThread(getClass().getName());
    }

    fPartListener = new PartListener();
    IWorkbenchPartSite site = fEditor.getSite();
    IWorkbenchWindow window = site.getWorkbenchWindow();
    window.getPartService().addPartListener(fPartListener);

    fModelListener = new Listener();
    fViewer.addTextInputListener(fModelListener);

    fResourceChangeListener = new ResourceChangeListener();
    IWorkspace workspace = EDTUIPlugin.getWorkspace();
    workspace.addResourceChangeListener(fResourceChangeListener);

    fPropertyListener = new EGLPropertyChangeListener();
    EDTUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPropertyListener);
  }
 /** Notifies the listener that the menu is about to be hidden. */
 public final void menuAboutToHide(final IMenuManager mgr) {
   gatherContributions(mgr);
   cleanupNeeded = true;
   // Remove this menu as a visible menu.
   final IWorkbenchPartSite site = part.getSite();
   if (site != null) {
     final IWorkbench workbench = site.getWorkbenchWindow().getWorkbench();
     if (workbench instanceof Workbench) {
       // try delaying this until after the selection event
       // has been fired.
       // This is less threatening if the popup: menu
       // contributions aren't tied to the evaluation service
       workbench
           .getDisplay()
           .asyncExec(
               new Runnable() {
                 public void run() {
                   final Workbench realWorkbench = (Workbench) workbench;
                   runCleanUp(realWorkbench);
                 }
               });
     }
   }
 }
  /** Notifies the listener that the menu is about to be shown. */
  public void menuAboutToShow(IMenuManager mgr) {
    registerE4Support();

    // Add this menu as a visible menu.
    final IWorkbenchPartSite site = part.getSite();
    if (site != null) {
      final IWorkbench workbench = site.getWorkbenchWindow().getWorkbench();
      if (workbench instanceof Workbench) {
        final Workbench realWorkbench = (Workbench) workbench;
        runCleanUp(realWorkbench);
        ISelection input = null;
        if ((bitSet & INCLUDE_EDITOR_INPUT) != 0) {
          if (part instanceof IEditorPart) {
            final IEditorPart editorPart = (IEditorPart) part;
            input = new StructuredSelection(new Object[] {editorPart.getEditorInput()});
          }
        }
        ISelection s = (selProvider == null ? null : selProvider.getSelection());
        realWorkbench.addShowingMenus(getMenuIds(), s, input);
      }
    }

    addMenuContributions(mgr);

    readStaticActions();
    // test for additions removed to comply with menu contributions
    if (menuWrapper != null) {
      mgr = menuWrapper;
      menuWrapper.removeAll();
    }
    if ((bitSet & INCLUDE_EDITOR_INPUT) != 0) {
      addEditorActions(mgr);
    }
    addObjectActions(mgr);
    addStaticActions(mgr);
  }
 /*
  * Return the workbench window for this action handler
  */
 private IWorkbenchWindow getWorkbenchWindow() {
   if (site != null) {
     return site.getWorkbenchWindow();
   }
   return null;
 }
Esempio n. 9
0
 @Override
 public IWorkbenchWindow getWorkbenchWindow() {
   return partSite.getWorkbenchWindow();
 }