use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class RevealSubNodeTemplateAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
List<NodeID> candidateList = new ArrayList<NodeID>();
List<AbstractExplorerFileStore> templates = new ArrayList<AbstractExplorerFileStore>();
for (NodeContainerEditPart p : nodes) {
Object model = p.getModel();
if (wraps(model, SubNodeContainer.class)) {
NodeContext.pushContext(Wrapper.unwrapNC(p.getNodeContainer()));
try {
SubNodeContainer snc = unwrap((UI) model, SubNodeContainer.class);
MetaNodeTemplateInformation i = snc.getTemplateInformation();
if (Role.Link.equals(i.getRole())) {
candidateList.add(snc.getID());
AbstractExplorerFileStore template = ExplorerFileSystem.INSTANCE.getStore(i.getSourceURI());
if (template != null) {
templates.add(template);
}
}
} finally {
NodeContext.removeLastContext();
}
}
}
List<Object> treeObjects = ContentDelegator.getTreeObjectList(templates);
if (treeObjects != null && treeObjects.size() > 0) {
IViewReference[] views = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
for (IViewReference view : views) {
if (ExplorerView.ID.equals(view.getId())) {
ExplorerView explorerView = (ExplorerView) view.getView(true);
explorerView.getViewer().setSelection(new StructuredSelection(treeObjects), true);
}
}
}
}
use of org.knime.core.node.workflow.NodeID in project knime-core by knime.
the class SaveAsSubNodeTemplateAction method getDefaultSaveLocation.
private ContentObject getDefaultSaveLocation(final WorkflowManager arg) {
final NodeID id = arg.getID();
URI uri = DisconnectSubNodeLinkCommand.RECENTLY_USED_URIS.get(id);
if (uri == null || !ExplorerFileSystem.SCHEME.equals(uri.getScheme())) {
return null;
}
final AbstractExplorerFileStore oldTemplateFileStore = ExplorerFileSystem.INSTANCE.getStore(uri);
final AbstractExplorerFileStore parent = oldTemplateFileStore == null ? null : oldTemplateFileStore.getParent();
if (parent != null) {
return ContentObject.forFile(parent);
}
return null;
}
use of org.knime.core.node.workflow.NodeID 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.NodeID 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.NodeID in project knime-core by knime.
the class DropNodeCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
// Add node to workflow and get the container
WorkflowManager hostWFM = getHostWFM();
try {
NodeID id = hostWFM.addNodeAndApplyContext(m_factory, m_dropContext);
m_container = hostWFM.getNodeContainer(id);
// create extra info and set it
NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(m_snapToGrid).setIsDropLocation(true).build();
m_container.setUIInformation(info);
// Open the dialog. Some times.
if (m_container instanceof SingleNodeContainer && m_container.getNodeContainerState().isIdle() && m_container.hasDialog() && // and has only a variable in port
m_container.getNrInPorts() == 1) {
// if not executable and has a dialog and is fully connected
// This is embedded in a special JFace wrapper dialog
//
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
WrappedNodeDialog dlg = new WrappedNodeDialog(Display.getCurrent().getActiveShell(), m_container);
dlg.open();
} catch (Exception e) {
// they need to open it manually then
}
}
});
}
} catch (Throwable t) {
// if fails notify the user
LOGGER.debug("Node cannot be created.", t);
MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_WARNING | SWT.OK);
mb.setText("Node cannot be created.");
mb.setMessage("The selected node could not be created " + "due to the following reason:\n" + t.getMessage());
mb.open();
return;
}
}
Aggregations