private JButton createButton(String imagePath, String description) {
    final JButton button = WidgetFactory.createImageButton(imageManager.getImageIcon(imagePath));

    final DCPopupBubble popupBubble = new DCPopupBubble(_glassPane, description, 0, 0, imagePath);
    popupBubble.attachTo(button);

    return button;
  }
예제 #2
0
 private JButton createRemoveButton(final Datastore datastore) {
   final String name = datastore.getName();
   final JButton removeButton = WidgetFactory.createSmallButton(IconUtils.ACTION_REMOVE);
   removeButton.setToolTipText("Remove datastore");
   removeButton.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           int result =
               JOptionPane.showConfirmDialog(
                   DatastorePanel.this,
                   "Are you sure you wish to remove the datastore '" + name + "'?",
                   "Confirm remove",
                   JOptionPane.YES_NO_OPTION);
           if (result == JOptionPane.YES_OPTION) {
             _datastoreCatalog.removeDatastore(datastore);
           }
         }
       });
   if (!_datastoreCatalog.isDatastoreMutable(name)) {
     removeButton.setEnabled(false);
   }
   return removeButton;
 }
  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();
  }
예제 #4
0
  private JComponent getLicensingPanel() {
    final String dcLicense = getLicense("lgpl");

    final DCLabel licenseHeader = DCLabel.dark("");
    licenseHeader.setFont(WidgetUtils.FONT_HEADER1);

    final DCLabel licenseLabel = DCLabel.darkMultiLine("");
    licenseLabel.setBackground(WidgetUtils.BG_COLOR_BRIGHTEST);
    licenseLabel.setFont(WidgetUtils.FONT_MONOSPACE);
    licenseLabel.setOpaque(true);

    final JButton dcLicenseButton = WidgetFactory.createSmallButton("images/menu/license.png");
    dcLicenseButton.setToolTipText("DataCleaner's license: GNU LGPL");
    dcLicenseButton.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            licenseHeader.setText("Displaying license of DataCleaner");
            licenseLabel.setText(dcLicense);
          }
        });

    final JComboBox librariesComboBox = new JComboBox();
    final JButton visitProjectButton = WidgetFactory.createSmallButton(IconUtils.WEBSITE);

    librariesComboBox.setRenderer(
        new DCListCellRenderer() {

          private static final long serialVersionUID = 1L;

          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            if (value instanceof LicensedProject) {
              LicensedProject project = (LicensedProject) value;
              String name = project.name;
              return super.getListCellRendererComponent(
                  list, name, index, isSelected, cellHasFocus);
            } else if (value instanceof String) {
              return super.getListCellRendererComponent(
                  list, value, index, isSelected, cellHasFocus);
            }
            throw new UnsupportedOperationException();
          }
        });
    librariesComboBox.addItemListener(
        new ItemListener() {
          @Override
          public void itemStateChanged(ItemEvent e) {
            Object item = e.getItem();
            if (item instanceof LicensedProject) {
              visitProjectButton.setEnabled(true);
              LicensedProject project = (LicensedProject) item;
              licenseLabel.setText(project.license);
              licenseHeader.setText("Displaying license of " + project.name + "");
            } else {
              visitProjectButton.setEnabled(false);
              licenseHeader.setText("Displaying license of DataCleaner");
              licenseLabel.setText(dcLicense);
            }
          }
        });

    visitProjectButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            Object item = librariesComboBox.getSelectedItem();
            LicensedProject project = (LicensedProject) item;
            String websiteUrl = project.websiteUrl;
            if (!StringUtils.isNullOrEmpty(websiteUrl)) {
              new OpenBrowserAction(websiteUrl).actionPerformed(e);
            }
          }
        });

    librariesComboBox.addItem("- select project -");
    final List<LicensedProject> licensedProjects = getLicensedProjects();
    for (LicensedProject licensedProject : licensedProjects) {
      librariesComboBox.addItem(licensedProject);
    }

    final JToolBar toolBar = WidgetFactory.createToolBar();
    toolBar.add(DCLabel.dark("DataCleaners license: "));
    toolBar.add(dcLicenseButton);
    toolBar.add(WidgetFactory.createToolBarSeparator());
    toolBar.add(DCLabel.dark("Included libraries: "));
    toolBar.add(librariesComboBox);
    toolBar.add(visitProjectButton);

    final JScrollPane licenseLabelScroll = WidgetUtils.scrolleable(licenseLabel);
    licenseLabelScroll.setBorder(
        new CompoundBorder(new EmptyBorder(10, 0, 10, 0), WidgetUtils.BORDER_THIN));

    final DCPanel headerPanel = new DCPanel();
    headerPanel.setLayout(new VerticalLayout());
    headerPanel.add(toolBar);
    headerPanel.add(Box.createVerticalStrut(20));
    headerPanel.add(licenseHeader);

    final DCPanel panel = new DCPanel(WidgetUtils.BG_COLOR_BRIGHT, WidgetUtils.BG_COLOR_BRIGHTEST);
    panel.setBorder(new EmptyBorder(4, 4, 4, 4));
    panel.setLayout(new BorderLayout());
    panel.add(headerPanel, BorderLayout.NORTH);
    panel.add(licenseLabelScroll, BorderLayout.CENTER);

    return panel;
  }
  @Inject
  public SingleResourcePropertyWidget(
      ConfiguredPropertyDescriptor propertyDescriptor,
      AbstractBeanJobBuilder<?, ?, ?> beanJobBuilder,
      UserPreferences userPreferences) {
    super(beanJobBuilder, propertyDescriptor);
    _userPreferences = userPreferences;

    boolean openFileDialog = true;
    String[] extensions = null;

    FileProperty fileProperty = propertyDescriptor.getAnnotation(FileProperty.class);
    if (fileProperty != null) {
      openFileDialog = fileProperty.accessMode() == FileAccessMode.OPEN;

      extensions = fileProperty.extension();
    }

    _resourceTypeComboBox =
        new DCComboBox<String>(new String[] {"file", "url", "classpath", "vfs"});
    _filenameField =
        new FilenameTextField(_userPreferences.getConfiguredFileDirectory(), openFileDialog);
    _otherPathTextField = WidgetFactory.createTextField();

    if (extensions != null && extensions.length > 0) {
      List<FileFilter> filters = new ArrayList<FileFilter>(extensions.length);
      for (String extension : extensions) {
        String extensionWithDot;
        if (extension.startsWith(".")) {
          extensionWithDot = extension;
        } else {
          extensionWithDot = "." + extension;
        }
        FileFilter filter =
            new ExtensionFilter(extension.toUpperCase() + " file", extensionWithDot);
        filters.add(filter);
        _filenameField.addChoosableFileFilter(filter);
      }
      if (filters.size() == 1) {
        _filenameField.setSelectedFileFilter(filters.get(0));
      } else {
        FileFilter filter =
            FileFilters.combined(
                "All suggested file formats", filters.toArray(new FileFilter[filters.size()]));
        _filenameField.setSelectedFileFilter(filter);
      }
    } else {
      _filenameField.setSelectedFileFilter(FileFilters.ALL);
    }

    final Resource currentValue = getCurrentValue();
    if (currentValue == null) {
      _otherPathTextField.setVisible(false);
      _immutableValue = null;
    } else if (currentValue instanceof FileResource) {
      _otherPathTextField.setVisible(false);
      _filenameField.setFile(((FileResource) currentValue).getFile());
      _immutableValue = null;
    } else if (currentValue instanceof UrlResource
        || currentValue instanceof VfsResource
        || currentValue instanceof ClasspathResource) {
      _filenameField.setVisible(false);
      _immutableValue = null;
    } else {
      _filenameField.setVisible(false);
      _immutableValue = currentValue;
    }

    if (_immutableValue == null) {
      _filenameField
          .getTextField()
          .getDocument()
          .addDocumentListener(
              new DCDocumentListener() {
                @Override
                protected void onChange(DocumentEvent e) {
                  fireValueChanged();
                }
              });

      _filenameField.addFileSelectionListener(
          new FileSelectionListener() {
            @Override
            public void onSelected(FilenameTextField filenameTextField, File file) {
              File dir = file.getParentFile();
              _userPreferences.setConfiguredFileDirectory(dir);
              fireValueChanged();
            }
          });

      _otherPathTextField
          .getDocument()
          .addDocumentListener(
              new DCDocumentListener() {
                @Override
                protected void onChange(DocumentEvent event) {
                  fireValueChanged();
                }
              });
      _resourceTypeComboBox.addListener(
          new Listener<String>() {
            @Override
            public void onItemSelected(String item) {
              boolean isFileMode = "file".equals(item);
              _filenameField.setVisible(isFileMode);
              _otherPathTextField.setVisible(!isFileMode);

              fireValueChanged();
            }
          });

      final DCPanel panel =
          DCPanel.flow(
              Alignment.LEFT, 0, 0, _resourceTypeComboBox, _filenameField, _otherPathTextField);
      add(panel);
    } else {
      add(DCLabel.dark("- Resource: " + _immutableValue.getName() + " -"));
    }
  }
예제 #6
0
  private JButton createEditButton(final Datastore datastore) {
    final JButton editButton = WidgetFactory.createSmallButton("images/actions/edit.png");
    editButton.setToolTipText("Edit datastore");

    if (datastore instanceof JdbcDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injectorWithDatastore =
                  _injectorBuilder.with(JdbcDatastore.class, datastore).createInjector();
              JdbcDatastoreDialog dialog =
                  injectorWithDatastore.getInstance(JdbcDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof CsvDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(CsvDatastore.class, datastore).createInjector();
              CsvDatastoreDialog dialog = injector.getInstance(CsvDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof AccessDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(AccessDatastore.class, datastore).createInjector();
              AccessDatastoreDialog dialog = injector.getInstance(AccessDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof ExcelDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(ExcelDatastore.class, datastore).createInjector();
              ExcelDatastoreDialog dialog = injector.getInstance(ExcelDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof SasDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(SasDatastore.class, datastore).createInjector();
              SasDatastoreDialog dialog = injector.getInstance(SasDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof XmlDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(XmlDatastore.class, datastore).createInjector();
              XmlDatastoreDialog dialog = injector.getInstance(XmlDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof OdbDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(OdbDatastore.class, datastore).createInjector();
              OdbDatastoreDialog dialog = injector.getInstance(OdbDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof FixedWidthDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(FixedWidthDatastore.class, datastore).createInjector();
              FixedWidthDatastoreDialog dialog =
                  injector.getInstance(FixedWidthDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof DbaseDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(DbaseDatastore.class, datastore).createInjector();
              DbaseDatastoreDialog dialog = injector.getInstance(DbaseDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof CouchDbDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(CouchDbDatastore.class, datastore).createInjector();
              CouchDbDatastoreDialog dialog = injector.getInstance(CouchDbDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof MongoDbDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(MongoDbDatastore.class, datastore).createInjector();
              MongoDbDatastoreDialog dialog = injector.getInstance(MongoDbDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof SalesforceDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(SalesforceDatastore.class, datastore).createInjector();
              SalesforceDatastoreDialog dialog =
                  injector.getInstance(SalesforceDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof SugarCrmDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              Injector injector =
                  _injectorBuilder.with(SugarCrmDatastore.class, datastore).createInjector();
              SugarCrmDatastoreDialog dialog = injector.getInstance(SugarCrmDatastoreDialog.class);
              dialog.open();
            }
          });
    } else if (datastore instanceof CompositeDatastore) {
      editButton.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              CompositeDatastoreDialog dialog =
                  new CompositeDatastoreDialog(
                      (CompositeDatastore) datastore, _datastoreCatalog, _windowContext);
              dialog.open();
            }
          });
    } else {
      editButton.setEnabled(false);
    }

    if (!_datastoreCatalog.isDatastoreMutable(datastore.getName())) {
      editButton.setEnabled(false);
    }

    return editButton;
  }