/** Returns info panel. */ @Override public final JComponent getInfoPanel() { if (infoPanel != null) { return infoPanel; } final boolean abExisted = getApplyButton() != null; /* main, button and options panels */ final JPanel mainPanel = new JPanel(); mainPanel.setBackground(ClusterBrowser.PANEL_BACKGROUND); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); final JTable headerTable = getTable(VMSVirtualDomainInfo.HEADER_TABLE); if (headerTable != null) { mainPanel.add(headerTable.getTableHeader()); mainPanel.add(headerTable); } addHardwareTable(mainPanel); final JPanel buttonPanel = new JPanel(new BorderLayout()); buttonPanel.setBackground(ClusterBrowser.BUTTON_PANEL_BACKGROUND); buttonPanel.setMinimumSize(new Dimension(0, 50)); buttonPanel.setPreferredSize(new Dimension(0, 50)); buttonPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, 50)); final JPanel optionsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 20)); optionsPanel.setBackground(ClusterBrowser.PANEL_BACKGROUND); final String[] params = getParametersFromXML(); initApplyButton(null); /* add item listeners to the apply button. */ if (!abExisted) { getApplyButton() .addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final Thread thread = new Thread( new Runnable() { @Override public void run() { getBrowser().clStatusLock(); apply(false); getBrowser().clStatusUnlock(); } }); thread.start(); } }); getRevertButton() .addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final Thread thread = new Thread( new Runnable() { @Override public void run() { getBrowser().clStatusLock(); revert(); getBrowser().clStatusUnlock(); } }); thread.start(); } }); } final JPanel extraButtonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 3, 0)); extraButtonPanel.setBackground(Browser.BUTTON_PANEL_BACKGROUND); buttonPanel.add(extraButtonPanel); addApplyButton(buttonPanel); addRevertButton(extraButtonPanel); final MyButton overviewButton = new MyButton("VM Host Overview", BACK_ICON); overviewButton.miniButton(); overviewButton.setPreferredSize(new Dimension(130, 50)); // overviewButton.setPreferredSize(new Dimension(200, 50)); overviewButton.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { vmsVirtualDomainInfo.selectMyself(); } }); extraButtonPanel.add(overviewButton); addParams( optionsPanel, params, ClusterBrowser.SERVICE_LABEL_WIDTH, ClusterBrowser.SERVICE_FIELD_WIDTH * 2, null); /* Actions */ buttonPanel.add(getActionsButton(), BorderLayout.EAST); mainPanel.add(optionsPanel); final JPanel newPanel = new JPanel(); newPanel.setBackground(ClusterBrowser.PANEL_BACKGROUND); newPanel.setLayout(new BoxLayout(newPanel, BoxLayout.Y_AXIS)); newPanel.add(buttonPanel); newPanel.add( getMoreOptionsPanel( ClusterBrowser.SERVICE_LABEL_WIDTH + ClusterBrowser.SERVICE_FIELD_WIDTH + 4)); newPanel.add(new JScrollPane(mainPanel)); SwingUtilities.invokeLater( new Runnable() { @Override public void run() { getApplyButton().setVisible(!getVMSVirtualDomainInfo().getResource().isNew()); setApplyButtons(null, params); } }); infoPanel = newPanel; infoPanelDone(); return infoPanel; }
/** 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; }
/** Returns combo box for parameter. */ @Override protected Widget createWidget(final String param, final String prefix, final int width) { String prefixS; if (prefix == null) { prefixS = ""; } else { prefixS = prefix; } if (DiskData.SOURCE_FILE.equals(param)) { final String sourceFile = getParamSaved(DiskData.SOURCE_FILE); final String regexp = ".*[^/]$"; final MyButton fileChooserBtn = new MyButton("Browse..."); fileChooserBtn.miniButton(); final Widget paramWi = WidgetFactory.createInstance( getFieldType(param), sourceFile, getParamPossibleChoices(param), regexp, width, Widget.NO_ABBRV, new AccessMode(getAccessType(param), false), /* only adv. mode */ fileChooserBtn); paramWi.setAlwaysEditable(true); sourceFileWi.put(prefixS, paramWi); if (Tools.isWindows()) { /* does not work on windows and I tried, ultimately because FilePane.usesShellFolder(fc) in BasicFileChooserUI returns true and it is not possible to descent into a directory. TODO: It may work in the future. */ paramWi.setTFButtonEnabled(false); } fileChooserBtn.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final Thread t = new Thread( new Runnable() { @Override public void run() { String file; final String oldFile = paramWi.getStringValue(); if (oldFile == null || "".equals(oldFile)) { file = LIBVIRT_IMAGE_LOCATION; } else { file = oldFile; } startFileChooser(paramWi, file, FILECHOOSER_FILE_ONLY); } }); t.start(); } }); widgetAdd(param, prefix, paramWi); return paramWi; } else { final Widget paramWi = super.createWidget(param, prefix, width); if (DiskData.TYPE.equals(param) || DiskData.TARGET_BUS_TYPE.equals(param)) { paramWi.setAlwaysEditable(false); } else if (DiskData.SOURCE_DEVICE.equals(param)) { paramWi.setAlwaysEditable(true); sourceDeviceWi.put(prefixS, paramWi); } else if (DiskData.SOURCE_NAME.equals(param)) { sourceNameWi.put(prefixS, paramWi); } else if (DiskData.SOURCE_PROTOCOL.equals(param)) { sourceProtocolWi.put(prefixS, paramWi); } else if (DiskData.SOURCE_HOST_NAME.equals(param)) { sourceHostNameWi.put(prefixS, paramWi); } else if (DiskData.SOURCE_HOST_PORT.equals(param)) { sourceHostPortWi.put(prefixS, paramWi); } else if (DiskData.AUTH_USERNAME.equals(param)) { authUsernameWi.put(prefixS, paramWi); } else if (DiskData.AUTH_SECRET_TYPE.equals(param)) { authSecretTypeWi.put(prefixS, paramWi); } else if (DiskData.AUTH_SECRET_UUID.equals(param)) { authSecretUuidWi.put(prefixS, paramWi); } else if (DiskData.TARGET_DEVICE.equals(param)) { paramWi.setAlwaysEditable(true); targetDeviceWi.put(prefixS, paramWi); } else if (DiskData.DRIVER_NAME.equals(param)) { driverNameWi.put(prefixS, paramWi); } else if (DiskData.DRIVER_TYPE.equals(param)) { driverTypeWi.put(prefixS, paramWi); } else if (DiskData.DRIVER_CACHE.equals(param)) { driverCacheWi.put(prefixS, paramWi); } else if (DiskData.READONLY.equals(param)) { readonlyWi.put(prefixS, paramWi); } return paramWi; } }