use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class ReconnectConnectionCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// confirm replacement?
// check if old target node was executed
WorkflowManager hostWFM = getHostWFM();
NodeContainer oldTarget = hostWFM.getNodeContainer(m_oldTarget);
NodeContainer newTarget = hostWFM.getNodeContainer(m_newTarget);
if (oldTarget == null || newTarget == null) {
// something is very wrong here
return;
}
boolean oldExecuted = oldTarget.getNodeContainerState().isExecuted();
boolean newExecuted = newTarget.getNodeContainerState().isExecuted();
// or new target node is executed
if (m_confirm && (oldExecuted || newExecuted)) {
// create comprehensible and correct confirmation message
StringBuffer message = new StringBuffer("Do you want to delete the existing connection? \n");
if (oldExecuted || newExecuted) {
message.append("This will reset ");
if (oldExecuted) {
message.append("the current destination node");
}
if (oldExecuted && newExecuted) {
message.append(" and");
}
if (newExecuted) {
message.append(" the new target node");
}
message.append('!');
}
MessageDialogWithToggle msgD = CreateConnectionCommand.openReconnectConfirmDialog(m_confirm, message.toString());
m_confirm = !msgD.getToggleState();
if (msgD.getReturnCode() != IDialogConstants.YES_ID) {
return;
}
}
// execute both commands
m_deleteCommand.execute();
m_createCommand.setConfirm(false);
m_createCommand.execute();
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class UpdateMetaNodeLinkCommand method undo.
/**
* {@inheritDoc}
*/
@Override
public void undo() {
LOGGER.debug("Undo: Reverting metanode links (" + m_newIDs.size() + " metanode(s))");
WorkflowManager hostWFM = getHostWFM();
for (int i = 0; i < m_newIDs.size(); i++) {
NodeID id = m_newIDs.get(i);
WorkflowPersistor p = m_undoPersistors.get(i);
NodeContainerTemplate nodeToBeDeleted = (NodeContainerTemplate) hostWFM.findNodeContainer(id);
WorkflowManager parent = nodeToBeDeleted.getParent();
parent.removeNode(nodeToBeDeleted.getID());
parent.paste(p);
}
}
use of org.knime.core.node.workflow.WorkflowManager 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.WorkflowManager 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.WorkflowManager in project knime-core by knime.
the class ConnectionBendpointEditPolicy method getMoveBendpointCommand.
/**
* {@inheritDoc}
*/
protected Command getMoveBendpointCommand(final BendpointRequest request) {
// index of the bendpoint to move
int index = request.getIndex();
Point loc = request.getLocation();
ConnectionContainerEditPart edit = (ConnectionContainerEditPart) getHost();
ZoomManager zoomManager = (ZoomManager) getHost().getRoot().getViewer().getProperty(ZoomManager.class.toString());
WorkflowManager m = getWorkflowManager();
return new NewBendpointMoveCommand(edit, m, index, loc, zoomManager);
}
Aggregations