use of org.knime.core.node.workflow.NodeID.NodeIDSuffix 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.NodeID.NodeIDSuffix 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.workflow.NodeID.NodeIDSuffix in project knime-core by knime.
the class WizardPageUtil method createWizardPage.
/**
* Creates the wizard page for a given node id. Throws exception if no wizard page available.
*
* Note: the workflow manager must be locked!
*
* @param manager the workflow that contains the component to create the wizard page for
* @param subnodeID the node id for the subnode to create the wizard page for
* @return The wizard page for the given node id
* @throws IllegalArgumentException if there is no component for the given id
*/
public static WizardPage createWizardPage(final WorkflowManager manager, final NodeID subnodeID) {
if (subnodeID == null) {
LOGGER.error("No node ID supplied for creating wizard page");
return null;
}
// NOSONAR
assert manager.isLockedByCurrentThread();
LinkedHashMap<NodeIDSuffix, NativeNodeContainer> resultMap = new LinkedHashMap<>();
Set<HiLiteHandler> initialHiliteHandlerSet = new HashSet<>();
SubNodeContainer subNC = manager.getNodeContainer(subnodeID, SubNodeContainer.class, true);
LinkedHashMap<NodeIDSuffix, SubNodeContainer> sncMap = new LinkedHashMap<>();
findNestedViewNodes(subNC, resultMap, sncMap, initialHiliteHandlerSet);
SubnodeContainerLayoutStringProvider layoutStringProvider = subNC.getSubnodeLayoutStringProvider();
if (layoutStringProvider.isEmptyLayout() || layoutStringProvider.isPlaceholderLayout()) {
try {
var subWfm = subNC.getWorkflowManager();
Map<NodeIDSuffix, SingleNodeContainer> viewMap = new LinkedHashMap<>();
getWizardPageNodes(subWfm).stream().forEach(n -> viewMap.put(toNodeIDSuffix(manager, n.getID()), n));
Map<NodeID, SubNodeContainer> nestedSubs = getSubPageNodes(subWfm);
nestedSubs.entrySet().stream().forEach(e -> viewMap.put(toNodeIDSuffix(manager, e.getKey()), e.getValue()));
layoutStringProvider.setLayoutString(LayoutUtil.createDefaultLayout(viewMap));
} catch (IOException ex) {
LOGGER.error("Default page layout could not be created: " + ex.getMessage(), ex);
}
}
try {
LayoutUtil.expandNestedLayout(layoutStringProvider, subNC.getWorkflowManager());
} catch (IOException ex) {
LOGGER.error("Nested layouts could not be expanded: " + ex.getMessage(), ex);
}
try {
var containerID = NodeID.fromString(NodeIDSuffix.create(manager.getID(), subNC.getWorkflowManager().getID()).toString());
LayoutUtil.addUnreferencedViews(layoutStringProvider, resultMap, sncMap, containerID);
} catch (IOException ex) {
LOGGER.error("Layout could not be amended by unreferenced views: " + ex.getMessage(), ex);
}
try {
LayoutUtil.updateLayout(layoutStringProvider);
} catch (Exception ex) {
// NOSONAR
LOGGER.error("Layout could not be updated: " + ex.getMessage(), ex);
}
Set<HiLiteHandler> knownHiLiteHandlers = new HashSet<>();
Set<HiLiteTranslator> knownTranslators = new HashSet<>();
Set<HiLiteManager> knownManagers = new HashSet<>();
for (HiLiteHandler initialHandler : initialHiliteHandlerSet) {
getHiLiteTranslators(initialHandler, knownHiLiteHandlers, knownTranslators, knownManagers);
}
List<HiLiteTranslator> translatorList = !knownTranslators.isEmpty() ? new ArrayList<>(knownTranslators) : null;
List<HiLiteManager> managerList = !knownManagers.isEmpty() ? new ArrayList<>(knownManagers) : null;
return new WizardPage(subnodeID, resultMap, layoutStringProvider.getLayoutString(), translatorList, managerList);
}
use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.
the class NodeIDTest method testCombine.
/**
* Checks if combining to node IDs works as expected.
*/
@Test
public void testCombine() {
NodeID p = NodeID.fromString("0:1");
NodeIDSuffix s = NodeIDSuffix.fromString("2:3");
assertThat("Unexpected combined NodeID", s.prependParent(p).toString(), is("0:1:2:3"));
p = NodeID.fromString("0:1");
s = NodeIDSuffix.fromString("2");
assertThat("Unexpected combined NodeID", s.prependParent(p).toString(), is("0:1:2"));
p = NodeID.fromString("0");
s = NodeIDSuffix.fromString("1");
assertThat("Unexpected combined NodeID", s.prependParent(p).toString(), is("0:1"));
p = NodeID.ROOTID;
s = NodeIDSuffix.fromString("0");
assertThat("Unexpected combined NodeID", s.prependParent(p).toString(), is("0"));
}
use of org.knime.core.node.workflow.NodeID.NodeIDSuffix in project knime-core by knime.
the class PortObjectRepository method addPortObjectReferenceReaderWithNodeReference.
/**
* Adds a "Port Object Reference Reader" node to the workflow, which will read the object passed in as argument.
*
* The added reference reader node references the data (i.e. port object) by referencing the port (original node id
* plus port index).
*
* @param outport the outport to get the port object and flow variables from that the to be added node will provide,
* too (the port object is just referenced by the original node id and port index)
* @param srcParentID the id of the workflow manager the referenced node (port) is part of
* @param wfm the workflow manager the new node should be added to
* @param nodeIDSuffix the id the to be added node will have (will be ignored if there is a node with the id
* already!)
* @return the id of the newly added node
*/
// TODO we might have to revisit this when implementing AP-13335
public static NodeID addPortObjectReferenceReaderWithNodeReference(final NodeOutPort outport, final NodeID srcParentID, final WorkflowManager wfm, final int nodeIDSuffix) {
NodeID sourceNodeID = outport.getConnectedNodeContainer().getID();
int portIndex = outport.getConnectedOutport().orElseThrow(() -> new IllegalStateException("Node is set, but no port"));
List<FlowVariable> variables = outport.getFlowObjectStack().getAllAvailableFlowVariables().values().stream().filter(f -> f.getScope() == Scope.Flow).collect(Collectors.toList());
PortObjectIDSettings portObjectIDSettings = new PortObjectIDSettings();
portObjectIDSettings.setNodeReference(NodeIDSuffix.create(srcParentID, sourceNodeID), portIndex);
portObjectIDSettings.setFlowVariables(variables);
boolean isTable = outport.getPortType().equals(BufferedDataTable.TYPE);
return addPortObjectReferenceReader(wfm, portObjectIDSettings, isTable, nodeIDSuffix);
}
Aggregations