use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class InsertHelper method reconnect.
/**
* Guesses the incoming/outgoing connections of the new node based on the connections of the old node.
* The connections are added from port 0 to port n. If no port type matches no connection is added.
* @param container of the new created node
* @param snapToGrid should new node snap to grid
* @param x coordinate of the new node
* @param y coordinate of the new node
*/
public void reconnect(final NodeContainer container, final boolean snapToGrid, final int x, final int y) {
// reset node position
NodeUIInformation info = NodeUIInformation.builder().setNodeLocation(x, y, -1, -1).setHasAbsoluteCoordinates(false).setSnapToGrid(snapToGrid).setIsDropLocation(false).build();
container.setUIInformation(info);
// skip fv port of nodes for now
int p = (container instanceof WorkflowManager) ? 0 : 1;
while (!hostWFM.canAddConnection(m_edge.getSource(), m_edge.getSourcePort(), container.getID(), p)) {
// search for a valid connection of the source node to this node
p++;
if (p >= container.getNrInPorts()) {
break;
}
}
if (p < container.getNrInPorts()) {
hostWFM.addConnection(m_edge.getSource(), m_edge.getSourcePort(), container.getID(), p);
} else if (!(container instanceof WorkflowManager)) {
// try if the fv port of nodes would work
if (hostWFM.canAddConnection(m_edge.getSource(), m_edge.getSourcePort(), container.getID(), 0)) {
hostWFM.addConnection(m_edge.getSource(), m_edge.getSourcePort(), container.getID(), 0);
}
}
// skip fv port of nodes for now;
int pout = (container instanceof WorkflowManager) ? 0 : 1;
while (!hostWFM.canAddConnection(container.getID(), pout, m_edge.getDest(), m_edge.getDestPort())) {
// search for a valid connection of this node to the destination node of the edge
pout++;
if (pout >= container.getNrOutPorts()) {
break;
}
}
if (pout < container.getNrOutPorts()) {
hostWFM.addConnection(container.getID(), pout, m_edge.getDest(), m_edge.getDestPort());
} else if (!(container instanceof WorkflowManager)) {
// try if the fv port of nodes would work
if (hostWFM.canAddConnection(container.getID(), 0, m_edge.getDest(), m_edge.getDestPort())) {
hostWFM.addConnection(container.getID(), 0, m_edge.getDest(), m_edge.getDestPort());
}
}
}
use of org.knime.core.node.workflow.WorkflowManager 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.WorkflowManager in project knime-core by knime.
the class PasteFromWorkflowPersistorCommand method canUndo.
/**
* {@inheritDoc}
*/
@Override
public boolean canUndo() {
WorkflowManager manager = m_editor.getWorkflowManager().get();
NodeID[] pastedNodes = m_pastedContent.getNodeIDs();
Annotation[] pastedAnnos = m_pastedContent.getAnnotations();
if ((pastedNodes == null || pastedNodes.length == 0) && (pastedAnnos == null || pastedAnnos.length == 0)) {
return false;
}
for (NodeID id : pastedNodes) {
if (!manager.canRemoveNode(id)) {
return false;
}
}
return true;
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class KnimeResourceContentProvider method getChildren.
/**
* {@inheritDoc}
*/
@Override
public Object[] getChildren(final Object element) {
if (element instanceof IFile) {
return EMPTY_ARRAY;
}
if (isKNIMEWorkflow(element)) {
IContainer project = (IContainer) element;
NodeContainerUI workflow = ProjectWorkflowMap.getWorkflowUI(project.getLocationURI());
if (workflow != null) {
// the number of contained nodes is returned
return getSortedNodeContainers(((WorkflowManagerUI) workflow).getNodeContainers());
}
} else if (element instanceof WorkflowManager) {
return getSortedNodeContainers(((WorkflowManagerUI) element).getNodeContainers());
}
return getFolders(element);
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class OpenCredentialVariablesDialogAction method run.
/**
* {@inheritDoc}
*/
@Override
public void run() {
super.run();
// get workflow
final WorkflowManager wf = getWorkflow();
// open the dialog
final Display d = Display.getDefault();
// run in UI thread
d.asyncExec(new Runnable() {
@Override
public void run() {
CredentialsStore store = wf.getCredentialsStore();
CredentialVariablesDialog dialog = new CredentialVariablesDialog(d.getActiveShell(), store, wf.getName());
if (dialog.open() == Window.OK) {
for (String name : store.listNames()) {
store.remove(name);
}
List<Credentials> credentials = dialog.getCredentials();
for (Credentials cred : credentials) {
store.add(cred);
}
}
}
});
}
Aggregations