Search in sources :

Example 1 with Manipulator

use of org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator in project knime-core by knime.

the class JSnippetPanel method updateManipulatorList.

private void updateManipulatorList(final String category) {
    Object selected = m_manipulators.getSelectedValue();
    DefaultListModel model = (DefaultListModel) m_manipulators.getModel();
    model.clear();
    for (Manipulator manipulator : m_manipProvider.getManipulators(category)) {
        model.addElement(manipulator);
    }
    m_manipulators.setSelectedValue(selected, true);
}
Also used : DefaultListModel(javax.swing.DefaultListModel) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)

Example 2 with Manipulator

use of org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator in project knime-core by knime.

the class JSnippetPanel method onSelectionInManipulatorList.

/**
 * Inserts text based on the selected manipulator.
 *
 * @param selected A {@link Manipulator}.
 * @since 2.8
 */
protected void onSelectionInManipulatorList(final Object selected) {
    if (selected != null) {
        Manipulator manipulator = (Manipulator) selected;
        String selectedString = m_expEdit.getSelectedText();
        StringBuilder newStr = new StringBuilder(manipulator.getName());
        newStr.append('(');
        for (int i = 0; i < manipulator.getNrArgs(); i++) {
            newStr.append(i > 0 ? ", " : "");
            if (i == 0 && selectedString != null) {
                newStr.append(selectedString);
            }
        }
        newStr.append(')');
        m_expEdit.replaceSelection(newStr.toString());
        if (manipulator.getNrArgs() > 0 && selectedString == null) {
            int caretPos = m_expEdit.getCaretPosition();
            m_expEdit.setCaretPosition(1 + m_expEdit.getText().indexOf('(', caretPos - newStr.toString().length()));
        }
        m_expEdit.requestFocus();
    }
}
Also used : Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)

Example 3 with Manipulator

use of org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator in project knime-core by knime.

the class JSnippetPanel method initCompletionProvider.

private void initCompletionProvider() {
    Collection<? extends Manipulator> manipulators = m_manipProvider.getManipulators(ManipulatorProvider.ALL_CATEGORY);
    for (Manipulator m : manipulators) {
        Completion completion = new BasicCompletion(m_completionProvider, m.getName(), m.getDisplayName(), m.getDescription());
        m_completionProvider.addCompletion(completion);
    }
}
Also used : Completion(org.fife.ui.autocomplete.Completion) BasicCompletion(org.fife.ui.autocomplete.BasicCompletion) AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) BasicCompletion(org.fife.ui.autocomplete.BasicCompletion) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)

Example 4 with Manipulator

use of org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator in project knime-core by knime.

the class JSnippetPanel method initComponents.

private void initComponents() {
    m_colList = new JList(new DefaultListModel());
    m_colList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_colList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_colList.getSelectedValue();
                if (selected != null) {
                    onSelectionInColumnList(selected);
                }
            }
        }
    });
    m_colList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_colList.getSelectedValue();
                if (selected != null) {
                    onSelectionInColumnList(selected);
                }
            }
        }
    });
    m_colList.setCellRenderer(new ListRenderer());
    m_flowVarsList = new JList(new DefaultListModel());
    m_flowVarsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // enable tooltip
    m_flowVarsList.setToolTipText("");
    m_flowVarsList.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_flowVarsList.getSelectedValue();
                if (selected != null) {
                    onSelectionInVariableList(selected);
                }
            }
        }
    });
    m_flowVarsList.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_flowVarsList.getSelectedValue();
                if (selected != null) {
                    onSelectionInVariableList(selected);
                }
            }
        }
    });
    m_flowVarsList.setCellRenderer(new FlowVariableListCellRenderer());
    m_categories = new JComboBox(m_manipProvider.getCategories().toArray());
    m_categories.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(final ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            String category = (String) cb.getSelectedItem();
            updateManipulatorList(category);
        }
    });
    m_manipulators = new JList(new DefaultListModel());
    m_manipulators.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    m_manipulators.setCellRenderer(new ManipulatorListCellRenderer());
    m_manipulators.addKeyListener(new KeyAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void keyTyped(final KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                Object selected = m_manipulators.getSelectedValue();
                if (selected != null) {
                    onSelectionInManipulatorList(selected);
                }
            }
        }
    });
    m_manipulators.addMouseListener(new MouseAdapter() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void mouseClicked(final MouseEvent e) {
            if (e.getClickCount() == 2) {
                Object selected = m_manipulators.getSelectedValue();
                if (selected != null) {
                    onSelectionInManipulatorList(selected);
                }
            }
        }
    });
    m_manipulators.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            Object selected = m_manipulators.getSelectedValue();
            if (selected != null) {
                Manipulator manipulator = (Manipulator) selected;
                m_description.setText(manipulator.getDescription());
                m_description.setCaretPosition(0);
            } else {
                m_description.setText("");
            }
        }
    });
    HTMLEditorKit kit = new HTMLEditorKit();
    StyleSheet css = new StyleSheet();
    css.addRule("* { font-family: sans-serif; }");
    kit.setStyleSheet(css);
    m_description = new JTextPane();
    m_description.setEditorKit(kit);
    m_description.setEditable(false);
    m_description.setBackground(getBackground());
    updateManipulatorList(ManipulatorProvider.ALL_CATEGORY);
    initSubComponents();
}
Also used : MouseEvent(java.awt.event.MouseEvent) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DefaultListModel(javax.swing.DefaultListModel) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) ListSelectionListener(javax.swing.event.ListSelectionListener) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator) KeyEvent(java.awt.event.KeyEvent) FlowVariableListCellRenderer(org.knime.core.node.util.FlowVariableListCellRenderer) JTextPane(javax.swing.JTextPane) StyleSheet(javax.swing.text.html.StyleSheet) ActionListener(java.awt.event.ActionListener) JList(javax.swing.JList)

Example 5 with Manipulator

use of org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator in project knime-core by knime.

the class StringManipulationSettings method determineReturnType.

private Class<?> determineReturnType(final String expression) throws InvalidSettingsException {
    if (expression.isEmpty()) {
        throw new InvalidSettingsException("Empty expressions are not supported.");
    }
    int endIndex = StringUtils.indexOf(expression, '(');
    if (endIndex < 0) {
        throw new InvalidSettingsException(getAmbigiousReturnTypeMessage());
    }
    String function = expression.substring(0, endIndex);
    StringManipulatorProvider provider = StringManipulatorProvider.getDefault();
    // Add StringManipulators to the imports
    Collection<Manipulator> manipulators = provider.getManipulators(ManipulatorProvider.ALL_CATEGORY);
    Class<?> returnType = null;
    for (Manipulator manipulator : manipulators) {
        if (function.equals(manipulator.getName())) {
            returnType = manipulator.getReturnType();
        }
    }
    if (null == returnType) {
        throw new InvalidSettingsException(getAmbigiousReturnTypeMessage());
    }
    return returnType;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)

Aggregations

Manipulator (org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)8 DefaultListModel (javax.swing.DefaultListModel)2 BasicCompletion (org.fife.ui.autocomplete.BasicCompletion)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 JComboBox (javax.swing.JComboBox)1 JList (javax.swing.JList)1 JTextPane (javax.swing.JTextPane)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 BadLocationException (javax.swing.text.BadLocationException)1 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)1