use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class ExecuteAndOpenViewAction method internalCalculateEnabled.
/**
* @return <code>true</code>, if just one node part is selected which is
* executable and additionally has at least one view.
*
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean internalCalculateEnabled() {
NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
// enable if we have at least one executable node in our selection
WorkflowManager wm = getEditor().getWorkflowManager().orElse(null);
if (wm == null) {
return false;
}
for (int i = 0; i < parts.length; i++) {
NodeContainerUI nc = parts[i].getNodeContainer();
boolean hasView = nc.getNrViews() > 0;
if (Wrapper.wraps(nc, NodeContainer.class)) {
hasView |= nc.hasInteractiveView() || unwrapNC(nc).getInteractiveWebViews().size() > 0;
hasView |= OpenSubnodeWebViewAction.hasContainerView(unwrapNC(nc));
}
if (wm.canExecuteNode(nc.getID()) && hasView) {
return true;
}
}
return false;
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class ExecuteAndOpenViewAction method runOnNodes.
/**
* Execute all selected nodes and open their first view (if available).
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
LOGGER.debug("Creating 'Execute and Open Views' job for " + nodeParts.length + " node(s)...");
for (NodeContainerEditPart p : nodeParts) {
final NodeContainer cont = unwrapNC(p.getNodeContainer());
executeAndOpen(cont);
}
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.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class ExpandSubNodeAction method runOnNodes.
/**
* Expand sub node!
*
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodeParts) {
if (nodeParts.length < 1) {
return;
}
LOGGER.debug("Creating 'Expand Wrapped Metanode' job for " + nodeParts.length + " node(s)...");
try {
WorkflowManager manager = getManager();
SubNodeContainer subNode = Wrapper.unwrap(nodeParts[0].getNodeContainer(), SubNodeContainer.class);
if (!subNode.getWorkflowManager().unlock(new GUIWorkflowCipherPrompt())) {
return;
}
// reset the metanode
if (manager.canResetNode(subNode.getID())) {
// yes: ask if we can reset, otherwise bail
MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.OK | SWT.CANCEL);
mb.setMessage("Executed Nodes inside Wrapped Metanode will be reset" + " - are you sure?");
mb.setText("Reset Executed Nodes");
int dialogreturn = mb.open();
if (dialogreturn == SWT.CANCEL) {
return;
}
// perform reset
if (manager.canResetNode(subNode.getID())) {
manager.resetAndConfigureNode(subNode.getID());
}
}
String res = manager.canExpandSubNode(subNode.getID());
if (res != null) {
throw new IllegalArgumentException(res);
}
ExpandSubNodeCommand emnc = new ExpandSubNodeCommand(manager, subNode.getID(), getEditor());
execute(emnc);
} catch (IllegalArgumentException e) {
MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ERROR);
mb.setMessage("Expanding Wrapped Metanode failed: " + e.getMessage());
mb.setText("Expand failed");
mb.open();
}
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.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class LockMetaNodeAction method internalCalculateEnabled.
/**
* @return true, if underlying model instance of
* <code>WorkflowManager</code>, otherwise false
*/
@Override
protected boolean internalCalculateEnabled() {
if (getManager().isWriteProtected()) {
return false;
}
NodeContainerEditPart[] nodes = getSelectedParts(NodeContainerEditPart.class);
if (nodes.length != 1) {
return false;
}
Object model = nodes[0].getModel();
if (model instanceof WorkflowManagerUI) {
WorkflowManagerUI metaNode = (WorkflowManagerUI) model;
if (metaNode.isWriteProtected()) {
return false;
}
return true;
} else {
return false;
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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);
}
}
Aggregations