use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.
the class CollapseMetaNodeCommand method create.
/**
* @param manager
* @param nodeParts
* @param annoParts
* @param encapsulateAsSubnode TODO
* @return
*/
public static Optional<CollapseMetaNodeCommand> create(final WorkflowManager manager, final NodeContainerEditPart[] nodeParts, final AnnotationEditPart[] annoParts, final boolean encapsulateAsSubnode) {
NodeID[] nodeIds = new NodeID[nodeParts.length];
for (int i = 0; i < nodeParts.length; i++) {
nodeIds[i] = nodeParts[i].getNodeContainer().getID();
}
WorkflowAnnotation[] annos = AnnotationEditPart.extractWorkflowAnnotations(annoParts);
try {
// before testing anything, let's see if we should reset
// the selected nodes:
List<NodeID> resetableIDs = new ArrayList<NodeID>();
for (NodeID id : nodeIds) {
if (manager.canResetNode(id)) {
resetableIDs.add(id);
}
}
if (resetableIDs.size() > 0) {
// found some: ask if we can reset, otherwise bail
MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
mb.setMessage("Executed Nodes will be reset - are you sure?");
mb.setText("Reset Executed Nodes");
int dialogreturn = mb.open();
if (dialogreturn == SWT.CANCEL) {
return Optional.empty();
}
} else {
// if there are no resetable nodes we can check if
// we can collapse - otherwise we need to first reset
// those nodes (which we don't want to do before we
// have not gathered all info - and allowed the user
// to cancel the operation!)
String res = manager.canCollapseNodesIntoMetaNode(nodeIds);
if (res != null) {
throw new IllegalArgumentException(res);
}
}
// let the user enter a name
String name = "Metanode";
InputDialog idia = new InputDialog(Display.getCurrent().getActiveShell(), "Enter Name of Metanode", "Enter name of Metanode:", name, null);
int dialogreturn = idia.open();
if (dialogreturn == Window.CANCEL) {
return Optional.empty();
}
if (dialogreturn == Window.OK) {
if (resetableIDs.size() > 0) {
// and skip the ones that were already reset in passing.
for (NodeID id : resetableIDs) {
if (manager.canResetNode(id)) {
manager.resetAndConfigureNode(id);
}
}
}
// check if there is another reason why we cannot collapse
String res = manager.canCollapseNodesIntoMetaNode(nodeIds);
if (res != null) {
throw new IllegalArgumentException(res);
}
name = idia.getValue();
return Optional.of(new CollapseMetaNodeCommand(manager, nodeIds, annos, name, encapsulateAsSubnode));
}
} catch (IllegalArgumentException e) {
MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
final String error = "Collapsing to metanode failed: " + e.getMessage();
LOGGER.error(error, e);
mb.setMessage(error);
mb.setText("Collapse failed");
mb.open();
}
return Optional.empty();
}
use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.
the class ExpandMetaNodeCommand method undo.
/**
* {@inheritDoc}
*/
@Override
public void undo() {
WorkflowManager hostWFM = getHostWFM();
for (NodeID id : m_pastedNodes) {
hostWFM.removeNode(id);
}
for (WorkflowAnnotation anno : m_pastedAnnotations) {
hostWFM.removeAnnotation(anno);
}
hostWFM.paste(m_undoCopyPersistor);
m_pastedNodes = null;
m_pastedAnnotations = null;
m_undoCopyPersistor = null;
}
use of org.knime.core.node.workflow.WorkflowAnnotation 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));
}
}
use of org.knime.core.node.workflow.WorkflowAnnotation 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);
}
use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.
the class CopyAction method runInSWT.
/**
* {@inheritDoc}
*/
@Override
public void runInSWT() {
m_nodeParts = getSelectedParts(NodeContainerEditPart.class);
m_annotationParts = getSelectedParts(AnnotationEditPart.class);
NodeID[] ids = new NodeID[m_nodeParts.length];
for (int i = 0; i < m_nodeParts.length; i++) {
NodeContainerEditPart nodeEP = m_nodeParts[i];
ids[i] = nodeEP.getNodeContainer().getID();
}
WorkflowAnnotation[] annotations = AnnotationEditPart.extractWorkflowAnnotations(m_annotationParts);
WorkflowCopyContent.Builder content = WorkflowCopyContent.builder();
content.setNodeIDs(ids);
content.setAnnotation(annotations);
WorkflowPersistor copyPersistor = getManager().copy(false, content.build());
// the information about the nodes is stored in the config XML format
// also used to store workflow information in the kflow files
getEditor().setClipboardContent(new ClipboardObject(copyPersistor));
// update the actions
getEditor().updateActions();
// Give focus to the editor again. Otherwise the actions (selection)
// is not updated correctly.
getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
}
Aggregations