use of org.knime.core.node.wizard.WizardNode 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.wizard.WizardNode in project knime-core by knime.
the class SubnodeLayoutWizard method addPages.
/**
* {@inheritDoc}
*/
@SuppressWarnings("rawtypes")
@Override
public void addPages() {
setWindowTitle("Node Usage and Layout");
setDefaultPageImageDescriptor(ImageRepository.getImageDescriptor(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout_55.png"));
WorkflowManager wfManager = m_subNodeContainer.getWorkflowManager();
// Map<NodeID, SubNodeContainer> nestedSubnodes = wfManager.findNodes(SubNodeContainer.class, false);
Map<NodeID, WizardNode> viewNodes = wfManager.findNodes(WizardNode.class, false);
LinkedHashMap<NodeIDSuffix, WizardNode> resultMap = new LinkedHashMap<>();
for (Map.Entry<NodeID, WizardNode> entry : viewNodes.entrySet()) {
NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(wfManager.getID(), entry.getKey());
resultMap.put(idSuffix, entry.getValue());
}
List<NodeID> nodeIDs = new ArrayList<NodeID>();
nodeIDs.addAll(viewNodes.keySet());
/*for (NodeID subnodeID : nestedSubnodes.keySet()) {
WorkflowManager nestedWFManager = nestedSubnodes.get(subnodeID).getWorkflowManager();
if (!nestedWFManager.findNodes(WizardNode.class, true).isEmpty()) {
nodeIDs.add(subnodeID);
}
}*/
Collections.sort(nodeIDs);
m_page = new SubnodeLayoutJSONEditorPage("Change the layout configuration");
m_page.setNodes(wfManager, m_subNodeContainer, resultMap);
addPage(m_page);
}
use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.
the class WebResourceController method getWizardNodeForVerifiedID.
/**
* Returns a wizard node to a given subnode and node id
* @param subnodeID the subnode id, which is the container for the wizard node
* @param wizardNodeID the node id of the wizard node
* @return the resolved wizard node or null, if node id does not denote a wizard node
* @since 3.7
*/
@SuppressWarnings("rawtypes")
protected WizardNode getWizardNodeForVerifiedID(final NodeID subnodeID, final NodeID wizardNodeID) {
CheckUtils.checkNotNull(subnodeID);
CheckUtils.checkNotNull(wizardNodeID);
WorkflowManager manager = m_manager;
assert manager.isLockedByCurrentThread();
SubNodeContainer subNodeNC = manager.getNodeContainer(subnodeID, SubNodeContainer.class, true);
NodeContainer cont = subNodeNC.getWorkflowManager().findNodeContainer(wizardNodeID);
if (cont instanceof NativeNodeContainer) {
NodeModel model = ((NativeNodeContainer) cont).getNodeModel();
if (model instanceof WizardNode) {
return (WizardNode) model;
} else {
LOGGER.error("Node model is not of type WizardNode");
}
LOGGER.error("Node container is not of type NativeNodeContainer");
}
return null;
}
use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.
the class WebResourceController method validateViewValuesInternal.
/**
* Validates a given set of serialized view values for a given subnode.
*
* @param viewValues the values to validate
* @param subnodeID the id of the subnode containing the appropriate view nodes
* @param wizardNodeSet the set of view nodes that the view values correspond to.
* @return an empty map if validation succeeds, map of errors otherwise
* @throws IllegalArgumentException if the provided subnode id is <code>null</code>
* @throws IllegalStateException if there are no nodes with the provided id prefixes in the page or the provided
* wizard-node-set doesn't contain the required wizard nodes
*/
@SuppressWarnings({ "rawtypes" })
protected Map<String, ValidationError> validateViewValuesInternal(final Map<String, String> viewValues, final NodeID subnodeID, final Map<NodeID, NativeNodeContainer> wizardNodeSet) {
if (subnodeID == null) {
throw new IllegalArgumentException("No node ID supplied for validating view values of wizard page");
}
WorkflowManager manager = m_manager;
assert manager.isLockedByCurrentThread();
Map<String, ValidationError> resultMap = new LinkedHashMap<>();
for (Map.Entry<String, String> entry : viewValues.entrySet()) {
NodeID.NodeIDSuffix suffix = NodeID.NodeIDSuffix.fromString(entry.getKey());
NodeID id = suffix.prependParent(manager.getProjectWFM().getID());
CheckUtils.checkState(id.hasPrefix(subnodeID), "The wizard page content for ID %s (suffix %s) does not belong to the current Component (ID %s)", id, entry.getKey(), subnodeID);
NativeNodeContainer wizardNode = wizardNodeSet.get(id);
CheckUtils.checkState(wizardNode != null, "No wizard node with ID %s in Component, valid IDs are: " + "%s", id, ConvenienceMethods.getShortStringFrom(wizardNodeSet.entrySet(), 10));
ValidationError validationError = null;
try {
if (wizardNode.getNodeModel() instanceof WizardNode) {
validationError = validateViewValueForWizardNode((WizardNode) wizardNode.getNodeModel(), entry.getValue());
} else if (wizardNode.getNode().getFactory() instanceof WizardPageContribution) {
validationError = ((WizardPageContribution) wizardNode.getNode().getFactory()).validateViewValue(wizardNode, entry.getValue()).map(ValidationError::new).orElse(null);
}
} catch (Exception e) {
// NOSONAR
validationError = new ValidationError("An unexpected error occurred while validating the view value: " + entry.getValue() + ": \n" + e.getMessage());
}
if (validationError != null) {
resultMap.put(entry.getKey(), validationError);
}
}
if (!resultMap.isEmpty()) {
return resultMap;
}
return Collections.emptyMap();
}
use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.
the class SubNodeContainer method setHideNodeFromWizard.
/**
* Sets a flag on a given {@link WizardNode} of nested subnode, whether or not it is hidden from wizard execution
* @param id the node to set the flag on
* @param hide true if the node is supposed to be hidden from WebPortal or wizard execution, false otherwise
* @since 3.5
* @noreference This method is not intended to be referenced by clients.
*/
public void setHideNodeFromWizard(final NodeID id, final boolean hide) {
try (WorkflowLock lock = lock()) {
NodeContainer container = m_wfm.getNodeContainer(id, NodeContainer.class, true);
ViewHideable vh = null;
NativeNodeContainer nnc = null;
if (container instanceof SubNodeContainer) {
vh = (SubNodeContainer) container;
} else if (container instanceof NativeNodeContainer) {
nnc = (NativeNodeContainer) container;
NodeModel model = nnc.getNodeModel();
CheckUtils.checkArgument(model instanceof WizardNode, "Can't set hide in wizard flag on non-wizard nodes.");
vh = (WizardNode<?, ?>) model;
} else {
throw new IllegalArgumentException("Node with id " + id + " needs to be a native node or a subnode container!");
}
if (vh != null) {
if (hide != vh.isHideInWizard()) {
vh.setHideInWizard(hide);
if (nnc != null) {
nnc.saveNodeSettingsToDefault();
nnc.setDirty();
}
}
}
}
}
Aggregations