private void cleanToolBar() {
    final ICoolBarManager coolBar = actionBarConfigurer.getCoolBarManager();
    String contribID = null;
    //
    //		toolbar = ((CoolBarManager2)coolBar).getControl();
    //		toolbar.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
    //
    //		toolbar.addPaintListener(new PaintListener() {
    //			public void paintControl(PaintEvent e) {
    //				Display display = e.display;
    //
    //				toolbar.setBackground(DesignUIPlugin.getColor(COLOR_SSGHT.YELLOW_LIGHT2));
    //
    //				if (!paintListenerAttached) {
    //					for (CoolItem it : toolbar.getItems()) {
    //						if (it != null) {
    //							it.getControl().setBackground(DesignUIPlugin.getColor(COLOR_SSGHT.YELLOW_LIGHT2));
    //							paintListenerAttached = true;
    //						}
    //					}
    //				}
    //			}
    //		});
    //		toolbar.redraw();

    for (IContributionItem contribItem : coolBar.getItems()) {
      contribID = contribItem.getId();
      if (contribID != null && contribID.startsWith("org.eclipse.")) {
        coolBar.remove(contribItem);
      }
    }
    coolBar.update(true); // refresh the display of the cool bar
  }
Example #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();
    }
  }
 /**
  * @param menu
  * @return
  */
 private MenuManager getOpenShiftMenuManager(IMenuManager menu) {
   for (IContributionItem item : menu.getItems()) {
     // make this call in this way, since item id can be null
     if (OPENSHIFT_SERVER_ADAPTER_MENU.equals(item.getId())) {
       return (MenuManager) item;
     }
   }
   MenuManager openshiftMenu = new MenuManager("OpenShift", OPENSHIFT_SERVER_ADAPTER_MENU);
   menu.add(openshiftMenu);
   menu.insertBefore(ServerActionProvider.TOP_SECTION_END_SEPARATOR, openshiftMenu);
   return openshiftMenu;
 }
  private void cleanMenuBar() {
    String contribID = null;

    for (IContributionItem contribItem : myMenuBar.getItems()) {
      contribID = contribItem.getId();

      if ((contribID.startsWith("org.eclipse."))
          || (contribID.startsWith(IWorkbenchActionConstants.MB_ADDITIONS))
          || (contribID.startsWith(IWorkbenchActionConstants.M_NAVIGATE))) {
        myMenuBar.remove(contribItem);
      }
    }

    //
    //	myMenuBar.getgetParent().getParent().getParent().setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));

    myMenuBar.update(true); // refresh the display of the menu bar
  }
  /**
   * Create on the table manger the toolbar actions for the outline. The actions are created only if
   * the toolbar manager dosen't contains them already. Actually the added action are the one the
   * show the standard outline and the one to show the thumbnail of the report.
   *
   * @param tbm the toolbar manager for the outline.
   */
  public void registerToolbarAction(IToolBarManager tbm) {
    IContributionItem items[] = tbm.getItems();
    HashSet<String> existingItems = new HashSet<String>();
    for (IContributionItem item : items) {
      existingItems.add(item.getId());
    }

    showOutlineAction =
        new Action() {
          @Override
          public void run() {
            showPage(ID_ACTION_OUTLINE);
          }
        };
    showOutlineAction.setId(ID_ACTION_OUTLINE);
    showOutlineAction.setImageDescriptor(
        JaspersoftStudioPlugin.getInstance()
            .getImageDescriptor("icons/outline.gif")); // $NON-NLS-1$
    showOutlineAction.setToolTipText(Messages.JDReportOutlineView_show_outline_tool_tip);
    if (!existingItems.contains(ID_ACTION_OUTLINE)) {
      ActionContributionItem showOutlineItem = new ActionContributionItem(showOutlineAction);
      showOutlineItem.setVisible(true);
      tbm.add(showOutlineItem);
    }

    showOverviewAction =
        new Action() {
          @Override
          public void run() {
            showPage(ID_ACTION_OVERVIEW);
          }
        };
    showOverviewAction.setId(ID_ACTION_OVERVIEW);
    showOverviewAction.setImageDescriptor(
        JaspersoftStudioPlugin.getInstance()
            .getImageDescriptor("icons/overview.gif")); // $NON-NLS-1$
    showOverviewAction.setToolTipText(Messages.JDReportOutlineView_show_overview_tool_tip);
    if (!existingItems.contains(ID_ACTION_OVERVIEW)) {
      ActionContributionItem showOverviewItem = new ActionContributionItem(showOverviewAction);
      showOverviewItem.setVisible(true);
      tbm.add(showOverviewItem);
    }
  }
  public void reconcileManagerToModel(IToolBarManager menuManager, MToolBar toolBar) {
    List<MToolBarElement> modelChildren = toolBar.getChildren();
    HashSet<MOpaqueToolItem> oldModelItems = new HashSet<MOpaqueToolItem>();
    for (MToolBarElement itemModel : modelChildren) {
      if (itemModel instanceof MOpaqueToolItem) {
        oldModelItems.add((MOpaqueToolItem) itemModel);
      }
    }

    IContributionItem[] items = menuManager.getItems();
    for (int src = 0, dest = 0; src < items.length; src++, dest++) {
      IContributionItem item = items[src];
      MToolBarElement element = getToolElement(item);
      if (element == null) {
        MOpaqueToolItem legacyItem = MenuFactoryImpl.eINSTANCE.createOpaqueToolItem();
        legacyItem.setElementId(item.getId());
        legacyItem.setVisible(item.isVisible());
        legacyItem.setOpaqueItem(item);
        linkModelToContribution(legacyItem, item);
        modelChildren.add(dest, legacyItem);
      } else if (element instanceof MOpaqueToolItem) {
        MOpaqueToolItem legacyItem = (MOpaqueToolItem) element;
        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 (MOpaqueToolItem model : oldModelItems) {
        clearModelToContribution(model, (IContributionItem) model.getOpaqueItem());
      }
    }
  }
Example #7
0
  private void fillNewWizardActions(IMenuManager menu) {
    // Fill the menu from the commonWizard contributions.
    newWizardActionGroup.setContext(getContext());
    newWizardActionGroup.fillContextMenu(menu);

    IContributionItem newResourceFolderItem = null;
    IContributionItem newModelResourceItem = null;
    IContributionItem newBinaryFileItem = null;
    IContributionItem newTextFileItem = null;

    String firstID = null;
    IContributionItem[] newWizardItems = menu.getItems();
    for (IContributionItem newWizardItem : newWizardItems) {
      if (newWizardItem instanceof ActionContributionItem) {
        IAction action = ((ActionContributionItem) newWizardItem).getAction();
        if (action instanceof IPluginContribution) {
          IPluginContribution pluginContribution = (IPluginContribution) action;
          String id = pluginContribution.getLocalId();
          if (NewFolderWizard.ID.equals(id)) {
            newResourceFolderItem = menu.remove(newWizardItem);
            continue;
          }

          if (NewResourceWizard.ID.equals(id)) {
            newModelResourceItem = menu.remove(newWizardItem);
            continue;
          }

          if (NewBinaryResourceWizard.ID.equals(id)) {
            newBinaryFileItem = menu.remove(newWizardItem);
            continue;
          }

          if (NewTextResourceWizard.ID.equals(id)) {
            newTextFileItem = menu.remove(newWizardItem);
            continue;
          }
        }

        // Filter out the dubious "Ecore Diagram" action that appears everywhere.
        if ("Ecore Diagram".equals(action.getText())) {
          menu.remove(newWizardItem);
          continue;
        }
      }

      if (firstID == null) {
        firstID = newWizardItem.getId();
      }
    }

    if (firstID == null) {
      Separator group = new Separator("cdo-new-wizards");
      menu.add(group);
      firstID = group.getId();
    }

    if (newResourceFolderItem != null) {
      menu.insertBefore(firstID, newResourceFolderItem);
    }

    if (newModelResourceItem != null) {
      menu.insertBefore(firstID, newModelResourceItem);
    }

    if (newBinaryFileItem != null) {
      menu.insertBefore(firstID, newBinaryFileItem);
    }

    if (newTextFileItem != null) {
      menu.insertBefore(firstID, newTextFileItem);
    }
  }
 /** @see IContributionItem#getId() */
 @Override
 public String getId() {
   return item.getId();
 }
  /**
   * @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());
      }
    }
  }