use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class DefaultOpenViewAction method internalCalculateEnabled.
/**
* @return true if at least one selected node is executing or queued
* @see org.eclipse.gef.ui.actions.WorkbenchPartAction#calculateEnabled()
*/
@Override
protected boolean internalCalculateEnabled() {
NodeContainerEditPart[] parts = getSelectedParts(NodeContainerEditPart.class);
// enable if we have at least one executing or queued node in our
// selection
boolean atLeastOneNodeIsExecuted = 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));
atLeastOneNodeIsExecuted |= nc.getNodeContainerState().isExecuted() && hasView;
}
}
return atLeastOneNodeIsExecuted;
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart 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.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class LockMetaNodeAction method runOnNodes.
/**
* {@inheritDoc}
*/
@Override
public void runOnNodes(final NodeContainerEditPart[] nodes) {
if (nodes.length != 1) {
return;
}
Object model = nodes[0].getModel();
if (!(model instanceof WorkflowManagerUI)) {
return;
}
WorkflowManagerUI metaNodeWFM = (WorkflowManagerUI) model;
final Shell shell = Display.getCurrent().getActiveShell();
if (!unwrapWFM(metaNodeWFM).unlock(new GUIWorkflowCipherPrompt())) {
return;
}
LockMetaNodeDialog lockDialog = new LockMetaNodeDialog(shell, unwrapWFM(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 metanode: " + e.getMessage();
LOGGER.error(msg, e);
MessageDialog.openError(shell, "Metanode encrypt", msg);
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class LockSubNodeAction method internalCalculateEnabled.
/**
* @return true, if underlying model instance of
* <code>SubNodeContainer</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 (Wrapper.wraps(model, SubNodeContainer.class)) {
SubNodeContainer snc = Wrapper.unwrap((UI) model, SubNodeContainer.class);
if (snc.isWriteProtected()) {
return false;
}
return true;
} else {
return false;
}
}
use of org.knime.workbench.editor2.editparts.NodeContainerEditPart in project knime-core by knime.
the class MoveNodeAbstractAction method getMoveableSelectedEditParts.
private List<EditPart> getMoveableSelectedEditParts() {
@SuppressWarnings("rawtypes") List selectedObjects = getSelectedObjects();
LinkedList<EditPart> result = new LinkedList<EditPart>();
for (Object o : selectedObjects) {
if ((o instanceof AnnotationEditPart) && !(o instanceof NodeAnnotationEditPart)) {
result.add((AnnotationEditPart) o);
continue;
}
if (o instanceof NodeContainerEditPart) {
result.add((NodeContainerEditPart) o);
continue;
}
}
return result;
}
Aggregations