private void updateComponents() {
    _listPanel.removeAll();

    final String[] names = _catalog.getStringPatternNames();
    Arrays.sort(names);

    final Icon icon = imageManager.getImageIcon("images/model/stringpattern.png");

    for (final String name : names) {
      final StringPattern stringPattern = _catalog.getStringPattern(name);

      final DCLabel stringPatternLabel =
          DCLabel.dark(
              "<html><b>" + name + "</b><br/>" + getDescription(stringPattern) + "</html>");
      stringPatternLabel.setIcon(icon);
      stringPatternLabel.setMaximumWidth(ReferenceDataDialog.REFERENCE_DATA_ITEM_MAX_WIDTH);

      final JButton editButton = WidgetFactory.createSmallButton("images/actions/edit.png");
      editButton.setToolTipText("Edit string pattern");

      if (stringPattern instanceof RegexStringPattern) {
        editButton.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                RegexStringPatternDialog dialog =
                    new RegexStringPatternDialog(
                        (RegexStringPattern) stringPattern, _catalog, _windowContext);
                dialog.setVisible(true);
              }
            });
      } else if (stringPattern instanceof SimpleStringPattern) {
        editButton.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                SimpleStringPatternDialog dialog =
                    new SimpleStringPatternDialog(
                        (SimpleStringPattern) stringPattern, _catalog, _windowContext);
                dialog.setVisible(true);
              }
            });
      } else {
        editButton.setEnabled(false);
      }

      final JButton removeButton = WidgetFactory.createSmallButton(IconUtils.ACTION_REMOVE);
      removeButton.setToolTipText("Remove string pattern");
      removeButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              int result =
                  JOptionPane.showConfirmDialog(
                      StringPatternListPanel.this,
                      "Are you sure you wish to remove the string pattern '" + name + "'?",
                      "Confirm remove",
                      JOptionPane.YES_NO_OPTION);
              if (result == JOptionPane.YES_OPTION) {
                _catalog.removeStringPattern(stringPattern);
              }
            }
          });

      if (!_catalog.isStringPatternMutable(name)) {
        editButton.setEnabled(false);
        removeButton.setEnabled(false);
      }

      final DCPanel stringPatternPanel = new DCPanel();
      stringPatternPanel.setBorder(WidgetUtils.BORDER_LIST_ITEM);
      WidgetUtils.addToGridBag(stringPatternLabel, stringPatternPanel, 0, 0, 1.0, 0.0);
      WidgetUtils.addToGridBag(editButton, stringPatternPanel, 1, 0, GridBagConstraints.EAST);
      WidgetUtils.addToGridBag(removeButton, stringPatternPanel, 2, 0, GridBagConstraints.EAST);
      _listPanel.add(stringPatternPanel);
    }

    if (names.length == 0) {
      _listPanel.add(DCLabel.dark("(none)"));
    }

    updateUI();
  }
예제 #2
0
  public DatastorePanel(
      Datastore datastore,
      MutableDatastoreCatalog datastoreCatalog,
      DatastoreListPanel datastoreListPanel,
      WindowContext windowContext,
      InjectorBuilder injectorBuilder) {
    super(WidgetUtils.BG_COLOR_BRIGHT, WidgetUtils.BG_COLOR_LESS_BRIGHT);
    _datastore = datastore;
    _datastoreCatalog = datastoreCatalog;
    _datastoreListPanel = datastoreListPanel;
    _windowContext = windowContext;
    _injectorBuilder = injectorBuilder;

    setOpaque(false);

    final Icon icon = IconUtils.getDatastoreIcon(datastore);
    final String description = getDescription(datastore);

    _checkBox = new JCheckBox();
    _checkBox.setOpaque(false);
    _checkBox.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            _datastoreListPanel.setSelectedDatastorePanel(DatastorePanel.this);
          }
        });
    _checkBox.addChangeListener(
        new ChangeListener() {
          @Override
          public void stateChanged(ChangeEvent e) {
            setOpaque(isSelected());
            updateUI();
          }
        });

    final String datastoreName = datastore.getName();
    final DCLabel datastoreNameLabel =
        DCLabel.dark("<html><b>" + datastoreName + "</b><br/>" + description + "</html>");
    datastoreNameLabel.setIconTextGap(10);
    datastoreNameLabel.setIcon(icon);
    datastoreNameLabel.setMaximumWidth(LABEL_MAX_WIDTH);
    MouseAdapter invokeCheckBoxMouseListener =
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            _checkBox.doClick();
            _datastoreListPanel.requestSearchFieldFocus();
            if (e.getClickCount() > 1) {
              // begin job on double click
              _datastoreListPanel.clickAnalyzeButton();
            }
          }
        };

    addMouseListener(invokeCheckBoxMouseListener);
    datastoreNameLabel.addMouseListener(invokeCheckBoxMouseListener);

    final JButton editButton = createEditButton(datastore);
    final JButton removeButton = createRemoveButton(datastore);

    setBorder(WidgetUtils.BORDER_LIST_ITEM);

    WidgetUtils.addToGridBag(
        DCPanel.flow(_checkBox, datastoreNameLabel), this, 0, 0, GridBagConstraints.WEST, 1.0, 1.0);
    WidgetUtils.addToGridBag(editButton, this, 1, 0, GridBagConstraints.EAST);
    WidgetUtils.addToGridBag(removeButton, this, 2, 0, GridBagConstraints.EAST);
  }