use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class ChangeMetaNodeLinkCommand method setLink.
private boolean setLink(final URI link) {
NodeContainer metaNode = getHostWFM().getNodeContainer(m_metaNodeID);
if (!(metaNode instanceof WorkflowManager)) {
LOGGER.error("Command failed: Specified node is not a metanode");
return false;
}
MetaNodeTemplateInformation templateInfo = ((WorkflowManager) metaNode).getTemplateInformation();
MetaNodeTemplateInformation newInfo;
try {
newInfo = templateInfo.createLinkWithUpdatedSource(m_newLink);
} catch (InvalidSettingsException e1) {
// will not happen.
LOGGER.error("Command failed: Specified node is not a metanode with a link." + e1.getMessage(), e1);
return false;
}
getHostWFM().setTemplateInformation(m_metaNodeID, newInfo);
return true;
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class DisconnectMetaNodeLinkCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
m_changedIDs = new ArrayList<NodeID>();
m_oldTemplInfos = new ArrayList<MetaNodeTemplateInformation>();
WorkflowManager hostWFM = getHostWFM();
for (NodeID id : m_ids) {
NodeContainer nc = hostWFM.getNodeContainer(id);
if (nc instanceof WorkflowManager) {
WorkflowManager wm = (WorkflowManager) nc;
MetaNodeTemplateInformation lI = wm.getTemplateInformation();
if (Role.Link.equals(lI.getRole())) {
MetaNodeTemplateInformation old = hostWFM.setTemplateInformation(id, MetaNodeTemplateInformation.NONE);
RECENTLY_USED_URIS.put(wm.getID(), old.getSourceURI());
m_changedIDs.add(id);
m_oldTemplInfos.add(old);
}
}
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class DisconnectSubNodeLinkCommand 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;
}
for (NodeID id : m_ids) {
NodeContainer nc = getHostWFM().getNodeContainer(id);
if (nc instanceof SubNodeContainer) {
SubNodeContainer snc = (SubNodeContainer) nc;
MetaNodeTemplateInformation lI = snc.getTemplateInformation();
if (Role.Link.equals(lI.getRole())) {
return true;
}
}
}
return false;
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class DisconnectSubNodeLinkCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
m_changedIDs = new ArrayList<NodeID>();
m_oldTemplInfos = new ArrayList<MetaNodeTemplateInformation>();
WorkflowManager hostWFM = getHostWFM();
for (NodeID id : m_ids) {
NodeContainer nc = hostWFM.getNodeContainer(id);
if (nc instanceof SubNodeContainer) {
SubNodeContainer snc = (SubNodeContainer) nc;
MetaNodeTemplateInformation lI = snc.getTemplateInformation();
if (Role.Link.equals(lI.getRole())) {
MetaNodeTemplateInformation old = hostWFM.setTemplateInformation(id, MetaNodeTemplateInformation.NONE);
RECENTLY_USED_URIS.put(snc.getID(), old.getSourceURI());
m_changedIDs.add(id);
m_oldTemplInfos.add(old);
}
}
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class PasteFromWorkflowPersistorCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
WorkflowManager manager = m_editor.getWorkflowManager().get();
WorkflowPersistor copyPersistor = m_clipboardObject.getCopyPersistor();
m_pastedContent = manager.paste(copyPersistor);
NodeID[] pastedNodes = m_pastedContent.getNodeIDs();
WorkflowAnnotation[] pastedAnnos = m_pastedContent.getAnnotations();
// fast lookup below
Set<NodeID> newIDs = new HashSet<NodeID>();
List<int[]> insertedElementBounds = new ArrayList<int[]>();
for (NodeID i : pastedNodes) {
NodeContainer nc = manager.getNodeContainer(i);
NodeUIInformation ui = nc.getUIInformation();
int[] bounds = ui.getBounds();
insertedElementBounds.add(bounds);
}
for (WorkflowAnnotation a : pastedAnnos) {
int[] bounds = new int[] { a.getX(), a.getY(), a.getWidth(), a.getHeight() };
insertedElementBounds.add(bounds);
}
int[] moveDist = m_shiftCalculator.calculateShift(insertedElementBounds, manager, m_clipboardObject);
// for redo-operations we need the exact same shift.
m_shiftCalculator = new FixedShiftCalculator(moveDist);
for (NodeID id : pastedNodes) {
newIDs.add(id);
NodeContainer nc = manager.getNodeContainer(id);
NodeUIInformation oldUI = nc.getUIInformation();
NodeUIInformation newUI = NodeUIInformation.builder(oldUI).translate(moveDist).build();
nc.setUIInformation(newUI);
}
for (ConnectionContainer conn : manager.getConnectionContainers()) {
if (newIDs.contains(conn.getDest()) && newIDs.contains(conn.getSource())) {
// get bend points and move them
ConnectionUIInformation oldUI = conn.getUIInfo();
if (oldUI != null) {
ConnectionUIInformation newUI = ConnectionUIInformation.builder(oldUI).translate(moveDist).build();
conn.setUIInfo(newUI);
}
}
}
for (WorkflowAnnotation a : pastedAnnos) {
a.shiftPosition(moveDist[0], moveDist[1]);
}
EditPartViewer partViewer = m_editor.getViewer();
partViewer.deselectAll();
// select the new ones....
if (partViewer.getRootEditPart().getContents() != null && partViewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
WorkflowRootEditPart rootEditPart = (WorkflowRootEditPart) partViewer.getRootEditPart().getContents();
rootEditPart.setFutureSelection(pastedNodes);
rootEditPart.setFutureAnnotationSelection(Arrays.asList(pastedAnnos));
}
}
Aggregations