@Override
  protected JComponent decorateCheckBox(final DCCheckBox<InputColumn<?>> checkBox) {
    final SourceColumnComboBox sourceColumnComboBox;
    final InputColumn<?> inputColumn = checkBox.getValue();
    if (_mappedColumnComboBoxes.containsKey(inputColumn)) {
      sourceColumnComboBox = _mappedColumnComboBoxes.get(inputColumn);
    } else {
      sourceColumnComboBox = createComboBox(inputColumn, null);
    }

    final JComponent decoratedSourceColumnComboBox =
        decorateSourceColumnComboBox(inputColumn, sourceColumnComboBox);

    checkBox.addListenerToHead(
        new DCCheckBox.Listener<InputColumn<?>>() {
          @Override
          public void onItemSelected(InputColumn<?> item, boolean selected) {
            _sourceColumnUpdating = true;
            decoratedSourceColumnComboBox.setVisible(selected);
          }
        });
    checkBox.addListener(
        new DCCheckBox.Listener<InputColumn<?>>() {
          @Override
          public void onItemSelected(InputColumn<?> item, boolean selected) {
            if (isBatchUpdating()) {
              return;
            }
            _mappedColumnNamesPropertyWidget.fireValueChanged();
            _sourceColumnUpdating = false;
          }
        });

    Table table = _tableRef.get();
    if (table != null) {
      sourceColumnComboBox.setModel(table);
    }

    decoratedSourceColumnComboBox.setVisible(checkBox.isSelected());

    final DCPanel panel = new DCPanel();
    panel.setLayout(new BorderLayout());
    panel.add(checkBox, BorderLayout.CENTER);
    panel.add(decoratedSourceColumnComboBox, BorderLayout.EAST);
    return panel;
  }
Ejemplo n.º 2
0
  private JComponent getAboutPanel() {
    final DCLabel headerLabel =
        DCLabel.dark("DataCleaner " + Version.getEdition() + " " + Version.getVersion());

    headerLabel.setFont(WidgetUtils.FONT_HEADER1);

    final ImageManager imageManager = ImageManager.get();

    final JButton datacleanerButton =
        new JButton(imageManager.getImageIcon("images/links/datacleaner.png"));
    datacleanerButton.addActionListener(new OpenBrowserAction("http://datacleaner.org"));
    datacleanerButton.setToolTipText("Visit the DataCleaner website");
    datacleanerButton.setBorder(null);

    final JButton bloggerButton =
        new JButton(imageManager.getImageIcon("images/links/blogger.png"));
    bloggerButton.addActionListener(new OpenBrowserAction("http://kasper.eobjects.org"));
    bloggerButton.setToolTipText("Follow along at our blog");
    bloggerButton.setBorder(null);

    final JButton linkedInButton =
        new JButton(imageManager.getImageIcon("images/links/linkedin.png"));
    linkedInButton.addActionListener(
        new OpenBrowserAction("http://www.linkedin.com/groups?gid=3352784"));
    linkedInButton.setToolTipText("Join the DataCleaner LinkedIn group");
    linkedInButton.setBorder(null);

    final DCPanel buttonPanel = new DCPanel();
    buttonPanel.setLayout(new HorizontalLayout());
    buttonPanel.add(datacleanerButton);
    buttonPanel.add(Box.createHorizontalStrut(10));
    buttonPanel.add(bloggerButton);
    buttonPanel.add(Box.createHorizontalStrut(10));
    buttonPanel.add(linkedInButton);

    final HumanInferenceToolbarButton humanInferenceButton =
        new HumanInferenceToolbarButton(
            imageManager.getImageIcon("images/powered-by-human-inference-bright.png"));

    final DCPanel contentPanel = new DCPanel();
    contentPanel.setLayout(new VerticalLayout());
    contentPanel.add(headerLabel);
    contentPanel.add(
        DCLabel.dark(
            "Copyright (C) " + Calendar.getInstance().get(Calendar.YEAR) + " Human Inference"));
    contentPanel.add(Box.createVerticalStrut(20));
    contentPanel.add(DCPanel.around(humanInferenceButton));

    if (Version.isCommunityEdition()) {
      contentPanel.add(Box.createVerticalStrut(20));
      contentPanel.add(DCLabel.dark("Licensed under the LGPL license"));
      contentPanel.add(DCLabel.dark("(see Licensing tab)."));
    } else {
      final String licenseKey = Version.getLicenseKey();
      contentPanel.add(Box.createVerticalStrut(20));
      contentPanel.add(DCLabel.dark("License key: " + licenseKey));
    }

    contentPanel.add(Box.createVerticalStrut(30));
    contentPanel.add(DCLabel.dark("Java runtime information:"));
    contentPanel.add(DCLabel.dark("  " + System.getProperty("java.vm.name")));
    contentPanel.add(DCLabel.dark("  by " + System.getProperty("java.vm.vendor")));
    contentPanel.add(DCLabel.dark("  version " + System.getProperty("java.runtime.version")));
    contentPanel.add(Box.createVerticalStrut(30));
    contentPanel.add(buttonPanel);

    final DCPanel mainPanel =
        new DCPanel(
            imageManager.getImage("images/window/app-icon-hires.png"),
            97,
            10,
            WidgetUtils.BG_COLOR_BRIGHT,
            WidgetUtils.BG_COLOR_BRIGHTEST);
    mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
    mainPanel.setLayout(new VerticalLayout());
    mainPanel.add(contentPanel);

    return mainPanel;
  }
Ejemplo n.º 3
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() + " -"));
    }
  }