Beispiel #1
0
  @Override
  public MenuBuilderImpl newTopLevelMenu(final MenuItem menu) {
    final CurrentContext currentContext = new CurrentContext();
    currentContext.menu = checkNotNull("menu", menu);
    context.push(currentContext);

    return this;
  }
Beispiel #2
0
  @Override
  public MenuBuilderImpl submenu(final String caption) {
    final CurrentContext currentContext = new CurrentContext();
    currentContext.caption = checkNotEmpty("caption", caption);
    currentContext.menuType = MenuType.GROUP;
    context.push(currentContext);

    return this;
  }
Beispiel #3
0
  @Override
  public MenuBuilderImpl newTopLevelMenu(final String caption) {
    final CurrentContext currentContext = new CurrentContext();
    currentContext.caption = checkNotEmpty("caption", caption);
    currentContext.menuType = MenuType.TOP_LEVEL;
    context.push(currentContext);

    return this;
  }
Beispiel #4
0
  @Override
  public MenuBuilderImpl newContributedMenu(final String caption) {
    final CurrentContext currentContext = new CurrentContext();
    currentContext.caption = checkNotEmpty("caption", caption);
    currentContext.menuType = MenuType.CONTRIBUTED;
    context.push(currentContext);

    return this;
  }
Beispiel #5
0
    MenuItem build() {
      if (menu != null) {
        return menu;
      }
      if (menuItems.size() > 0 || menuRawItems.size() > 0) {
        if (menuRawItems.size() > 0) {
          for (final CurrentContext current : menuRawItems) {
            menuItems.add(current.build());
          }
        }
        return new MenuGroup() {
          private final List<EnabledStateChangeListener> enabledStateChangeListeners =
              new ArrayList<EnabledStateChangeListener>();
          private boolean isEnabled = true;

          @Override
          public List<MenuItem> getItems() {
            return menuItems;
          }

          @Override
          public String getContributionPoint() {
            return contributionPoint;
          }

          @Override
          public String getCaption() {
            return caption;
          }

          @Override
          public MenuPosition getPosition() {
            return position;
          }

          @Override
          public int getOrder() {
            return order;
          }

          @Override
          public boolean isEnabled() {
            return isEnabled;
          }

          @Override
          public void setEnabled(final boolean enabled) {
            this.isEnabled = enabled;
            notifyListeners(enabled);
          }

          @Override
          public void addEnabledStateChangeListener(final EnabledStateChangeListener listener) {
            enabledStateChangeListeners.add(listener);
          }

          @Override
          public String getSignatureId() {
            if (contributionPoint != null) {
              return getClass().getName() + "#" + contributionPoint + "#" + caption;
            }
            return getClass().getName() + "#" + caption;
          }

          @Override
          public Collection<String> getRoles() {
            return roles;
          }

          @Override
          public Collection<String> getTraits() {
            return emptyList();
          }

          private void notifyListeners(final boolean enabled) {
            for (final EnabledStateChangeListener listener : enabledStateChangeListeners) {
              listener.enabledStateChanged(enabled);
            }
          }
        };
      } else if (command != null) {
        return new MenuItemCommand() {

          private final List<EnabledStateChangeListener> enabledStateChangeListeners =
              new ArrayList<EnabledStateChangeListener>();
          private boolean isEnabled = true;

          @Override
          public Command getCommand() {
            return command; // To change body of implemented methods use File | Settings | File
                            // Templates.
          }

          @Override
          public String getContributionPoint() {
            return contributionPoint;
          }

          @Override
          public String getCaption() {
            return caption;
          }

          @Override
          public MenuPosition getPosition() {
            return position;
          }

          @Override
          public int getOrder() {
            return order;
          }

          @Override
          public boolean isEnabled() {
            return isEnabled;
          }

          @Override
          public void setEnabled(final boolean enabled) {
            this.isEnabled = enabled;
            notifyListeners(enabled);
          }

          @Override
          public void addEnabledStateChangeListener(final EnabledStateChangeListener listener) {
            enabledStateChangeListeners.add(listener);
          }

          @Override
          public String getSignatureId() {
            if (contributionPoint != null) {
              return getClass().getName() + "#" + contributionPoint + "#" + caption;
            }
            return getClass().getName() + "#" + caption;
          }

          @Override
          public Collection<String> getRoles() {
            return roles;
          }

          @Override
          public Collection<String> getTraits() {
            return emptyList();
          }

          private void notifyListeners(final boolean enabled) {
            for (final EnabledStateChangeListener listener : enabledStateChangeListeners) {
              listener.enabledStateChanged(enabled);
            }
          }
        };
      }
      return new MenuItem() {

        private final List<EnabledStateChangeListener> enabledStateChangeListeners =
            new ArrayList<EnabledStateChangeListener>();
        private boolean isEnabled = true;

        @Override
        public String getContributionPoint() {
          return contributionPoint;
        }

        @Override
        public String getCaption() {
          return caption;
        }

        @Override
        public MenuPosition getPosition() {
          return position;
        }

        @Override
        public int getOrder() {
          return order;
        }

        @Override
        public boolean isEnabled() {
          return isEnabled;
        }

        @Override
        public void setEnabled(final boolean enabled) {
          this.isEnabled = enabled;
          notifyListeners(enabled);
        }

        @Override
        public void addEnabledStateChangeListener(final EnabledStateChangeListener listener) {
          enabledStateChangeListeners.add(listener);
        }

        @Override
        public String getSignatureId() {
          if (contributionPoint != null) {
            return getClass().getName() + "#" + contributionPoint + "#" + caption;
          }
          return getClass().getName() + "#" + caption;
        }

        @Override
        public Collection<String> getRoles() {
          return roles;
        }

        @Override
        public Collection<String> getTraits() {
          return emptyList();
        }

        private void notifyListeners(final boolean enabled) {
          for (final EnabledStateChangeListener listener : enabledStateChangeListeners) {
            listener.enabledStateChanged(enabled);
          }
        }
      };
    }
Beispiel #6
0
 public MenuBuilderImpl(final MenuType menuType, final String caption) {
   final CurrentContext currentContext = new CurrentContext();
   currentContext.caption = checkNotEmpty("caption", caption);
   currentContext.menuType = checkNotNull("menuType", menuType);
   context.push(currentContext);
 }