Search in sources :

Example 11 with WizardNode

use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.

the class WebResourceController method loadViewValues.

@SuppressWarnings("rawtypes")
private static void loadViewValues(final Map<String, String> filteredViewContentMap, final Map<NodeID, NativeNodeContainer> wizardNodeSet, final WorkflowManager manager, final boolean useAsDefault) {
    for (Map.Entry<String, String> entry : filteredViewContentMap.entrySet()) {
        NodeID.NodeIDSuffix suffix = NodeID.NodeIDSuffix.fromString(entry.getKey());
        NodeID id = suffix.prependParent(manager.getProjectWFM().getID());
        NativeNodeContainer wizardNode = wizardNodeSet.get(id);
        try {
            if (wizardNode.getNodeModel() instanceof WizardNode) {
                loadViewValueForWizardNode(wizardNode, (WizardNode) wizardNode.getNodeModel(), entry.getValue(), useAsDefault);
            } else if (wizardNode.getNode().getFactory() instanceof WizardPageContribution) {
                ((WizardPageContribution) wizardNode.getNode().getFactory()).loadViewValue(wizardNode, entry.getValue());
            } else {
                throw new IllegalStateException("The node '" + wizardNode.getNameWithID() + "' doesn't contribute to a wizard page. View values can't be loaded.");
            }
        } catch (Exception e) {
            LOGGER.error("Failed to load view value into node \"" + wizardNode.getID() + "\" although validation succeeded", e);
        }
    }
}
Also used : WizardNode(org.knime.core.node.wizard.WizardNode) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) WizardPageContribution(org.knime.core.node.wizard.page.WizardPageContribution) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) ViewRequestHandlingException(org.knime.core.node.interactive.ViewRequestHandlingException)

Example 12 with WizardNode

use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.

the class WebResourceController method processViewRequestInternal.

/**
 * Retrieves the response for a view request, which is from a node within a subnode
 *
 * @param subnodeID the node id of the subnode container
 * @param nodeID the node id of the wizard node, as fetched from the combined view
 * @param viewRequest the JSON serialized view request string
 * @param exec the execution monitor to set progress and check possible cancellation
 * @return a {@link WizardViewResponse} which is generated by the concrete node
 * @throws ViewRequestHandlingException If the request handling or response generation fails for any
 * reason.
 * @throws InterruptedException If the thread handling the request is interrupted.
 * @throws CanceledExecutionException If the handling of the request was canceled e.g. by user
 * intervention.
 * @since 3.7
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
protected WizardViewResponse processViewRequestInternal(final NodeID subnodeID, final String nodeID, final String viewRequest, final ExecutionMonitor exec) throws ViewRequestHandlingException, InterruptedException, CanceledExecutionException {
    WorkflowManager manager = m_manager;
    assert manager.isLockedByCurrentThread();
    NodeID.NodeIDSuffix suffix = NodeID.NodeIDSuffix.fromString(nodeID);
    NodeID id = suffix.prependParent(manager.getID());
    WizardNode model = getWizardNodeForVerifiedID(subnodeID, id);
    if (model == null || !(model instanceof WizardViewRequestHandler)) {
        throw new ViewRequestHandlingException("Node model can not process view requests. Possible implementation error.");
    }
    WizardViewRequest req = ((WizardViewRequestHandler) model).createEmptyViewRequest();
    try {
        req.loadFromStream(new ByteArrayInputStream(viewRequest.getBytes(Charset.forName("UTF-8"))));
    } catch (IOException ex) {
        throw new ViewRequestHandlingException("Error deserializing request: " + ex.getMessage(), ex);
    }
    return (WizardViewResponse) ((WizardViewRequestHandler) model).handleRequest(req, exec);
}
Also used : WizardViewRequest(org.knime.core.node.wizard.WizardViewRequest) ViewRequestHandlingException(org.knime.core.node.interactive.ViewRequestHandlingException) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) WizardNode(org.knime.core.node.wizard.WizardNode) WizardViewRequestHandler(org.knime.core.node.wizard.WizardViewRequestHandler) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) WizardViewResponse(org.knime.core.node.wizard.WizardViewResponse)

Aggregations

WizardNode (org.knime.core.node.wizard.WizardNode)12 NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)10 IOException (java.io.IOException)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 HashMap (java.util.HashMap)3 NodeModel (org.knime.core.node.NodeModel)3 ViewRequestHandlingException (org.knime.core.node.interactive.ViewRequestHandlingException)3 ValidationError (org.knime.core.node.web.ValidationError)3 NodeID (org.knime.core.node.workflow.NodeID)3 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Font (org.eclipse.swt.graphics.Font)2 FontData (org.eclipse.swt.graphics.FontData)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2