Ejemplo n.º 1
0
  public void addServer(HashMap<String, String> params) {
    Model root = (Model) treeViewer.getInput();
    Server server =
        new Server(
            root,
            params.get("SERVER_NAME"),
            Activator.getImageDescriptor("/icons/disconserver.gif").createImage(display));
    ServerConnect serverConnect =
        new ServerConnect(
            NBLabel.get(0x0099) + " : " + NBLabel.get(0x0098),
            Activator.getImageDescriptor("/icons/net_connect.gif").createImage(display));

    serverConnect.setChannel(params.get("IP_MONADDRESS"));
    serverConnect.setChannelPort(
        Integer.parseInt(params.get("MONPORT").equals("") ? "0" : params.get("MONPORT")));
    serverConnect.setHostAddr(params.get("IP_ADDRESS"));
    serverConnect.setHostPort(
        Integer.parseInt(params.get("PORT").equals("") ? "0" : params.get("PORT")));
    serverConnect.setServerEncoding(params.get("ENCODING"));
    serverConnect.setUser(params.get("USER"));

    server.setConnection(serverConnect);

    if (!params.get("SAVE_FLAG").equals("")) serverConnect.setPassword(params.get("PASSWORD"));

    treeViewer.insert(root, server, -1);
    treeViewer.refresh();
  }
Ejemplo n.º 2
0
  public BackBoard(Composite parent, int style) {
    super(parent, SWT.NONE);

    this.display = parent.getDisplay();

    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    super.setLayout(layout);

    Composite back = new Composite(this, SWT.NONE);
    back.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    back.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true));

    GridLayout backLayout = new GridLayout();
    backLayout.numColumns = 1;
    backLayout.verticalSpacing = 10;
    backLayout.marginWidth = 0;
    backLayout.marginHeight = 0;
    back.setLayout(backLayout);

    GridData titleBarGridData = new GridData(GridData.FILL, GridData.FILL, true, false);
    titleBarGridData.heightHint = 33;

    titleBar = new Canvas(back, SWT.NONE);
    titleBar.setLayoutData(titleBarGridData);
    titleBar.setBackgroundImage(
        Activator.getImageDescriptor("/icons/titleback.gif").createImage(display));

    backLayout = new GridLayout();
    backLayout.horizontalSpacing = 10;
    backLayout.marginWidth = 0;
    backLayout.marginHeight = 3;
    backLayout.marginRight = 10;
    titleBar.setLayout(backLayout);

    paintListener =
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            if (e.widget == titleBar) {
              drawTitle(e);
            }
          }
        };

    titleBar.addPaintListener(paintListener);

    contents = new Composite(back, SWT.NONE);
    GridData contentsGridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    contents.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
    contents.setLayoutData(contentsGridData);

    GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true);
    gridData.horizontalAlignment = SWT.RIGHT;

    toolBar = new ToolBar(titleBar, SWT.FLAT);
    toolBar.setLayoutData(gridData);
    toolBar.setBackgroundImage(
        Activator.getImageDescriptor("/icons/titleback.gif").createImage(display));
  }
Ejemplo n.º 3
0
  public void closeConnection(Server server) {
    try {
      server.getConnect().getProtocol()._close();
    } catch (IOException e) {
      IMessageBox.Error(shell, e.getMessage());
    }

    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());
  }
Ejemplo n.º 4
0
  public boolean connectServer(HashMap<String, String> params) {
    ServerConnect connect = null;
    Server server = null;

    if (!treeViewer.getSelection().isEmpty()) {
      IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();

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

      if (params.containsKey("SAVE_FLAG") && params.get("SAVE_FLAG").equals("true"))
        connect.setPassword(params.get("PASSWORD"));

      params.put("IP_ADDRESS", connect.getHostAddr());
      params.put("PORT", Integer.toString(connect.getHostPort()));
      params.put("ENCODING", connect.getServerEncoding());
    } else if (params.containsKey("SERVER_NAME")) {
      String serverName = params.get("SERVER_NAME");

      ArrayList<Model> children = ((Model) treeViewer.getInput()).getChildren();
      for (int i = 0; i < children.size(); i++) {
        if (serverName.equals(children.get(i).getName())) {
          server = (Server) children.get(i);
          connect = ((Server) children.get(i)).getConnect();
        }
      }

    } else {
      IMessageBox.Error(shell, NBLabel.get(0x0090));
      return true;
    }

    try {
      Socket socket =
          new Socket(params.get("IP_ADDRESS"), Integer.parseInt(params.get("PORT")), 4096, 30);

      InstanceHeaderFields fields = new InstanceHeaderFields();
      fields.put(
          "LENGTH", new TelegramFieldContext("LENGTH", "LENGTH", 0, 4, true, ' ', ' ', 'I', ""));
      fields.put(
          "MSG_TYPE",
          new TelegramFieldContext("MSG_TYPE", "MSG_TYPE", 1, 4, true, ' ', ' ', 'I', ""));
      fields.put(
          "RETURN", new TelegramFieldContext("RETURN", "RETURN", 2, 4, true, ' ', ' ', 'I', ""));
      fields.setLengthFieldIndex("LENGTH");
      fields.setMsgTypeFieldIndex("MSG_TYPE");
      fields.setReturnFieldIndex("RETURN");

      IPCProtocol protocol =
          new IPCProtocol(
              socket, params.get("USER"), params.get("PASSWORD"), fields, params.get("ENCODING"));
      connect.setProtocol(protocol);

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

      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 (NumberFormatException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (NetException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return false;
    } catch (SocketClosedException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (ClassNotFoundException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (TimeoutException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return false;
    } catch (UnsupportedEncodingException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (NoSuchAlgorithmException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (DataTypeException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (ProtocolException e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    } catch (Exception e) {
      try {
        if (connect.getProtocol() != null) connect.getProtocol()._close();
      } catch (IOException e1) {
      }
      IMessageBox.Error(shell, e.getMessage());
      return true;
    }
    return true;
  }