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);
}
}
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;
}
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;
}
Aggregations