Search in sources :

Example 86 with MouseAdapter

use of java.awt.event.MouseAdapter in project knime-core by knime.

the class MissingValueHandling2NodeDialogPane method loadSettingsFrom.

/**
 * {@inheritDoc}
 */
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs) throws NotConfigurableException {
    m_searchableListModifier = m_searchableListPanel.update(specs[0]);
    MissingValueHandling2ColSetting[] defaults = MissingValueHandling2ColSetting.loadMetaColSettings(settings, specs[0]);
    MissingValueHandling2ColSetting[] individuals = MissingValueHandling2ColSetting.loadIndividualColSettings(settings, specs[0]);
    m_defaultsPanel.removeAll();
    for (int i = 0; i < defaults.length; i++) {
        final MissingValueHandling2Panel p = new MissingValueHandling2Panel(defaults[i], (DataColumnSpec) null);
        m_defaultsPanel.add(p);
    }
    m_individualsPanel.removeAll();
    Set<String> invalidColumns = new LinkedHashSet<String>();
    for (int i = 0; i < individuals.length; i++) {
        String[] names = individuals[i].getNames();
        ArrayList<DataColumnSpec> colSpecs = new ArrayList<DataColumnSpec>();
        for (int j = 0; j < names.length; j++) {
            final DataColumnSpec cspec = specs[0].getColumnSpec(names[j]);
            if (cspec == null) {
                LOGGER.debug("No such column in spec: " + names[j]);
                DataColumnSpec createUnkownSpec = createUnkownSpec(names[j], individuals[i]);
                colSpecs.add(createUnkownSpec);
                invalidColumns.add(names[j]);
            } else {
                colSpecs.add(cspec);
            }
        }
        if (!colSpecs.isEmpty()) {
            names = new String[colSpecs.size()];
            for (int j = 0; j < names.length; j++) {
                names[j] = colSpecs.get(j).getName();
            }
            individuals[i].setNames(names);
            markIncompatibleTypedColumns(individuals[i].getType(), colSpecs);
            final MissingValueHandling2Panel p = new MissingValueHandling2Panel(individuals[i], colSpecs.toArray(new DataColumnSpec[0]));
            p.registerMouseListener(new MouseAdapter() {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public void mouseClicked(final MouseEvent me) {
                    selectColumns(p.getSettings());
                }
            });
            addToIndividualPanel(p);
        }
    }
    m_searchableListModifier.addInvalidColumns(invalidColumns.toArray(new String[invalidColumns.size()]));
    m_individualsPanel.setPreferredSize(m_defaultsPanel.getPreferredSize());
    checkButtonStatus();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) MouseAdapter(java.awt.event.MouseAdapter) DataColumnSpec(org.knime.core.data.DataColumnSpec)

Example 87 with MouseAdapter

use of java.awt.event.MouseAdapter in project knime-core by knime.

the class MissingValueHandling2NodeDialogPane method onAdd.

private void onAdd(final List<DataColumnSpec> specs) {
    if (specs == null || specs.isEmpty()) {
        return;
    }
    final MissingValueHandling2Panel p = new MissingValueHandling2Panel(specs);
    p.registerMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent me) {
            selectColumns(p.getSettings());
        }
    });
    addToIndividualPanel(p);
    checkButtonStatus();
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter)

Example 88 with MouseAdapter

use of java.awt.event.MouseAdapter in project knime-core by knime.

the class ColumnSelectionSearchableListPanel method addKeyMouseSelectionListerersToColumnList.

private void addKeyMouseSelectionListerersToColumnList() {
    m_columnList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (KeyEvent.VK_ENTER == e.getKeyChar()) {
                fireConfigurationRequested(Type.CREATION);
            } else if (KeyEvent.VK_DELETE == e.getKeyChar()) {
                fireConfigurationRequested(Type.DELETION);
            }
        }
    });
    m_columnList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                fireConfigurationRequested(Type.CREATION);
            }
        }
    });
    m_columnList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            fireConfigurationRequested(Type.SELECTION);
        }
    });
}
Also used : KeyEvent(java.awt.event.KeyEvent) MouseEvent(java.awt.event.MouseEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 89 with MouseAdapter

use of java.awt.event.MouseAdapter in project knime-core by knime.

the class DataValidatorColPanel method createWestLayout.

/**
 * @param tabPanel
 * @param spec
 * @param setting
 * @param icon
 * @param name
 */
private void createWestLayout(final JPanel tabPanel, final List<DataColumnSpec> spec) {
    m_defaultListModel = new DefaultListModel<>();
    for (DataColumnSpec s : spec) {
        m_defaultListModel.addElement(s);
    }
    m_defaultListModel.addElement(DROP_COLUMN_PLACEHOLDER);
    final JList<Object> jList = new JList<>(m_defaultListModel);
    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) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value != DROP_COLUMN_PLACEHOLDER) {
                return this;
            }
            setIcon(DnDConfigurationPanel.ADD_ICON_16);
            setText("<drop columns>");
            setForeground(isSelected ? Color.white : Color.gray);
            return this;
        }
    });
    jList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    jList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selectedItem = jList.getSelectedValue();
                if (selectedItem != null && selectedItem instanceof DataColumnSpec) {
                    DataColumnSpec selectedValue = (DataColumnSpec) selectedItem;
                    m_defaultListModel.removeElement(selectedValue);
                    String colName = selectedValue.getName();
                    List<String> asList = new ArrayList<>(Arrays.asList(m_setting.getNames()));
                    asList.remove(colName);
                    if (asList.isEmpty()) {
                        firePropertyChange(REMOVE_ACTION, null, null);
                    } else {
                        firePropertyChange(REMOVED_COLUMNS, null, new DataColumnSpec[] { selectedValue });
                        DataColumnSpec[] currSpecs = new DataColumnSpec[m_defaultListModel.size() - 1];
                        // let the last item go
                        for (int i = 0; i < m_defaultListModel.size() - 1; i++) {
                            currSpecs[i] = (DataColumnSpec) m_defaultListModel.get(i);
                        }
                        if (isInvalid(selectedValue)) {
                            DataValidatorColPanel.this.removeAll();
                            createContent(Arrays.asList(currSpecs));
                        } else {
                            updateUiElements(Arrays.asList(currSpecs));
                            DataValidatorColPanel.this.repaint();
                        }
                    }
                    m_setting.setNames(asList.toArray(new String[asList.size()]));
                }
            }
        }
    });
    JScrollPane columns = new JScrollPane(jList);
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(10, 10, 10, 10);
    c.gridx = 0;
    c.gridy = 1;
    c.gridheight = 2;
    c.weightx = 1;
    tabPanel.add(columns, c);
}
Also used : JScrollPane(javax.swing.JScrollPane) DataColumnSpecListCellRenderer(org.knime.core.node.util.DataColumnSpecListCellRenderer) GridBagConstraints(java.awt.GridBagConstraints) MouseEvent(java.awt.event.MouseEvent) Insets(java.awt.Insets) MouseAdapter(java.awt.event.MouseAdapter) DataColumnSpec(org.knime.core.data.DataColumnSpec) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) JComponent(javax.swing.JComponent) Component(java.awt.Component) JList(javax.swing.JList)

Example 90 with MouseAdapter

use of java.awt.event.MouseAdapter in project knime-core by knime.

the class DataValidatorNodeDialogPane method onAdd.

private void onAdd(final List<DataColumnSpec> specs) {
    if (specs == null || specs.isEmpty()) {
        return;
    }
    final DataValidatorColPanel p = new DataValidatorColPanel(this, specs);
    p.registerMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent me) {
            selectColumns(p.getSettings());
        }
    });
    addToIndividualPanel(p);
    moveToSelection();
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter)

Aggregations

MouseAdapter (java.awt.event.MouseAdapter)202 MouseEvent (java.awt.event.MouseEvent)199 JLabel (javax.swing.JLabel)52 JPanel (javax.swing.JPanel)48 ActionEvent (java.awt.event.ActionEvent)36 JScrollPane (javax.swing.JScrollPane)36 BorderLayout (java.awt.BorderLayout)35 Dimension (java.awt.Dimension)34 JButton (javax.swing.JButton)33 ActionListener (java.awt.event.ActionListener)32 Insets (java.awt.Insets)24 GridBagConstraints (java.awt.GridBagConstraints)20 KeyEvent (java.awt.event.KeyEvent)20 KeyAdapter (java.awt.event.KeyAdapter)19 JTextField (javax.swing.JTextField)16 ListSelectionEvent (javax.swing.event.ListSelectionEvent)16 Component (java.awt.Component)15 Point (java.awt.Point)15 JTable (javax.swing.JTable)15 ListSelectionListener (javax.swing.event.ListSelectionListener)15