use of org.knime.core.node.workflow.SubnodeContainerLayoutStringProvider 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);
}
Aggregations