Search in sources :

Example 1 with NotConfigurableException

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);
    }
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) SubNodeContainerUI(org.knime.core.ui.node.workflow.SubNodeContainerUI) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NotConfigurableException(org.knime.core.node.NotConfigurableException) Point(org.eclipse.draw2d.geometry.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) Callable(java.util.concurrent.Callable) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) MessageBox(org.eclipse.swt.widgets.MessageBox) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Future(java.util.concurrent.Future) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) WrappedNodeDialog(org.knime.workbench.ui.wrapper.WrappedNodeDialog)

Example 2 with NotConfigurableException

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());
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) SettingsModelBoolean(org.knime.core.node.defaultnodesettings.SettingsModelBoolean) ActionListener(java.awt.event.ActionListener) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) KnimeSyntaxTextArea(org.knime.base.node.util.KnimeSyntaxTextArea)

Example 3 with NotConfigurableException

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();
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) DataValue(org.knime.core.data.DataValue) DataType(org.knime.core.data.DataType) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) DataValueColumnFilter(org.knime.core.node.util.DataValueColumnFilter) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue)

Example 4 with NotConfigurableException

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);
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) DataTableSpec(org.knime.core.data.DataTableSpec) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 5 with NotConfigurableException

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();
                }
            }
        }
    });
}
Also used : NotConfigurableException(org.knime.core.node.NotConfigurableException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) FileOutputStream(java.io.FileOutputStream) SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) IOException(java.io.IOException) FileDialog(org.eclipse.swt.widgets.FileDialog) FileInputStream(java.io.FileInputStream)

Aggregations

NotConfigurableException (org.knime.core.node.NotConfigurableException)79 DataColumnSpec (org.knime.core.data.DataColumnSpec)35 DataTableSpec (org.knime.core.data.DataTableSpec)35 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)31 DataColumnSpecFilterConfiguration (org.knime.core.node.util.filter.column.DataColumnSpecFilterConfiguration)8 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)5 DataType (org.knime.core.data.DataType)5 NominalValue (org.knime.core.data.NominalValue)5 DatabasePortObjectSpec (org.knime.core.node.port.database.DatabasePortObjectSpec)5 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)4 Container (java.awt.Container)3 Frame (java.awt.Frame)3 GridBagConstraints (java.awt.GridBagConstraints)3 ActionListener (java.awt.event.ActionListener)3 ItemListener (java.awt.event.ItemListener)3 AbstractButton (javax.swing.AbstractButton)3 DefaultListModel (javax.swing.DefaultListModel)3 LinkedHashMap (java.util.LinkedHashMap)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)2