private void contributeToActionBars() {
   IActionBars bars = getViewSite().getActionBars();
   fillLocalPullDown(bars.getMenuManager());
   fillLocalToolBar(bars.getToolBarManager());
   bars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), fRefreshAction);
   bars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction);
   bars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fPropertiesAction);
 }
Beispiel #2
0
  @Override
  protected void initPage(IPageBookViewPage page) {
    super.initPage(page);
    IActionBars actionBars = page.getSite().getActionBars();
    actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), fSearchAgainAction);
    actionBars.updateActionBars();

    fUndoRedoActionGroup.fillActionBars(actionBars);

    ISearchResultPage srPage = (ISearchResultPage) page;
    IMemento memento = null;
    if (fPageState != null) {
      IMemento[] mementos = fPageState.getChildren(MEMENTO_TYPE);
      for (int i = 0; i < mementos.length; i++) {
        if (mementos[i].getID().equals(srPage.getID())) {
          memento = mementos[i];
          break;
        }
      }
    }
    srPage.restoreState(memento);
  }
Beispiel #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);
  }