@Override
 public void fillContextMenu(IMenuManager menu) {
   IMenuManager buildPathMenu = (IMenuManager) menu.find(BUILD_PATH_MENU_ID);
   if (buildPathMenu != null) {
     buildPathMenu.addMenuListener(
         new IMenuListener() {
           @Override
           public void menuAboutToShow(IMenuManager manager) {
             ISelection selection = selectionProvider.getSelection();
             if (selection instanceof IStructuredSelection) {
               IStructuredSelection structuredSelection = (IStructuredSelection) selection;
               if (structuredSelection.size() == 1) {
                 Object firstElement = structuredSelection.getFirstElement();
                 if (firstElement instanceof IPackageFragment) {
                   IPackageFragment packageFragment = (IPackageFragment) firstElement;
                   IProject project = packageFragment.getJavaProject().getProject();
                   if (isCeylonProject(project)) {
                     Module module = getModule(project, packageFragment.getElementName());
                     if (module != null) {
                       manager.add(new AddCeylonTestImportAction(project, module));
                     }
                   }
                 }
               }
             }
           }
         });
   }
 }
  /**
   * This adds to the menu bar a menu and some separators for editor additions, as well as the
   * sub-menus for object creation items.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @generated
   */
  @Override
  public void contributeToMenu(IMenuManager menuManager) {
    super.contributeToMenu(menuManager);

    IMenuManager submenuManager =
        new MenuManager(DsmlEditorPlugin.INSTANCE.getString("_UI_DsmlEditor_menu"), "dsmlMenuID");
    menuManager.insertAfter("additions", submenuManager);
    submenuManager.add(new Separator("settings"));
    submenuManager.add(new Separator("actions"));
    submenuManager.add(new Separator("additions"));
    submenuManager.add(new Separator("additions-end"));

    // Prepare for CreateChild item addition or removal.
    //
    createChildMenuManager =
        new MenuManager(DsmlEditorPlugin.INSTANCE.getString("_UI_CreateChild_menu_item"));
    submenuManager.insertBefore("additions", createChildMenuManager);

    // Prepare for CreateSibling item addition or removal.
    //
    createSiblingMenuManager =
        new MenuManager(DsmlEditorPlugin.INSTANCE.getString("_UI_CreateSibling_menu_item"));
    submenuManager.insertBefore("additions", createSiblingMenuManager);

    // Force an update because Eclipse hides empty menus now.
    //
    submenuManager.addMenuListener(
        new IMenuListener() {
          public void menuAboutToShow(IMenuManager menuManager) {
            menuManager.updateAll(true);
          }
        });

    addGlobalActions(submenuManager);
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.jface.action.ContributionItem#setParent(org.eclipse.jface
  * .action.IContributionManager)
  */
 public void setParent(IContributionManager parent) {
   if (getParent() instanceof IMenuManager) {
     IMenuManager menuMgr = (IMenuManager) getParent();
     menuMgr.removeMenuListener(menuListener);
   }
   if (parent instanceof IMenuManager) {
     IMenuManager menuMgr = (IMenuManager) parent;
     menuMgr.addMenuListener(menuListener);
   }
   super.setParent(parent);
 }
 /*
  * (non-Javadoc) Method declared in ActionGroup
  */
 public void fillContextMenu(IMenuManager menu) {
   super.fillContextMenu(menu);
   if (!canOperateOnSelection()) return;
   String menuText = PHPUIMessages.IncludePathActionGroup_label;
   IMenuManager subMenu = new MenuManager(menuText, MENU_ID);
   subMenu.addMenuListener(
       new IMenuListener() {
         public void menuAboutToShow(IMenuManager manager) {
           fillViewSubMenu(manager);
         }
       });
   subMenu.setRemoveAllWhenShown(true);
   subMenu.add(new ConfigureBuildPathAction(fSite));
   menu.appendToGroup(fGroupName, subMenu);
 }
示例#5
0
  @Override
  public void makeContributions(
      IMenuManager menuManager,
      IToolBarManager toolBarManager,
      IStatusLineManager statusLineManager) {

    // menuManager.setRemoveAllWhenShown(true);

    // menuManager.add(new Action("1"){});

    menuManager.addMenuListener(
        new IMenuListener() {

          @Override
          public void menuAboutToShow(final IMenuManager manager) {
            manager.removeAll();
            final CompilationUnit unit =
                Workspace.getInstance()
                    .getCompilationUnit(((FileEditorInput) m_editor.getEditorInput()).getFile());
            final IType type = unit.getReconciledType();
            final LanguageElementImageProvider leip = new LanguageElementImageProvider();
            /*if (type==null) return;
            type = type.getBaseType();
            List<String> realized = new ArrayList<String>();
            while (type!=null){
            	for (final IMethod m : type.getMethods()){
            		if (m.isVirtual()){
            			if (m.getBody()==null){
            				if (!realized.contains(m.getSignature()))
            					manager.add(new Action(){
            						public String getText() {
            							return m.getSignature();
            						}

            						public void run(){
            							System.out.println(m.getVariableType().toString() + " " + m.getSignature());
            						}

            					});
            			}
            			else
            				realized.add(m.getSignature());
            		}
            	}
            	type = type.getBaseType();
            }*/

            List<IAction> actions = new ArrayList<IAction>();
            IType curr = type.getBaseType();
            while (curr != null) {
              for (final IMethod m : curr.getMethods())
                if (m.getBody() == null && m.isVirtual()) {
                  IType curr1 = type;
                  boolean found = false;
                  while (curr1 != curr) {
                    for (IMethod m1 : curr1.getMethods())
                      if (m1.getSignature().equals(m.getSignature())) {
                        found = true;
                        break;
                      }
                    curr1 = curr1.getBaseType();
                  }
                  if (!found) {
                    String method = m.getName() + "(";
                    boolean first = true;
                    for (IVariable v : m.getParameters()) {
                      method += (first ? "" : ", ") + v.getSignature() + " " + v.getName();
                      first = false;
                    }
                    method += ")  ";
                    method += m.getVariableType().getSignature();
                    actions.add(
                        new Action(method) {
                          @Override
                          public ImageDescriptor getImageDescriptor() {
                            return leip.getImageDescriptor(
                                m, LanguageElementImageProvider.SMALL_ICONS);
                          }

                          @Override
                          public void run() {
                            MultipleTransactions mt = new MultipleTransactions((Z8Editor) m_editor);
                            InitHelper.checkImport(mt, type, m.getVariableType().getType());
                            String call = "super.";
                            call += m.getName() + "(";
                            String sign =
                                m.getVariableType().getSignature() + " " + m.getName() + "(";
                            if (m.isPublic()) sign = "public " + sign;
                            if (m.isProtected()) sign = "protected " + sign;
                            if (m.isPrivate()) sign = "private " + sign;
                            if (m.isStatic()) sign = "static " + sign;
                            if (m.isVirtual()) sign = "virtual " + sign;
                            boolean first = true;
                            for (IVariable arg : m.getParameters()) {
                              if (!first) {
                                sign += ", ";
                                call += ", ";
                              } else first = false;
                              call += arg.getName();
                              sign += arg.getVariableType().getSignature() + " " + arg.getName();
                              InitHelper.checkImport(mt, type, arg.getVariableType().getType());
                            }
                            call += ");";
                            sign += ") {";
                            String methodString = "\r\n\t" + sign + "\r\n\t\t";
                            int len = methodString.length();
                            methodString =
                                methodString
                                    + "\r\n\t\t"
                                    + (m.getVariableType().getSignature().equals("void")
                                        ? ""
                                        : "return ")
                                    + call;
                            List<Transaction> trs = mt.getTransactions();
                            for (int i = 0; i < trs.size(); i++) {
                              len += trs.get(i).getWhat().length();
                            }
                            methodString += "\r\n\t}";
                            int posToInsert =
                                new InitHelper(type)
                                    .getNewMethodPosition(
                                        ((Z8Editor) m_editor).getDocument(), m.getName());
                            mt.add(0, posToInsert, methodString);
                            mt.execute();

                            m_editor.setFocus();
                            m_editor
                                .getSelectionProvider()
                                .setSelection(new TextSelection(posToInsert + len, 0));
                          }
                        });
                    // methodsStrings.add(method);
                    // methods.add(m);
                  }
                }
              curr = curr.getBaseType();
            }
            IAction[] as = actions.toArray(new IAction[0]);
            Arrays.sort(
                as,
                new Comparator<IAction>() {

                  @Override
                  public int compare(IAction o1, IAction o2) {
                    return o1.getText().compareToIgnoreCase(o2.getText());
                  }
                });
            for (IAction a : as) manager.add(a);
          }
        });
  }
  /**
   * This adds to the menu bar a menu and some separators for editor additions, as well as the
   * sub-menus for object creation items.
   * <!--
   * begin-user-doc -->
   * <!-- end-user-doc -->
   *
   * @param menuManager the menu manager
   * @generated_not
   */
  @Override
  public void contributeToMenu(IMenuManager menuManager) {
    super.contributeToMenu(menuManager);

    IMenuManager submenuManager =
        new MenuManager(
            DsEditorPlugin.INSTANCE.getString("_UI_DsEditor_menu"),
            "org.wso2.carbonstudio.eclipse.dsMenuID");
    menuManager.insertAfter("additions", submenuManager);
    submenuManager.add(new Separator("settings"));
    submenuManager.add(new Separator("actions"));
    submenuManager.add(new Separator("additions"));
    submenuManager.add(new Separator("additions-end"));

    // Prepare for item addition or removal.

    if (generateDataSourceMenu) {
      submenuManager.insertBefore("additions", dsMenuManager);
    }

    if (generateQueryAndOperationAndResourceMenu) {
      submenuManager.insertBefore("additions", configPropertyAction);
      submenuManager.insertBefore("additions", queryAction);
      submenuManager.insertBefore("additions", operationAction);
      submenuManager.insertBefore("additions", resourceAction);
    }

    if (generateQueryChildrenMenu) {
      submenuManager.insertBefore("additions", resultAction);
      submenuManager.insertBefore("additions", inputParamAction);
      submenuManager.insertBefore("additions", eventTriggerAction);
      submenuManager.insertBefore("additions", queryPropertyGroupAction);
    }

    if (generateSubscriptionMenu) {
      submenuManager.insertBefore("additions", subscriptionAction);
    }

    if (generateCallQueryInputMappingMenu) {
      submenuManager.insertBefore("additions", callQueryInputMappingAction);
    }

    if (generateOutputMappingMenu) {
      submenuManager.insertBefore("additions", outputMappingsMenuManager);
    }

    if (generateCallQueryMenu) {
      submenuManager.insertBefore("additions", callQueryAction);
    }

    if (generateValidatorMenu) {
      submenuManager.insertBefore("additions", validatorMenuManager);
    }

    if (generateQueryPropertyListMenu) {
      submenuManager.insertBefore("additions", queryPropertyAction);
    }

    // Force an update because Eclipse hides empty menus now.

    submenuManager.addMenuListener(
        new IMenuListener() {
          public void menuAboutToShow(IMenuManager menuManager) {
            menuManager.updateAll(true);
          }
        });

    addGlobalActions(submenuManager);
  }