Search in sources :

Example 46 with NodeContainer

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

the class SubnodeLayoutPage method createControl.

/**
 * {@inheritDoc}
 */
@Override
public void createControl(final Composite parent) {
    ScrolledComposite scrollPane = new ScrolledComposite(parent, 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(4, false));
    composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    Label titleLabel = new Label(composite, SWT.LEFT);
    FontData fontData = titleLabel.getFont().getFontData()[0];
    Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
    titleLabel.setText("Node");
    titleLabel.setFont(boldFont);
    Label xLabel = new Label(composite, SWT.LEFT);
    xLabel.setText("X");
    xLabel.setFont(boldFont);
    Label yLabel = new Label(composite, SWT.LEFT);
    yLabel.setText("Y");
    yLabel.setFont(boldFont);
    Label paddingLabel = new Label(composite, SWT.LEFT);
    paddingLabel.setText("Padding");
    paddingLabel.setFont(boldFont);
    for (final NodeID nodeID : m_viewNodes) {
        NodeContainer nodeContainer = m_wfManager.getNodeContainer(nodeID);
        WizardNodeLayoutInfo layoutInfo = null;
        if (m_subNodeContainer != null && m_subNodeContainer.getLayoutInfo() != null) {
            layoutInfo = m_subNodeContainer.getLayoutInfo().get(nodeID.getIndex());
            if (layoutInfo != null) {
                m_layoutMap.put(nodeID.getIndex(), layoutInfo);
            }
        }
        Composite labelComposite = new Composite(composite, SWT.NONE);
        labelComposite.setLayout(new GridLayout(2, false));
        labelComposite.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
        Label iconLabel = new Label(labelComposite, SWT.CENTER);
        iconLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        try (InputStream iconURLStream = FileLocator.resolve(nodeContainer.getIcon()).openStream()) {
            iconLabel.setImage(new Image(Display.getCurrent(), iconURLStream));
        } catch (IOException e) {
        /* do nothing */
        }
        Label nodeLabel = new Label(labelComposite, SWT.LEFT);
        nodeLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
        String nodeName = nodeContainer.getName();
        String annotation = nodeContainer.getNodeAnnotation().getText();
        nodeLabel.setText(nodeName + "\nID: " + nodeID.getIndex() + "\n" + annotation);
        GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
        gridData.widthHint = 80;
        final Text xText = new Text(composite, SWT.SINGLE | SWT.BORDER);
        xText.setLayoutData(gridData);
        xText.setText(layoutInfo == null ? "" : layoutInfo.getX());
        xText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                editX(nodeID, xText);
            }
        });
        final Text yText = new Text(composite, SWT.SINGLE | SWT.BORDER);
        yText.setLayoutData(gridData);
        yText.setText(layoutInfo == null ? "" : layoutInfo.getY());
        yText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                editY(nodeID, yText);
            }
        });
        final Text paddingText = new Text(composite, SWT.SINGLE | SWT.BORDER);
        paddingText.setLayoutData(gridData);
        paddingText.setText(layoutInfo == null || layoutInfo.getPadding() == null ? "" : layoutInfo.getPadding());
        paddingText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(final ModifyEvent e) {
                editPadding(nodeID, paddingText);
            }
        });
    }
    scrollPane.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    setControl(scrollPane);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ModifyListener(org.eclipse.swt.events.ModifyListener) InputStream(java.io.InputStream) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) Text(org.eclipse.swt.widgets.Text) IOException(java.io.IOException) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) GridData(org.eclipse.swt.layout.GridData) NodeID(org.knime.core.node.workflow.NodeID) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) WizardNodeLayoutInfo(org.knime.core.node.wizard.WizardNodeLayoutInfo)

Example 47 with NodeContainer

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

the class NodeRecommendationManager method getNodeRecommendationFor.

/**
 * Determines lists of node recommendation based on the given nodes (e.g. that are selected in the workflow editor).
 * The {@link NodeRecommendation}s are determined based on the statistics of {@link NodeTriple}s (i.e. predecessor,
 * node, successor, count -> (p,n,s,c)) that are provided by {@link NodeTripleProvider}s.
 *
 * Given the list's of node triples, {(predecessor, node, successor, count/frequency)} = {(p,n,s,c)} and given a
 * selected node 'sn', the recommendations are determined for each node-triple-list as follows:
 *
 * (1) find all node triples (p,n,s,c) where n==sn and add them to the result list; in that case the predecessor is
 * essentially ignored and recommendation are determined only based on n. The recommendation is the successor 's'
 * given by each found triple. Since there will be multiple triples for the same 'n' and therewith successor
 * duplicates (i.e. recommendations), those will be joined by taking the mean of the respective frequencies 'c' (2)
 * determine all current predecessors ('sp') of the selected node 'sn' and find all node triples that match the
 * given predecessor-node pairs ('sp','sn') (i.e. 'sp'='p' and 'sn'='n'). The recommended nodes are the successor
 * nodes 's' given by the found triples. Those are added to the same list as the recommendations of (1). (3)
 * Post-processing: duplicate recommendations are resolved by removing the recommendations with a smaller
 * counts/frequencies
 *
 * If the array of given nodes is empty, all potential source nodes are recommended, i.e. all nodes 'n' in the node
 * triples list that don't have a predecessor 'p'.
 *
 * @param nnc if it's an empty array, source nodes only will be recommended, if more than one node is given, the
 *            node recommendations for different nodes will end up in the same list
 * @return an array of lists of node recommendations, i.e. a list of node recommendations for each used node
 *         {@link NodeTripleProvider}. It will return <code>null</code> if something went wrong with loading the
 *         node statistics!
 */
public List<NodeRecommendation>[] getNodeRecommendationFor(final NativeNodeContainer... nnc) {
    if (m_recommendations == null) {
        return null;
    }
    @SuppressWarnings("unchecked") List<NodeRecommendation>[] res = new List[m_recommendations.size()];
    for (int idx = 0; idx < res.length; idx++) {
        if (nnc.length == 0) {
            // recommendations if no node is given -> source nodes are recommended
            res[idx] = m_recommendations.get(idx).get(SOURCE_NODES_KEY);
            if (res[idx] == null) {
                res[idx] = Collections.emptyList();
            }
        } else if (nnc.length == 1) {
            String nodeID = getKey(nnc[0]);
            Set<NodeRecommendation> set = new HashSet<NodeRecommendationManager.NodeRecommendation>();
            /* recommendations based on the given node and possible predecessors */
            for (int i = 0; i < nnc[0].getNrInPorts(); i++) {
                ConnectionContainer cc = nnc[0].getParent().getIncomingConnectionFor(nnc[0].getID(), i);
                if (cc != null) {
                    // only take the predecessor if its not leaving the workflow (e.g. the actual predecessor is outside of a metanode)
                    if (cc.getType() != ConnectionType.WFMIN) {
                        NodeContainer predecessor = nnc[0].getParent().getNodeContainer(cc.getSource());
                        if (predecessor instanceof NativeNodeContainer) {
                            List<NodeRecommendation> l = m_recommendations.get(idx).get(getKey((NativeNodeContainer) predecessor) + NODE_NAME_SEP + getKey(nnc[0]));
                            if (l != null) {
                                set.addAll(l);
                            }
                        }
                    }
                }
            }
            /* recommendation based on the given node only */
            List<NodeRecommendation> p1 = m_recommendations.get(idx).get(nodeID);
            if (p1 != null) {
                set.addAll(p1);
            }
            // add to the result list
            res[idx] = new ArrayList<NodeRecommendationManager.NodeRecommendation>(set.size());
            res[idx].addAll(set);
        } else {
            throw new UnsupportedOperationException("Recommendations for more than one node are not supported, yet.");
        }
        /* post-process result */
        Collections.sort(res[idx]);
        if (nnc.length == 1) {
            // remove the node, the recommendations have bee requested for, from the list
            // in order to match the nodes [NodeFactory]#[NodeName] needs to be compared, otherwise it won't work with dynamically generated nodes
            res[idx] = res[idx].stream().filter(nr -> !getKey(nr.getNodeTemplate()).equals(getKey(nnc[0]))).collect(Collectors.toList());
        }
        // update the total frequencies
        int tmpFreqs = 0;
        for (NodeRecommendation np : res[idx]) {
            tmpFreqs += np.getFrequency();
        }
        for (NodeRecommendation np : res[idx]) {
            np.setTotalFrequency(tmpFreqs);
        }
    }
    return res;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) ArrayList(java.util.ArrayList) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) ArrayList(java.util.ArrayList) List(java.util.List) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Example 48 with NodeContainer

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

the class KnimeResourcePatternFilter method select.

/**
 * {@inheritDoc}
 */
@Override
public boolean select(final Viewer viewer, final Object parentElement, final Object element) {
    if (element instanceof IContainer) {
        IContainer folder = (IContainer) element;
        boolean select = false;
        select = folder.exists(KnimeResourceLabelProvider.WORKFLOW_FILE);
        select |= folder.exists(KnimeResourceLabelProvider.METAINFO_FILE);
        select |= folder.exists(KnimeResourceLabelProvider.NODE_FILE);
        return select;
    }
    if (element instanceof NodeContainer) {
        return true;
    }
    return false;
}
Also used : NodeContainer(org.knime.core.node.workflow.NodeContainer) IContainer(org.eclipse.core.resources.IContainer)

Example 49 with NodeContainer

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

the class TimerinfoNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataContainer result = exec.createDataContainer(createSpec());
    WorkflowManager wfm = NodeContext.getContext().getWorkflowManager();
    for (NodeContainer nc : wfm.getNodeContainers()) {
        NodeTimer nt = nc.getNodeTimer();
        DataRow row = new DefaultRow(new RowKey("Node " + nc.getID().getIndex()), new StringCell(nc.getName()), nt.getLastExecutionDuration() >= 0 ? new LongCell(nt.getLastExecutionDuration()) : DataType.getMissingCell(), new LongCell(nt.getExecutionDurationSinceReset()), new LongCell(nt.getExecutionDurationSinceStart()), new IntCell(nt.getNrExecsSinceReset()), new IntCell(nt.getNrExecsSinceStart()), new StringCell(nc.getID().toString()), new StringCell(nc instanceof NativeNodeContainer ? ((NativeNodeContainer) nc).getNodeModel().getClass().getName() : "n/a"));
        result.addRowToTable(row);
    }
    result.close();
    return new PortObject[] { result.getTable() };
}
Also used : LongCell(org.knime.core.data.def.LongCell) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) NodeTimer(org.knime.core.node.workflow.NodeTimer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PortObject(org.knime.core.node.port.PortObject) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) IntCell(org.knime.core.data.def.IntCell)

Example 50 with NodeContainer

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

the class SandboxedNodeCreator method deepCopyFilesInWorkflowDir.

/**
 * Deep copies data and drop folders contained in the source directory to the target directory.
 * @param source Source node
 * @param targetParent Target node's parent
 */
private static void deepCopyFilesInWorkflowDir(final NodeContainer source, final WorkflowManager targetParent) {
    NodeContainer target = targetParent.getNodeContainer(targetParent.getID().createChild(source.getID().getIndex()));
    ReferencedFile sourceDirRef = source.getNodeContainerDirectory();
    ReferencedFile targetDirRef = target.getNodeContainerDirectory();
    if (sourceDirRef == null) {
        // The source node has never been saved, there are no files to copy
        return;
    }
    File sourceDir = sourceDirRef.getFile();
    File targetDir = targetDirRef.getFile();
    for (String magicFolderName : MAGIC_DATA_FOLDERS) {
        File dataSourceDir = new File(sourceDir, magicFolderName);
        if (dataSourceDir.isDirectory()) {
            File dataTargetDir = new File(targetDir, magicFolderName);
            try {
                FileUtils.copyDirectory(dataSourceDir, dataTargetDir);
                LOGGER.debugWithFormat("Copied directory \"%s\" to \"%s\"", dataSourceDir.getAbsolutePath(), dataTargetDir.getAbsolutePath());
            } catch (IOException ex) {
                LOGGER.error(String.format("Could not copy directory \"%s\" to \"%s\": %s", dataSourceDir.getAbsolutePath(), dataTargetDir.getAbsolutePath(), ex.getMessage()), ex);
            }
        }
    }
    Collection<NodeContainer> childrenList = Collections.emptyList();
    WorkflowManager childTargetParent = null;
    if (source instanceof WorkflowManager) {
        childrenList = ((WorkflowManager) source).getNodeContainers();
        childTargetParent = (WorkflowManager) target;
    } else if (source instanceof SubNodeContainer) {
        childrenList = ((SubNodeContainer) source).getWorkflowManager().getNodeContainers();
        childTargetParent = ((SubNodeContainer) target).getWorkflowManager();
    }
    for (NodeContainer child : childrenList) {
        deepCopyFilesInWorkflowDir(child, childTargetParent);
    }
}
Also used : SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NodeContainer(org.knime.core.node.workflow.NodeContainer) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) IOException(java.io.IOException) ReferencedFile(org.knime.core.internal.ReferencedFile) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

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