Exemplo n.º 1
0
  private void registContextMenu(Composite parent) {
    IWorkbenchWindow window = getSite().getWorkbenchWindow();

    IWorkbenchAction renameAction = ActionFactory.RENAME.create(window);
    renameAction.setToolTipText(NBLabel.get(0x006B));
    renameAction.setText(NBLabel.get(0x006E));

    IWorkbenchAction refreshAction = ActionFactory.REFRESH.create(window);
    refreshAction.setToolTipText(NBLabel.get(0x025F));
    refreshAction.setText(NBLabel.get(0x0260));

    IWorkbenchAction deleteAction = ActionFactory.DELETE.create(window);
    deleteAction.setToolTipText(NBLabel.get(0x0062));
    deleteAction.setText(NBLabel.get(0x0068));

    MenuManager newMgr = new MenuManager("&New                    ", "file.mnuNew");
    newMgr.add(new NewServerAction(window));
    newMgr.add(new Separator());
    newMgr.add(new GroupMarker("file.new.OTHERS"));

    MenuManager mgr = new MenuManager();
    mgr.add(newMgr);
    mgr.add(new Separator());
    mgr.add(ResourceFactory.CONNECT.create(window));
    mgr.add(ResourceFactory.DISCONNECT.create(window));
    mgr.add(new Separator());
    mgr.add(refreshAction);
    mgr.add(new Separator());
    mgr.add(deleteAction);
    mgr.add(renameAction);
    mgr.add(new Separator());
    mgr.add(new PropertyAction(window));

    Menu menu = mgr.createContextMenu(parent);
    treeViewer.getTree().setMenu(menu);
  }
Exemplo n.º 2
0
 /**
  * Constructs an action for renaming resource.
  *
  * @param page the resource explorer page
  */
 public RenameResourceAction(LibraryExplorerTreeViewPage page) {
   super(Messages.getString("RenameLibraryAction.Text"), page); // $NON-NLS-1$
   setId(ActionFactory.RENAME.getId());
 }
Exemplo n.º 3
0
  private void addRetargetableAction(Composite parent) {
    deleteAction =
        new Action() {
          public void run() {

            ISelection incomming = treeViewer.getSelection();
            if (incomming instanceof IStructuredSelection) {
              if (IMessageBox.Confirm(shell, NBLabel.get(0x0092)) != SWT.OK) return;

              IStructuredSelection selection = (IStructuredSelection) incomming;
              deleteServer((Server) selection.getFirstElement());
            }
          }
        };

    refreshAction =
        new Action() {
          public void run() {
            Server server = null;
            IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();

            if (selection.getFirstElement() instanceof Server) {
              server = (Server) selection.getFirstElement();
            } else {
              IMessageBox.Error(shell, NBLabel.get(0x0091));
              return;
            }

            server.setImage(
                Activator.getImageDescriptor("/icons/disconserver.gif").createImage(display));

            server.removeConfig();
            server.removeUserList();
            server.removeInstance();
            treeViewer.refresh();

            connectAction.setEnabled(true);
            disconnectAction.setEnabled(false);
            refreshAction.setEnabled(false);
            terminateAction.setEnabled(false);

            closeInstanceView(server.getName());

            IPCProtocol protocol =
                ((ServerConnect) ((Server) selection.getFirstElement()).getConnect()).getProtocol();

            NBFields netFields = new NBFields();
            netFields.put(IPC.NB_LOAD_CLASS, "com.nabsys.management.instance.InstanceConfig");
            netFields.put("CMD_CODE", "L");

            try {
              netFields = protocol.execute(netFields);

              if (protocol.getUserAuthority().equals("Admin")) {
                new ServerConfig(
                    server,
                    NBLabel.get(0x0049),
                    Activator.getImageDescriptor("/icons/config_obj.gif").createImage(display));
                new UserList(
                    server,
                    NBLabel.get(0x009D),
                    Activator.getImageDescriptor("/icons/user_view.gif").createImage(display));
                new InstanceList(
                    server,
                    NBLabel.get(0x0093),
                    Activator.getImageDescriptor("/icons/pview.gif").createImage(display));
                terminateAction.setEnabled(true);
              } else if (protocol.getUserAuthority().equals("Operator")) {
                new UserList(
                    server,
                    NBLabel.get(0x009D),
                    Activator.getImageDescriptor("/icons/user_view.gif").createImage(display));
                new InstanceList(
                    server,
                    NBLabel.get(0x0093),
                    Activator.getImageDescriptor("/icons/pview.gif").createImage(display));
              } else if (protocol.getUserAuthority().equals("Developer")) {
                new InstanceList(
                    server,
                    NBLabel.get(0x0093),
                    Activator.getImageDescriptor("/icons/pview.gif").createImage(display));
              }

              server.setImage(
                  Activator.getImageDescriptor("/icons/conserver.gif").createImage(display));
              treeViewer.refresh();

              connectAction.setEnabled(false);
              disconnectAction.setEnabled(true);

              treeViewer.expandToLevel(server, 1);

              openInstanceView(server.getName(), server.getInstance(), netFields, server);
            } catch (SocketClosedException e) {
              IMessageBox.Error(shell, NBLabel.get(0x0090));
              closeConnection();
            } catch (TimeoutException e) {
              IMessageBox.Error(shell, e.getMessage());
            } catch (NetException e) {
              IMessageBox.Error(shell, NBLabel.get(0x0090));
              closeConnection();
            } catch (UnsupportedEncodingException e) {
              IMessageBox.Error(shell, NBLabel.get(0x0090));
              closeConnection();
            } catch (NoSuchAlgorithmException e) {
              IMessageBox.Error(shell, NBLabel.get(0x0090));
              closeConnection();
            } catch (DataTypeException e) {
              IMessageBox.Error(shell, NBLabel.get(0x0090));
              closeConnection();
            } catch (ProtocolException e) {
              IMessageBox.Error(shell, NBLabel.get(0x0090));
              closeConnection();
            }
          }
        };

    renameAction =
        new Action() {
          public void run() {
            final HashMap<String, String> params = new HashMap<String, String>();
            SimpleInputBox inputBox = new SimpleInputBox(shell, params);
            inputBox.setTitle(NBLabel.get(0x009A));
            inputBox.setImage("/icons/topic.gif");
            inputBox.setLabel(NBLabel.get(0x009B));
            inputBox.open(getSite().getWorkbenchWindow(), false);

            if (params.containsKey("EVENT") && params.get("EVENT").equals("CANCEL")) {
              return;
            }

            ISelection incomming = treeViewer.getSelection();
            if (incomming instanceof IStructuredSelection) {
              IStructuredSelection selection = (IStructuredSelection) incomming;
              Server server = (Server) selection.getFirstElement();
              DOMConfigurator config = null;
              try {
                Bundle bundle = Platform.getBundle(Application.PLUGIN_ID);
                URL fileURL =
                    FileLocator.toFileURL(BundleUtility.find(bundle, "configuration/nabee.xml"));

                config = new DOMConfigurator(fileURL.getPath());

                config.modifyConf("monitor/server", server.getName(), params.get("TEXT"));

                if (server.getConnect().isConnect()) {
                  InstanceView instanceView =
                      ((InstanceView)
                          getSite().getWorkbenchWindow().getActivePage().findView(InstanceView.ID));
                  if (instanceView.getPartProperty("SERVER_NAME").equals(server.getName())) {
                    instanceView.serverNameChanged(params.get("TEXT"));
                  }
                }

                server.setName(params.get("TEXT"));
                treeViewer.refresh();

              } catch (ParserConfigurationException e) {
                IMessageBox.Error(shell, NBLabel.get(0x008F));
                return;
              } catch (TransformerException e) {
                IMessageBox.Error(shell, NBLabel.get(0x008F));
                return;
              } catch (IOException e) {
                IMessageBox.Error(shell, NBLabel.get(0x008F));
                return;
              } catch (SAXException e) {
                IMessageBox.Error(shell, NBLabel.get(0x008F));
                return;
              } catch (Exception e) {
                IMessageBox.Error(shell, NBLabel.get(0x008F));
                return;
              }
            }
          }
        };

    terminateAction =
        new TerminateAction(getSite().getWorkbenchWindow()) {
          public void run() {

            IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();

            if (selection.getFirstElement() instanceof Server) {
              Server server = (Server) selection.getFirstElement();

              if (IMessageBox.Confirm(shell, "[" + server.getName() + "] " + NBLabel.get(0x022B))
                  != SWT.OK) return;

              IPCProtocol protocol =
                  ((ServerConnect) ((Server) selection.getFirstElement()).getConnect())
                      .getProtocol();
              boolean rtn = controlServer(IPC.CMD_SHUTDOWN, protocol);

              if (rtn) {
                disconnectServer(false);
                setEnabled(false);
              }
            }
          }

          public void selectionChanged(IWorkbenchPart part, ISelection incoming) {
            if (incoming instanceof IStructuredSelection) {
              IStructuredSelection selection = (IStructuredSelection) incoming;

              if (selection.getFirstElement() != null
                  && selection.getFirstElement() instanceof Server) {
                IPCProtocol protocol =
                    ((Server) selection.getFirstElement()).getConnect().getProtocol();
                if (selection.size() == 1
                    && selection.getFirstElement() instanceof Server
                    && protocol != null) {
                  setEnabled(protocol.getUserAuthority().equals("Admin") && protocol.isConnected());
                } else {
                  setEnabled(false);
                }
              } else {
                setEnabled(false);
              }
            } else {
              setEnabled(false);
            }
          }
        };

    connectAction = new ConnectAction(getSite().getWorkbenchWindow());
    disconnectAction = new DisconnectAction(getSite().getWorkbenchWindow());

    IActionBars actionBars = getViewSite().getActionBars();

    actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), deleteAction);
    actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), renameAction);
    actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
    actionBars.setGlobalActionHandler("connect", connectAction);
    actionBars.setGlobalActionHandler("disconnect", disconnectAction);
    actionBars.setGlobalActionHandler(ResourceFactory.TERMINATE.getId(), terminateAction);
  }
  @Override
  public void buildContextMenu(final IMenuManager menu) {
    IAction action;
    GEFActionConstants.addStandardActionGroups(menu);

    // Undo
    action = getActionRegistry().getAction(ActionFactory.UNDO.getId());
    menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);

    // Redo
    action = getActionRegistry().getAction(ActionFactory.REDO.getId());
    menu.appendToGroup(GEFActionConstants.GROUP_UNDO, action);

    // Delete
    action = getActionRegistry().getAction(ActionFactory.DELETE.getId());
    menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);

    // Rename
    action = getActionRegistry().getAction(ActionFactory.RENAME.getId());
    menu.appendToGroup(GEFActionConstants.GROUP_EDIT, action);

    // Color
    action = getActionRegistry().getAction(ChangeColorAction.changeColorProperty);
    menu.appendToGroup(GEFActionConstants.GROUP_VIEW, action);

    // Opacity
    final MenuManager opacitySubmenu = new MenuManager("Figure opacity"); // $NON-NLS-1$

    action = getActionRegistry().getAction(OpacityTenAction.opacityPropertyTen);
    opacitySubmenu.add(action);

    action = getActionRegistry().getAction(OpacityTwentyAction.opacityPropertyTwenty);
    opacitySubmenu.add(action);

    action = getActionRegistry().getAction(OpacityFourtyAction.opacityPropertyFourty);
    opacitySubmenu.add(action);

    action = getActionRegistry().getAction(OpacitySixtyAction.opacityPropertySixty);
    opacitySubmenu.add(action);

    action = getActionRegistry().getAction(OpacityEightyAction.opacityPropertyEighty);
    opacitySubmenu.add(action);

    action = getActionRegistry().getAction(OpacityHundredAction.opacityPropertyHundred);
    opacitySubmenu.add(action);

    menu.appendToGroup(GEFActionConstants.GROUP_VIEW, opacitySubmenu);

    // Font Style
    final MenuManager fontStyleSubmenu = new MenuManager("Font style"); // $NON-NLS-1$

    action = getActionRegistry().getAction(FontStyleNormalAction.fontStylePropertyNormal);
    fontStyleSubmenu.add(action);

    action = getActionRegistry().getAction(FontStyleBoldAction.fontStylePropertyBold);
    fontStyleSubmenu.add(action);

    action = getActionRegistry().getAction(FontStyleItalicAction.fontStylePropertyItalic);
    fontStyleSubmenu.add(action);

    action = getActionRegistry().getAction(FontStyleBoldItalicAction.fontStylePropertyBoldItalic);
    fontStyleSubmenu.add(action);

    menu.appendToGroup(GEFActionConstants.GROUP_REST, fontStyleSubmenu);

    // Font Size
    final MenuManager fontSizeSubmenu = new MenuManager("Font size"); // $NON-NLS-1$

    action = getActionRegistry().getAction(FontSizeSevenAction.fontSizePropertySeven);
    fontSizeSubmenu.add(action);

    action = getActionRegistry().getAction(FontSizeNineAction.fontSizePropertyNine);
    fontSizeSubmenu.add(action);

    action = getActionRegistry().getAction(FontSizeTenAction.fontSizePropertyTen);
    fontSizeSubmenu.add(action);

    action = getActionRegistry().getAction(FontSizeThirteenAction.fontSizePropertyThirteen);
    fontSizeSubmenu.add(action);

    action = getActionRegistry().getAction(FontSizeSixteenAction.fontSizePropertySixteen);
    fontSizeSubmenu.add(action);

    action = getActionRegistry().getAction(FontSizeTwentyAction.fontSizePropertyTwenty);
    fontSizeSubmenu.add(action);

    action = getActionRegistry().getAction(FontSizeTwentyfiveAction.fontSizePropertyTwentyfive);
    fontSizeSubmenu.add(action);

    menu.appendToGroup(GEFActionConstants.GROUP_REST, fontSizeSubmenu);

    // Font Color
    action = getActionRegistry().getAction(FontColorAction.fontColorProperty);
    menu.appendToGroup(GEFActionConstants.GROUP_REST, action);

    // Label Color
    action = getActionRegistry().getAction(ChangeLabelColorAction.changeLabelColorProperty);
    menu.appendToGroup(GEFActionConstants.GROUP_REST, action);
  }