Search in sources :

Example 6 with Manipulator

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

the class RuleMainPanel method onSelectionInManipulatorList.

/**
 * {@inheritDoc}
 */
@Override
protected void onSelectionInManipulatorList(final Object selected) {
    if (selected instanceof InfixManipulator) {
        InfixManipulator infix = (InfixManipulator) selected;
        String textToInsert = infix.getName() + " ";
        try {
            if (m_textEditor.getCaretPosition() == 0 || m_textEditor.getText().isEmpty() || m_textEditor.getText(m_textEditor.getCaretPosition(), 1).charAt(0) != ' ') {
                textToInsert = " " + textToInsert;
            }
        } catch (BadLocationException e) {
            LOGGER.coding("Not fatal error, but should not happen, requires no action.", e);
        }
        m_textEditor.insert(textToInsert, m_textEditor.getCaretPosition());
        m_textEditor.requestFocus();
    } else if (selected instanceof PrefixUnaryManipulator || selected instanceof ConstantManipulator) {
        Manipulator prefix = (Manipulator) selected;
        m_textEditor.replaceSelection(prefix.getName() + " ");
        m_textEditor.requestFocus();
    } else {
        super.onSelectionInManipulatorList(selected);
    }
}
Also used : ConstantManipulator(org.knime.base.node.rules.engine.manipulator.ConstantManipulator) PrefixUnaryManipulator(org.knime.base.node.rules.engine.manipulator.PrefixUnaryManipulator) InfixManipulator(org.knime.base.node.rules.engine.manipulator.InfixManipulator) BadLocationException(javax.swing.text.BadLocationException) InfixManipulator(org.knime.base.node.rules.engine.manipulator.InfixManipulator) ConstantManipulator(org.knime.base.node.rules.engine.manipulator.ConstantManipulator) PrefixUnaryManipulator(org.knime.base.node.rules.engine.manipulator.PrefixUnaryManipulator) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)

Example 7 with Manipulator

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

the class StringManipulationNodeDialog method createCompletionProvider.

/**
 * Create a simple provider that adds some Java-related completions.
 *
 * @return The completion provider.
 * @since 3.3
 */
protected KnimeCompletionProvider createCompletionProvider() {
    m_completionProvider = new JavaScriptingCompletionProvider();
    Collection<Manipulator> manipulators = StringManipulatorProvider.getDefault().getManipulators(ManipulatorProvider.ALL_CATEGORY);
    for (Manipulator m : manipulators) {
        // A BasicCompletion is just a straightforward word completion.
        m_completionProvider.addCompletion(new BasicCompletion(m_completionProvider, m.getName(), m.getDisplayName(), m.getDescription()));
    }
    return m_completionProvider;
}
Also used : JavaScriptingCompletionProvider(org.knime.base.node.util.JavaScriptingCompletionProvider) BasicCompletion(org.fife.ui.autocomplete.BasicCompletion) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator)

Example 8 with Manipulator

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

the class StringManipulationSettings method createJavaScriptingSettings.

/**
 * Create settings to be used by {@link ColumnCalculator} in order
 * to execute the expression.
 *
 * @return settings java scripting settings
 * @throws InvalidSettingsException when settings are not correct
 * @since 3.3
 */
public JavaScriptingSettings createJavaScriptingSettings() throws InvalidSettingsException {
    // determine return type
    m_returnType = null == m_returnType ? determineReturnType(StringUtils.strip(m_expression)) : m_returnType;
    JavaScriptingSettings s = new JavaScriptingSettings(null);
    s.setArrayReturn(false);
    s.setColName(this.getColName());
    s.setExpression("return " + this.getExpression() + ";");
    s.setExpressionVersion(Expression.VERSION_2X);
    s.setHeader("");
    s.setInsertMissingAsNull(this.isInsertMissingAsNull());
    Bundle bundle = FrameworkUtil.getBundle(this.getClass());
    try {
        List<String> includes = new ArrayList<String>();
        URL snippetIncURL = FileLocator.find(bundle, new Path("/lib/snippet_inc"), null);
        File includeDir = new File(FileLocator.toFileURL(snippetIncURL).getPath());
        for (File includeJar : includeDir.listFiles()) {
            if (includeJar.isFile() && includeJar.getName().endsWith(".jar")) {
                includes.add(includeJar.getPath());
                LOGGER.debug("Include jar file: " + includeJar.getPath());
            }
        }
        StringManipulatorProvider provider = StringManipulatorProvider.getDefault();
        includes.add(provider.getJarFile().getAbsolutePath());
        includes.add(FileLocator.getBundleFile(FrameworkUtil.getBundle(StringUtils.class)).getAbsolutePath());
        s.setJarFiles(includes.toArray(new String[includes.size()]));
    } catch (IOException e) {
        throw new IllegalStateException("Cannot locate necessary libraries due to I/O problem: " + e.getMessage(), e);
    }
    s.setReplace(this.isReplace());
    s.setReturnType(m_returnType.getName());
    s.setTestCompilationOnDialogClose(this.isTestCompilationOnDialogClose());
    List<String> imports = new ArrayList<String>();
    // Use defaults imports
    imports.addAll(Arrays.asList(Expression.getDefaultImports()));
    StringManipulatorProvider provider = StringManipulatorProvider.getDefault();
    // Add StringManipulators to the imports
    Collection<Manipulator> manipulators = provider.getManipulators(ManipulatorProvider.ALL_CATEGORY);
    for (Manipulator manipulator : manipulators) {
        String toImport = manipulator.getClass().getName();
        imports.add("static " + toImport + ".*");
    }
    s.setImports(imports.toArray(new String[imports.size()]));
    return s;
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings) URL(java.net.URL) Manipulator(org.knime.base.node.preproc.stringmanipulation.manipulator.Manipulator) StringUtils(org.apache.commons.lang3.StringUtils) File(java.io.File)

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