Search in sources :

Example 1 with ConfigType

use of org.knime.timeseries.node.timemissvaluehandler.TimeMissingValueHandlingColSetting.ConfigType in project knime-core by knime.

the class TimeMissingValueHandlingPanel method createContent.

private void createContent(final TimeMissingValueHandlingColSetting setting, final DataColumnSpec... spec) throws InternalError {
    final List<String> warningMessages = new ArrayList<String>();
    // if we got incompatible types the original type is overwritten by unkown.
    ConfigType settingTypeBackup = setting.getType();
    JPanel tabPanel = new JPanel(new BorderLayout(0, 5));
    final JPanel comboRemovePanel = new JPanel(new BorderLayout(0, 2));
    Border border;
    final JComponent removePanel;
    final String typeName = ConfigType.NUMERICAL.equals(setting.getType()) ? "Numeric Columns" : "Non-numeric Columns";
    if (setting.isMetaConfig()) {
        border = BorderFactory.createTitledBorder(typeName);
        removePanel = new JLabel();
    } else {
        final List<String> names = new ArrayList<String>(Arrays.asList(setting.getNames()));
        for (DataColumnSpec cspec : spec) {
            names.remove(cspec.getName());
        }
        if (!names.isEmpty()) {
            throw new NullPointerException("Not equal on init: '" + Arrays.toString(setting.getNames()) + "' vs. '" + Arrays.toString(spec) + "'.");
        }
        JButton requestRemoveButton = new JButton("Remove");
        requestRemoveButton.addActionListener(new ActionListener() {

            /**
             * {@inheritDoc}
             */
            @Override
            public void actionPerformed(final ActionEvent e) {
                firePropertyChange(REMOVE_ACTION, null, null);
            }
        });
        removePanel = new JPanel();
        removePanel.setLayout(new BorderLayout());
        removePanel.add(requestRemoveButton, BorderLayout.NORTH);
        final List<DataColumnSpec> notExistingColumns = getNotExistingColumns(spec);
        final List<DataColumnSpec> incompatibleColumns = getIncompatibleTypedColumns(setting.getType(), spec);
        if (!notExistingColumns.isEmpty()) {
            warningMessages.add("Some columns no longer exist (red bordered)");
        }
        if (!incompatibleColumns.isEmpty()) {
            warningMessages.add(String.format("Some columns have an incompatible type to %s (yellow borderd)", ConfigType.typeToString(setting.getType())));
        }
        final Set<DataColumnSpec> invalidColumns = new HashSet<DataColumnSpec>();
        invalidColumns.addAll(notExistingColumns);
        invalidColumns.addAll(incompatibleColumns);
        if (!invalidColumns.isEmpty() && // if all columns are invalid a clean is the same as a remove
        !(invalidColumns.size() == spec.length)) {
            JButton removeNotExistingColumns = new JButton("Clean");
            removeNotExistingColumns.setToolTipText("Removes all invalid columns from the configuration.");
            removeNotExistingColumns.addActionListener(new ActionListener() {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public void actionPerformed(final ActionEvent e) {
                    TimeMissingValueHandlingPanel.this.removeAll();
                    // recreate the content, based on the new settings with removed invalid columns
                    createContent(diff(m_setting, invalidColumns), diff(spec, invalidColumns));
                    firePropertyChange(REMOVED_INVALID_COLUMNS, null, invalidColumns.toArray(new DataColumnSpec[invalidColumns.size()]));
                }
            });
            removePanel.add(removeNotExistingColumns);
        }
        if (!warningMessages.isEmpty()) {
            LOGGER.warn("get warnings during panel validation: " + warningMessages);
            border = BorderFactory.createLineBorder(Color.RED, 2);
            tabPanel.add(createWarningLabel(warningMessages), BorderLayout.NORTH);
        } else {
            border = BorderFactory.createLineBorder(Color.BLACK);
        }
    }
    createWestLayout(setting, tabPanel, typeName, spec);
    comboRemovePanel.add(m_comboBox, BorderLayout.CENTER);
    comboRemovePanel.add(removePanel, BorderLayout.EAST);
    fillComboBox(setting);
    setting.setType(settingTypeBackup);
    m_setting = setting;
    setBorder(border != null ? BorderFactory.createTitledBorder(border, typeName) : null);
    tabPanel.add(comboRemovePanel, BorderLayout.NORTH);
    tabPanel.add(createSpacer(65), BorderLayout.SOUTH);
    add(tabPanel);
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DataColumnSpec(org.knime.core.data.DataColumnSpec) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) ConfigType(org.knime.timeseries.node.timemissvaluehandler.TimeMissingValueHandlingColSetting.ConfigType) Border(javax.swing.border.Border) HashSet(java.util.HashSet)

Example 2 with ConfigType

use of org.knime.timeseries.node.timemissvaluehandler.TimeMissingValueHandlingColSetting.ConfigType in project knime-core by knime.

the class TimeMissingValueHandlingNodeDialogPane method checkButtonStatus.

/**
 * Enables/disables the button according to list selection.
 */
private void checkButtonStatus() {
    List<DataColumnSpec> selectedColumns = m_searchableListPanel.getSelectedColumns();
    if (selectedColumns.isEmpty()) {
        m_addButton.setEnabled(false);
    } else {
        // at least one item is selected, get its type and compare it
        // with all the other selected elements
        final ConfigType type = TimeMissValueNodeModel.initType(selectedColumns.get(0));
        for (DataColumnSpec dcs : selectedColumns) {
            ConfigType type2 = TimeMissValueNodeModel.initType(dcs);
            if (!type.equals(type2)) {
                m_addButton.setEnabled(false);
                return;
            }
        }
        final Component[] c = m_individualsPanel.getComponents();
        for (int i = 0; i < c.length; i++) {
            TimeMissingValueHandlingPanel p = (TimeMissingValueHandlingPanel) c[i];
            if (p.getSettings().isMetaConfig()) {
                continue;
            }
            final List<String> names = Arrays.asList(p.getSettings().getNames());
            for (DataColumnSpec dcs : selectedColumns) {
                if (names.contains(dcs.getName())) {
                    m_addButton.setEnabled(false);
                    return;
                }
            }
        }
        m_addButton.setEnabled(true);
    }
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) Component(java.awt.Component) ConfigType(org.knime.timeseries.node.timemissvaluehandler.TimeMissingValueHandlingColSetting.ConfigType)

Aggregations

DataColumnSpec (org.knime.core.data.DataColumnSpec)2 ConfigType (org.knime.timeseries.node.timemissvaluehandler.TimeMissingValueHandlingColSetting.ConfigType)2 BorderLayout (java.awt.BorderLayout)1 Component (java.awt.Component)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 Border (javax.swing.border.Border)1