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
  }
Beispiel #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();
    }
  }
        public void handleEvent(Event event) {
          // Ensure that this event is for a MMenuItem
          if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) return;

          MMenuItem itemModel = (MMenuItem) event.getProperty(UIEvents.EventTags.ELEMENT);
          IContributionItem ici = getContribution(itemModel);
          if (ici != null) {
            ici.update();
          }
        }
 /**
  * @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;
 }
        public void handleEvent(Event event) {
          // Ensure that this event is for a MMenuItem
          if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MToolBarElement)) return;

          MToolBarElement itemModel =
              (MToolBarElement) event.getProperty(UIEvents.EventTags.ELEMENT);
          String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
          if (UIEvents.UIElement.TOBERENDERED.equals(attName)) {
            Object obj = itemModel.getParent();
            if (!(obj instanceof MToolBar)) {
              return;
            }
            ToolBarManager parent = getManager((MToolBar) obj);
            if (itemModel.isToBeRendered()) {
              if (parent != null) {
                modelProcessSwitch(parent, itemModel);
                parent.update(true);
                ToolBar tb = parent.getControl();
                if (tb != null && !tb.isDisposed()) {
                  tb.pack(true);
                  tb.getShell().layout(new Control[] {tb}, SWT.DEFER);
                }
              }
            } else {
              IContributionItem ici = modelToContribution.remove(itemModel);
              if (ici != null && parent != null) {
                parent.remove(ici);
              }
              if (ici != null) {
                ici.dispose();
              }
            }
          } else if (UIEvents.UIElement.VISIBLE.equals(attName)) {
            IContributionItem ici = getContribution(itemModel);
            if (ici == null) {
              return;
            }
            ici.setVisible(itemModel.isVisible());
            ToolBarManager parent = (ToolBarManager) ((ContributionItem) ici).getParent();
            if (parent != null) {
              parent.markDirty();
              parent.update(true);
              // MUIElement tbModel = itemModel.getParent();
              // disposeToolbarIfNecessary((MToolBar) tbModel);
              ToolBar tb = parent.getControl();
              if (tb != null && !tb.isDisposed()) {
                tb.pack(true);
                tb.getShell().layout(new Control[] {tb}, SWT.DEFER);
              }
            }
          }
        }
 public void handleEvent(Event event) {
   Object element = event.getProperty(UIEvents.EventTags.ELEMENT);
   String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
   if (element instanceof MMenuItem) {
     MMenuItem itemModel = (MMenuItem) element;
     if (UIEvents.UIElement.TOBERENDERED.equals(attName)) {
       Object obj = itemModel.getParent();
       if (!(obj instanceof MMenu)) {
         return;
       }
       MenuManager parent = getManager((MMenu) obj);
       if (itemModel.isToBeRendered()) {
         if (parent != null) {
           modelProcessSwitch(parent, itemModel);
         }
       } else {
         IContributionItem ici = getContribution(itemModel);
         clearModelToContribution(itemModel, ici);
         if (ici != null && parent != null) {
           parent.remove(ici);
         }
         if (ici != null) {
           ici.dispose();
         }
       }
     }
   }
   if (UIEvents.UIElement.VISIBLE.equals(attName)) {
     if (element instanceof MMenu) {
       MMenu menuModel = (MMenu) element;
       MenuManager manager = getManager(menuModel);
       if (manager == null) {
         return;
       }
       manager.setVisible(menuModel.isVisible());
       if (manager.getParent() != null) {
         manager.getParent().markDirty();
       }
     } else if (element instanceof MMenuElement) {
       MMenuElement itemModel = (MMenuElement) element;
       Object obj = getContribution(itemModel);
       if (!(obj instanceof ContributionItem)) {
         return;
       }
       ContributionItem item = (ContributionItem) obj;
       item.setVisible(itemModel.isVisible());
       if (item.getParent() != null) {
         item.getParent().markDirty();
       }
     }
   }
 }
  private void updateRecentDocuments(final String file) {
    for (IAction action : recentList) {
      IContributionItem item = fileMenu.remove(action.getId());
      LOG.debug("Removed item : " + item);
      if (item != null) {
        item.update();
      }
    }
    recentList.clear();

    getConfiguration().addRecentDocument(file);
    reloadRecentDocuments();
  }
 void processOpaqueItem(ToolBarManager parentManager, MOpaqueToolItem itemModel) {
   IContributionItem ici = getContribution(itemModel);
   if (ici != null) {
     return;
   }
   Object obj = itemModel.getOpaqueItem();
   if (obj instanceof IContributionItem) {
     ici = (IContributionItem) obj;
   } else {
     return;
   }
   ici.setVisible(itemModel.isVisible());
   addToManager(parentManager, itemModel, ici);
   linkModelToContribution(itemModel, ici);
 }
 protected void update(final boolean force, final boolean recursive) {
   super.update(force, recursive);
   if (menuParent != null && (force || isDirty())) {
     disposeToolItems();
     IContributionItem[] items = getItems();
     if (items.length > 0 && menuParent != null) {
       for (int i = 0; i < items.length; i++) {
         IContributionItem item = items[i];
         if (item.isVisible()) {
           makeEntry(item);
         }
       }
     }
     menuParent.layout(true, true);
   }
 }
  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
  }
        public void handleEvent(Event event) {
          // Ensure that this event is for a MMenuItem
          if (!(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MMenuItem)) return;

          MMenuItem itemModel = (MMenuItem) event.getProperty(UIEvents.EventTags.ELEMENT);

          IContributionItem ici = getContribution(itemModel);
          if (ici == null) {
            return;
          }

          String attName = (String) event.getProperty(UIEvents.EventTags.ATTNAME);
          if (UIEvents.UILabel.LABEL.equals(attName)) {
            ici.update();
          } else if (UIEvents.UILabel.ICONURI.equals(attName)) {
            ici.update();
          }
        }
  /**
   * Tests the initial enablement of the zoom toolbar entry. See Bugzilla 110815.
   *
   * @throws Exception
   */
  public void testZoomToolbarEnablement() throws Exception {

    getTestFixture().openDiagram();

    IContributionItem[] items =
        ((IEditorSite) getDiagramWorkbenchPart().getSite())
            .getActionBars()
            .getToolBarManager()
            .getItems();
    boolean foundIt = false;
    for (int i = 0; i < items.length; i++) {
      IContributionItem item = items[i];
      if (item instanceof ZoomContributionItem) {
        foundIt = true;
        assertTrue(item.isEnabled());
      }
    }
    assertTrue(foundIt);
  }
  /**
   * 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());
      }
    }
  }
 /**
  * @param parentManager
  * @param itemModel
  */
 void processRenderedItem(MenuManager parentManager, MRenderedMenuItem itemModel) {
   IContributionItem ici = getContribution(itemModel);
   if (ici != null) {
     return;
   }
   Object obj = itemModel.getContributionItem();
   if (obj instanceof IContextFunction) {
     final IEclipseContext lclContext = getContext(itemModel);
     ici = (IContributionItem) ((IContextFunction) obj).compute(lclContext);
     itemModel.setContributionItem(ici);
   } else if (obj instanceof IContributionItem) {
     ici = (IContributionItem) obj;
   } else {
     // TODO potentially log the state, we've got something we're not
     // happy with
     return;
   }
   ici.setVisible(itemModel.isVisible());
   addToManager(parentManager, itemModel, ici);
   linkModelToContribution(itemModel, ici);
 }
 /** @see IContributionItem#getId() */
 @Override
 public String getId() {
   return item.getId();
 }
 /** @see IContributionItem#fill(CoolBar, int) */
 @Override
 public void fill(CoolBar parent, int index) {
   item.fill(parent, index);
 }
 /** @see IContributionItem#fill(Menu, int) */
 @Override
 public void fill(Menu parent, int index) {
   item.fill(parent, index);
 }
 /** @see IContributionItem#fill(Composite) */
 @Override
 public void fill(Composite parent) {
   item.fill(parent);
 }
 /** @see IContributionItem#dispose() */
 @Override
 public void dispose() {
   item.dispose();
 }
 /** @see IContributionItem#update(String) */
 @Override
 public void update(String id) {
   item.update(id);
 }
 /** @see IContributionItem#update() */
 @Override
 public void update() {
   item.update();
 }
 /** @see IContributionItem#setVisible(boolean) */
 @Override
 public void setVisible(boolean visible) {
   item.setVisible(visible);
 }
 /** @see IContributionItem#setParent(IContributionManager) */
 @Override
 public void setParent(IContributionManager parent) {
   item.setParent(parent);
 }
 /** @see IContributionItem#isDirty() */
 @Override
 public boolean isDirty() {
   return item.isDirty();
 }
 /** @see IContributionItem#isEnabled() */
 @Override
 public boolean isEnabled() {
   return item.isEnabled();
 }
 /** @see IContributionItem#isDynamic() */
 @Override
 public boolean isDynamic() {
   return item.isDynamic();
 }
 /** @see IContributionItem#saveWidgetState() */
 @Override
 public void saveWidgetState() {
   item.saveWidgetState();
 }
Beispiel #29
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#isVisible() */
 @Override
 public boolean isVisible() {
   return item.isVisible();
 }