Ejemplo n.º 1
0
    public JComponent[] getMenuPresenters() {
      assert SwingUtilities.isEventDispatchThread() : "Must be called from AWT";
      removeAll();
      final TopComponent tc = WindowManager.getDefault().getRegistry().getActivated();
      if (tc != null) {
        setEnabled(true);
        MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
        if (handler != null) {
          ButtonGroup group = new ButtonGroup();
          MultiViewPerspective[] pers = handler.getPerspectives();
          final String[] names = new String[pers.length];
          for (int i = 0; i < pers.length; i++) {
            MultiViewPerspective thisPers = pers[i];

            JRadioButtonMenuItem item = new JRadioButtonMenuItem();
            names[i] = thisPers.getDisplayName();
            Mnemonics.setLocalizedText(item, thisPers.getDisplayName());
            item.setActionCommand(thisPers.getDisplayName());
            item.addActionListener(
                new ActionListener() {
                  public void actionPerformed(ActionEvent event) {
                    MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
                    if (handler == null) {
                      return;
                    }
                    MultiViewPerspective thisPers = null;
                    MultiViewPerspective[] pers = handler.getPerspectives();
                    assert pers.length == names.length : "Arrays must have the same length";
                    for (int i = 0; i < pers.length; i++) {
                      if (event.getActionCommand().equals(names[i])) {
                        thisPers = pers[i];
                        break;
                      }
                    }
                    if (thisPers != null) {
                      handler.requestActive(thisPers);
                    }
                  }
                });
            if (thisPers
                .getDisplayName()
                .equals(handler.getSelectedPerspective().getDisplayName())) {
              item.setSelected(true);
            }
            group.add(item);
            add(item);
          }
        } else { // handler == null
          // No reason to enable action on any TC because now it was enabled even for Welcome page
          setEnabled(false);
          /*JRadioButtonMenuItem but = new JRadioButtonMenuItem();
          Mnemonics.setLocalizedText(but, NbBundle.getMessage(EditorsAction.class, "EditorsAction.source"));
          but.setSelected(true);
          add(but);*/
        }
      } else { // tc == null
        setEnabled(false);
      }
      return new JComponent[] {this};
    }
Ejemplo n.º 2
0
 /**
  * Shows the desired multiview element. Must be called after the editor has been opened (i.e.
  * WSDLEditorSupport.open()) so the TopComponent will be the active one in the registry.
  *
  * @param id identifier of the multiview element.
  */
 public static void requestMultiviewActive(String id) {
   TopComponent activeTC = TopComponent.getRegistry().getActivated();
   MultiViewHandler handler = MultiViews.findMultiViewHandler(activeTC);
   if (handler != null) {
     MultiViewPerspective[] perspectives = handler.getPerspectives();
     for (MultiViewPerspective perspective : perspectives) {
       if (perspective.preferredID().equals(id)) {
         handler.requestActive(perspective);
       }
     }
   }
 }