use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class DefaultOpenViewAction method runOnNodes.
/**
* This opens the first view of all the selected nodes.
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
LOGGER.debug("Creating open default view job for " + nodeParts.length + " node(s)...");
for (NodeContainerEditPart p : nodeParts) {
final NodeContainer cont = unwrapNC(p.getNodeContainer());
final InteractiveWebViewsResult webViewsResult = cont.getInteractiveWebViews();
boolean hasView = cont.getNrViews() > 0;
hasView |= cont.hasInteractiveView() || webViewsResult.size() > 0;
hasView |= OpenSubnodeWebViewAction.hasContainerView(cont);
if (cont.getNodeContainerState().isExecuted() && hasView) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
try {
final IAction action;
if (cont.hasInteractiveView()) {
action = new OpenInteractiveViewAction(cont);
} else if (cont instanceof SubNodeContainer) {
action = new OpenSubnodeWebViewAction((SubNodeContainer) cont);
} else if (webViewsResult.size() > 0) {
action = new OpenInteractiveWebViewAction(cont, webViewsResult.get(0));
} else {
action = new OpenViewAction(cont, 0);
}
action.run();
} catch (Throwable t) {
MessageBox mb = new MessageBox(Display.getDefault().getActiveShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText("View cannot be opened");
mb.setMessage("The view cannot be opened for the " + "following reason:\n" + t.getMessage());
mb.open();
LOGGER.error("The view for node '" + cont.getNameWithID() + "' has thrown a '" + t.getClass().getSimpleName() + "'. That is most likely an " + "implementation error.", t);
}
}
});
}
}
try {
// Give focus to the editor again. Otherwise the actions (selection)
// is not updated correctly.
getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
} catch (Exception e) {
// ignore
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class SubNodeReconfigureAction method internalCalculateEnabled.
/**
* @return true, if underlying model instance of <code>WorkflowManager</code>, otherwise false
*/
@Override
protected boolean internalCalculateEnabled() {
NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
if (nodes.length != 1) {
return false;
}
NodeContainer nc = Wrapper.unwrapOptionalNC(nodes[0].getNodeContainer()).orElse(null);
if (nc instanceof SubNodeContainer) {
return !((SubNodeContainer) nc).isWriteProtected();
}
return false;
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class AbstractCreateNewConnectedNodeCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
m_newNode = createNewNode();
if (m_newNode != null) {
if (m_connectTo != null) {
autoConnectNewNode();
}
NodeContainer newNode = getHostWFM().getNodeContainer(m_newNode);
NodeUIInformation uiInfo = newNode.getUIInformation();
// create extra info and set it
if (uiInfo == null) {
uiInfo = NodeUIInformation.builder().setNodeLocation(m_location.x, m_location.y, -1, -1).build();
} else {
uiInfo = NodeUIInformation.builder(uiInfo).setNodeLocation(m_location.x, m_location.y, uiInfo.getBounds()[2], uiInfo.getBounds()[3]).build();
}
newNode.setUIInformation(uiInfo);
}
// make sure the new node is selected and visible
m_viewer.deselectAll();
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class AbstractCreateNewConnectedNodeCommand method autoConnectNewNode.
private void autoConnectNewNode() {
if (m_newNode == null) {
return;
}
if (m_connectTo == null) {
return;
}
WorkflowManager hostWFM = getHostWFM();
NodeContainer sourceNode = hostWFM.getNodeContainer(m_connectTo);
NodeContainer nc = hostWFM.getNodeContainer(m_newNode);
Map<Integer, Integer> matchingPorts = getMatchingPorts(sourceNode, nc);
if (matchingPorts.size() == 0) {
LOGGER.info("Can't auto-connect new node (" + m_newNode + "): " + "no matching port type found at node " + sourceNode.getNameWithID());
return;
}
for (Map.Entry<Integer, Integer> entry : matchingPorts.entrySet()) {
Integer leftPort = entry.getKey();
Integer rightPort = entry.getValue();
LOGGER.info("Autoconnect: Connecting new node " + m_newNode + " port " + rightPort + " with existing node " + sourceNode + " port " + leftPort);
try {
hostWFM.addConnection(m_connectTo, leftPort, m_newNode, rightPort).getID();
NodeTimer.GLOBAL_TIMER.addConnectionCreation(sourceNode, nc);
} catch (Exception e) {
String from = sourceNode.getNameWithID();
String to = nc.getNameWithID();
String msg = "Unable to add connection from " + from + " port " + leftPort + " to " + to + "port " + rightPort + ": " + e.getMessage();
LOGGER.error(msg);
}
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class ChangeNodeBoundsCommand method undo.
/**
* Sets the old bounds.
*
* @see org.eclipse.gef.commands.Command#execute()
*/
@Override
public void undo() {
if (!Arrays.equals(m_oldBounds, m_newBounds)) {
NodeUIInformation information = NodeUIInformation.builder().setNodeLocation(m_oldBounds[0], m_oldBounds[1], m_oldBounds[2], m_oldBounds[3]).build();
NodeContainer container = getHostWFM().getNodeContainer(m_nodeID);
container.setUIInformation(information);
}
}
Aggregations