use of org.knime.core.node.workflow.WorkflowPersistor in project knime-core by knime.
the class NewWorkflowContainerEditPolicy method getCreateCommand.
/**
* {@inheritDoc}
*/
@Override
protected Command getCreateCommand(final CreateRequest request) {
// point where the command occurred
// The node/description should be initially located here
boolean snapToGrid = WorkflowEditor.getActiveEditorSnapToGrid();
WorkflowRootEditPart workflowPart = (WorkflowRootEditPart) this.getHost();
if (!Wrapper.wraps(workflowPart.getWorkflowManager(), WorkflowManager.class)) {
// adding new nodes not supported yet by UI-interfaces and implemenations
LOGGER.error("Adding new nodes not supported by '" + workflowPart.getWorkflowManager().getClass().getSimpleName() + "'.");
return null;
}
WorkflowManager manager = Wrapper.unwrapWFM(workflowPart.getWorkflowManager());
if (request instanceof CreateDropRequest) {
Object obj = request.getNewObject();
CreateDropRequest cdr = (CreateDropRequest) request;
if (obj instanceof NodeFactory) {
return handleNodeDrop(manager, (NodeFactory<? extends NodeModel>) obj, cdr);
} else if (obj instanceof AbstractExplorerFileStore) {
AbstractExplorerFileStore fs = (AbstractExplorerFileStore) obj;
if (AbstractExplorerFileStore.isWorkflowTemplate(fs)) {
return handleMetaNodeTemplateDrop(manager, cdr, fs);
}
} else if (obj instanceof WorkflowPersistor) {
return handleMetaNodeDrop(manager, (WorkflowPersistor) obj, cdr);
} else if (obj instanceof ReaderNodeSettings) {
ReaderNodeSettings settings = (ReaderNodeSettings) obj;
return new DropNodeCommand(manager, settings.getFactory(), new NodeCreationContext(settings.getUrl()), request.getLocation(), snapToGrid);
} else {
LOGGER.error("Illegal drop object: " + obj);
}
}
return null;
}
use of org.knime.core.node.workflow.WorkflowPersistor 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.WorkflowPersistor in project knime-core by knime.
the class UpdateMetaNodeTemplateRunnable method run.
/**
* {@inheritDoc}
*/
@Override
public void run(final IProgressMonitor pm) throws InterruptedException {
m_newIDs = new ArrayList<NodeID>();
m_undoPersistors = new ArrayList<WorkflowPersistor>();
// create progress monitor
ProgressHandler progressHandler = new ProgressHandler(pm, 101, "Updating node links...");
final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
progressMonitor.addProgressListener(progressHandler);
final Display d = Display.getDefault();
ExecutionMonitor exec = new ExecutionMonitor(progressMonitor);
IStatus[] stats = new IStatus[m_ids.length];
for (int i = 0; i < m_ids.length; i++) {
NodeID id = m_ids[i];
NodeContainerTemplate tnc = (NodeContainerTemplate) m_parentWFM.findNodeContainer(id);
LOGGER.debug("Updating " + tnc.getNameWithID() + " from " + tnc.getTemplateInformation().getSourceURI());
ExecutionMonitor subExec = exec.createSubProgress(1.0 / m_ids.length);
String progMsg = "Node Link \"" + tnc.getNameWithID() + "\"";
exec.setMessage(progMsg);
GUIWorkflowLoadHelper loadHelper = new GUIWorkflowLoadHelper(d, progMsg, null, null, null, true);
NodeContainerTemplateLinkUpdateResult updateMetaNodeLinkResult;
try {
updateMetaNodeLinkResult = tnc.getParent().updateMetaNodeLink(id, subExec, loadHelper);
} catch (CanceledExecutionException e) {
String message = "Node update canceled";
LOGGER.warn(message, e);
throw new InterruptedException(message);
}
WorkflowPersistor p = updateMetaNodeLinkResult.getUndoPersistor();
if (p != null) {
// no error
m_newIDs.add(updateMetaNodeLinkResult.getNCTemplate().getID());
m_undoPersistors.add(p);
}
// metanodes don't have data
// data load errors are unexpected but OK
IStatus status = createStatus(updateMetaNodeLinkResult, true);
subExec.setProgress(1.0);
switch(status.getSeverity()) {
case IStatus.OK:
break;
case IStatus.WARNING:
logPreseveLineBreaks("Warnings during load: " + updateMetaNodeLinkResult.getFilteredError("", LoadResultEntryType.Warning), false);
break;
default:
logPreseveLineBreaks("Errors during load: " + updateMetaNodeLinkResult.getFilteredError("", LoadResultEntryType.Warning), true);
}
stats[i] = status;
}
pm.done();
final IStatus status = createMultiStatus("Update node links", stats);
final String message;
switch(status.getSeverity()) {
case IStatus.OK:
message = "No problems during node link update.";
break;
case IStatus.WARNING:
message = "Warnings during node link update";
break;
default:
message = "Errors during node link update";
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
// will not open if status is OK.
ErrorDialog.openError(Display.getDefault().getActiveShell(), "Update Node Links", message, status);
}
});
}
use of org.knime.core.node.workflow.WorkflowPersistor 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());
}
use of org.knime.core.node.workflow.WorkflowPersistor 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);
}
}
Aggregations