コード例 #1
0
 private MWindow getWindow() {
   if (workbenchWindow != null) return workbenchWindow;
   if (application.getSelectedElement() != null) return application.getSelectedElement();
   List<MWindow> windows = application.getChildren();
   if (windows.size() != 0) return windows.get(0);
   return null;
 }
コード例 #2
0
  /**
   * Locate an action (a menu item, actually) with the given id in the current menu bar and run it.
   *
   * @param actionId the action to find
   * @return true if an action was found, false otherwise
   */
  private boolean runAction(String actionId) {
    MWindow window = app.getSelectedElement();
    if (window == null) {
      return false;
    }
    MMenu topMenu = window.getMainMenu();
    MMenuItem item = findAction(actionId, topMenu);
    if (item == null || !item.isEnabled()) {
      return false;
    }
    try {
      // disable the about and prefs items -- they shouldn't be
      // able to be run when another item is being triggered
      final Display display = Display.getDefault();
      MenuItem aboutItem = null;
      boolean aboutEnabled = true;
      MenuItem prefsItem = null;
      boolean prefsEnabled = true;

      Menu appMenuBar = display.getMenuBar();
      if (appMenuBar != null) {
        aboutItem = findMenuItemById(appMenuBar, SWT.ID_ABOUT);
        if (aboutItem != null) {
          aboutEnabled = aboutItem.getEnabled();
          aboutItem.setEnabled(false);
        }
        prefsItem = findMenuItemById(appMenuBar, SWT.ID_PREFERENCES);
        if (prefsItem != null) {
          prefsEnabled = prefsItem.getEnabled();
          prefsItem.setEnabled(false);
        }
      }
      try {
        simulateMenuSelection(item);
      } finally {
        if (prefsItem != null) {
          prefsItem.setEnabled(prefsEnabled);
        }
        if (aboutItem != null) {
          aboutItem.setEnabled(aboutEnabled);
        }
      }
    } catch (Exception e) {
      // theoretically, one of
      // SecurityException,Illegal*Exception,InvocationTargetException,NoSuch*Exception
      // not expected to happen at all.
      log(e);
      // return false?
    }
    return true;
  }
コード例 #3
0
 private static IEclipseContext getActiveChildContext(MApplication application) {
   MWindowElement nonContainer =
       getNonContainer(application.getSelectedElement().getSelectedElement());
   return ((MContext) nonContainer).getContext();
 }