use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class LockSubNodeAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
if (nodes.length != 1) {
return;
}
Object model = nodes[0].getModel();
if (!(Wrapper.wraps(model, SubNodeContainer.class))) {
return;
}
WorkflowManager metaNodeWFM = Wrapper.unwrap((UI) model, SubNodeContainer.class).getWorkflowManager();
final Shell shell = Display.getCurrent().getActiveShell();
if (!metaNodeWFM.unlock(new GUIWorkflowCipherPrompt())) {
return;
}
LockMetaNodeDialog lockDialog = new LockMetaNodeDialog(shell, metaNodeWFM);
if (lockDialog.open() != Window.OK) {
return;
}
String password = lockDialog.getPassword();
String hint = lockDialog.getPasswordHint();
try {
metaNodeWFM.setWorkflowPassword(password, hint);
} catch (NoSuchAlgorithmException e) {
String msg = "Unable to encrypt Wrapped Metanode: " + e.getMessage();
LOGGER.error(msg, e);
MessageDialog.openError(shell, "Wrapped Metanode encrypt", msg);
}
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class PasteActionContextMenu method newShiftCalculator.
/**
* {@inheritDoc}
*/
@Override
protected ShiftCalculator newShiftCalculator() {
return new ShiftCalculator() {
/**
* {@inheritDoc}
*/
@Override
public int[] calculateShift(final Iterable<int[]> boundsList, final WorkflowManager manager, final ClipboardObject clipObject) {
int x = getEditor().getSelectionTool().getXLocation();
int y = getEditor().getSelectionTool().getYLocation();
int smallestX = Integer.MAX_VALUE;
int smallestY = Integer.MAX_VALUE;
for (int[] bounds : boundsList) {
int currentX = bounds[0];
int currentY = bounds[1];
if (currentX < smallestX) {
smallestX = currentX;
}
if (currentY < smallestY) {
smallestY = currentY;
}
}
ZoomManager zoomManager = (ZoomManager) getEditor().getViewer().getProperty(ZoomManager.class.toString());
Point viewPortLocation = zoomManager.getViewport().getViewLocation();
x += viewPortLocation.x;
y += viewPortLocation.y;
double zoom = zoomManager.getZoom();
x /= zoom;
y /= zoom;
int shiftx = x - smallestX;
int shifty = y - smallestY;
if (getEditor().getEditorSnapToGrid()) {
shiftx = getEditor().getEditorGridXOffset(shiftx);
shifty = getEditor().getEditorGridYOffset(shifty);
}
return new int[] { shiftx, shifty };
}
};
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class ResumeLoopAction method runOnNodes.
/**
* Resume paused loop.
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
LOGGER.debug("Creating 'Resume Loop Execution' job for " + nodeParts.length + " node(s)...");
WorkflowManager manager = getManager();
for (NodeContainerEditPart p : nodeParts) {
NodeContainerUI nc = p.getNodeContainer();
if (Wrapper.wraps(nc, NativeNodeContainer.class)) {
NativeNodeContainer nnc = Wrapper.unwrap(nc, NativeNodeContainer.class);
if (nnc.isModelCompatibleTo(LoopEndNode.class) && nnc.getLoopStatus().equals(LoopStatus.PAUSED)) {
manager.resumeLoopExecution(nnc, /*oneStep=*/
false);
}
}
}
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.WorkflowManager in project knime-core by knime.
the class SaveAsMetaNodeTemplateAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
if (nodes.length < 1) {
return;
}
WorkflowManager wm = Wrapper.unwrapWFM(nodes[0].getNodeContainer());
List<String> validMountPointList = new ArrayList<String>();
// Workbench.getInstance().getActiveWorkbenchWindow().getActivePage().findView(ID)
for (Map.Entry<String, AbstractContentProvider> entry : ExplorerMountTable.getMountedContent().entrySet()) {
AbstractContentProvider contentProvider = entry.getValue();
if (contentProvider.isWritable() && contentProvider.canHostMetaNodeTemplates()) {
validMountPointList.add(entry.getKey());
}
}
if (validMountPointList.isEmpty()) {
throw new IllegalStateException("No valid mount points found - " + "this is inconsistent with calculateEnabled()");
}
String[] validMountPoints = validMountPointList.toArray(new String[0]);
final Shell shell = Display.getCurrent().getActiveShell();
ContentObject defSel = getDefaultSaveLocation(wm);
SpaceResourceSelectionDialog dialog = new SpaceResourceSelectionDialog(shell, validMountPoints, defSel);
dialog.setTitle("Save As Metanode Template");
dialog.setHeader("Select destination workflow group for metanode template");
dialog.setValidator(new Validator() {
@Override
public String validateSelectionValue(final AbstractExplorerFileStore selection, final String name) {
final AbstractExplorerFileInfo info = selection.fetchInfo();
if (info.isWorkflowGroup()) {
return null;
}
return "Only workflow groups can be selected as target.";
}
});
if (dialog.open() != Window.OK) {
return;
}
AbstractExplorerFileStore target = dialog.getSelection();
AbstractContentProvider contentProvider = target.getContentProvider();
contentProvider.saveMetaNodeTemplate(wm, target);
}
use of org.knime.core.node.workflow.WorkflowManager in project knime-core by knime.
the class SelectLoopAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
WorkflowManager wfm = getManager();
for (NodeContainerEditPart selNode : nodeParts) {
NodeContainerUI selNC = selNode.getNodeContainer();
if (selNC instanceof SingleNodeContainerUI) {
EditPartViewer viewer = selNode.getViewer();
List<NodeContainer> loopNodes = wfm.getNodesInScope(Wrapper.unwrap(selNC, SingleNodeContainer.class));
for (NodeContainer nc : loopNodes) {
NodeContainerEditPart sel = (NodeContainerEditPart) viewer.getEditPartRegistry().get(NodeContainerWrapper.wrap(nc));
viewer.appendSelection(sel);
}
}
}
try {
// Give focus to the editor again. Otherwise the actions (selection)
// is not updated correctly.
getWorkbenchPart().getSite().getPage().activate(getWorkbenchPart());
} catch (Exception e) {
// ignore
}
}
Aggregations