Example #1
0
  /** Loads info from xml that is supplied as an argument to the internal data objects. */
  public void loadXML(final String xml) {
    final Document document = getXMLDocument(xml);
    if (document == null) {
      return;
    }
    /* get root <drbdgui> */
    final Node rootNode = getChildNode(document, "drbdgui");
    final Map<String, List<Host>> hostMap = new LinkedHashMap<String, List<Host>>();
    if (rootNode != null) {
      /* download area */
      final String downloadUser = getAttribute(rootNode, DOWNLOAD_USER_ATTR);
      final String downloadPasswd = getAttribute(rootNode, DOWNLOAD_PASSWD_ATTR);
      if (downloadUser != null && downloadPasswd != null) {
        Tools.getConfigData().setDownloadLogin(downloadUser, downloadPasswd, true);
      }
      /* hosts */
      final Node hostsNode = getChildNode(rootNode, "hosts");
      if (hostsNode != null) {
        final NodeList hosts = hostsNode.getChildNodes();
        if (hosts != null) {
          for (int i = 0; i < hosts.getLength(); i++) {
            final Node hostNode = hosts.item(i);
            if (hostNode.getNodeName().equals(HOST_NODE_STRING)) {
              final String nodeName = getAttribute(hostNode, HOST_NAME_ATTR);
              final String sshPort = getAttribute(hostNode, HOST_SSHPORT_ATTR);
              final String color = getAttribute(hostNode, HOST_COLOR_ATTR);
              final String useSudo = getAttribute(hostNode, HOST_USESUDO_ATTR);
              final Node ipNode = getChildNode(hostNode, "ip");
              String ip = null;
              if (ipNode != null) {
                ip = getText(ipNode);
              }
              final Node usernameNode = getChildNode(hostNode, "user");
              final String username = getText(usernameNode);
              setHost(
                  hostMap, username, nodeName, ip, sshPort, color, "true".equals(useSudo), true);
            }
          }
        }
      }

      /* clusters */
      final Node clustersNode = getChildNode(rootNode, "clusters");
      if (clustersNode != null) {
        final NodeList clusters = clustersNode.getChildNodes();
        if (clusters != null) {
          for (int i = 0; i < clusters.getLength(); i++) {
            final Node clusterNode = clusters.item(i);
            if (clusterNode.getNodeName().equals("cluster")) {
              final String clusterName = getAttribute(clusterNode, CLUSTER_NAME_ATTR);
              final Cluster cluster = new Cluster();
              cluster.setName(clusterName);
              Tools.getConfigData().addClusterToClusters(cluster);
              loadClusterHosts(clusterNode, cluster, hostMap);
            }
          }
        }
      }
    }
  }
Example #2
0
  /**
   * Creates body of the dialog. You can redefine getDialogTitle(), getDescription(), getInputPane()
   * methods to customize this body.
   */
  protected final JPanel body() {
    final JPanel pane = new JPanel();
    pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));
    final JEditorPane descPane =
        new JEditorPane(
            Tools.MIME_TYPE_TEXT_HTML,
            "<span style='font:bold italic;font-family:Dialog; font-size:"
                + Tools.getConfigData().scaled(14)
                + ";'>"
                + getDialogTitle()
                + "</span><br>"
                + "<span style='font-family:Dialog; font-size:"
                + Tools.getConfigData().scaled(12)
                + ";'>"
                + getDescription()
                + "</span>");
    descPane.setSize(300, Integer.MAX_VALUE);

    descPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background"));
    descPane.setEditable(false);
    final JScrollPane descSP = new JScrollPane(descPane);
    descSP.setBorder(null);
    descSP.setAlignmentX(Component.LEFT_ALIGNMENT);
    descSP.setMinimumSize(new Dimension(0, 50));
    pane.add(descSP);
    final JComponent inputPane = getInputPane();
    if (inputPane != null) {
      inputPane.setMinimumSize(new Dimension(Short.MAX_VALUE, INPUT_PANE_HEIGHT));
      inputPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background"));
      inputPane.setAlignmentX(Component.LEFT_ALIGNMENT);
      pane.add(inputPane);
    }
    pane.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light"));
    return pane;
  }
Example #3
0
 /** Prepares a new <code>CusterBrowser</code> object. */
 EmptyBrowser() {
   super();
   /* Load the default file */
   final String saveFile = Tools.getConfigData().getSaveFile();
   String xml = Tools.loadFile(saveFile, false);
   if (xml == null) {
     final String saveFileOld = Tools.getConfigData().getSaveFileOld();
     xml = Tools.loadFile(saveFileOld, false);
   }
   if (xml != null) {
     Tools.loadXML(xml);
   }
   setTreeTop();
 }
Example #4
0
 /** Inits the dialog after it becomes visible. */
 @Override
 protected void initDialogAfterVisible() {
   final DrbdResourceInfo dri = getDrbdVolumeInfo().getDrbdResourceInfo();
   final boolean ch = dri.checkResourceFieldsChanged(null, PARAMS);
   final boolean cor = dri.checkResourceFieldsCorrect(null, PARAMS);
   if (cor) {
     enableComponents();
   } else {
     /* don't enable */
     enableComponents(new JComponent[] {buttonClass(nextButton())});
   }
   SwingUtilities.invokeLater(
       new Runnable() {
         public void run() {
           makeDefaultButton(buttonClass(nextButton()));
         }
       });
   if (Tools.getConfigData().getAutoOptionGlobal("autodrbd") != null) {
     SwingUtilities.invokeLater(
         new Runnable() {
           @Override
           public void run() {
             pressNextButton();
           }
         });
   }
 }
Example #5
0
  /** Create host object and initialize it from user config. */
  public void setHost(
      final Map<String, List<Host>> hostMap,
      String username,
      final String nodeName,
      final String ip,
      String sshPort,
      final String color,
      final boolean sudo,
      final boolean savable) {
    Tools.getConfigData().setLastEnteredUser(username);
    final Host host = new Host();
    host.setSavable(savable);
    host.setHostname(nodeName);
    if (sshPort == null) {
      sshPort = "22";
    }
    host.setSSHPort(sshPort);
    Tools.getConfigData().setLastEnteredSSHPort(sshPort);
    if (color != null) {
      host.setSavedColor(color);
    }
    host.setUseSudo(sudo);
    Tools.getConfigData().setLastEnteredUseSudo(sudo);
    Tools.getConfigData().addHostToHosts(host);

    new TerminalPanel(host);
    host.setIp(ip);
    if (username == null && sudo) {
      username = System.getProperty("user.name");
    }
    if (username == null) {
      username = Host.ROOT_USER;
    }
    host.setUsername(username);
    List<Host> hostList = hostMap.get(nodeName);
    if (hostList == null) {
      hostList = new ArrayList<Host>();
      hostMap.put(nodeName, hostList);
    }
    hostList.add(host);
  }
Example #6
0
 /** Update menus with positions and calles their update methods. */
 @Override
 void updateMenus(final Point2D pos) {
   super.updateMenus(pos);
   if (!Tools.getConfigData().isSlow()) {
     final ClusterStatus cs = getBrowser().getClusterStatus();
     final List<String> resources = cs.getGroupResources(getHeartbeatId(false), false);
     if (resources != null) {
       for (final String hbId : resources) {
         final ServiceInfo si = getBrowser().getServiceInfoFromCRMId(hbId);
         if (si != null) {
           si.updateMenus(pos);
         }
       }
     }
   }
 }
Example #7
0
 /** Updates resources of a cluster in the tree. */
 void updateHosts() {
   /* all hosts */
   final Host[] allHosts = Tools.getConfigData().getHosts().getHostsArray();
   SwingUtilities.invokeLater(
       new Runnable() {
         @Override
         public void run() {
           DefaultMutableTreeNode resource;
           allHostsNode.removeAllChildren();
           for (Host host : allHosts) {
             final HostBrowser hostBrowser = host.getBrowser();
             resource = new DefaultMutableTreeNode(hostBrowser.getHostInfo());
             // setNode(resource);
             allHostsNode.add(resource);
           }
         }
       });
   reload(allHostsNode, false);
   selectPath(new Object[] {getTreeTop(), allHostsNode});
 }
Example #8
0
 /** Starts specified clusters and connects to the hosts of this clusters. */
 public void startClusters(final List<Cluster> selectedClusters) {
   final Set<Cluster> clusters = Tools.getConfigData().getClusters().getClusterSet();
   if (clusters != null) {
     /* clusters */
     for (final Cluster cluster : clusters) {
       if (selectedClusters != null && !selectedClusters.contains(cluster)) {
         continue;
       }
       Tools.getGUIData().addClusterTab(cluster);
       if (cluster.getHosts().isEmpty()) {
         continue;
       }
       final boolean ok = cluster.connect(null, true, 1);
       if (!ok) {
         Tools.getGUIData().getClustersPanel().removeTab(cluster);
         continue;
       }
       final Runnable runnable =
           new Runnable() {
             @Override
             public void run() {
               for (final Host host : cluster.getHosts()) {
                 host.waitOnLoading();
               }
               cluster.getClusterTab().addClusterView();
               SwingUtilities.invokeLater(
                   new Runnable() {
                     public void run() {
                       cluster.getClusterTab().requestFocus();
                     }
                   });
             }
           };
       final Thread thread = new Thread(runnable);
       thread.start();
     }
   }
 }
Example #9
0
  /** Returns items for the group popup. */
  @Override
  public List<UpdatableItem> createPopup() {
    final boolean testOnly = false;
    final GroupInfo thisGroupInfo = this;
    /* add group service */
    final MyMenu addGroupServiceMenuItem =
        new MyMenu(
            Tools.getString("ClusterBrowser.Hb.AddGroupService"),
            new AccessMode(ConfigData.AccessType.ADMIN, false),
            new AccessMode(ConfigData.AccessType.OP, false)) {
          private static final long serialVersionUID = 1L;
          private final Lock mUpdateLock = new ReentrantLock();

          @Override
          public String enablePredicate() {
            if (getBrowser().clStatusFailed()) {
              return ClusterBrowser.UNKNOWN_CLUSTER_STATUS_STRING;
            } else {
              return null;
            }
          }

          @Override
          public void update() {
            final Thread t =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (mUpdateLock.tryLock()) {
                          try {
                            updateThread();
                          } finally {
                            mUpdateLock.unlock();
                          }
                        }
                      }
                    });
            t.start();
          }

          private void updateThread() {
            Tools.invokeLater(
                new Runnable() {
                  @Override
                  public void run() {
                    setEnabled(false);
                  }
                });
            Tools.invokeAndWait(
                new Runnable() {
                  @Override
                  public void run() {
                    removeAll();
                  }
                });
            final List<JDialog> popups = new ArrayList<JDialog>();
            for (final String cl : ClusterBrowser.HB_CLASSES) {
              final MyMenu classItem =
                  new MyMenu(
                      ClusterBrowser.HB_CLASS_MENU.get(cl),
                      new AccessMode(ConfigData.AccessType.ADMIN, false),
                      new AccessMode(ConfigData.AccessType.OP, false));
              MyListModel<MyMenuItem> dlm = new MyListModel<MyMenuItem>();
              for (final ResourceAgent ra : getAddGroupServiceList(cl)) {
                final MyMenuItem mmi =
                    new MyMenuItem(
                        ra.getMenuName(),
                        null,
                        null,
                        new AccessMode(ConfigData.AccessType.ADMIN, false),
                        new AccessMode(ConfigData.AccessType.OP, false)) {
                      private static final long serialVersionUID = 1L;

                      @Override
                      public void action() {
                        final CloneInfo ci = getCloneInfo();
                        if (ci != null) {
                          ci.hidePopup();
                        }
                        hidePopup();
                        for (final JDialog otherP : popups) {
                          otherP.dispose();
                        }
                        if (ra.isLinbitDrbd() && !getBrowser().linbitDrbdConfirmDialog()) {
                          return;
                        }
                        addGroupServicePanel(ra, true);
                        repaint();
                      }
                    };
                dlm.addElement(mmi);
              }
              final boolean ret =
                  Tools.getScrollingMenu(
                      ClusterBrowser.HB_CLASS_MENU.get(cl),
                      null, /* options */
                      classItem,
                      dlm,
                      new MyList<MyMenuItem>(dlm, getBackground()),
                      thisGroupInfo,
                      popups,
                      null);
              if (!ret) {
                classItem.setEnabled(false);
              }
              Tools.invokeLater(
                  new Runnable() {
                    @Override
                    public void run() {
                      add(classItem);
                    }
                  });
            }
            Tools.waitForSwing();
            super.update();
          }
        };
    final List<UpdatableItem> items = new ArrayList<UpdatableItem>();
    items.add((UpdatableItem) addGroupServiceMenuItem);
    for (final UpdatableItem item : super.createPopup()) {
      items.add(item);
    }

    /* group services */
    if (!Tools.getConfigData().isSlow()) {
      final ClusterStatus cs = getBrowser().getClusterStatus();
      final List<String> resources = cs.getGroupResources(getHeartbeatId(testOnly), testOnly);
      if (resources != null) {
        for (final String hbId : resources) {
          final ServiceInfo gsi = getBrowser().getServiceInfoFromCRMId(hbId);
          if (gsi == null) {
            continue;
          }
          final MyMenu groupServicesMenu =
              new MyMenu(
                  gsi.toString(),
                  new AccessMode(ConfigData.AccessType.RO, false),
                  new AccessMode(ConfigData.AccessType.RO, false)) {
                private static final long serialVersionUID = 1L;
                private final Lock mUpdateLock = new ReentrantLock();

                @Override
                public String enablePredicate() {
                  return null;
                }

                @Override
                public void update() {
                  final Thread t =
                      new Thread(
                          new Runnable() {
                            @Override
                            public void run() {
                              if (mUpdateLock.tryLock()) {
                                try {
                                  updateThread();
                                } finally {
                                  mUpdateLock.unlock();
                                }
                              }
                            }
                          });
                  t.start();
                }

                public void updateThread() {
                  Tools.invokeLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          setEnabled(false);
                        }
                      });
                  Tools.invokeAndWait(
                      new Runnable() {
                        @Override
                        public void run() {
                          removeAll();
                        }
                      });
                  final List<UpdatableItem> serviceMenus = new ArrayList<UpdatableItem>();
                  for (final UpdatableItem u : gsi.createPopup()) {
                    serviceMenus.add(u);
                    u.update();
                  }
                  Tools.invokeLater(
                      new Runnable() {
                        @Override
                        public void run() {
                          for (final UpdatableItem u : serviceMenus) {
                            add((JMenuItem) u);
                          }
                        }
                      });
                  super.update();
                }
              };
          items.add((UpdatableItem) groupServicesMenu);
        }
      }
    }
    return items;
  }
Example #10
0
  /** Saves data about clusters and hosts to the supplied output stream. */
  public String saveXML(final OutputStream outputStream, final boolean saveAll) throws IOException {
    final String encoding = "UTF-8";
    final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = null;

    try {
      db = dbf.newDocumentBuilder();
    } catch (ParserConfigurationException pce) {
      assert false;
    }
    final Document doc = db.newDocument();
    final Element root = (Element) doc.appendChild(doc.createElement("drbdgui"));
    if (Tools.getConfigData().getLoginSave()) {
      final String downloadUser = Tools.getConfigData().getDownloadUser();
      final String downloadPasswd = Tools.getConfigData().getDownloadPassword();
      if (downloadUser != null && downloadPasswd != null) {
        root.setAttribute(DOWNLOAD_USER_ATTR, downloadUser);
        root.setAttribute(DOWNLOAD_PASSWD_ATTR, downloadPasswd);
      }
    }
    final Element hosts = (Element) root.appendChild(doc.createElement("hosts"));
    for (final Host host : Tools.getConfigData().getHosts().getHostSet()) {
      if (!saveAll && !host.isSavable()) {
        continue;
      }
      host.setSavable(true);
      final String hostName = host.getHostname();
      final String ip = host.getIp();
      final String username = host.getUsername();
      final String sshPort = host.getSSHPort();
      final Boolean useSudo = host.isUseSudo();
      final String color = host.getColor();
      final Element hostNode = (Element) hosts.appendChild(doc.createElement(HOST_NODE_STRING));
      hostNode.setAttribute(HOST_NAME_ATTR, hostName);
      hostNode.setAttribute(HOST_SSHPORT_ATTR, sshPort);
      if (color != null) {
        hostNode.setAttribute(HOST_COLOR_ATTR, color);
      }
      if (useSudo != null && useSudo) {
        hostNode.setAttribute(HOST_USESUDO_ATTR, "true");
      }
      if (ip != null) {
        final Node ipNode = (Element) hostNode.appendChild(doc.createElement("ip"));

        ipNode.appendChild(doc.createTextNode(ip));
      }
      if (username != null) {
        final Node usernameNode = (Element) hostNode.appendChild(doc.createElement("user"));

        usernameNode.appendChild(doc.createTextNode(username));
      }
    }
    final Element clusters = (Element) root.appendChild(doc.createElement("clusters"));

    final Set<Cluster> clusterSet = Tools.getConfigData().getClusters().getClusterSet();
    for (final Cluster cluster : clusterSet) {
      if (!saveAll && !cluster.isSavable()) {
        continue;
      }
      cluster.setSavable(true);
      final String clusterName = cluster.getName();
      final Element clusterNode = (Element) clusters.appendChild(doc.createElement("cluster"));
      clusterNode.setAttribute(CLUSTER_NAME_ATTR, clusterName);
      for (final Host host : cluster.getHosts()) {
        final String hostName = host.getHostname();
        final Element hostNode =
            (Element) clusterNode.appendChild(doc.createElement(HOST_NODE_STRING));
        hostNode.appendChild(doc.createTextNode(hostName));
      }
    }

    final TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = null;
    try {
      t = tf.newTransformer();
      t.setOutputProperty(OutputKeys.INDENT, "yes");
      t.setOutputProperty(OutputKeys.METHOD, "xml");
      t.setOutputProperty(OutputKeys.ENCODING, encoding);
    } catch (TransformerConfigurationException tce) {
      assert false;
    }
    final DOMSource doms = new DOMSource(doc);
    final StreamResult sr = new StreamResult(outputStream);
    try {
      t.transform(doms, sr);
    } catch (TransformerException te) {
      final IOException ioe = new IOException();
      ioe.initCause(te);
      throw ioe;
    }
    return "";
  }
Example #11
0
  /** Returns info panel. */
  @Override
  public JComponent getInfoPanel() {
    if (getBrowser().getClusterBrowser() == null) {
      return new JPanel();
    }
    final Font f = new Font("Monospaced", Font.PLAIN, Tools.getConfigData().scaled(12));
    crmShowInProgress = true;
    final JTextArea ta = new JTextArea(Tools.getString("HostInfo.crmShellLoading"));
    ta.setEditable(false);
    ta.setFont(f);

    final MyButton crmConfigureCommitButton =
        new MyButton(Tools.getString("HostInfo.crmShellCommitButton"), Browser.APPLY_ICON);
    registerComponentEnableAccessMode(
        crmConfigureCommitButton, new AccessMode(ConfigData.AccessType.ADMIN, false));
    final MyButton hostInfoButton = new MyButton(Tools.getString("HostInfo.crmShellStatusButton"));
    hostInfoButton.miniButton();

    final MyButton crmConfigureShowButton =
        new MyButton(Tools.getString("HostInfo.crmShellShowButton"));
    crmConfigureShowButton.miniButton();
    crmConfigureCommitButton.setEnabled(false);
    final ExecCallback execCallback =
        new ExecCallback() {
          @Override
          public void done(final String ans) {
            ta.setText(ans);
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    crmConfigureShowButton.setEnabled(true);
                    hostInfoButton.setEnabled(true);
                    crmShowInProgress = false;
                  }
                });
          }

          @Override
          public void doneError(final String ans, final int exitCode) {
            ta.setText(ans);
            Tools.sshError(host, "", ans, "", exitCode);
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    crmConfigureCommitButton.setEnabled(false);
                  }
                });
          }
        };
    hostInfoButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            registerComponentEditAccessMode(ta, new AccessMode(ConfigData.AccessType.GOD, false));
            crmInfo = true;
            hostInfoButton.setEnabled(false);
            crmConfigureCommitButton.setEnabled(false);
            String command = "HostBrowser.getHostInfo";
            if (!host.isCsInit()) {
              command = "HostBrowser.getHostInfoHeartbeat";
            }
            host.execCommand(
                command,
                execCallback,
                null, /* ConvertCmdCallback */
                false, /* outputVisible */
                SSH.DEFAULT_COMMAND_TIMEOUT);
          }
        });
    host.registerEnableOnConnect(hostInfoButton);

    crmConfigureShowButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            registerComponentEditAccessMode(ta, new AccessMode(ConfigData.AccessType.ADMIN, false));
            updateAdvancedPanels();
            crmShowInProgress = true;
            crmInfo = false;
            crmConfigureShowButton.setEnabled(false);
            crmConfigureCommitButton.setEnabled(false);
            host.execCommand(
                "HostBrowser.getCrmConfigureShow",
                execCallback,
                null, /* ConvertCmdCallback */
                false, /* outputVisible */
                SSH.DEFAULT_COMMAND_TIMEOUT);
          }
        });
    final CRMGraph crmg = getBrowser().getClusterBrowser().getCRMGraph();
    final Document taDocument = ta.getDocument();
    taDocument.addDocumentListener(
        new DocumentListener() {
          private void update() {
            if (!crmShowInProgress && !crmInfo) {
              crmConfigureCommitButton.setEnabled(true);
            }
          }

          public void changedUpdate(final DocumentEvent documentEvent) {
            update();
          }

          public void insertUpdate(final DocumentEvent documentEvent) {
            update();
          }

          public void removeUpdate(final DocumentEvent documentEvent) {
            update();
          }
        });

    final ButtonCallback buttonCallback =
        new ButtonCallback() {
          private volatile boolean mouseStillOver = false;

          /** Whether the whole thing should be enabled. */
          @Override
          public boolean isEnabled() {
            if (Tools.versionBeforePacemaker(host)) {
              return false;
            }
            return true;
          }

          @Override
          public void mouseOut() {
            if (!isEnabled()) {
              return;
            }
            mouseStillOver = false;
            crmg.stopTestAnimation(crmConfigureCommitButton);
            crmConfigureCommitButton.setToolTipText(null);
          }

          @Override
          public void mouseOver() {
            if (!isEnabled()) {
              return;
            }
            mouseStillOver = true;
            crmConfigureCommitButton.setToolTipText(ClusterBrowser.STARTING_PTEST_TOOLTIP);
            crmConfigureCommitButton.setToolTipBackground(
                Tools.getDefaultColor("ClusterBrowser.Test.Tooltip.Background"));
            Tools.sleep(250);
            if (!mouseStillOver) {
              return;
            }
            mouseStillOver = false;
            final CountDownLatch startTestLatch = new CountDownLatch(1);
            crmg.startTestAnimation(crmConfigureCommitButton, startTestLatch);
            final Host dcHost = getBrowser().getClusterBrowser().getDCHost();
            getBrowser().getClusterBrowser().ptestLockAcquire();
            final ClusterStatus clStatus = getBrowser().getClusterBrowser().getClusterStatus();
            clStatus.setPtestData(null);
            CRM.crmConfigureCommit(host, ta.getText(), true);
            final PtestData ptestData = new PtestData(CRM.getPtest(dcHost));
            crmConfigureCommitButton.setToolTipText(ptestData.getToolTip());
            clStatus.setPtestData(ptestData);
            getBrowser().getClusterBrowser().ptestLockRelease();
            startTestLatch.countDown();
          }
        };
    addMouseOverListener(crmConfigureCommitButton, buttonCallback);
    crmConfigureCommitButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            crmConfigureCommitButton.setEnabled(false);
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        getBrowser().getClusterBrowser().clStatusLock();
                        final String ret = CRM.crmConfigureCommit(host, ta.getText(), false);
                        getBrowser().getClusterBrowser().clStatusUnlock();
                      }
                    });
            thread.start();
          }
        });

    final JPanel mainPanel = new JPanel();
    mainPanel.setBackground(HostBrowser.PANEL_BACKGROUND);
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));

    final JPanel buttonPanel = new JPanel(new BorderLayout());
    buttonPanel.setBackground(HostBrowser.BUTTON_PANEL_BACKGROUND);
    buttonPanel.setMinimumSize(new Dimension(0, 50));
    buttonPanel.setPreferredSize(new Dimension(0, 50));
    buttonPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 50));
    mainPanel.add(buttonPanel);

    /* Actions */
    buttonPanel.add(getActionsButton(), BorderLayout.EAST);
    final JPanel p = new JPanel(new SpringLayout());
    p.setBackground(HostBrowser.BUTTON_PANEL_BACKGROUND);

    p.add(hostInfoButton);
    p.add(crmConfigureShowButton);
    p.add(crmConfigureCommitButton);

    p.add(new JLabel(""));
    SpringUtilities.makeCompactGrid(
        p, 1, 3, // rows, cols
        1, 1, // initX, initY
        1, 1); // xPad, yPad
    mainPanel.setMinimumSize(
        new Dimension(
            Tools.getDefaultSize("HostBrowser.ResourceInfoArea.Width"),
            Tools.getDefaultSize("HostBrowser.ResourceInfoArea.Height")));
    mainPanel.setPreferredSize(
        new Dimension(
            Tools.getDefaultSize("HostBrowser.ResourceInfoArea.Width"),
            Tools.getDefaultSize("HostBrowser.ResourceInfoArea.Height")));
    buttonPanel.add(p);
    mainPanel.add(new JLabel(Tools.getString("HostInfo.crmShellInfo")));
    mainPanel.add(new JScrollPane(ta));
    String command = "HostBrowser.getHostInfo";
    if (!host.isCsInit()) {
      command = "HostBrowser.getHostInfoHeartbeat";
    }
    host.execCommand(
        command,
        execCallback,
        null, /* ConvertCmdCallback */
        false, /* outputVisible */
        SSH.DEFAULT_COMMAND_TIMEOUT);
    return mainPanel;
  }
Example #12
0
  /** Prepares a new <code>TerminalPanel</code> object. */
  public TerminalPanel(final Host host) {
    super();
    this.host = host;
    host.setTerminalPanel(this);
    /* Sets terminal some of the output colors. This is in no way complete
     * or correct and probably doesn't have to be. */
    terminalColor.put("0", Tools.getDefaultColor("TerminalPanel.TerminalWhite"));
    terminalColor.put("30", Tools.getDefaultColor("TerminalPanel.TerminalBlack"));
    terminalColor.put("31", Tools.getDefaultColor("TerminalPanel.TerminalRed"));
    terminalColor.put("32", Tools.getDefaultColor("TerminalPanel.TerminalGreen"));
    terminalColor.put("33", Tools.getDefaultColor("TerminalPanel.TerminalYellow"));
    terminalColor.put("34", Tools.getDefaultColor("TerminalPanel.TerminalBlue"));
    terminalColor.put("35", Tools.getDefaultColor("TerminalPanel.TerminalPurple"));
    terminalColor.put("36", Tools.getDefaultColor("TerminalPanel.TerminalCyan"));
    final Font f = new Font("Monospaced", Font.PLAIN, Tools.getConfigData().scaled(14));
    terminalArea = new JTextPane();
    terminalArea.setStyledDocument(new MyDocument());
    final DefaultCaret caret =
        new DefaultCaret() {
          private static final long serialVersionUID = 1L;

          @Override
          protected synchronized void damage(final Rectangle r) {
            if (r != null) {
              x = r.x;
              y = r.y;
              width = 8;
              height = r.height;
              repaint();
            }
          }

          @Override
          public void paint(final Graphics g) {
            /* painting cursor. If it is not visible it is out of focus, we
             * make it barely visible. */
            try {
              TextUI mapper = getComponent().getUI();
              Rectangle r = mapper.modelToView(getComponent(), getDot(), getDotBias());
              if (r == null) {
                return;
              }
              g.setColor(getComponent().getCaretColor());
              if (isVisible() && editEnabled) {
                g.fillRect(r.x, r.y, 8, r.height);
              } else {
                g.drawRect(r.x, r.y, 8, r.height);
              }
            } catch (BadLocationException e) {
              Tools.appError("Drawing of cursor failed", e);
            }
          }
        };
    terminalArea.setCaret(caret);
    terminalArea.addCaretListener(
        new CaretListener() {
          @Override
          public void caretUpdate(final CaretEvent e) {
            /* don't do this if caret moved because of selection */
            mPosLock.lock();
            try {
              if (e != null && e.getDot() < commandOffset && e.getDot() == e.getMark()) {
                terminalArea.setCaretPosition(commandOffset);
              }
            } finally {
              mPosLock.unlock();
            }
          }
        });

    /* set font and colors */
    terminalArea.setFont(f);
    terminalArea.setBackground(Tools.getDefaultColor("TerminalPanel.Background"));

    commandColor = new SimpleAttributeSet();
    StyleConstants.setForeground(commandColor, Tools.getDefaultColor("TerminalPanel.Command"));

    errorColor = new SimpleAttributeSet();
    StyleConstants.setForeground(errorColor, Tools.getDefaultColor("TerminalPanel.Error"));

    outputColor = new SimpleAttributeSet();
    defaultOutputColor = Tools.getDefaultColor("TerminalPanel.Output");
    StyleConstants.setForeground(outputColor, defaultOutputColor);

    promptColor = new SimpleAttributeSet();
    StyleConstants.setForeground(promptColor, host.getPmColors()[0]);

    append(prompt(), promptColor);
    terminalArea.setEditable(true);
    getViewport().add(terminalArea, BorderLayout.PAGE_END);
    setPreferredSize(
        new Dimension(Short.MAX_VALUE, Tools.getDefaultInt("MainPanel.TerminalPanelHeight")));
    setMinimumSize(getPreferredSize());
    setMaximumSize(getPreferredSize());
  }
Example #13
0
  /** Prepares a new <code>ClusterViewPanel</code> object. */
  EmptyViewPanel() {
    super();
    browser = new EmptyBrowser();
    Tools.getGUIData().setEmptyBrowser(browser);
    browser.setEmptyViewPanel(this);
    browser.initHosts();

    final JPanel buttonPanel = new JPanel(new FlowLayout());
    buttonPanel.setMinimumSize(new Dimension(0, 110));
    buttonPanel.setPreferredSize(new Dimension(0, 110));
    buttonPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 110));
    buttonPanel.setBackground(STATUS_BACKGROUND);
    add(buttonPanel, BorderLayout.NORTH);
    final JPanel logoPanel = new JPanel(new CardLayout());
    logoPanel.setBackground(java.awt.Color.WHITE);
    final ImageIcon logoImage = Tools.createImageIcon("startpage_head.jpg");

    final JLabel logo = new JLabel(logoImage);
    final JPanel lPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
    lPanel.setBackground(java.awt.Color.WHITE);
    lPanel.add(logo);
    logoPanel.add(lPanel, LOGO_PANEL_STRING);
    final JPanel smallButtonPanel = new JPanel();
    smallButtonPanel.setBackground(STATUS_BACKGROUND);
    smallButtonPanel.setLayout(new BoxLayout(smallButtonPanel, BoxLayout.Y_AXIS));
    buttonPanel.add(smallButtonPanel);
    /* check for upgrade field. */
    smallButtonPanel.add(Tools.getGUIData().getClustersPanel().registerUpgradeTextField());
    /* add new host button */
    final MyButton addHostButton =
        new MyButton(Tools.getString("ClusterTab.AddNewHost"), HOST_ICON);
    addHostButton.setBackgroundColor(Browser.STATUS_BACKGROUND);
    addHostButton.setPreferredSize(BIG_BUTTON_DIMENSION);
    addHostButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        final AddHostDialog ahd = new AddHostDialog();
                        ahd.showDialogs();
                      }
                    });
            thread.start();
          }
        });
    Tools.getGUIData().registerAddHostButton(addHostButton);
    buttonPanel.add(addHostButton);
    createEmptyView();
    add(logoPanel, BorderLayout.SOUTH);
    Tools.getGUIData().registerAllHostsUpdate(this);
    Tools.getGUIData().allHostsUpdate();

    /* add new cluster button */
    final MyButton addClusterButton =
        new MyButton(Tools.getString("ClusterTab.AddNewCluster"), CLUSTER_ICON);
    addClusterButton.setBackgroundColor(Browser.STATUS_BACKGROUND);
    addClusterButton.setPreferredSize(BIG_BUTTON_DIMENSION);
    addClusterButton.setMinimumSize(BIG_BUTTON_DIMENSION);
    addClusterButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        AddClusterDialog acd = new AddClusterDialog();
                        acd.showDialogs();
                      }
                    });
            thread.start();
          }
        });
    Tools.getGUIData().registerAddClusterButton(addClusterButton);
    Tools.getGUIData().checkAddClusterButtons();
    buttonPanel.add(addClusterButton);
    if (!Tools.getConfigData().getAutoHosts().isEmpty()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              addHostButton.pressButton();
            }
          });
    }
  }