Search in sources :

Example 1 with NodeContainer

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

the class ChangeSubNodeLinkAction method internalCalculateEnabled.

/**
 * @return true, if underlying model instance of <code>WorkflowManager</code>, otherwise false
 */
@Override
protected boolean internalCalculateEnabled() {
    NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
    if (nodes.length != 1) {
        return false;
    }
    NodeContainer nc = Wrapper.unwrapNC(nodes[0].getNodeContainer());
    if (!(nc instanceof SubNodeContainer)) {
        return false;
    }
    SubNodeContainer subNode = (SubNodeContainer) nc;
    if (!Role.Link.equals(subNode.getTemplateInformation().getRole()) || subNode.getParent().isWriteProtected()) {
        // sub node must be linked and parent must not forbid the change
        return false;
    }
    // we can reconfigure the template link - but only if template and flow are in the same mountpoint
    URI targetURI = subNode.getTemplateInformation().getSourceURI();
    try {
        if (ResolverUtil.isMountpointRelativeURL(targetURI) || ResolverUtil.isWorkflowRelativeURL(targetURI)) {
            return true;
        }
    } catch (IOException e) {
        return false;
    }
    // we can change absolute links if the mount points of flow and template are the same
    AbstractContentProvider workflowMountPoint = null;
    WorkflowContext wfc = subNode.getProjectWFM().getContext();
    LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfc.getMountpointRoot());
    if (fs != null) {
        workflowMountPoint = fs.getContentProvider();
    }
    if (workflowMountPoint == null) {
        return false;
    }
    AbstractExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.getStore(targetURI);
    if (targetfs == null) {
        return false;
    }
    return workflowMountPoint.equals(targetfs.getContentProvider());
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AbstractExplorerFileStore(org.knime.workbench.explorer.filesystem.AbstractExplorerFileStore) LocalExplorerFileStore(org.knime.workbench.explorer.filesystem.LocalExplorerFileStore) WorkflowContext(org.knime.core.node.workflow.WorkflowContext) AbstractContentProvider(org.knime.workbench.explorer.view.AbstractContentProvider) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) IOException(java.io.IOException) URI(java.net.URI)

Example 2 with NodeContainer

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

the class NewWorkflowXYLayoutPolicy method createChangeConstraintCommand.

/**
 * Creates command to move / resize <code>NodeContainer</code> components on
 * the project's client area.
 *
 * {@inheritDoc}
 */
@Override
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
    // only rectangular constraints are supported
    if (!(constraint instanceof Rectangle)) {
        return null;
    }
    Command command = null;
    Rectangle rect = ((Rectangle) constraint).getCopy();
    if (child.getModel() instanceof NodeContainerUI) {
        NodeContainerUI container = (NodeContainerUI) child.getModel();
        if (!Wrapper.wraps(container, NodeContainer.class)) {
            // not supported for others than ordinary NodeContainers
            return null;
        }
        NodeContainerEditPart nodePart = (NodeContainerEditPart) child;
        command = new ChangeNodeBoundsCommand(Wrapper.unwrapNC(container), (NodeContainerFigure) nodePart.getFigure(), rect);
    } else if (child instanceof AbstractWorkflowPortBarEditPart) {
        command = new ChangeWorkflowPortBarCommand((AbstractWorkflowPortBarEditPart) child, rect);
    } else if (child instanceof AnnotationEditPart) {
        AnnotationEditPart annoPart = (AnnotationEditPart) child;
        // TODO the workflow annotation could know what its WFM is?
        WorkflowRootEditPart root = (WorkflowRootEditPart) annoPart.getParent();
        WorkflowManagerUI wm = root.getWorkflowManager();
        if (!Wrapper.wraps(wm, WorkflowManager.class)) {
            // not supported for others than an ordinary workflow manager
            return null;
        }
        command = new ChangeAnnotationBoundsCommand(Wrapper.unwrapWFM(wm), annoPart, rect);
    }
    return command;
}
Also used : NodeContainerUI(org.knime.core.ui.node.workflow.NodeContainerUI) ChangeNodeBoundsCommand(org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand) AbstractWorkflowPortBarEditPart(org.knime.workbench.editor2.editparts.AbstractWorkflowPortBarEditPart) WorkflowRootEditPart(org.knime.workbench.editor2.editparts.WorkflowRootEditPart) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ChangeWorkflowPortBarCommand(org.knime.workbench.editor2.commands.ChangeWorkflowPortBarCommand) WorkflowManagerUI(org.knime.core.ui.node.workflow.WorkflowManagerUI) NodeContainer(org.knime.core.node.workflow.NodeContainer) NodeContainerFigure(org.knime.workbench.editor2.figures.NodeContainerFigure) ChangeAnnotationBoundsCommand(org.knime.workbench.editor2.commands.ChangeAnnotationBoundsCommand) NodeContainerEditPart(org.knime.workbench.editor2.editparts.NodeContainerEditPart) AnnotationEditPart(org.knime.workbench.editor2.editparts.AnnotationEditPart) NodeAnnotationEditPart(org.knime.workbench.editor2.editparts.NodeAnnotationEditPart) ChangeWorkflowPortBarCommand(org.knime.workbench.editor2.commands.ChangeWorkflowPortBarCommand) ChangeNodeBoundsCommand(org.knime.workbench.editor2.commands.ChangeNodeBoundsCommand) ChangeAnnotationBoundsCommand(org.knime.workbench.editor2.commands.ChangeAnnotationBoundsCommand) Command(org.eclipse.gef.commands.Command)

Example 3 with NodeContainer

use of org.knime.core.node.workflow.NodeContainer 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 4 with NodeContainer

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

the class ReconfigureMetaNodeCommand method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() {
    NodeContainer nc = getHostWFM().getNodeContainer(m_metanodeID);
    if (nc instanceof WorkflowManager) {
        if (m_name != null) {
            WorkflowManager metaNode = (WorkflowManager) nc;
            m_oldName = metaNode.getName();
            metaNode.setName(m_name);
        }
        if (m_inPorts != null) {
            m_reverseInports = createReverseOperationList(getHostWFM().getMetanodeInputPortInfo(m_metanodeID), m_inPorts);
            getHostWFM().changeMetaNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
        }
        if (m_outPorts != null) {
            m_reverseOutports = createReverseOperationList(getHostWFM().getMetanodeOutputPortInfo(m_metanodeID), m_outPorts);
            getHostWFM().changeMetaNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
        }
    } else if (nc instanceof SubNodeContainer) {
        SubNodeContainer snc = (SubNodeContainer) nc;
        if (m_name != null) {
            m_oldName = snc.getName();
            snc.setName(m_name);
        }
        if (m_inPorts != null) {
            m_reverseInports = createReverseOperationList(getHostWFM().getSubnodeInputPortInfo(m_metanodeID), m_inPorts);
            getHostWFM().changeSubNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
        }
        if (m_outPorts != null) {
            m_reverseOutports = createReverseOperationList(getHostWFM().getSubnodeOutputPortInfo(m_metanodeID), m_outPorts);
            getHostWFM().changeSubNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
        }
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) MetaPortInfo(org.knime.core.node.port.MetaPortInfo)

Example 5 with NodeContainer

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

the class NodeContainerProperties method setPropertyValue.

/**
 * {@inheritDoc}
 */
@Override
public void setPropertyValue(final Object id, final Object value) {
    if ((id instanceof String) && (value instanceof String)) {
        String strVal = (String) value;
        String strID = (String) id;
        if (strID.startsWith(m_prefix)) {
            String[] hierarchy = strID.split(CONFIG_SEPARATOR);
            String key = hierarchy[hierarchy.length - 1];
            // apply it to the node's settings:
            NodeContainer node = getNode();
            if (node == null) {
                return;
            }
            WorkflowManager wfm = node.getParent();
            NodeSettings nodeSettings = new NodeSettings("Transfer");
            NodeSettings settings;
            try {
                wfm.saveNodeSettings(node.getID(), nodeSettings);
                // overwrite our config in the settings
                settings = nodeSettings.getNodeSettings("model");
                if (hierarchy.length > 1) {
                    for (int i = 0; i < hierarchy.length - 1; i++) {
                        settings = settings.getNodeSettings(hierarchy[i]);
                        if (settings == null) {
                            return;
                        }
                    }
                }
            } catch (InvalidSettingsException e) {
                // somehow node is not able to save its settings anymore
                return;
            }
            AbstractConfigEntry entry = settings.getEntry(key);
            if (entry == null || entry instanceof Config) {
                // settings are not complete or correct anymore
                return;
            }
            switch(entry.getType()) {
                case xboolean:
                    settings.addBoolean(key, Boolean.parseBoolean(strVal));
                    break;
                case xbyte:
                    settings.addByte(key, Byte.parseByte(strVal));
                    break;
                case xchar:
                    String decoded = TokenizerSettings.unescapeString(strVal);
                    settings.addChar(key, decoded.charAt(0));
                    break;
                case xdouble:
                    settings.addDouble(key, Double.parseDouble(strVal));
                    break;
                case xfloat:
                    settings.addFloat(key, Float.parseFloat(strVal));
                    break;
                case xint:
                    settings.addInt(key, Integer.parseInt(strVal));
                    break;
                case xlong:
                    settings.addLong(key, Long.parseLong(strVal));
                    break;
                case xshort:
                    settings.addShort(key, Short.parseShort(strVal));
                    break;
                case xstring:
                    String dec = TokenizerSettings.unescapeString(strVal);
                    settings.addString(key, dec);
                    break;
                default:
                    // ignore the new value
                    return;
            }
            try {
                wfm.loadNodeSettings(node.getID(), nodeSettings);
            } catch (Exception ex) {
                LOGGER.error("Invalid Value (" + strVal + "): " + ex.getMessage(), ex);
                return;
            }
            return;
        }
    }
}
Also used : AbstractConfigEntry(org.knime.core.node.config.base.AbstractConfigEntry) NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) Config(org.knime.core.node.config.Config) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Aggregations

NodeContainer (org.knime.core.node.workflow.NodeContainer)56 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)24 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)22 NodeID (org.knime.core.node.workflow.NodeID)19 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)17 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)13 IOException (java.io.IOException)9 Map (java.util.Map)9 ConnectionContainer (org.knime.core.node.workflow.ConnectionContainer)9 NodeContainerEditPart (org.knime.workbench.editor2.editparts.NodeContainerEditPart)9 ArrayList (java.util.ArrayList)8 NodeUIInformation (org.knime.core.node.workflow.NodeUIInformation)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)7 File (java.io.File)6 List (java.util.List)6 PortObject (org.knime.core.node.port.PortObject)6 ConnectionID (org.knime.core.node.workflow.ConnectionID)6 UUID (java.util.UUID)5 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)5 NodeSettings (org.knime.core.node.NodeSettings)5