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