use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.
the class AddAnnotationCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// adapt location to the viewport location and the zoom factor
// this seems to be a workaround for a bug in the framework
ZoomManager zoomManager = (ZoomManager) m_viewer.getProperty(ZoomManager.class.toString());
// adjust the location according to the viewport position
// seems to be a workaround for a bug in the framework
// (should imediately deliver the correct view position and not
// the position of the viewport)
PrecisionPoint location = new PrecisionPoint(m_location.x, m_location.y);
WorkflowEditor.adaptZoom(zoomManager, location, true);
m_anno = new WorkflowAnnotation();
AnnotationData data = new AnnotationData();
// it is a workflow annotation
data.setBgColor(INITIAL_FLOWANNO_COLOR);
data.setDimension((int) location.preciseX, (int) location.preciseY, DEFAULT_WIDTH, DEFAULT_HEIGHT);
data.setBorderSize(AnnotationEditPart.getAnnotationDefaultBorderSizePrefValue());
data.setBorderColor(INITAL_FLOWBORDER_COLOR);
data.setText(INITIAL_FLOWANNO_TEXT);
data.setStyleRanges(new AnnotationData.StyleRange[0]);
m_anno.copyFrom(data, true);
WorkflowManager hostWFM = getHostWFM();
hostWFM.addWorkflowAnnotation(m_anno);
m_viewer.deselectAll();
// select the new ones....
if (m_viewer.getRootEditPart().getContents() != null && m_viewer.getRootEditPart().getContents() instanceof WorkflowRootEditPart) {
((WorkflowRootEditPart) m_viewer.getRootEditPart().getContents()).setFutureAnnotationSelection(Collections.singleton(m_anno));
}
}
use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.
the class CreateMetaNodeCommand method undo.
/**
* {@inheritDoc}
*/
@Override
public void undo() {
NodeID[] ids = m_copyContent.getNodeIDs();
if (LOGGER.isDebugEnabled()) {
String debug = "Removing node";
if (ids.length == 1) {
debug = debug + " " + ids[0];
} else {
debug = debug + "s " + Arrays.asList(ids);
}
LOGGER.debug(debug);
}
WorkflowManager wm = getHostWFM();
if (canUndo()) {
for (NodeID id : ids) {
wm.removeNode(id);
}
for (WorkflowAnnotation anno : m_copyContent.getAnnotations()) {
wm.removeAnnotation(anno);
}
} else {
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Operation no allowed", "The node(s) " + Arrays.asList(ids) + " can currently not be removed");
}
}
use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.
the class ExpandSubNodeCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
try {
WorkflowManager hostWFM = getHostWFM();
// close editor of subnode and children
NodeID wfmID = ((SubNodeContainer) hostWFM.getNodeContainer(m_id)).getWorkflowManager().getID();
for (IEditorPart child : m_editor.getSubEditors(m_id)) {
child.getEditorSite().getPage().closeEditor(child, false);
}
m_expandResult = hostWFM.expandSubWorkflow(m_id);
WorkflowAnnotation[] annotations = m_expandResult.getExpandedCopyContent().getAnnotations();
NodeID[] nodeIDs = m_expandResult.getExpandedCopyContent().getNodeIDs();
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(nodeIDs);
rootEditPart.setFutureAnnotationSelection(Arrays.asList(annotations));
}
} catch (Exception e) {
String error = "Expanding Wrapped Metanode failed: " + e.getMessage();
LOGGER.error(error, e);
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Expand failed", error);
}
}
use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.
the class DeleteCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
WorkflowManager hostWFM = getHostWFM();
// removed.
if (m_nodeIDs.length > 0 || m_annotations.length > 0) {
WorkflowCopyContent.Builder content = WorkflowCopyContent.builder();
content.setNodeIDs(m_nodeIDs);
content.setAnnotation(m_annotations);
m_undoPersitor = hostWFM.copy(true, content.build());
}
for (WorkflowAnnotation anno : m_annotations) {
hostWFM.removeAnnotation(anno);
}
for (NodeID id : m_nodeIDs) {
hostWFM.removeNode(id);
}
for (ConnectionContainer cc : m_connections) {
hostWFM.removeConnection(cc);
}
}
use of org.knime.core.node.workflow.WorkflowAnnotation in project knime-core by knime.
the class AnnotationEditPart method createFigure.
/**
* {@inheritDoc}
*/
@Override
protected IFigure createFigure() {
Annotation anno = getModel();
NodeAnnotationFigure f = new WorkflowAnnotationFigure(anno);
if (anno instanceof WorkflowAnnotation) {
f.setBounds(new Rectangle(anno.getX(), anno.getY(), anno.getWidth(), anno.getHeight()));
}
return f;
}
Aggregations