private int extractStyle(final MenuManager manager) {
   int style = SWT.NONE;
   if (manager.getItems() != null && manager.getItems().length > 0) {
     style = SWT.DROP_DOWN;
   }
   return style;
 }
示例#2
0
  private void hideMenuCheck() {
    try {
      URL pluginUrl = Platform.getBundle(GrassUiPlugin.PLUGIN_ID).getResource("/");
      String pluginPath = FileLocator.toFileURL(pluginUrl).getPath();
      File pluginFile = new File(pluginPath);
      File installFolder = pluginFile.getParentFile().getParentFile().getParentFile();

      File grassFolderFile = new File(installFolder, "grass");
      if (Platform.getOS().equals(Platform.OS_WIN32)) {
        if (!grassFolderFile.exists() || !grassFolderFile.isDirectory()) {
          IWorkbenchWindow[] wwindows = PlatformUI.getWorkbench().getWorkbenchWindows();
          String actionSetID = "eu.hydrologis.jgrass.ui.grassactionset";

          for (IWorkbenchWindow iWorkbenchWindow : wwindows) {
            IWorkbenchPage activePage = iWorkbenchWindow.getActivePage();
            if (activePage != null) {
              activePage.hideActionSet(actionSetID);
              MenuManager mbManager = ((ApplicationWindow) iWorkbenchWindow).getMenuBarManager();
              for (int i = 0; i < mbManager.getItems().length; i++) {
                IContributionItem item = mbManager.getItems()[i];
                if (item.getId().equals(actionSetID)) {
                  item.setVisible(false);
                }
              }
            }
          }
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 /**
  * Recursive method to create a menu from the contribute items of a manger
  *
  * @param menu actual menu
  * @param items manager contributor items
  */
 private void createMenu(Menu menu, IContributionItem[] items) {
   for (IContributionItem item : items) {
     if (item instanceof MenuManager) {
       MenuManager manager = (MenuManager) item;
       MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE);
       subMenuItem.setText(manager.getMenuText());
       Menu subMenu = new Menu(Display.getCurrent().getActiveShell(), SWT.DROP_DOWN);
       subMenuItem.setMenu(subMenu);
       createMenu(subMenu, manager.getItems());
     } else if (item instanceof ActionContributionItem) {
       ActionContributionItem actionItem = (ActionContributionItem) item;
       if (actionItem.getAction() instanceof CustomSelectionAction) {
         final CustomSelectionAction action = (CustomSelectionAction) actionItem.getAction();
         MenuItem actionEnrty = new MenuItem(menu, SWT.CHECK);
         action.setSelection(getLastRawSelection());
         actionEnrty.setText(actionItem.getAction().getText());
         actionEnrty.setSelection(action.isChecked());
         actionEnrty.setEnabled(action.canExecute());
         actionEnrty.addSelectionListener(
             new SelectionAdapter() {
               @Override
               public void widgetSelected(SelectionEvent e) {
                 action.run();
               }
             });
       }
     }
   }
 }
示例#4
0
  public void fill(Menu menu, int index) {
    if (getParent() instanceof MenuManager) {
      ((MenuManager) getParent()).addMenuListener(menuListener);
    }

    if (!dirty) {
      return;
    }

    if (currentManager != null && currentManager.getSize() > 0) {
      IMenuService service = (IMenuService) locator.getService(IMenuService.class);
      service.releaseContributions(currentManager);
      currentManager.removeAll();
    }

    currentManager = new MenuManager();
    fillMenu(currentManager);
    IContributionItem[] items = currentManager.getItems();
    if (items.length == 0) {
      MenuItem item = new MenuItem(menu, SWT.NONE, index++);
      item.setText(NO_TARGETS_MSG);
      item.setEnabled(false);
    } else {
      for (int i = 0; i < items.length; i++) {
        if (items[i].isVisible()) {
          items[i].fill(menu, index++);
        }
      }
    }
    dirty = false;
  }
示例#5
0
    public final void testAdditionalNonePresent() {
      ShapeWrapper sw =
          new ShapeWrapper(
              "rect",
              new RectangleShape(
                  new WorldLocation(12.1, 12.3, 12), new WorldLocation(1.1, 1.1, 12)),
              Color.red,
              new HiResDate(2222));
      Editable[] editables = new Editable[] {sw};
      MenuManager menu = new MenuManager("Holder");

      RightClickSupport.getDropdownListFor(menu, editables, null, null, null, true);

      boolean foundTransparent = false;

      // note: this next test may return 4 if run from within IDE,
      // some contributions provided by plugins
      assertEquals("Has items", 2, menu.getSize(), 2);

      IContributionItem[] items = menu.getItems();
      for (int i = 0; i < items.length; i++) {
        IContributionItem thisI = items[i];
        if (thisI instanceof MenuManager) {
          MenuManager subMenu = (MenuManager) thisI;
          IContributionItem[] subItems = subMenu.getItems();
          for (int j = 0; j < subItems.length; j++) {
            IContributionItem subI = subItems[j];
            if (subI instanceof ActionContributionItem) {
              ActionContributionItem ac = (ActionContributionItem) subI;
              String theName = ac.getAction().getText();
              if (theName.equals("Semi transparent")) foundTransparent = true;
            }
          }
        }
      }

      assertTrue("The additional bean info got processed!", foundTransparent);
    }
  /**
   * Create the popoup menu about all the exporters. If the menu is already build this method do
   * nothing.
   */
  private void createPopupMenu() {

    if (popupMenu != null && !popupMenu.isDisposed()) popupMenu.dispose();

    manager = new MenuManager();
    ActionRegistry registry = new ActionRegistry();
    // Create the PDF decorator
    PDF508ElementDecorator pdfDecorator = new PDF508ElementDecorator();
    IWorkbenchPart activePart = getWorkbenchPart();
    pdfDecorator.registerActions(registry, new ArrayList<String>(), activePart);
    pdfDecorator.fillContextMenu(registry, manager);
    // Create the XLS decorator
    XLSElementDecorator xlsDecorator = new XLSElementDecorator();
    xlsDecorator.registerActions(registry, new ArrayList<String>(), activePart);
    xlsDecorator.fillContextMenu(registry, manager);
    // Create the CSV action
    CSVElementDecorator csvDecorator = new CSVElementDecorator();
    csvDecorator.registerActions(registry, new ArrayList<String>(), activePart);
    ISelection actualSelection = getLastRawSelection();
    csvDecorator.fillContextMenu(registry, manager, (IStructuredSelection) actualSelection);
    popupMenu = new Menu(Display.getCurrent().getActiveShell());
    createMenu(popupMenu, manager.getItems());
  }
  /**
   * @param menuManager
   * @param menuModel
   */
  public void reconcileManagerToModel(MenuManager menuManager, MMenu menuModel) {
    List<MMenuElement> modelChildren = menuModel.getChildren();

    HashSet<MOpaqueMenuItem> oldModelItems = new HashSet<MOpaqueMenuItem>();
    HashSet<MOpaqueMenu> oldMenus = new HashSet<MOpaqueMenu>();
    HashSet<MOpaqueMenuSeparator> oldSeps = new HashSet<MOpaqueMenuSeparator>();
    for (MMenuElement itemModel : modelChildren) {
      if (itemModel instanceof MOpaqueMenuSeparator) {
        oldSeps.add((MOpaqueMenuSeparator) itemModel);
      } else if (itemModel instanceof MOpaqueMenuItem) {
        oldModelItems.add((MOpaqueMenuItem) itemModel);
      } else if (itemModel instanceof MOpaqueMenu) {
        oldMenus.add((MOpaqueMenu) itemModel);
      }
    }

    IContributionItem[] items = menuManager.getItems();
    for (int src = 0, dest = 0; src < items.length; src++, dest++) {
      IContributionItem item = items[src];
      if (item instanceof MenuManager) {
        MenuManager childManager = (MenuManager) item;
        MMenu childModel = getMenuModel(childManager);
        if (childModel == null) {
          MMenu legacyModel = MenuFactoryImpl.eINSTANCE.createOpaqueMenu();
          legacyModel.setElementId(childManager.getId());
          legacyModel.setVisible(childManager.isVisible());
          linkModelToManager(legacyModel, childManager);
          modelChildren.add(dest, legacyModel);
          reconcileManagerToModel(childManager, legacyModel);
        } else {
          if (childModel instanceof MOpaqueMenu) {
            oldMenus.remove(childModel);
          }
          if (modelChildren.size() > dest) {
            if (modelChildren.get(dest) != childModel) {
              modelChildren.remove(childModel);
              modelChildren.add(dest, childModel);
            }
          } else {
            modelChildren.add(childModel);
          }
        }
      } else if (item.isSeparator() || item.isGroupMarker()) {
        MMenuElement menuElement = getMenuElement(item);
        if (menuElement == null) {
          MOpaqueMenuSeparator legacySep = MenuFactoryImpl.eINSTANCE.createOpaqueMenuSeparator();
          legacySep.setElementId(item.getId());
          legacySep.setVisible(item.isVisible());
          legacySep.setOpaqueItem(item);
          linkModelToContribution(legacySep, item);
          modelChildren.add(dest, legacySep);
        } else if (menuElement instanceof MOpaqueMenuSeparator) {
          MOpaqueMenuSeparator legacySep = (MOpaqueMenuSeparator) menuElement;
          oldSeps.remove(legacySep);
          if (modelChildren.size() > dest) {
            if (modelChildren.get(dest) != legacySep) {
              modelChildren.remove(legacySep);
              modelChildren.add(dest, legacySep);
            }
          } else {
            modelChildren.add(legacySep);
          }
        }
      } else {
        MMenuElement menuElement = getMenuElement(item);
        if (menuElement == null) {
          MOpaqueMenuItem legacyItem = MenuFactoryImpl.eINSTANCE.createOpaqueMenuItem();
          legacyItem.setElementId(item.getId());
          legacyItem.setVisible(item.isVisible());
          legacyItem.setOpaqueItem(item);
          linkModelToContribution(legacyItem, item);
          modelChildren.add(dest, legacyItem);
        } else if (menuElement instanceof MOpaqueMenuItem) {
          MOpaqueMenuItem legacyItem = (MOpaqueMenuItem) menuElement;
          oldModelItems.remove(legacyItem);
          if (modelChildren.size() > dest) {
            if (modelChildren.get(dest) != legacyItem) {
              modelChildren.remove(legacyItem);
              modelChildren.add(dest, legacyItem);
            }
          } else {
            modelChildren.add(legacyItem);
          }
        }
      }
    }
    if (!oldModelItems.isEmpty()) {
      modelChildren.removeAll(oldModelItems);
      for (MOpaqueMenuItem model : oldModelItems) {
        clearModelToContribution(model, (IContributionItem) model.getOpaqueItem());
      }
    }
    if (!oldMenus.isEmpty()) {
      modelChildren.removeAll(oldMenus);
      for (MOpaqueMenu oldMenu : oldMenus) {
        MenuManager oldManager = getManager(oldMenu);
        clearModelToManager(oldMenu, oldManager);
      }
    }
    if (!oldSeps.isEmpty()) {
      modelChildren.removeAll(oldSeps);
      for (MOpaqueMenuSeparator model : oldSeps) {
        clearModelToContribution(model, (IContributionItem) model.getOpaqueItem());
      }
    }
  }