Search in sources :

Example 1 with NodeIDSuffix

use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.

the class NodeUsageComposite method createNodeGrid.

private void createNodeGrid(final SubNodeContainer subNodeContainer, @SuppressWarnings("rawtypes") final Map<NodeIDSuffix, WizardNode> viewNodes) {
    ScrolledComposite scrollPane = new ScrolledComposite(this, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
    scrollPane.setExpandHorizontal(true);
    scrollPane.setExpandVertical(true);
    Composite composite = new Composite(scrollPane, SWT.NONE);
    scrollPane.setContent(composite);
    scrollPane.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    composite.setLayout(new GridLayout(3, false));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
    // titles
    new Composite(composite, SWT.NONE);
    /* Placeholder */
    Label wizardLabel = new Label(composite, SWT.CENTER);
    FontData fontData = wizardLabel.getFont().getFontData()[0];
    Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
    wizardLabel.setText("WebPortal /\nWrapped Metanode View");
    wizardLabel.setFont(boldFont);
    Label dialogLabel = new Label(composite, SWT.CENTER);
    dialogLabel.setText("\nWrapped Metanode Dialog");
    dialogLabel.setFont(boldFont);
    // select all checkboxes
    Label selectAllLabel = new Label(composite, SWT.LEFT);
    selectAllLabel.setText("Enable/Disable");
    Button selectAllWizard = createCheckbox(composite);
    Button selectAllDialog = createCheckbox(composite);
    // individual nodes
    for (@SuppressWarnings("rawtypes") Entry<NodeIDSuffix, WizardNode> entry : viewNodes.entrySet()) {
        NodeIDSuffix suffix = entry.getKey();
        NodeID id = suffix.prependParent(subNodeContainer.getWorkflowManager().getID());
        NodeContainer nodeContainer = viewNodes.containsKey(suffix) ? subNodeContainer.getWorkflowManager().getNodeContainer(id) : null;
        createNodeLabelComposite(composite, id, nodeContainer);
        @SuppressWarnings("rawtypes") WizardNode model = entry.getValue();
        Button wizardButton = createCheckbox(composite);
        wizardButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent e) {
                checkAllSelected(m_wizardUsageMap, selectAllWizard);
            }
        });
        wizardButton.setToolTipText("Enable/disable for usage in WebPortal and wizard execution.");
        wizardButton.setSelection(!((WizardNode<?, ?>) model).isHideInWizard());
        m_wizardUsageMap.put(id, wizardButton);
        if (model instanceof DialogNode) {
            Button dialogButton = createCheckbox(composite);
            dialogButton.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent e) {
                    checkAllSelected(m_dialogUsageMap, selectAllDialog);
                }
            });
            dialogButton.setToolTipText("Enable/disable for usage in wrapped metanode configure dialog.");
            dialogButton.setSelection(!((DialogNode<?, ?>) model).isHideInDialog());
            m_dialogUsageMap.put(id, dialogButton);
        } else {
            new Composite(composite, SWT.NONE);
        /* Placeholder */
        }
    }
    checkAllSelected(m_wizardUsageMap, selectAllWizard);
    checkAllSelected(m_dialogUsageMap, selectAllDialog);
    selectAllWizard.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectAllWizard.setGrayed(false);
            for (Button b : m_wizardUsageMap.values()) {
                b.setSelection(selectAllWizard.getSelection());
            }
        }
    });
    if (m_wizardUsageMap.size() < 1) {
        selectAllWizard.setEnabled(false);
    }
    selectAllDialog.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(final SelectionEvent e) {
            selectAllDialog.setGrayed(false);
            for (Button b : m_dialogUsageMap.values()) {
                b.setSelection(selectAllDialog.getSelection());
            }
        }
    });
    if (m_dialogUsageMap.size() < 1) {
        selectAllDialog.setEnabled(false);
    }
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FontData(org.eclipse.swt.graphics.FontData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) DialogNode(org.knime.core.node.dialog.DialogNode) WizardNode(org.knime.core.node.wizard.WizardNode) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) NodeID(org.knime.core.node.workflow.NodeID) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Example 2 with NodeIDSuffix

use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.

the class SubnodeLayoutWizard method addPages.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("rawtypes")
@Override
public void addPages() {
    setWindowTitle("Node Usage and Layout");
    setDefaultPageImageDescriptor(ImageRepository.getImageDescriptor(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout_55.png"));
    WorkflowManager wfManager = m_subNodeContainer.getWorkflowManager();
    // Map<NodeID, SubNodeContainer> nestedSubnodes = wfManager.findNodes(SubNodeContainer.class, false);
    Map<NodeID, WizardNode> viewNodes = wfManager.findNodes(WizardNode.class, false);
    LinkedHashMap<NodeIDSuffix, WizardNode> resultMap = new LinkedHashMap<>();
    for (Map.Entry<NodeID, WizardNode> entry : viewNodes.entrySet()) {
        NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(wfManager.getID(), entry.getKey());
        resultMap.put(idSuffix, entry.getValue());
    }
    List<NodeID> nodeIDs = new ArrayList<NodeID>();
    nodeIDs.addAll(viewNodes.keySet());
    /*for (NodeID subnodeID : nestedSubnodes.keySet()) {
            WorkflowManager nestedWFManager = nestedSubnodes.get(subnodeID).getWorkflowManager();
            if (!nestedWFManager.findNodes(WizardNode.class, true).isEmpty()) {
                nodeIDs.add(subnodeID);
            }
        }*/
    Collections.sort(nodeIDs);
    m_page = new SubnodeLayoutJSONEditorPage("Change the layout configuration");
    m_page.setNodes(wfManager, m_subNodeContainer, resultMap);
    addPage(m_page);
}
Also used : WorkflowManager(org.knime.core.node.workflow.WorkflowManager) ArrayList(java.util.ArrayList) WizardNode(org.knime.core.node.wizard.WizardNode) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) LinkedHashMap(java.util.LinkedHashMap) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) NodeID(org.knime.core.node.workflow.NodeID) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with NodeIDSuffix

use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.

the class WizardPageUtil method createWizardPage.

/**
 * Creates the wizard page for a given node id. Throws exception if no wizard page available.
 *
 * Note: the workflow manager must be locked!
 *
 * @param manager the workflow that contains the component to create the wizard page for
 * @param subnodeID the node id for the subnode to create the wizard page for
 * @return The wizard page for the given node id
 * @throws IllegalArgumentException if there is no component for the given id
 */
public static WizardPage createWizardPage(final WorkflowManager manager, final NodeID subnodeID) {
    if (subnodeID == null) {
        LOGGER.error("No node ID supplied for creating wizard page");
        return null;
    }
    // NOSONAR
    assert manager.isLockedByCurrentThread();
    LinkedHashMap<NodeIDSuffix, NativeNodeContainer> resultMap = new LinkedHashMap<>();
    Set<HiLiteHandler> initialHiliteHandlerSet = new HashSet<>();
    SubNodeContainer subNC = manager.getNodeContainer(subnodeID, SubNodeContainer.class, true);
    LinkedHashMap<NodeIDSuffix, SubNodeContainer> sncMap = new LinkedHashMap<>();
    findNestedViewNodes(subNC, resultMap, sncMap, initialHiliteHandlerSet);
    SubnodeContainerLayoutStringProvider layoutStringProvider = subNC.getSubnodeLayoutStringProvider();
    if (layoutStringProvider.isEmptyLayout() || layoutStringProvider.isPlaceholderLayout()) {
        try {
            var subWfm = subNC.getWorkflowManager();
            Map<NodeIDSuffix, SingleNodeContainer> viewMap = new LinkedHashMap<>();
            getWizardPageNodes(subWfm).stream().forEach(n -> viewMap.put(toNodeIDSuffix(manager, n.getID()), n));
            Map<NodeID, SubNodeContainer> nestedSubs = getSubPageNodes(subWfm);
            nestedSubs.entrySet().stream().forEach(e -> viewMap.put(toNodeIDSuffix(manager, e.getKey()), e.getValue()));
            layoutStringProvider.setLayoutString(LayoutUtil.createDefaultLayout(viewMap));
        } catch (IOException ex) {
            LOGGER.error("Default page layout could not be created: " + ex.getMessage(), ex);
        }
    }
    try {
        LayoutUtil.expandNestedLayout(layoutStringProvider, subNC.getWorkflowManager());
    } catch (IOException ex) {
        LOGGER.error("Nested layouts could not be expanded: " + ex.getMessage(), ex);
    }
    try {
        var containerID = NodeID.fromString(NodeIDSuffix.create(manager.getID(), subNC.getWorkflowManager().getID()).toString());
        LayoutUtil.addUnreferencedViews(layoutStringProvider, resultMap, sncMap, containerID);
    } catch (IOException ex) {
        LOGGER.error("Layout could not be amended by unreferenced views: " + ex.getMessage(), ex);
    }
    try {
        LayoutUtil.updateLayout(layoutStringProvider);
    } catch (Exception ex) {
        // NOSONAR
        LOGGER.error("Layout could not be updated: " + ex.getMessage(), ex);
    }
    Set<HiLiteHandler> knownHiLiteHandlers = new HashSet<>();
    Set<HiLiteTranslator> knownTranslators = new HashSet<>();
    Set<HiLiteManager> knownManagers = new HashSet<>();
    for (HiLiteHandler initialHandler : initialHiliteHandlerSet) {
        getHiLiteTranslators(initialHandler, knownHiLiteHandlers, knownTranslators, knownManagers);
    }
    List<HiLiteTranslator> translatorList = !knownTranslators.isEmpty() ? new ArrayList<>(knownTranslators) : null;
    List<HiLiteManager> managerList = !knownManagers.isEmpty() ? new ArrayList<>(knownManagers) : null;
    return new WizardPage(subnodeID, resultMap, layoutStringProvider.getLayoutString(), translatorList, managerList);
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) LinkedHashMap(java.util.LinkedHashMap) NodeID(org.knime.core.node.workflow.NodeID) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) HiLiteTranslator(org.knime.core.node.property.hilite.HiLiteTranslator) IOException(java.io.IOException) HiLiteManager(org.knime.core.node.property.hilite.HiLiteManager) IOException(java.io.IOException) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) SubnodeContainerLayoutStringProvider(org.knime.core.node.workflow.SubnodeContainerLayoutStringProvider) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Example 4 with NodeIDSuffix

use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.

the class NodeIDTest method testCombine.

/**
 * Checks if combining to node IDs works as expected.
 */
@Test
public void testCombine() {
    NodeID p = NodeID.fromString("0:1");
    NodeIDSuffix s = NodeIDSuffix.fromString("2:3");
    assertThat("Unexpected combined NodeID", s.prependParent(p).toString(), is("0:1:2:3"));
    p = NodeID.fromString("0:1");
    s = NodeIDSuffix.fromString("2");
    assertThat("Unexpected combined NodeID", s.prependParent(p).toString(), is("0:1:2"));
    p = NodeID.fromString("0");
    s = NodeIDSuffix.fromString("1");
    assertThat("Unexpected combined NodeID", s.prependParent(p).toString(), is("0:1"));
    p = NodeID.ROOTID;
    s = NodeIDSuffix.fromString("0");
    assertThat("Unexpected combined NodeID", s.prependParent(p).toString(), is("0"));
}
Also used : NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) Test(org.junit.Test)

Example 5 with NodeIDSuffix

use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.

the class PortObjectRepository method addPortObjectReferenceReaderWithNodeReference.

/**
 * Adds a "Port Object Reference Reader" node to the workflow, which will read the object passed in as argument.
 *
 * The added reference reader node references the data (i.e. port object) by referencing the port (original node id
 * plus port index).
 *
 * @param outport the outport to get the port object and flow variables from that the to be added node will provide,
 *            too (the port object is just referenced by the original node id and port index)
 * @param srcParentID the id of the workflow manager the referenced node (port) is part of
 * @param wfm the workflow manager the new node should be added to
 * @param nodeIDSuffix the id the to be added node will have (will be ignored if there is a node with the id
 *            already!)
 * @return the id of the newly added node
 */
// TODO we might have to revisit this when implementing AP-13335
public static NodeID addPortObjectReferenceReaderWithNodeReference(final NodeOutPort outport, final NodeID srcParentID, final WorkflowManager wfm, final int nodeIDSuffix) {
    NodeID sourceNodeID = outport.getConnectedNodeContainer().getID();
    int portIndex = outport.getConnectedOutport().orElseThrow(() -> new IllegalStateException("Node is set, but no port"));
    List<FlowVariable> variables = outport.getFlowObjectStack().getAllAvailableFlowVariables().values().stream().filter(f -> f.getScope() == Scope.Flow).collect(Collectors.toList());
    PortObjectIDSettings portObjectIDSettings = new PortObjectIDSettings();
    portObjectIDSettings.setNodeReference(NodeIDSuffix.create(srcParentID, sourceNodeID), portIndex);
    portObjectIDSettings.setFlowVariables(variables);
    boolean isTable = outport.getPortType().equals(BufferedDataTable.TYPE);
    return addPortObjectReferenceReader(wfm, portObjectIDSettings, isTable, nodeIDSuffix);
}
Also used : FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FlowVariable(org.knime.core.node.workflow.FlowVariable) ObjectInputStream(java.io.ObjectInputStream) ObjectStreamClass(java.io.ObjectStreamClass) HashMap(java.util.HashMap) NodeSettings(org.knime.core.node.NodeSettings) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) DataCellSerializer(org.knime.core.data.DataCellSerializer) System.identityHashCode(java.lang.System.identityHashCode) ExecutionContext(org.knime.core.node.ExecutionContext) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) Node(org.knime.core.node.Node) ByteArrayInputStream(java.io.ByteArrayInputStream) DataTypeRegistry(org.knime.core.data.DataTypeRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) BlobDataCell(org.knime.core.data.container.BlobDataCell) PortObjectInNodeModel(org.knime.core.node.exec.dataexchange.in.PortObjectInNodeModel) Scope(org.knime.core.node.workflow.FlowVariable.Scope) ObjectOutputStream(java.io.ObjectOutputStream) DataCell(org.knime.core.data.DataCell) OutputStream(java.io.OutputStream) DefaultRow(org.knime.core.data.def.DefaultRow) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) NodeFactory(org.knime.core.node.NodeFactory) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) IOException(java.io.IOException) UUID(java.util.UUID) NotInWorkflowWriteFileStoreHandler(org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) Collectors(java.util.stream.Collectors) DataRow(org.knime.core.data.DataRow) SandboxedNodeCreator(org.knime.core.node.exec.SandboxedNodeCreator) List(java.util.List) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCellDataInput(org.knime.core.data.DataCellDataInput) DataCellDataOutput(org.knime.core.data.DataCellDataOutput) NodeID(org.knime.core.node.workflow.NodeID) Optional(java.util.Optional) CheckUtils(org.knime.core.node.util.CheckUtils) PortObject(org.knime.core.node.port.PortObject) InputStream(java.io.InputStream) NodeID(org.knime.core.node.workflow.NodeID) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Aggregations

NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)19 NodeID (org.knime.core.node.workflow.NodeID)7 HashSet (java.util.HashSet)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 WizardNode (org.knime.core.node.wizard.WizardNode)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)4 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)4 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 PortObjectInNodeModel (org.knime.core.node.exec.dataexchange.in.PortObjectInNodeModel)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 LinkedHashSet (java.util.LinkedHashSet)2 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