Search in sources :

Example 1 with SubnodeContainerLayoutStringProvider

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);
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) LinkedHashMap(java.util.LinkedHashMap) NodeID(org.knime.core.node.workflow.NodeID) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer) HiLiteTranslator(org.knime.core.node.property.hilite.HiLiteTranslator) IOException(java.io.IOException) HiLiteManager(org.knime.core.node.property.hilite.HiLiteManager) IOException(java.io.IOException) SubNodeContainer(org.knime.core.node.workflow.SubNodeContainer) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) SubnodeContainerLayoutStringProvider(org.knime.core.node.workflow.SubnodeContainerLayoutStringProvider) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer)

Aggregations

IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 HiLiteHandler (org.knime.core.node.property.hilite.HiLiteHandler)1 HiLiteManager (org.knime.core.node.property.hilite.HiLiteManager)1 HiLiteTranslator (org.knime.core.node.property.hilite.HiLiteTranslator)1 NativeNodeContainer (org.knime.core.node.workflow.NativeNodeContainer)1 NodeID (org.knime.core.node.workflow.NodeID)1 NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)1 SingleNodeContainer (org.knime.core.node.workflow.SingleNodeContainer)1 SubNodeContainer (org.knime.core.node.workflow.SubNodeContainer)1 SubnodeContainerLayoutStringProvider (org.knime.core.node.workflow.SubnodeContainerLayoutStringProvider)1