use of org.knime.core.node.NotConfigurableException in project knime-core by knime.
the class NodeContainerEditPart method openNodeDialog.
/**
* Opens the node's dialog (also metanode dialogs).
*
* @since 2.6
*/
public void openNodeDialog() {
final NodeContainerUI container = (NodeContainerUI) getModel();
// if this node does not have a dialog
if (!container.hasDialog()) {
LOGGER.debug("No dialog for " + container.getNameWithID());
return;
}
final Shell shell = Display.getCurrent().getActiveShell();
shell.setEnabled(false);
try {
if (container.hasDataAwareDialogPane() && !container.isAllInputDataAvailable() && container.canExecuteUpToHere()) {
IPreferenceStore store = KNIMEUIPlugin.getDefault().getPreferenceStore();
String prefPrompt = store.getString(PreferenceConstants.P_EXEC_NODES_DATA_AWARE_DIALOGS);
boolean isExecuteUpstreamNodes;
if (MessageDialogWithToggle.PROMPT.equals(prefPrompt)) {
int returnCode = MessageDialogWithToggle.openYesNoCancelQuestion(shell, "Execute upstream nodes", "The " + container.getName() + " node can be configured using the full input data.\n\n" + "Execute upstream nodes?", "Remember my decision", false, store, PreferenceConstants.P_EXEC_NODES_DATA_AWARE_DIALOGS).getReturnCode();
if (returnCode == Window.CANCEL) {
return;
} else if (returnCode == IDialogConstants.YES_ID) {
isExecuteUpstreamNodes = true;
} else {
isExecuteUpstreamNodes = false;
}
} else if (MessageDialogWithToggle.ALWAYS.equals(prefPrompt)) {
isExecuteUpstreamNodes = true;
} else {
isExecuteUpstreamNodes = false;
}
if (isExecuteUpstreamNodes) {
try {
PlatformUI.getWorkbench().getProgressService().run(true, true, new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
Future<Void> submit = DATA_AWARE_DIALOG_EXECUTOR.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
container.getParent().executePredecessorsAndWait(container.getID());
return null;
}
});
while (!submit.isDone()) {
if (monitor.isCanceled()) {
submit.cancel(true);
throw new InterruptedException();
}
try {
submit.get(300, TimeUnit.MILLISECONDS);
} catch (ExecutionException e) {
LOGGER.error("Error while waiting for execution to finish", e);
} catch (InterruptedException e) {
submit.cancel(true);
throw e;
} catch (TimeoutException e) {
// do another round
}
}
}
});
} catch (InvocationTargetException e) {
String error = "Exception while waiting for completion of execution";
LOGGER.warn(error, e);
ErrorDialog.openError(shell, "Failed opening dialog", error, new Status(IStatus.ERROR, KNIMEEditorPlugin.PLUGIN_ID, error, e));
} catch (InterruptedException e) {
return;
}
}
}
//
try {
if (Wrapper.wraps(container, NodeContainer.class)) {
WrappedNodeDialog dlg = new WrappedNodeDialog(shell, Wrapper.unwrapNC(container));
dlg.open();
}
} catch (NotConfigurableException ex) {
MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
mb.setText("Dialog cannot be opened");
mb.setMessage("The dialog cannot be opened for the following" + " reason:\n" + ex.getMessage());
mb.open();
} catch (Throwable t) {
LOGGER.error("The dialog pane for node '" + container.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an implementation error.", t);
}
} finally {
shell.setEnabled(true);
}
}
use of org.knime.core.node.NotConfigurableException 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.core.node.NotConfigurableException in project knime-core by knime.
the class DateTimeDifferenceNodeDialog method updateDateTimeComponents.
@SuppressWarnings("unchecked")
private void updateDateTimeComponents(final SettingsModelDateTime dateTimeModel) {
if (m_dialogComp1stColSelect.getSelectedAsSpec() != null) {
final DataType type = m_dialogComp1stColSelect.getSelectedAsSpec().getType();
// adapt column filter of column selection for 2nd column
try {
final List<Class<? extends DataValue>> valueClasses = type.getValueClasses();
if (valueClasses.contains(ZonedDateTimeValue.class)) {
m_dialogComp2ndColSelect.setColumnFilter(new DataValueColumnFilter(ZonedDateTimeValue.class));
} else if (valueClasses.contains(LocalDateTimeValue.class)) {
m_dialogComp2ndColSelect.setColumnFilter(new DataValueColumnFilter(LocalDateTimeValue.class));
} else if (valueClasses.contains(LocalDateValue.class)) {
m_dialogComp2ndColSelect.setColumnFilter(new DataValueColumnFilter(LocalDateValue.class));
} else if (valueClasses.contains(LocalTimeValue.class)) {
m_dialogComp2ndColSelect.setColumnFilter(new DataValueColumnFilter(LocalTimeValue.class));
}
} catch (NotConfigurableException ex) {
// will never happen, because there is always at least the selected 1st column available
}
// adapt date&time component
dateTimeModel.setUseDate(!type.isCompatible(LocalTimeValue.class));
dateTimeModel.setUseTime(!type.isCompatible(LocalDateValue.class));
dateTimeModel.setUseZone(type.isCompatible(ZonedDateTimeValue.class));
}
updateWarningLabel();
}
use of org.knime.core.node.NotConfigurableException in project knime-core by knime.
the class StringManipulationNodeDialog method loadSettingsFrom.
/**
* {@inheritDoc}
*/
@Override
protected void loadSettingsFrom(final NodeSettingsRO settings, final PortObjectSpec[] specs) throws NotConfigurableException {
DataTableSpec spec;
if (m_isOnlyVariables) {
spec = new DataTableSpec();
} else {
spec = (DataTableSpec) specs[0];
}
StringManipulationSettings s = new StringManipulationSettings();
s.loadSettingsInDialog(settings, spec);
String exp = s.getExpression();
String defaultNewName = "new " + m_columnOrVariable;
String newName = s.getColName();
boolean isReplace = s.isReplace();
boolean isTestCompilation = s.isTestCompilationOnDialogClose();
boolean isInsertMissingAsNull = s.isInsertMissingAsNull();
m_newNameField.setText("");
final Map<String, FlowVariable> availableFlowVariables = getAvailableFlowVariables();
if (m_isOnlyVariables) {
DefaultComboBoxModel<FlowVariable> cmbModel = (DefaultComboBoxModel<FlowVariable>) m_replaceVariableCombo.getModel();
cmbModel.removeAllElements();
for (FlowVariable v : availableFlowVariables.values()) {
switch(v.getScope()) {
case Flow:
cmbModel.addElement(v);
break;
default:
}
}
if (availableFlowVariables.containsValue(newName)) {
m_replaceVariableCombo.setSelectedItem(availableFlowVariables.get(newName));
}
} else {
// will select newColName only if it is in the spec list
try {
m_replaceColumnCombo.update(spec, newName);
} catch (NotConfigurableException e1) {
NodeLogger.getLogger(getClass()).coding("Combo box throws exception although content is not required", e1);
}
}
m_currentSpec = spec;
// whether there are variables or columns available
// -- which of two depends on the customizer
boolean fieldsAvailable;
if (m_isOnlyVariables) {
fieldsAvailable = m_replaceVariableCombo.getItemCount() > 0;
} else {
fieldsAvailable = m_replaceColumnCombo.getNrItemsInList() > 0;
}
m_replaceRadio.setEnabled(fieldsAvailable);
if (isReplace && fieldsAvailable) {
m_replaceRadio.doClick();
} else {
m_appendRadio.doClick();
String newNameString = (newName != null ? newName : defaultNewName);
m_newNameField.setText(newNameString);
}
m_snippetPanel.update(exp, spec, availableFlowVariables);
m_compileOnCloseChecker.setSelected(isTestCompilation);
m_insertMissingAsNullChecker.setSelected(isInsertMissingAsNull);
}
use of org.knime.core.node.NotConfigurableException in project knime-core by knime.
the class WrappedNodeDialog method configureShell.
/**
* Configure shell, create top level menu.
*
* {@inheritDoc}
*/
@Override
protected void configureShell(final Shell newShell) {
super.configureShell(newShell);
Menu menuBar = new Menu(newShell, SWT.BAR);
newShell.setMenuBar(menuBar);
Menu menu = new Menu(newShell, SWT.DROP_DOWN);
MenuItem rootItem = new MenuItem(menuBar, SWT.CASCADE);
rootItem.setText("File");
rootItem.setAccelerator(SWT.MOD1 | 'F');
rootItem.setMenu(menu);
final FileDialog openDialog = new FileDialog(newShell, SWT.OPEN);
final FileDialog saveDialog = new FileDialog(newShell, SWT.SAVE);
MenuItem itemLoad = new MenuItem(menu, SWT.PUSH);
itemLoad.setText("Load Settings");
itemLoad.setAccelerator(SWT.MOD1 | 'L');
itemLoad.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
String file = openDialog.open();
if (file != null) {
NodeContext.pushContext(m_nodeContainer);
try {
m_dialogPane.loadSettingsFrom(new FileInputStream(file));
} catch (IOException ioe) {
showErrorMessage(ioe.getMessage());
} catch (NotConfigurableException ex) {
showErrorMessage(ex.getMessage());
} finally {
NodeContext.removeLastContext();
}
}
}
});
MenuItem itemSave = new MenuItem(menu, SWT.PUSH);
itemSave.setText("Save Settings");
itemSave.setAccelerator(SWT.MOD1 | 'S');
itemSave.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
String file = saveDialog.open();
if (file != null) {
NodeContext.pushContext(m_nodeContainer);
try {
m_dialogPane.saveSettingsTo(new FileOutputStream(file));
} catch (IOException ioe) {
showErrorMessage(ioe.getMessage());
// SWT-AWT-Bridge doesn't properly
// repaint after dialog disappears
m_dialogPane.getPanel().repaint();
} catch (InvalidSettingsException ise) {
showErrorMessage("Invalid Settings\n" + ise.getMessage());
// SWT-AWT-Bridge doesn't properly
// repaint after dialog disappears
m_dialogPane.getPanel().repaint();
} finally {
NodeContext.removeLastContext();
}
}
}
});
}
Aggregations