use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class UpdateMetaNodeLinkCommand method canExecute.
/**
* We can execute, if all components were 'non-null' in the constructor.
* {@inheritDoc}
*/
@Override
public boolean canExecute() {
if (!super.canExecute()) {
return false;
}
if (m_ids == null) {
return false;
}
boolean containsUpdateableMN = false;
WorkflowManager hostWFM = getHostWFM();
for (NodeID id : m_ids) {
NodeContainer nc = hostWFM.findNodeContainer(id);
if (nc instanceof NodeContainerTemplate) {
NodeContainerTemplate tnc = (NodeContainerTemplate) nc;
final WorkflowManager parent = tnc.getParent();
if (parent.hasUpdateableMetaNodeLink(id)) {
containsUpdateableMN = true;
}
if (!parent.canUpdateMetaNodeLink(id)) {
return false;
}
}
}
return containsUpdateableMN;
}
use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class ReplaceHelper method reconnect.
/**
* Connects new node with connection of the old node.
*
* @param container new node container
*/
public void reconnect(final NodeContainer container) {
// reset node location
NodeUIInformation uiInformation = m_oldNode.getUIInformation();
int[] bounds = uiInformation.getBounds();
NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(bounds[0], bounds[1], -1, -1).setHasAbsoluteCoordinates(true).setSnapToGrid(uiInformation.getSnapToGrid()).setIsDropLocation(false).build();
container.setUIInformation(info);
int inShift;
int outShift;
if (m_oldNode instanceof WorkflowManager && !(container instanceof WorkflowManager)) {
inShift = 0;
// replacing a metanode (no opt. flow var ports) with a "normal" node (that has optional flow var ports)
if (m_oldNode.getNrInPorts() > 0 && container.getNrInPorts() > 1) {
// shift ports one index - unless we need to use the invisible optional flow var port of new node
if (!m_oldNode.getInPort(0).getPortType().equals(FlowVariablePortObject.TYPE)) {
inShift = 1;
} else if (container.getInPort(1).getPortType().equals(FlowVariablePortObject.TYPE)) {
inShift = 1;
}
}
outShift = 0;
if (m_oldNode.getNrOutPorts() > 0 && container.getNrOutPorts() > 1) {
if (!m_oldNode.getOutPort(0).getPortType().equals(FlowVariablePortObject.TYPE)) {
outShift = 1;
} else if (container.getOutPort(1).getPortType().equals(FlowVariablePortObject.TYPE)) {
outShift = 1;
}
}
} else if (!(m_oldNode instanceof WorkflowManager) && container instanceof WorkflowManager) {
// replacing a "normal" node with a metanode
inShift = -1;
for (ConnectionContainer cc : m_incomingConnections) {
if (cc.getDestPort() == 0) {
inShift = 0;
break;
}
}
outShift = -1;
for (ConnectionContainer cc : m_outgoingConnections) {
if (cc.getSourcePort() == 0) {
outShift = 0;
break;
}
}
} else {
inShift = 0;
outShift = 0;
}
// set incoming connections
NodeID newId = container.getID();
for (ConnectionContainer c : m_incomingConnections) {
if (m_wfm.canAddConnection(c.getSource(), c.getSourcePort(), newId, c.getDestPort() + inShift)) {
m_wfm.addConnection(c.getSource(), c.getSourcePort(), newId, c.getDestPort() + inShift);
} else {
break;
}
}
// set outgoing connections
for (ConnectionContainer c : m_outgoingConnections) {
if (m_wfm.canAddConnection(newId, c.getSourcePort() + outShift, c.getDest(), c.getDestPort())) {
m_wfm.addConnection(newId, c.getSourcePort() + outShift, c.getDest(), c.getDestPort());
} else {
break;
}
}
}
use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class SetupSubnodeWizard method addPages.
/**
* {@inheritDoc}
*/
@Override
public void addPages() {
setWindowTitle("Setup Wrapped Metanode Wizard");
setDefaultPageImageDescriptor(ImageDescriptor.createFromImage(ImageRepository.getImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/meta/meta_node_wizard2.png")));
WorkflowManager wfManager = m_subNode.getWorkflowManager();
Map<NodeID, NodeModel> allNodes = wfManager.findNodes(NodeModel.class, false);
LinkedHashMap<NodeID, NodeModel> usageNodes = new LinkedHashMap<NodeID, NodeModel>();
List<NodeID> nodeIDs = new ArrayList<NodeID>();
nodeIDs.addAll(allNodes.keySet());
Collections.sort(nodeIDs);
for (NodeID id : nodeIDs) {
NodeModel model = allNodes.get(id);
if (considerNodeForUsage(model)) {
usageNodes.put(id, model);
}
}
m_portsPage = new ConfigureMetaNodePortsPage("Change the Wrapped Metanode configuration");
m_portsPage.setSubNode(m_subNode);
m_portsPage.setTemplate(null);
addPage(m_portsPage);
}
use of org.knime.core.node.workflow.NodeID 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);
}
use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class ExpandSubnodeResult method undo.
public void undo() {
WorkflowManager hostWFM = m_hostWFM;
for (NodeID id : m_expandedCopyContent.getNodeIDs()) {
hostWFM.removeNode(id);
}
for (WorkflowAnnotation anno : m_expandedCopyContent.getAnnotations()) {
hostWFM.removeAnnotation(anno);
}
hostWFM.paste(m_undoCopyPersistor);
}
Aggregations