예제 #1
0
파일: LVResize.java 프로젝트: npk/lcmc
 /** Check if it is DRBD device and if it could be resized. */
 private boolean checkDRBD() {
   if (blockDevInfo.getBlockDevice().isDrbd()) {
     final DrbdVolumeInfo dvi = blockDevInfo.getDrbdVolumeInfo();
     final BlockDevInfo oBDI = blockDevInfo.getOtherBlockDevInfo();
     if (!dvi.isConnected(false)) {
       printErrorAndRetry("Not resizing. DRBD resource is not connected.");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     } else if (dvi.isSyncing()) {
       printErrorAndRetry("Not resizing. DRBD resource is syncing.");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     } else if (!oBDI.getBlockDevice().isAttached()) {
       printErrorAndRetry(
           "Not resizing. DRBD resource is not attached on " + oBDI.getHost() + ".");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     } else if (!blockDevInfo.getBlockDevice().isAttached()) {
       printErrorAndRetry(
           "Not resizing. DRBD resource is not attached on " + blockDevInfo.getHost() + ".");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     } else if (!oBDI.getBlockDevice().isPrimary() && !blockDevInfo.getBlockDevice().isPrimary()) {
       printErrorAndRetry("Not resizing. Must be primary at least on one node.");
       sizeWi.setEnabled(false);
       resizeButton.setEnabled(false);
       return false;
     }
   }
   return true;
 }
예제 #2
0
파일: WizardDialog.java 프로젝트: npk/lcmc
  /** Presses the retry button. */
  final void pressRetryButton() {
    final MyButton rb = buttonClass(retryButton());

    if (rb != null && rb.isVisible() && rb.isEnabled()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              rb.pressButton();
            }
          });
    }
  }
예제 #3
0
파일: WizardDialog.java 프로젝트: npk/lcmc
  /** Hides the retry button if it is there. */
  public final void hideRetryButton() {
    final MyButton rb = buttonClass(retryButton());

    if (rb != null && rb.isVisible()) {
      SwingUtilities.invokeLater(
          new Runnable() {
            @Override
            public void run() {
              rb.setVisible(false);
            }
          });
    }
  }
예제 #4
0
 /** Returns "add new" button. */
 static MyButton getNewBtn(final VMSVirtualDomainInfo vdi) {
   final MyButton newBtn = new MyButton("Add Disk");
   newBtn.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(final ActionEvent e) {
           final Thread t =
               new Thread(
                   new Runnable() {
                     @Override
                     public void run() {
                       vdi.addDiskPanel();
                     }
                   });
           t.start();
         }
       });
   return newBtn;
 }
예제 #5
0
파일: ConfigDialog.java 프로젝트: npk/lcmc
  /**
   * Shows dialog and wait for answer. Returns next dialog, or null if it there is no next dialog.
   */
  public final ConfigDialog showDialog() {
    /* making non modal dialog */
    dialogGate = new CountDownLatch(1);
    dialogPanel = null; /* TODO: disabled caching because back button
                               wouldn't work with
                               dialogPanel.setContentPane(optionPane) method
                               it would work with optionPane.createDialog...
                               but that causes lockups with old javas and
                               gnome. */
    if (dialogPanel == null) {
      final ImageIcon[] icons = getIcons();
      MyButton defaultButtonClass = null;
      final List<JComponent> allOptions = new ArrayList<JComponent>(additionalOptions);
      if (skipButtonEnabled()) {
        skipButton = new JCheckBox(Tools.getString("Dialog.ConfigDialog.SkipButton"));
        skipButton.setEnabled(false);
        skipButton.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Light"));
        skipButton.addItemListener(skipButtonListener());
        allOptions.add(skipButton);
      }
      final String[] buttons = buttons();
      /* populate buttonToObjectMap */
      for (int i = 0; i < buttons.length; i++) {
        options[i] = new MyButton(buttons[i], icons[i]);
        options[i].setBackgroundColor(Tools.getDefaultColor("ConfigDialog.Button"));
        allOptions.add(options[i]);
        buttonToObjectMap.put(buttons[i], options[i]);
        if (buttons[i].equals(defaultButton())) {
          defaultButtonClass = options[i];
        }
      }
      /* create option pane */
      final JPanel b = body();
      final MyButton dbc = defaultButtonClass;
      Tools.invokeAndWait(
          new Runnable() {
            public void run() {
              optionPane =
                  new JOptionPane(
                      b,
                      getMessageType(),
                      JOptionPane.DEFAULT_OPTION,
                      icon(),
                      allOptions.toArray(new JComponent[allOptions.size()]),
                      dbc);
              optionPane.setPreferredSize(new Dimension(dialogWidth(), dialogHeight()));
              optionPane.setMaximumSize(new Dimension(dialogWidth(), dialogHeight()));
              optionPane.setMinimumSize(new Dimension(dialogWidth(), dialogHeight()));

              optionPane.setBackground(Tools.getDefaultColor("ConfigDialog.Background.Dark"));
              final Container mainFrame = Tools.getGUIData().getMainFrame();
              if (mainFrame instanceof JApplet) {
                final JFrame noframe = new JFrame();
                dialogPanel = new JDialog(noframe);
                dialogPanel.setContentPane(optionPane);
              } else {
                dialogPanel = new JDialog((JFrame) mainFrame);
                dialogPanel.setContentPane(optionPane);
              }
              dialogPanel.setModal(false);
              dialogPanel.setResizable(true);
            }
          });
      /* set location like the previous dialog */
    }
    /* add action listeners */
    final Map<MyButton, OptionPaneActionListener> optionPaneActionListeners =
        new HashMap<MyButton, OptionPaneActionListener>();
    for (final MyButton o : options) {
      final OptionPaneActionListener ol = new OptionPaneActionListener();
      optionPaneActionListeners.put(o, ol);
      o.addActionListener(ol);
    }

    final PropertyChangeListener propertyChangeListener =
        new PropertyChangeListener() {
          @Override
          public void propertyChange(final PropertyChangeEvent evt) {
            if (JOptionPane.VALUE_PROPERTY.equals(evt.getPropertyName())
                && !"uninitializedValue".equals(evt.getNewValue())) {
              optionPaneAnswer = optionPane.getValue();
              dialogGate.countDown();
            }
          }
        };
    optionPane.addPropertyChangeListener(propertyChangeListener);
    initDialog();
    Tools.invokeAndWait(
        new Runnable() {
          public void run() {
            dialogPanel.setPreferredSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setMaximumSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setMinimumSize(new Dimension(dialogWidth(), dialogHeight()));
            dialogPanel.setLocationRelativeTo(Tools.getGUIData().getMainFrame());
            dialogPanel.setVisible(true);
          }
        });
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            dialogPanel.setLocationRelativeTo(Tools.getGUIData().getMainFrameContentPane());
            /* although the location was set before, it is set again as a
             * workaround for gray dialogs with nothing in it, that appear
             * in some comination of Java and compiz. */
          }
        });
    initDialogAfterVisible();
    try {
      dialogGate.await();
    } catch (InterruptedException ignored) {
      Thread.currentThread().interrupt();
    }

    if (optionPaneAnswer instanceof String) {
      setPressedButton((String) optionPaneAnswer);
    } else {
      setPressedButton(cancelButton());
    }
    optionPane.removePropertyChangeListener(propertyChangeListener);
    /* remove action listeners */
    for (final MyButton o : options) {
      o.removeActionListener(optionPaneActionListeners.get(o));
    }
    dialogPanel.dispose();
    return checkAnswer();
  }
예제 #6
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;
  }
예제 #7
0
  /** 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;
  }
예제 #8
0
파일: VGCreate.java 프로젝트: rdndnl/lcmc
  /** Returns the input pane. */
  @Override
  protected JComponent getInputPane() {
    createButton.setEnabled(false);
    final JPanel pane = new JPanel(new SpringLayout());
    /* vg name */
    final JPanel inputPane = new JPanel(new SpringLayout());
    inputPane.setBackground(Browser.BUTTON_PANEL_BACKGROUND);

    /* find next free group volume name */
    String defaultName;
    final Set<String> volumeGroups = host.getVolumeGroupNames();
    int i = 0;
    while (true) {
      defaultName = "vg" + String.format("%02d", i);
      if (volumeGroups == null || !volumeGroups.contains(defaultName)) {
        break;
      }
      i++;
    }
    vgNameWi =
        WidgetFactory.createInstance(
            Widget.Type.TEXTFIELD,
            defaultName,
            Widget.NO_ITEMS,
            Widget.NO_REGEXP,
            250,
            Widget.NO_ABBRV,
            new AccessMode(ConfigData.AccessType.OP, !AccessMode.ADVANCED),
            Widget.NO_BUTTON);
    inputPane.add(new JLabel("VG Name"));
    inputPane.add(vgNameWi);

    createButton.addActionListener(new CreateActionListener());
    inputPane.add(createButton);
    SpringUtilities.makeCompactGrid(
        inputPane, 1, 3, /* rows, cols */ 1, 1, /* initX, initY */ 1, 1); /* xPad, yPad */

    pane.add(inputPane);
    /* Volume groups. */
    final JPanel pvsPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    final Set<String> selectedPVs = new HashSet<String>();
    final Set<Host> selectedHosts = new HashSet<Host>();
    for (final BlockDevInfo sbdi : selectedBlockDevInfos) {
      if (sbdi.getBlockDevice().isDrbd()) {
        selectedPVs.add(sbdi.getBlockDevice().getDrbdBlockDevice().getName());
      } else {
        selectedPVs.add(sbdi.getName());
      }
      selectedHosts.add(sbdi.getHost());
    }
    pvCheckBoxes = getPVCheckBoxes(selectedPVs);
    pvsPane.add(new JLabel("Select physical volumes: "));
    for (final String pvName : pvCheckBoxes.keySet()) {
      pvCheckBoxes.get(pvName).addItemListener(new ItemChangeListener(true));
      pvsPane.add(pvCheckBoxes.get(pvName));
    }
    final JScrollPane pvSP = new JScrollPane(pvsPane);
    pvSP.setPreferredSize(new Dimension(0, 45));
    pane.add(pvSP);

    final JPanel hostsPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
    final Cluster cluster = host.getCluster();
    hostCheckBoxes = Tools.getHostCheckBoxes(cluster);
    hostsPane.add(new JLabel("Select Hosts: "));
    for (final Host h : hostCheckBoxes.keySet()) {
      hostCheckBoxes.get(h).addItemListener(new ItemChangeListener(true));
      if (host == h) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(true);
      } else if (isOneDrbd(selectedBlockDevInfos)) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(false);
      } else if (hostHasPVS(h)) {
        hostCheckBoxes.get(h).setEnabled(true);
        hostCheckBoxes.get(h).setSelected(selectedHosts.contains(h));
      } else {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(false);
      }
      hostsPane.add(hostCheckBoxes.get(h));
    }
    final JScrollPane sp = new JScrollPane(hostsPane);
    sp.setPreferredSize(new Dimension(0, 45));
    pane.add(sp);
    pane.add(getProgressBarPane(null));
    pane.add(getAnswerPane(""));
    SpringUtilities.makeCompactGrid(
        pane, 5, 1, /* rows, cols */ 0, 0, /* initX, initY */ 0, 0); /* xPad, yPad */
    checkButtons();
    return pane;
  }
예제 #9
0
파일: LVResize.java 프로젝트: npk/lcmc
  /** Returns the input pane. */
  protected JComponent getInputPane() {
    resizeButton.setEnabled(false);
    final JPanel pane = new JPanel(new SpringLayout());
    final JPanel inputPane = new JPanel(new SpringLayout());
    inputPane.setBackground(Browser.BUTTON_PANEL_BACKGROUND);
    /* old size */
    final JLabel oldSizeLabel = new JLabel("Current Size");
    oldSizeLabel.setEnabled(false);

    final String oldBlockSize = blockDevInfo.getBlockDevice().getBlockSize();
    oldSizeWi =
        new TextfieldWithUnit(
            Tools.convertKilobytes(oldBlockSize),
            getUnits(),
            Widget.NO_REGEXP,
            250,
            Widget.NO_ABBRV,
            new AccessMode(ConfigData.AccessType.OP, !AccessMode.ADVANCED),
            Widget.NO_BUTTON);
    oldSizeWi.setEnabled(false);
    inputPane.add(oldSizeLabel);
    inputPane.add(oldSizeWi);
    inputPane.add(new JLabel());

    final String maxBlockSize = getMaxBlockSize();
    /* size */
    final String newBlockSize =
        Long.toString((Long.parseLong(oldBlockSize) + Long.parseLong(maxBlockSize)) / 2);
    final JLabel sizeLabel = new JLabel("New Size");

    sizeWi =
        new TextfieldWithUnit(
            Tools.convertKilobytes(newBlockSize),
            getUnits(),
            Widget.NO_REGEXP,
            250,
            Widget.NO_ABBRV,
            new AccessMode(ConfigData.AccessType.OP, !AccessMode.ADVANCED),
            Widget.NO_BUTTON);
    inputPane.add(sizeLabel);
    inputPane.add(sizeWi);
    resizeButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final Thread thread =
                new Thread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (checkDRBD()) {
                          Tools.invokeAndWait(new EnableResizeRunnable(false));
                          disableComponents();
                          getProgressBar().start(RESIZE_TIMEOUT * hostCheckBoxes.size());
                          final boolean ret = resize(sizeWi.getStringValue());
                          final Host host = blockDevInfo.getHost();
                          host.getBrowser().getClusterBrowser().updateHWInfo(host);
                          setComboBoxes();
                          if (ret) {
                            progressBarDone();
                          } else {
                            progressBarDoneError();
                          }
                          enableComponents();
                        }
                      }
                    });
            thread.start();
          }
        });

    inputPane.add(resizeButton);
    /* max size */
    final JLabel maxSizeLabel = new JLabel("Max Size");
    maxSizeLabel.setEnabled(false);
    maxSizeWi =
        new TextfieldWithUnit(
            Tools.convertKilobytes(maxBlockSize),
            getUnits(),
            Widget.NO_REGEXP,
            250,
            Widget.NO_ABBRV,
            new AccessMode(ConfigData.AccessType.OP, !AccessMode.ADVANCED),
            Widget.NO_BUTTON);
    maxSizeWi.setEnabled(false);
    inputPane.add(maxSizeLabel);
    inputPane.add(maxSizeWi);
    inputPane.add(new JLabel());
    sizeWi.addListeners(
        new WidgetListener() {
          @Override
          public void check(final Object value) {
            checkButtons();
          }
        });

    SpringUtilities.makeCompactGrid(
        inputPane, 3, 3, /* rows, cols */ 1, 1, /* initX, initY */ 1, 1); /* xPad, yPad */

    pane.add(inputPane);
    final JPanel hostsPane = new JPanel(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));
    final Cluster cluster = blockDevInfo.getHost().getCluster();
    hostCheckBoxes = Tools.getHostCheckBoxes(cluster);
    hostsPane.add(new JLabel("Select Hosts: "));
    final Host host = blockDevInfo.getHost();
    final String lv = blockDevInfo.getBlockDevice().getLogicalVolume();
    for (final Host h : hostCheckBoxes.keySet()) {
      final Set<String> allLVS = h.getAllLogicalVolumes();
      hostCheckBoxes
          .get(h)
          .addItemListener(
              new ItemListener() {
                @Override
                public void itemStateChanged(final ItemEvent e) {
                  checkButtons();
                }
              });
      if (host == h) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(true);
      } else if (blockDevInfo.getBlockDevice().isDrbd()
          && blockDevInfo.getOtherBlockDevInfo().getHost() == h) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(true);
      } else if (!blockDevInfo.getBlockDevice().isDrbd() && !allLVS.contains(lv)) {
        hostCheckBoxes.get(h).setEnabled(false);
        hostCheckBoxes.get(h).setSelected(false);
      } else {
        hostCheckBoxes.get(h).setEnabled(true);
        hostCheckBoxes.get(h).setSelected(false);
      }
      hostsPane.add(hostCheckBoxes.get(h));
    }
    final javax.swing.JScrollPane sp = new javax.swing.JScrollPane(hostsPane);
    sp.setPreferredSize(new java.awt.Dimension(0, 45));
    pane.add(sp);
    pane.add(getProgressBarPane(null));
    pane.add(getAnswerPane(""));
    SpringUtilities.makeCompactGrid(
        pane, 4, 1, /* rows, cols */ 0, 0, /* initX, initY */ 0, 0); /* xPad, yPad */
    checkButtons();
    return pane;
  }
예제 #10
0
 /** 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;
   }
 }
예제 #11
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();
            }
          });
    }
  }