Search in sources :

Example 1 with FlowVariableModel

use of org.knime.core.node.FlowVariableModel in project knime-core by knime.

the class RuleEngineNodeDialog method createEditorPart.

/*
     * Editor part (from top to bottom, from left to right): default label
     * (label, text field) new column name (label, text field) rule editor (rule
     * text field, outcome text field, add button, clear button) error text
     * field
     */
private Box createEditorPart() {
    /*
         * Default label box
         */
    m_defaultLabelEditor = new JTextField(10);
    m_defaultLabelEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
    m_defaultLabelEditor.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            if (m_defaultLabelEditor.getText().equals(DEFAULT_LABEL)) {
                m_defaultLabelEditor.setText("");
            }
            m_lastUsedTextfield = m_defaultLabelEditor;
        }
    });
    JPanel defaultLabelBox = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 0.1;
    c.anchor = GridBagConstraints.WEST;
    c.insets = new Insets(0, 20, 0, 0);
    defaultLabelBox.add(new JLabel("Default label (if no rule matches): "), c);
    c.insets = new Insets(0, 0, 0, 0);
    c.gridx++;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    defaultLabelBox.add(m_defaultLabelEditor, c);
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.1;
    // also add a variable Model + corresponding icon to make this
    // option controllable via a variable
    FlowVariableModel fvm = createFlowVariableModel(RuleEngineSettings.CFG_DEFAULT_LABEL, FlowVariable.Type.STRING);
    fvm.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent evt) {
            FlowVariableModel svm = (FlowVariableModel) (evt.getSource());
            m_defaultLabelEditor.setEnabled(!svm.isVariableReplacementEnabled());
        }
    });
    c.gridx++;
    defaultLabelBox.add(new FlowVariableModelButton(fvm), c);
    c.gridx++;
    defaultLabelBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
    c.gridy++;
    c.gridx = 1;
    m_defaultLabelIsColumn = new JCheckBox("is a column reference");
    defaultLabelBox.add(m_defaultLabelIsColumn, c);
    /*
         * New column name box
         */
    m_newColumnName = new JTextField(10);
    m_newColumnName.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
    m_newColumnName.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            if (m_newColumnName.getText().equals(NEW_COL_NAME)) {
                m_newColumnName.setText("");
            }
        }
    });
    Box newColNameBox = Box.createHorizontalBox();
    newColNameBox.add(Box.createHorizontalStrut(20));
    newColNameBox.add(new JLabel("Appended column name: "));
    newColNameBox.add(Box.createHorizontalGlue());
    newColNameBox.add(m_newColumnName);
    newColNameBox.add(Box.createHorizontalGlue());
    newColNameBox.add(Box.createHorizontalStrut(10));
    newColNameBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, 30));
    /*
         * Rule Box
         */
    JPanel ruleBox = new JPanel(new GridBagLayout());
    m_ruleEditor = new JTextField(RULE_LABEL, 35);
    m_ruleEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
    m_ruleEditor.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            if (m_ruleEditor.getText().equals(RULE_LABEL)) {
                m_ruleEditor.setText("");
            }
            m_lastUsedTextfield = m_ruleEditor;
        }
    });
    m_ruleLabelEditor = new JTextField(OUTCOME_LABEL, 10);
    m_ruleLabelEditor.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
    m_ruleLabelEditor.addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(final FocusEvent e) {
            if (m_ruleLabelEditor.getText().equals(OUTCOME_LABEL)) {
                m_ruleLabelEditor.setText("");
            }
            m_lastUsedTextfield = m_ruleLabelEditor;
        }
    });
    m_lastUsedTextfield = m_ruleEditor;
    /*
         * Add Button
         */
    JButton add = new JButton("Add");
    add.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent arg0) {
            LOGGER.debug("adding: " + m_ruleEditor.getText() + "=>" + m_ruleLabelEditor.getText());
            addRule();
            m_lastUsedTextfield = m_ruleEditor;
        }
    });
    /*
         * Clear Button
         */
    JButton clear = new JButton("Clear");
    clear.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent arg0) {
            m_ruleEditor.setText("");
            m_ruleLabelEditor.setText("");
        }
    });
    m_outcomeIsColumn = new JCheckBox("is a column reference");
    /*
         * Putting the rule editor together (rule, outcome, add, clear)
         */
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(0, 20, 0, 0);
    c.weightx = 0.8;
    c.fill = GridBagConstraints.HORIZONTAL;
    ruleBox.add(new JLabel("Condition"), c);
    c.gridx++;
    c.weightx = 0.1;
    c.insets = new Insets(0, 5, 0, 0);
    ruleBox.add(new JLabel("Outcome"), c);
    c.gridx = 0;
    c.gridy++;
    c.insets = new Insets(0, 20, 0, 0);
    ruleBox.add(m_ruleEditor, c);
    c.insets = new Insets(0, 5, 0, 0);
    c.gridx++;
    c.weightx = 0.1;
    ruleBox.add(m_ruleLabelEditor, c);
    c.insets = new Insets(0, 10, 0, 0);
    c.fill = GridBagConstraints.NONE;
    c.gridx++;
    ruleBox.add(add, c);
    c.gridx++;
    ruleBox.add(clear, c);
    c.gridy++;
    c.gridx = 1;
    c.insets = new Insets(0, 5, 0, 0);
    ruleBox.add(m_outcomeIsColumn, c);
    /*
         * Putting it all together
         */
    Box editorBox = Box.createVerticalBox();
    editorBox.add(newColNameBox);
    editorBox.add(Box.createVerticalStrut(20));
    editorBox.add(defaultLabelBox);
    editorBox.add(Box.createVerticalStrut(20));
    editorBox.add(ruleBox);
    editorBox.add(Box.createVerticalStrut(20));
    m_error = new JLabel(" ");
    m_error.setForeground(Color.RED);
    editorBox.add(m_error);
    editorBox.setBorder(BorderFactory.createEtchedBorder());
    return editorBox;
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) FocusEvent(java.awt.event.FocusEvent) FlowVariableModel(org.knime.core.node.FlowVariableModel) JCheckBox(javax.swing.JCheckBox) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) FlowVariableModelButton(org.knime.core.node.FlowVariableModelButton) ChangeListener(javax.swing.event.ChangeListener)

Example 2 with FlowVariableModel

use of org.knime.core.node.FlowVariableModel in project knime-core by knime.

the class DialogComponentNumberEdit method setEnabledComponents.

/**
 * {@inheritDoc}
 */
@Override
protected void setEnabledComponents(final boolean enabled) {
    boolean valueFieldEnabled = enabled;
    // enable the spinner according to the variable model
    if (m_fvmButton != null) {
        FlowVariableModel svmModel = m_fvmButton.getFlowVariableModel();
        if (svmModel.isVariableReplacementEnabled()) {
            valueFieldEnabled = false;
        }
        m_fvmButton.setEnabled(enabled);
    }
    m_valueField.setEnabled(valueFieldEnabled);
}
Also used : FlowVariableModel(org.knime.core.node.FlowVariableModel)

Example 3 with FlowVariableModel

use of org.knime.core.node.FlowVariableModel in project knime-core by knime.

the class ColumnRowFilterPanel method instantiateComponents.

@SuppressWarnings("unchecked")
private void instantiateComponents(final RowFilterNodeDialogPane parentPane, final DataTableSpec tSpec) throws NotConfigurableException {
    /* instantiate the col idx selector, depending on the table spec */
    assert ((tSpec != null) && (tSpec.getNumColumns() > 0));
    Vector<String> colNames = new Vector<String>();
    for (int c = 0; c < tSpec.getNumColumns(); c++) {
        colNames.add(tSpec.getColumnSpec(c).getName());
    }
    m_colCombo = new ColumnSelectionComboxBox((Border) null, DataValue.class);
    m_colCombo.update(tSpec, null);
    m_colCombo.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            selectedColChanged();
        }
    });
    m_deepFiltering = new JCheckBox("filter based on collection elements");
    /* the selectors for what kind of checking will be done */
    m_useRange = new JRadioButton("use range checking");
    m_useRegExpr = new JRadioButton("use pattern matching");
    m_useMissValue = new JRadioButton("only missing values match");
    m_useRange.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            radiosChanged();
        }
    });
    m_useRegExpr.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            radiosChanged();
        }
    });
    m_useMissValue.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            radiosChanged();
        }
    });
    m_radios = new ButtonGroup();
    m_radios.add(m_useRange);
    m_radios.add(m_useRegExpr);
    m_radios.add(m_useMissValue);
    /* the bound edit fields */
    m_lowerLabel = new JLabel("lower bound:");
    m_lowerLabel.setToolTipText("Smallest value of the range to be filtered.");
    m_lowerBound = new JTextField();
    m_upperLabel = new JLabel("upper bound:");
    m_upperLabel.setToolTipText("Largest value of the range to be filtered.");
    m_upperBound = new JTextField();
    m_lowerBound.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(final DocumentEvent e) {
            boundsChanged();
        }

        @Override
        public void removeUpdate(final DocumentEvent e) {
            boundsChanged();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            boundsChanged();
        }
    });
    m_upperBound.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(final DocumentEvent e) {
            boundsChanged();
        }

        @Override
        public void removeUpdate(final DocumentEvent e) {
            boundsChanged();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            boundsChanged();
        }
    });
    /* the regular expression stuff */
    m_regLabel = new JLabel("pattern:");
    // it's important that the column selection is created before!
    m_regExpr = new JComboBox(getPossibleValuesOfSelectedColumn());
    m_regExpr.setEditable(true);
    m_regExpr.setSelectedItem("");
    m_regExpr.setMinimumSize(new Dimension(50, m_regExpr.getPreferredSize().height));
    // m_regExpr.setPreferredSize(new Dimension(200, 50));
    m_regExpr.setMaximumSize(new Dimension(300, 50));
    JTextField ed = (JTextField) m_regExpr.getEditor().getEditorComponent();
    ed.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void insertUpdate(final DocumentEvent e) {
            regExprChanged();
        }

        @Override
        public void removeUpdate(final DocumentEvent e) {
            regExprChanged();
        }

        @Override
        public void changedUpdate(final DocumentEvent e) {
            regExprChanged();
        }
    });
    m_regExpr.addItemListener(this);
    /* add flow variable button for the pattern/regexpr */
    FlowVariableModel fvm = parentPane.createFlowVariableModel(new String[] { RowFilterNodeModel.CFGFILTER, StringCompareRowFilter.CFGKEY_PATTERN }, FlowVariable.Type.STRING);
    fvm.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent evt) {
            FlowVariableModel fvm = (FlowVariableModel) (evt.getSource());
            m_regExpr.setEnabled(!fvm.isVariableReplacementEnabled());
            if (fvm.isVariableReplacementEnabled() && m_regExpr.getSelectedItem().equals("")) {
                // TODO: replace with more meaningful default - empty
                // pattern are rejected by dialog.
                m_regExpr.setSelectedItem(fvm.getInputVariableName());
            }
        }
    });
    m_regExprVarButton = new FlowVariableModelButton(fvm);
    m_caseSensitive = new JCheckBox("case sensitive match");
    m_isRegExpr = new JCheckBox("regular expression");
    m_hasWildCards = new JCheckBox("contains wild cards");
    m_hasWildCards.setToolTipText("insert '?' or '*' to match any one " + "character or any sequence (including none) of characters.");
    m_isRegExpr.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            wildRegExprChanged(e);
            // also trigger regular expression recompile
            regExprChanged();
        }
    });
    m_hasWildCards.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            wildRegExprChanged(e);
            // also trigger regular expression recompile
            regExprChanged();
        }
    });
    /* and a label to display errors/warnings */
    m_errText = new JTextArea();
    m_errText.setEditable(false);
    m_errText.setLineWrap(true);
    m_errText.setWrapStyleWord(true);
    m_errText.setBackground(getBackground());
    m_errText.setFont(new Font(m_errText.getFont().getName(), Font.BOLD, m_errText.getFont().getSize()));
    m_errText.setMinimumSize(new Dimension(350, 50));
    m_errText.setMaximumSize(new Dimension(350, 100));
    m_errText.setForeground(Color.RED);
    /* set the default values */
    m_useRegExpr.setSelected(true);
}
Also used : DocumentListener(javax.swing.event.DocumentListener) ItemEvent(java.awt.event.ItemEvent) JRadioButton(javax.swing.JRadioButton) JTextArea(javax.swing.JTextArea) DataValue(org.knime.core.data.DataValue) ColumnSelectionComboxBox(org.knime.core.node.util.ColumnSelectionComboxBox) JTextField(javax.swing.JTextField) Font(java.awt.Font) FlowVariableModel(org.knime.core.node.FlowVariableModel) ChangeListener(javax.swing.event.ChangeListener) Vector(java.util.Vector) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) JCheckBox(javax.swing.JCheckBox) ChangeEvent(javax.swing.event.ChangeEvent) ButtonGroup(javax.swing.ButtonGroup) FlowVariableModelButton(org.knime.core.node.FlowVariableModelButton) ItemListener(java.awt.event.ItemListener) Border(javax.swing.border.Border)

Example 4 with FlowVariableModel

use of org.knime.core.node.FlowVariableModel in project knime-core by knime.

the class FixedWidthFRNodeDialog method createFileNamePanel.

private JPanel createFileNamePanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Enter ASCII data file location: (press 'Enter' to update preview)"));
    FlowVariableModel flowVarBrowseModel = createFlowVariableModel(FixedWidthFRSettings.CFGKEY_URL, Type.STRING);
    m_url = new FilesHistoryPanel(flowVarBrowseModel, FILEREADER_HISTORY_ID, LocationValidation.FileInput, new String[] { ".txt", ".csv" });
    m_url.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(final ChangeEvent e) {
            if (!m_loadSettings) {
                try {
                    URL newUrl = FileUtil.toURL(m_url.getSelectedFile());
                    m_nodeSettings.setFileLocation(newUrl);
                } catch (IOException | InvalidPathException ioe) {
                    m_nodeSettings.setFileLocation(null);
                }
                if (!m_preserveSettings.isSelected() && !m_url.isVariableReplacementEnabled()) {
                    m_nodeSettings.reset();
                }
                m_hasColHeaders.setSelected(m_nodeSettings.getHasColHeaders());
                m_hasRowHeaders.setSelected(m_nodeSettings.getHasRowHeader());
                updateColPropTable();
                updatePreview();
                updateEnables();
            }
        }
    });
    // the checkbox for preserving the current settings on file change
    Box preserveBox = Box.createHorizontalBox();
    m_preserveSettings = new JCheckBox("Preserve user settings for new location");
    m_preserveSettings.setToolTipText("if not checked, the settings you" + " have set are reset, if a new location is entered");
    m_preserveSettings.setSelected(false);
    m_preserveSettings.setEnabled(true);
    preserveBox.add(Box.createHorizontalGlue());
    preserveBox.add(m_preserveSettings);
    preserveBox.add(Box.createHorizontalGlue());
    panel.add(m_url);
    panel.add(preserveBox);
    panel.setMaximumSize(new Dimension(PANEL_WIDTH, 70));
    panel.setMinimumSize(new Dimension(PANEL_WIDTH, 70));
    return panel;
}
Also used : FlowVariableModel(org.knime.core.node.FlowVariableModel) JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) BoxLayout(javax.swing.BoxLayout) FilesHistoryPanel(org.knime.core.node.util.FilesHistoryPanel) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) URL(java.net.URL)

Example 5 with FlowVariableModel

use of org.knime.core.node.FlowVariableModel in project knime-core by knime.

the class ListFilesNodeDialog method createLocationPanel.

/**
 * This Methods build the Location Panel.
 *
 * @return Location Panel
 */
private JPanel createLocationPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Location:"));
    // Creating the browse button to get its preferred height
    FlowVariableModel fvm = createFlowVariableModel("file_location", FlowVariable.Type.STRING);
    // Directory (local location)
    m_localdirectory = new FilesHistoryPanel(fvm, "filereader_history", LocationValidation.DirectoryInput, new String[] {});
    m_localdirectory.setSelectMode(JFileChooser.DIRECTORIES_ONLY);
    m_localdirectory.setAllowRemoteURLs(false);
    m_recursive = new JCheckBox();
    m_recursive.setText("include sub folders");
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    panel.add(m_localdirectory, c);
    c.gridy++;
    panel.add(m_recursive, c);
    return panel;
}
Also used : FlowVariableModel(org.knime.core.node.FlowVariableModel) JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) FilesHistoryPanel(org.knime.core.node.util.FilesHistoryPanel)

Aggregations

FlowVariableModel (org.knime.core.node.FlowVariableModel)7 JCheckBox (javax.swing.JCheckBox)4 Dimension (java.awt.Dimension)3 JPanel (javax.swing.JPanel)3 ChangeEvent (javax.swing.event.ChangeEvent)3 ChangeListener (javax.swing.event.ChangeListener)3 FilesHistoryPanel (org.knime.core.node.util.FilesHistoryPanel)3 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 Box (javax.swing.Box)2 JLabel (javax.swing.JLabel)2 JRadioButton (javax.swing.JRadioButton)2 JTextField (javax.swing.JTextField)2 FlowVariableModelButton (org.knime.core.node.FlowVariableModelButton)2 Font (java.awt.Font)1 Insets (java.awt.Insets)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1