use of org.knime.base.node.util.KnimeSyntaxTextArea in project knime-core by knime.
the class RulePanel method loadSettingsFrom.
/**
* Loads the settings from the serialized model ({@code settings}).
*
* @param settings The container for the model.
* @param specs The current {@link DataTableSpec}s.
* @param availableFlowVariables The {@link FlowVariable}s.
* @throws NotConfigurableException The information in the {@code settings} model is invalid.
*/
public void loadSettingsFrom(final NodeSettingsRO settings, final DataTableSpec[] specs, final Map<String, FlowVariable> availableFlowVariables) throws NotConfigurableException {
if (specs == null || specs.length == 0 || specs[0] == null) /*|| specs[0].getNumColumns() == 0*/
{
throw new NotConfigurableException("No columns available!");
}
m_spec = specs[0];
m_parser.setDataTableSpec(m_spec);
m_parser.setFlowVariables(availableFlowVariables);
RuleEngineSettings ruleSettings = new RuleEngineSettings();
ruleSettings.loadSettingsForDialog(settings);
update(specs[0], availableFlowVariables);
if (m_nodeType.hasOutput()) {
String newColName = ruleSettings.getNewColName();
m_newColumnName.setText(newColName);
if (m_replaceColumn != null) {
m_outputGroup.setSelected(m_outputGroup.getElements().nextElement().getModel(), ruleSettings.isAppendColumn());
m_outputGroup.setSelected(m_replaceColRadio.getModel(), !ruleSettings.isAppendColumn());
for (ActionListener listener : m_replaceColRadio.getActionListeners()) {
listener.actionPerformed(null);
}
m_replaceColumn.setSelectedColumn(ruleSettings.getReplaceColumn());
}
}
m_disallowLongOutputForCompatibility = ruleSettings.isDisallowLongOutputForCompatibility();
update(m_spec, availableFlowVariables);
final KnimeSyntaxTextArea textEditor = m_mainPanel.getTextEditor();
textEditor.setText("");
StringBuilder text = new StringBuilder();
for (Iterator<String> it = ruleSettings.rules().iterator(); it.hasNext(); ) {
final String rs = it.next();
text.append(rs);
if (it.hasNext()) {
text.append('\n');
}
}
if (!ruleSettings.rules().iterator().hasNext()) {
final String defaultText = m_nodeType.defaultText();
final String noText = RuleSupport.toComment(defaultText);
textEditor.setText(noText);
text.append(noText);
}
if (!m_nodeType.hasOutput()) {
try {
final SettingsModelBoolean includeOnMatch = new SettingsModelBoolean(RuleEngineFilterNodeModel.CFGKEY_INCLUDE_ON_MATCH, RuleEngineFilterNodeModel.DEFAULT_INCLUDE_ON_MATCH);
includeOnMatch.loadSettingsFrom(settings);
m_top.setSelected(includeOnMatch.getBooleanValue());
m_bottom.setSelected(!includeOnMatch.getBooleanValue());
} catch (InvalidSettingsException e) {
boolean defaultTop = true;
m_top.setSelected(defaultTop);
m_bottom.setSelected(!defaultTop);
}
}
updateText(text.toString());
}
use of org.knime.base.node.util.KnimeSyntaxTextArea in project knime-core by knime.
the class RuleMainPanel method createEditorComponent.
/**
* {@inheritDoc}
*/
@Override
protected JComponent createEditorComponent() {
m_textEditor = new KnimeSyntaxTextArea(20, 60);
final RSyntaxTextArea textArea = m_textEditor;
// An AutoCompletion acts as a "middle-man" between a text component
// and a CompletionProvider. It manages any options associated with
// the auto-completion (the popup trigger key, whether to display a
// documentation window along with completion choices, etc.). Unlike
// CompletionProviders, instances of AutoCompletion cannot be shared
// among multiple text components.
AutoCompletion ac = new AutoCompletion(getCompletionProvider());
ac.setShowDescWindow(true);
ac.install(textArea);
setExpEdit(textArea);
textArea.setSyntaxEditingStyle(m_syntaxStyle);
textArea.getPopupMenu().add(new ToggleRuleAction("Toggle comment", textArea));
RTextScrollPane textScrollPane = new RTextScrollPane(textArea);
textScrollPane.setLineNumbersEnabled(true);
textScrollPane.setIconRowHeaderEnabled(true);
m_gutter = textScrollPane.getGutter();
addRowHeaderMouseListener(new MouseAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
try {
new ToggleRuleAction(textArea).actionPerformed(new ToggleRuleAction.LinePosition(textArea, (int) (new Date().getTime() & 0x7fffffff), "toggle comment", e.getModifiers(), textArea.getLineOfOffset(textArea.viewToModel(e.getPoint()))));
} catch (BadLocationException e1) {
LOGGER.debug(e1.getMessage(), e1);
}
}
}
});
return textScrollPane;
}
use of org.knime.base.node.util.KnimeSyntaxTextArea in project knime-core by knime.
the class RulePanel method setOutputMarkers.
/**
* Sets the icon of output type markers in the {@link RSyntaxTextArea} according to the {@code outputTypes}
* parameter. <br/>
* <strong>Should be on EDT</strong>
*
* @param startDate When the computation of the output types started.
* @param outputTypes The new output type.
*/
protected synchronized void setOutputMarkers(final long startDate, final DataType[] outputTypes) {
final KnimeSyntaxTextArea textArea = m_mainPanel.getTextEditor();
if (startDate - m_outputMarkersLastSet > 0 && !textArea.getText().isEmpty()) {
final Gutter gutter = m_mainPanel.getGutter();
gutter.removeAllTrackingIcons();
textArea.removeAllLineHighlights();
String[] lines = textArea.getText().split("\n", -1);
for (int i = outputTypes.length; i-- > 0; ) {
try {
if (outputTypes[i] == null && !(i < lines.length && lines[i].trim().isEmpty())) {
// error
gutter.addLineTrackingIcon(i, RuleMainPanel.ERROR_ICON);
textArea.addLineHighlight(i, Color.PINK);
} else if (m_nodeType.hasOutput() && outputTypes[i] != null) {
gutter.addLineTrackingIcon(i, outputTypes[i].getIcon());
}
} catch (BadLocationException e) {
// Do nothing. This can happen when the text is not up-to-date with the rules.
// Example config dialog closed with cancel after added some lines.
// Next invocations will fix it.
}
}
m_outputMarkersLastSet = startDate;
}
}
Aggregations