use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class ChangeSubNodeLinkAction 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.unwrapNC(nodes[0].getNodeContainer());
if (!(nc instanceof SubNodeContainer)) {
return false;
}
SubNodeContainer subNode = (SubNodeContainer) nc;
if (!Role.Link.equals(subNode.getTemplateInformation().getRole()) || subNode.getParent().isWriteProtected()) {
// sub node must be linked and parent must not forbid the change
return false;
}
// we can reconfigure the template link - but only if template and flow are in the same mountpoint
URI targetURI = subNode.getTemplateInformation().getSourceURI();
try {
if (ResolverUtil.isMountpointRelativeURL(targetURI) || ResolverUtil.isWorkflowRelativeURL(targetURI)) {
return true;
}
} catch (IOException e) {
return false;
}
// we can change absolute links if the mount points of flow and template are the same
AbstractContentProvider workflowMountPoint = null;
WorkflowContext wfc = subNode.getProjectWFM().getContext();
LocalExplorerFileStore fs = ExplorerFileSystem.INSTANCE.fromLocalFile(wfc.getMountpointRoot());
if (fs != null) {
workflowMountPoint = fs.getContentProvider();
}
if (workflowMountPoint == null) {
return false;
}
AbstractExplorerFileStore targetfs = ExplorerFileSystem.INSTANCE.getStore(targetURI);
if (targetfs == null) {
return false;
}
return workflowMountPoint.equals(targetfs.getContentProvider());
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class NewWorkflowXYLayoutPolicy method createChangeConstraintCommand.
/**
* Creates command to move / resize <code>NodeContainer</code> components on
* the project's client area.
*
* {@inheritDoc}
*/
@Override
protected Command createChangeConstraintCommand(final EditPart child, final Object constraint) {
// only rectangular constraints are supported
if (!(constraint instanceof Rectangle)) {
return null;
}
Command command = null;
Rectangle rect = ((Rectangle) constraint).getCopy();
if (child.getModel() instanceof NodeContainerUI) {
NodeContainerUI container = (NodeContainerUI) child.getModel();
if (!Wrapper.wraps(container, NodeContainer.class)) {
// not supported for others than ordinary NodeContainers
return null;
}
NodeContainerEditPart nodePart = (NodeContainerEditPart) child;
command = new ChangeNodeBoundsCommand(Wrapper.unwrapNC(container), (NodeContainerFigure) nodePart.getFigure(), rect);
} else if (child instanceof AbstractWorkflowPortBarEditPart) {
command = new ChangeWorkflowPortBarCommand((AbstractWorkflowPortBarEditPart) child, rect);
} else if (child instanceof AnnotationEditPart) {
AnnotationEditPart annoPart = (AnnotationEditPart) child;
// TODO the workflow annotation could know what its WFM is?
WorkflowRootEditPart root = (WorkflowRootEditPart) annoPart.getParent();
WorkflowManagerUI wm = root.getWorkflowManager();
if (!Wrapper.wraps(wm, WorkflowManager.class)) {
// not supported for others than an ordinary workflow manager
return null;
}
command = new ChangeAnnotationBoundsCommand(Wrapper.unwrapWFM(wm), annoPart, rect);
}
return command;
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class NodeUsageComposite method createNodeGrid.
private void createNodeGrid(final SubNodeContainer subNodeContainer, @SuppressWarnings("rawtypes") final Map<NodeIDSuffix, WizardNode> viewNodes) {
ScrolledComposite scrollPane = new ScrolledComposite(this, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
scrollPane.setExpandHorizontal(true);
scrollPane.setExpandVertical(true);
Composite composite = new Composite(scrollPane, SWT.NONE);
scrollPane.setContent(composite);
scrollPane.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
composite.setLayout(new GridLayout(3, false));
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
// titles
new Composite(composite, SWT.NONE);
/* Placeholder */
Label wizardLabel = new Label(composite, SWT.CENTER);
FontData fontData = wizardLabel.getFont().getFontData()[0];
Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
wizardLabel.setText("WebPortal /\nWrapped Metanode View");
wizardLabel.setFont(boldFont);
Label dialogLabel = new Label(composite, SWT.CENTER);
dialogLabel.setText("\nWrapped Metanode Dialog");
dialogLabel.setFont(boldFont);
// select all checkboxes
Label selectAllLabel = new Label(composite, SWT.LEFT);
selectAllLabel.setText("Enable/Disable");
Button selectAllWizard = createCheckbox(composite);
Button selectAllDialog = createCheckbox(composite);
// individual nodes
for (@SuppressWarnings("rawtypes") Entry<NodeIDSuffix, WizardNode> entry : viewNodes.entrySet()) {
NodeIDSuffix suffix = entry.getKey();
NodeID id = suffix.prependParent(subNodeContainer.getWorkflowManager().getID());
NodeContainer nodeContainer = viewNodes.containsKey(suffix) ? subNodeContainer.getWorkflowManager().getNodeContainer(id) : null;
createNodeLabelComposite(composite, id, nodeContainer);
@SuppressWarnings("rawtypes") WizardNode model = entry.getValue();
Button wizardButton = createCheckbox(composite);
wizardButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
checkAllSelected(m_wizardUsageMap, selectAllWizard);
}
});
wizardButton.setToolTipText("Enable/disable for usage in WebPortal and wizard execution.");
wizardButton.setSelection(!((WizardNode<?, ?>) model).isHideInWizard());
m_wizardUsageMap.put(id, wizardButton);
if (model instanceof DialogNode) {
Button dialogButton = createCheckbox(composite);
dialogButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
checkAllSelected(m_dialogUsageMap, selectAllDialog);
}
});
dialogButton.setToolTipText("Enable/disable for usage in wrapped metanode configure dialog.");
dialogButton.setSelection(!((DialogNode<?, ?>) model).isHideInDialog());
m_dialogUsageMap.put(id, dialogButton);
} else {
new Composite(composite, SWT.NONE);
/* Placeholder */
}
}
checkAllSelected(m_wizardUsageMap, selectAllWizard);
checkAllSelected(m_dialogUsageMap, selectAllDialog);
selectAllWizard.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
selectAllWizard.setGrayed(false);
for (Button b : m_wizardUsageMap.values()) {
b.setSelection(selectAllWizard.getSelection());
}
}
});
if (m_wizardUsageMap.size() < 1) {
selectAllWizard.setEnabled(false);
}
selectAllDialog.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
selectAllDialog.setGrayed(false);
for (Button b : m_dialogUsageMap.values()) {
b.setSelection(selectAllDialog.getSelection());
}
}
});
if (m_dialogUsageMap.size() < 1) {
selectAllDialog.setEnabled(false);
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class ReconfigureMetaNodeCommand method execute.
/**
* {@inheritDoc}
*/
@Override
public void execute() {
NodeContainer nc = getHostWFM().getNodeContainer(m_metanodeID);
if (nc instanceof WorkflowManager) {
if (m_name != null) {
WorkflowManager metaNode = (WorkflowManager) nc;
m_oldName = metaNode.getName();
metaNode.setName(m_name);
}
if (m_inPorts != null) {
m_reverseInports = createReverseOperationList(getHostWFM().getMetanodeInputPortInfo(m_metanodeID), m_inPorts);
getHostWFM().changeMetaNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
}
if (m_outPorts != null) {
m_reverseOutports = createReverseOperationList(getHostWFM().getMetanodeOutputPortInfo(m_metanodeID), m_outPorts);
getHostWFM().changeMetaNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
}
} else if (nc instanceof SubNodeContainer) {
SubNodeContainer snc = (SubNodeContainer) nc;
if (m_name != null) {
m_oldName = snc.getName();
snc.setName(m_name);
}
if (m_inPorts != null) {
m_reverseInports = createReverseOperationList(getHostWFM().getSubnodeInputPortInfo(m_metanodeID), m_inPorts);
getHostWFM().changeSubNodeInputPorts(m_metanodeID, m_inPorts.toArray(new MetaPortInfo[m_inPorts.size()]));
}
if (m_outPorts != null) {
m_reverseOutports = createReverseOperationList(getHostWFM().getSubnodeOutputPortInfo(m_metanodeID), m_outPorts);
getHostWFM().changeSubNodeOutputPorts(m_metanodeID, m_outPorts.toArray(new MetaPortInfo[m_outPorts.size()]));
}
}
}
use of org.knime.core.node.workflow.NodeContainer in project knime-core by knime.
the class NodeContainerProperties method setPropertyValue.
/**
* {@inheritDoc}
*/
@Override
public void setPropertyValue(final Object id, final Object value) {
if ((id instanceof String) && (value instanceof String)) {
String strVal = (String) value;
String strID = (String) id;
if (strID.startsWith(m_prefix)) {
String[] hierarchy = strID.split(CONFIG_SEPARATOR);
String key = hierarchy[hierarchy.length - 1];
// apply it to the node's settings:
NodeContainer node = getNode();
if (node == null) {
return;
}
WorkflowManager wfm = node.getParent();
NodeSettings nodeSettings = new NodeSettings("Transfer");
NodeSettings settings;
try {
wfm.saveNodeSettings(node.getID(), nodeSettings);
// overwrite our config in the settings
settings = nodeSettings.getNodeSettings("model");
if (hierarchy.length > 1) {
for (int i = 0; i < hierarchy.length - 1; i++) {
settings = settings.getNodeSettings(hierarchy[i]);
if (settings == null) {
return;
}
}
}
} catch (InvalidSettingsException e) {
// somehow node is not able to save its settings anymore
return;
}
AbstractConfigEntry entry = settings.getEntry(key);
if (entry == null || entry instanceof Config) {
// settings are not complete or correct anymore
return;
}
switch(entry.getType()) {
case xboolean:
settings.addBoolean(key, Boolean.parseBoolean(strVal));
break;
case xbyte:
settings.addByte(key, Byte.parseByte(strVal));
break;
case xchar:
String decoded = TokenizerSettings.unescapeString(strVal);
settings.addChar(key, decoded.charAt(0));
break;
case xdouble:
settings.addDouble(key, Double.parseDouble(strVal));
break;
case xfloat:
settings.addFloat(key, Float.parseFloat(strVal));
break;
case xint:
settings.addInt(key, Integer.parseInt(strVal));
break;
case xlong:
settings.addLong(key, Long.parseLong(strVal));
break;
case xshort:
settings.addShort(key, Short.parseShort(strVal));
break;
case xstring:
String dec = TokenizerSettings.unescapeString(strVal);
settings.addString(key, dec);
break;
default:
// ignore the new value
return;
}
try {
wfm.loadNodeSettings(node.getID(), nodeSettings);
} catch (Exception ex) {
LOGGER.error("Invalid Value (" + strVal + "): " + ex.getMessage(), ex);
return;
}
return;
}
}
}
Aggregations