Search in sources :

Example 6 with DataColumnSpecListCellRenderer

use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.

the class AddOutFieldDialog method initKnimeNameComboBox.

/**
 * Initialize the selection list for the knime name.
 */
private void initKnimeNameComboBox() {
    m_replacedKnimeName.removeAllItems();
    if (m_fieldType.getSelectedItem().equals(FieldType.Column)) {
        for (DataColumnSpec colSpec : m_spec) {
            m_replacedKnimeName.addItem(colSpec);
        }
        m_replacedKnimeName.setRenderer(new DataColumnSpecListCellRenderer());
    } else {
        for (FlowVariable flowVar : m_flowVars.values()) {
            // created.
            if (OutFieldsTableModel.verifyNameOfFlowVariable(flowVar.getName())) {
                m_replacedKnimeName.addItem(flowVar);
            }
        }
        m_replacedKnimeName.setRenderer(new FlowVariableListCellRenderer());
    }
    if (m_replacedKnimeName.getItemCount() <= 0) {
        m_replacedKnimeName.setEnabled(false);
        m_knimeName.setEnabled(true);
        m_replace.setEnabled(false);
        m_replace.setSelected(false);
        m_append.setSelected(true);
    } else {
        m_replacedKnimeName.setEnabled(true);
        m_replace.setEnabled(true);
    }
}
Also used : DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) FlowVariableListCellRenderer(org.knime.core.node.util.FlowVariableListCellRenderer) DataColumnSpec(org.knime.core.data.DataColumnSpec) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 7 with DataColumnSpecListCellRenderer

use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.

the class RankNodeDialog method initRankTableBox.

private Box initRankTableBox() {
    Box columnTableBox = Box.createVerticalBox();
    columnTableBox.setBorder(new TitledBorder("Ranking Attributes"));
    m_rankTableModel = new DefaultTableModel(new String[] { "Attribute", "Order" }, 0);
    DefaultTableColumnModel columnModel = new DefaultTableColumnModel();
    m_rankJTable = new JTable(m_rankTableModel, columnModel);
    m_rankJTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_rankJTable.setCellSelectionEnabled(false);
    m_rankJTable.setColumnSelectionAllowed(false);
    m_rankJTable.getTableHeader().setReorderingAllowed(false);
    m_rankJTable.setRowSelectionAllowed(true);
    TableColumn colColumn = new TableColumn();
    colColumn.setHeaderValue("Column");
    colColumn.setCellRenderer(new DataColumnSpecTableCellRenderer());
    m_rankColEditorModel = new DefaultComboBoxModel<DataColumnSpec>();
    m_rankColEditor = new JComboBox<DataColumnSpec>(m_rankColEditorModel);
    m_rankColEditor.setRenderer(new DataColumnSpecListCellRenderer());
    m_rankColEditor.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            // TODO Auto-generated method stub
            if (!m_availableEdited) {
                DataColumnSpec colSpec = (DataColumnSpec) e.getItem();
                int state = e.getStateChange();
                if (state == ItemEvent.SELECTED && m_rankJTable.isEditing()) {
                    m_availableCols.remove(colSpec);
                    removeItemGroupColEditor(colSpec);
                    // removeItemRankColEditor(colSpec);
                    m_rankCols.add(colSpec);
                } else if (state == ItemEvent.DESELECTED && m_rankJTable.isEditing()) {
                    m_rankCols.remove(colSpec);
                    if (!m_rankCols.contains(colSpec)) {
                        add2AvailableList(colSpec);
                        addItemGroupColEditor(colSpec);
                    }
                }
            }
        }
    });
    colColumn.setCellEditor(new DefaultCellEditor(m_rankColEditor));
    TableColumn orderColumn = new TableColumn(1);
    orderColumn.setHeaderValue("Order");
    // combo box for order column
    JComboBox<String> orderColumnEditor = new JComboBox<String>();
    orderColumnEditor.addItem("Ascending");
    orderColumnEditor.addItem("Descending");
    orderColumn.setCellEditor(new DefaultCellEditor(orderColumnEditor));
    columnModel.addColumn(colColumn);
    columnModel.addColumn(orderColumn);
    JScrollPane scrollPane = new JScrollPane(m_rankJTable);
    scrollPane.setPreferredSize(m_rankJTable.getPreferredSize());
    columnTableBox.add(scrollPane);
    columnTableBox.setSize(scrollPane.getSize());
    return columnTableBox;
}
Also used : JScrollPane(javax.swing.JScrollPane) DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) ItemEvent(java.awt.event.ItemEvent) DefaultTableColumnModel(javax.swing.table.DefaultTableColumnModel) JComboBox(javax.swing.JComboBox) DefaultTableModel(javax.swing.table.DefaultTableModel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) TitledBorder(javax.swing.border.TitledBorder) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) DataColumnSpec(org.knime.core.data.DataColumnSpec) JTable(javax.swing.JTable) DataColumnSpecTableCellRenderer(org.knime.core.node.util.DataColumnSpecTableCellRenderer) ItemListener(java.awt.event.ItemListener)

Example 8 with DataColumnSpecListCellRenderer

use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.

the class RankNodeDialog method initGroupTableBox.

private Box initGroupTableBox() {
    Box groupTableBox = Box.createVerticalBox();
    groupTableBox.setBorder(new TitledBorder("Grouping Attributes"));
    m_groupTableModel = new DefaultTableModel(new String[] { "Attribute" }, 0);
    m_groupJTable = new JTable(m_groupTableModel);
    m_groupJTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    TableColumn column = m_groupJTable.getColumn("Attribute");
    column.setCellRenderer(new DataColumnSpecTableCellRenderer());
    m_groupColEditorModel = new DefaultComboBoxModel<DataColumnSpec>();
    m_groupColEditor = new JComboBox<DataColumnSpec>(m_groupColEditorModel);
    m_groupColEditor.setRenderer(new DataColumnSpecListCellRenderer());
    m_groupColEditor.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (!m_availableEdited) {
                DataColumnSpec colSpec = (DataColumnSpec) e.getItem();
                int state = e.getStateChange();
                if (state == ItemEvent.SELECTED && m_groupJTable.isEditing()) {
                    m_availableCols.remove(colSpec);
                    removeItemRankColEditor(colSpec);
                    m_groupCols.add(colSpec);
                } else if (state == ItemEvent.DESELECTED && m_groupJTable.isEditing()) {
                    m_groupCols.remove(colSpec);
                    if (!m_groupCols.contains(colSpec)) {
                        add2AvailableList(colSpec);
                        addItemRankColEditor(colSpec);
                    }
                }
            }
        }
    });
    column.setCellEditor(new DefaultCellEditor(m_groupColEditor));
    JScrollPane scrollPane = new JScrollPane(m_groupJTable);
    scrollPane.setMinimumSize(m_rankJTable.getPreferredSize());
    scrollPane.setPreferredSize(m_rankJTable.getPreferredSize());
    groupTableBox.add(new JScrollPane(scrollPane));
    return groupTableBox;
}
Also used : JScrollPane(javax.swing.JScrollPane) DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) ItemEvent(java.awt.event.ItemEvent) DefaultTableModel(javax.swing.table.DefaultTableModel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) TitledBorder(javax.swing.border.TitledBorder) TableColumn(javax.swing.table.TableColumn) DefaultCellEditor(javax.swing.DefaultCellEditor) DataColumnSpec(org.knime.core.data.DataColumnSpec) JTable(javax.swing.JTable) DataColumnSpecTableCellRenderer(org.knime.core.node.util.DataColumnSpecTableCellRenderer) ItemListener(java.awt.event.ItemListener)

Example 9 with DataColumnSpecListCellRenderer

use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.

the class ColumnHandlingFactorySelectionPanel method createContent.

private void createContent(final PortObjectSpec[] specs, final int tableIndex) {
    this.setLayout(new BorderLayout());
    final DataTableSpec tableSpec = (DataTableSpec) specs[tableIndex];
    final JList<String> jList = new JList<String>(m_settings.getColumns().toArray(new String[0]));
    final Border border;
    final JPanel eastPanel = new JPanel(new BorderLayout());
    jList.setCellRenderer(new DataColumnSpecListCellRenderer() {

        @SuppressWarnings("rawtypes")
        @Override
        public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
            DataColumnSpec spec = tableSpec.getColumnSpec(value.toString());
            if (spec == null) {
                spec = createInvalidSpec(value.toString());
            }
            // The super method will reset the icon if we call this method
            // last. So we let super do its job first and then we take care
            // that everything is properly set.
            super.getListCellRendererComponent(list, spec, index, isSelected, cellHasFocus);
            if (MissingValueHandlerNodeDialog.isIncompatible(spec)) {
                setBorder(BorderFactory.createLineBorder(Color.YELLOW));
            }
            return this;
        }
    });
    jList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            jList.setSelectedIndices(new int[0]);
        }
    });
    // Make the list scrollable by embedding it in a scroll pane
    JScrollPane columns = new JScrollPane(jList);
    columns.setMaximumSize(new Dimension(120, 150));
    columns.setPreferredSize(new Dimension(120, 150));
    // This button fires the remove event so that the panel is removed from its parent
    JButton requestRemoveButton = new JButton("Remove");
    requestRemoveButton.addActionListener(new ActionListener() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void actionPerformed(final ActionEvent e) {
            firePropertyChange(REMOVE_ACTION, null, null);
        }
    });
    JPanel removePanel = new JPanel();
    removePanel.setLayout(new GridLayout(0, 2));
    final List<String> notExistingColumns = getNotExistingColumns(tableSpec);
    // If the factory allows all types, there are no incompatible columns
    final List<String> incompatibleColumns = getIncompatibleTypedColumns(m_settings.getSettings().getFactory(), tableSpec);
    final List<String> warningMessages = new ArrayList<String>();
    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 for factory %s (yellow borderd)", m_settings.getSettings().getFactory().getDisplayName()));
    }
    final Set<String> invalidColumns = new HashSet<String>();
    invalidColumns.addAll(notExistingColumns);
    invalidColumns.addAll(incompatibleColumns);
    if (!invalidColumns.isEmpty() && // if all columns are invalid a clean is the same as a remove
    !(invalidColumns.size() == m_settings.getColumns().size())) {
        final 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) {
                List<String> toRemove = new ArrayList<String>();
                // recreate the content, based on the new settings with removed invalid columns
                for (String s : m_settings.getColumns()) {
                    for (String spec : invalidColumns) {
                        if (spec.equals(s)) {
                            toRemove.add(s);
                        }
                    }
                }
                for (String s : toRemove) {
                    m_settings.getColumns().remove(s);
                }
                removeNotExistingColumns.setVisible(false);
                jList.setListData(m_settings.getColumns().toArray(new String[0]));
                ColumnHandlingFactorySelectionPanel.this.setBorder(BorderFactory.createLineBorder(Color.GRAY));
                firePropertyChange(REMOVED_INVALID_COLUMNS, null, invalidColumns.toArray(new String[invalidColumns.size()]));
            }
        });
        removePanel.add(removeNotExistingColumns);
    } else {
        // Add dummy label to keep the remove button on the right side
        removePanel.add(new JLabel());
    }
    removePanel.add(requestRemoveButton);
    if (!warningMessages.isEmpty()) {
        LOGGER.warn("get warnings during panel validation: " + warningMessages);
        border = BorderFactory.createLineBorder(Color.RED, 2);
        eastPanel.add(createWarningLabel(warningMessages), BorderLayout.NORTH);
    } else {
        border = BorderFactory.createLineBorder(Color.GRAY);
    }
    setBorder(border);
    eastPanel.add(removePanel, BorderLayout.NORTH);
    // Determine data type
    List<String> validCols = new ArrayList<String>();
    validCols.addAll(m_settings.getColumns());
    validCols.removeAll(invalidColumns);
    DataType[] dt = new DataType[validCols.size()];
    if (validCols.size() > 0) {
        for (int i = 0; i < validCols.size(); i++) {
            dt[i] = tableSpec.getColumnSpec(validCols.get(i)).getType();
        }
    }
    m_settingsPanel = new MissingValueHandlerFactorySelectionPanel(dt, m_settings.getSettings(), m_factoryManager, specs);
    m_settingsPanel.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals(MissingValueHandlerFactorySelectionPanel.SELECTED_FACTORY_CHANGE)) {
                ColumnHandlingFactorySelectionPanel.this.firePropertyChange(MissingValueHandlerFactorySelectionPanel.SELECTED_FACTORY_CHANGE, null, null);
            }
        }
    });
    eastPanel.add(m_settingsPanel, BorderLayout.CENTER);
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, columns, eastPanel);
    this.add(splitPane, BorderLayout.CENTER);
    splitPane.setResizeWeight(0.5);
}
Also used : JPanel(javax.swing.JPanel) DataTableSpec(org.knime.core.data.DataTableSpec) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) GridLayout(java.awt.GridLayout) DataColumnSpec(org.knime.core.data.DataColumnSpec) BorderLayout(java.awt.BorderLayout) DataType(org.knime.core.data.DataType) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) Component(java.awt.Component) HashSet(java.util.HashSet) JScrollPane(javax.swing.JScrollPane) DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) PropertyChangeEvent(java.beans.PropertyChangeEvent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) Border(javax.swing.border.Border) JList(javax.swing.JList)

Example 10 with DataColumnSpecListCellRenderer

use of org.knime.core.node.util.DataColumnSpecListCellRenderer in project knime-core by knime.

the class TimeMissingValueHandlingPanel method createWestLayout.

private void createWestLayout(final TimeMissingValueHandlingColSetting setting, final JPanel tabPanel, final String typeName, final DataColumnSpec... spec) {
    if (setting.isMetaConfig()) {
        JPanel typePanel = new JPanel(new BorderLayout());
        typePanel.add(m_comboBox, BorderLayout.NORTH);
        tabPanel.add(typePanel, BorderLayout.WEST);
    } else {
        final JList<?> jList = new JList<Object>(spec);
        jList.setCellRenderer(new DataColumnSpecListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(@SuppressWarnings("rawtypes") final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
                // The super method will reset the icon if we call this method
                // last. So we let super do its job first and then we take care
                // that everything is properly set.
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                String text = null;
                if (value instanceof DataColumnSpec && TimeMissingValueHandlingNodeDialogPane.isIncompatible((DataColumnSpec) value)) {
                    setBorder(BorderFactory.createLineBorder(Color.YELLOW));
                }
                setToolTipText(text);
                return this;
            }
        });
        jList.addListSelectionListener(new ListSelectionListener() {

            @Override
            public void valueChanged(final ListSelectionEvent e) {
                jList.setSelectedIndices(new int[0]);
            }
        });
        JScrollPane columns = new JScrollPane(jList);
        columns.setPreferredSize(new Dimension(250, 50));
        tabPanel.add(columns, BorderLayout.CENTER);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) ListSelectionEvent(javax.swing.event.ListSelectionEvent) Dimension(java.awt.Dimension) ListSelectionListener(javax.swing.event.ListSelectionListener) DataColumnSpec(org.knime.core.data.DataColumnSpec) BorderLayout(java.awt.BorderLayout) JComponent(javax.swing.JComponent) Component(java.awt.Component) JList(javax.swing.JList)

Aggregations

DataColumnSpecListCellRenderer (org.knime.core.node.util.DataColumnSpecListCellRenderer)11 JScrollPane (javax.swing.JScrollPane)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)8 JList (javax.swing.JList)6 Dimension (java.awt.Dimension)5 BorderLayout (java.awt.BorderLayout)4 Component (java.awt.Component)4 Box (javax.swing.Box)4 JPanel (javax.swing.JPanel)4 ListSelectionEvent (javax.swing.event.ListSelectionEvent)4 ListSelectionListener (javax.swing.event.ListSelectionListener)4 JCheckBox (javax.swing.JCheckBox)3 JComponent (javax.swing.JComponent)3 JLabel (javax.swing.JLabel)3 JSplitPane (javax.swing.JSplitPane)3 TitledBorder (javax.swing.border.TitledBorder)3 FlowVariableListCellRenderer (org.knime.core.node.util.FlowVariableListCellRenderer)3 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 MouseAdapter (java.awt.event.MouseAdapter)2