예제 #1
0
  /**
   * 获得eclipse预定义action,如果没有则返回null
   *
   * @param window
   * @param id
   * @return
   */
  public static IWorkbenchAction getWorkbenchAction(IWorkbenchWindow window, String id) {
    IWorkbenchAction ret = null;
    if (id != null) {
      try {
        Field field = actionFactoryCls.getField(id);
        if (field != null) {
          Object obj = field.get(null);
          if (obj != null && obj instanceof ActionFactory) {
            ActionFactory actionFactory = (ActionFactory) obj;
            ret = actionFactory.create(window);
          }
        }
      } catch (Exception e) {

      }
    }
    return ret;
  }
예제 #2
0
  private Action addAction(
      ActionFactory actionFactory, int textOperation, String actionDefinitionId) {
    IWorkbenchWindow window = getEditorSite().getWorkbenchWindow();
    IWorkbenchAction globalAction = actionFactory.create(window);

    // Create our text action.
    QueryViewAction action = new QueryViewAction(textOperation, actionDefinitionId);
    actions.put(actionFactory.getId(), action);
    // Copy its properties from the global action.
    action.setText(globalAction.getText());
    action.setToolTipText(globalAction.getToolTipText());
    action.setDescription(globalAction.getDescription());
    action.setImageDescriptor(globalAction.getImageDescriptor());

    action.setDisabledImageDescriptor(globalAction.getDisabledImageDescriptor());
    action.setAccelerator(globalAction.getAccelerator());

    // Register our text action with the global action handler.
    IActionBars actionBars = getEditorSite().getActionBars();
    actionBars.setGlobalActionHandler(actionFactory.getId(), action);
    return action;
  }
예제 #3
0
 private void addWorkbenchAction(ActionFactory factory, int textOp) {
   IWorkbenchAction action = factory.create(window);
   TextAction textAction = new TextAction(textOp);
   textAction.setId(action.getId());
   textAction.setActionDefinitionId(action.getActionDefinitionId());
   textAction.setText(action.getText());
   textAction.setToolTipText(action.getToolTipText());
   textAction.setDescription(action.getDescription());
   textAction.setImageDescriptor(action.getImageDescriptor());
   textAction.setDisabledImageDescriptor(action.getDisabledImageDescriptor());
   textAction.setHoverImageDescriptor(action.getHoverImageDescriptor());
   action.dispose();
   actionHandlers.put(action.getActionDefinitionId(), textAction);
   textActions.put(textAction.getId(), textAction);
 }