Search in sources :

Example 1 with HiLiteManager

use of org.knime.core.node.property.hilite.HiLiteManager in project knime-core by knime.

the class WebResourceController method getHiLiteTranslators.

private void getHiLiteTranslators(final HiLiteHandler handler, final Set<HiLiteHandler> knownHiLiteHandlers, final Set<HiLiteTranslator> knownTranslators, final Set<HiLiteManager> knownManagers) {
    if (handler == null || !knownHiLiteHandlers.add(handler)) {
        return;
    }
    Set<HiLiteTranslator> translators = handler.getHiLiteTranslators();
    for (HiLiteTranslator translator : translators) {
        if (translator != null && knownTranslators.add(translator)) {
            followHiLiteTranslator(translator, knownHiLiteHandlers, knownTranslators, knownManagers);
        }
    }
    Set<HiLiteManager> managers = handler.getHiLiteManagers();
    for (HiLiteManager manager : managers) {
        if (manager != null && knownManagers.add(manager)) {
            followHiLiteManager(manager, knownHiLiteHandlers, knownTranslators, knownManagers);
        }
    }
}
Also used : HiLiteTranslator(org.knime.core.node.property.hilite.HiLiteTranslator) HiLiteManager(org.knime.core.node.property.hilite.HiLiteManager)

Example 2 with HiLiteManager

use of org.knime.core.node.property.hilite.HiLiteManager in project knime-core by knime.

the class WebResourceController method getWizardPageInternal.

/**
 * Crates the wizard page for a given node id. Throws exception if no wizard page available.
 *
 * @param subnodeID the node id for the subnode to retrieve the wizard page for
 * @return The wizard page for the given node id
 */
@SuppressWarnings("rawtypes")
protected WizardPageContent getWizardPageInternal(final NodeID subnodeID) {
    if (subnodeID == null) {
        LOGGER.error("No node ID supplied for creating wizard page");
        return null;
    }
    final WorkflowManager manager = m_manager;
    assert manager.isLockedByCurrentThread();
    // int currentSubnodeIDSuffix = m_promptedSubnodeIDSuffixes.peek();
    // final NodeID subNodeID = toNodeID(currentSubnodeIDSuffix);
    SubNodeContainer subNC = manager.getNodeContainer(subnodeID, SubNodeContainer.class, true);
    WorkflowManager subWFM = subNC.getWorkflowManager();
    Map<NodeID, WizardNode> wizardNodeMap = subWFM.findNodes(WizardNode.class, NOT_HIDDEN_FILTER, false);
    LinkedHashMap<NodeIDSuffix, WizardNode> resultMap = new LinkedHashMap<NodeIDSuffix, WizardNode>();
    // LinkedHashMap<NodeIDSuffix, WizardNode> errorMap = new LinkedHashMap<NodeIDSuffix, WizardNode>();
    LinkedHashMap<NodeIDSuffix, WizardPageNodeInfo> infoMap = new LinkedHashMap<NodeIDSuffix, WizardPageNodeInfo>();
    Set<HiLiteHandler> initialHiliteHandlerSet = new HashSet<HiLiteHandler>();
    for (Map.Entry<NodeID, WizardNode> entry : wizardNodeMap.entrySet()) {
        NodeContainer nc = subWFM.getNodeContainer(entry.getKey());
        if ((nc instanceof SingleNodeContainer) && ((SingleNodeContainer) nc).isInactive()) {
            // skip nodes in inactive branches
            continue;
        }
        NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(manager.getID(), entry.getKey());
        WizardPageNodeInfo nodeInfo = new WizardPageNodeInfo();
        nodeInfo.setNodeName(nc.getName());
        nodeInfo.setNodeAnnotation(nc.getNodeAnnotation().toString());
        nodeInfo.setNodeState(nc.getInternalState());
        nodeInfo.setNodeMessage(nc.getNodeMessage());
        infoMap.put(idSuffix, nodeInfo);
        if (EXECUTED.equals(nc.getInternalState())) {
            // regular viewable nodes need to be executed
            resultMap.put(idSuffix, entry.getValue());
        }
        for (int i = 0; i < nc.getNrInPorts() - 1; i++) {
            HiLiteHandler hiLiteHandler = ((NodeModel) entry.getValue()).getInHiLiteHandler(i);
            if (hiLiteHandler != null) {
                initialHiliteHandlerSet.add(hiLiteHandler);
            }
        }
    }
    NodeID.NodeIDSuffix pageID = NodeID.NodeIDSuffix.create(manager.getID(), subWFM.getID());
    String pageLayout = subNC.getLayoutJSONString();
    if (StringUtils.isEmpty(pageLayout)) {
        try {
            pageLayout = LayoutUtil.createDefaultLayout(resultMap);
        } catch (IOException ex) {
            LOGGER.error("Default page layout could not be created: " + ex.getMessage(), ex);
        }
    }
    Set<HiLiteHandler> knownHiLiteHandlers = new HashSet<HiLiteHandler>();
    Set<HiLiteTranslator> knownTranslators = new HashSet<HiLiteTranslator>();
    Set<HiLiteManager> knownManagers = new HashSet<HiLiteManager>();
    for (HiLiteHandler initialHandler : initialHiliteHandlerSet) {
        getHiLiteTranslators(initialHandler, knownHiLiteHandlers, knownTranslators, knownManagers);
    }
    List<HiLiteTranslator> translatorList = knownTranslators.size() > 0 ? new ArrayList<HiLiteTranslator>(knownTranslators) : null;
    List<HiLiteManager> managerList = knownManagers.size() > 0 ? new ArrayList<HiLiteManager>(knownManagers) : null;
    WizardPageContent page = new WizardPageContent(pageID, resultMap, pageLayout, translatorList, managerList);
    page.setInfoMap(infoMap);
    return page;
}
Also used : HiLiteHandler(org.knime.core.node.property.hilite.HiLiteHandler) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) LinkedHashMap(java.util.LinkedHashMap) NodeModel(org.knime.core.node.NodeModel) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HiLiteTranslator(org.knime.core.node.property.hilite.HiLiteTranslator) IOException(java.io.IOException) HiLiteManager(org.knime.core.node.property.hilite.HiLiteManager) WizardNode(org.knime.core.node.wizard.WizardNode) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) WizardPageNodeInfo(org.knime.core.node.workflow.WebResourceController.WizardPageContent.WizardPageNodeInfo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 3 with HiLiteManager

use of org.knime.core.node.property.hilite.HiLiteManager in project knime-core by knime.

the class AbstractPageManager method createWizardPageInternal.

/**
 * Performs a transformation from {@link WizardPageContent} to {@link JSONWebNodePage} which can be used for serialization.
 * @param page the {@link WizardPageContent} to transform
 * @return the transformed {@link JSONWebNodePage}
 * @throws IOException if layout of page can not be generated
 */
protected JSONWebNodePage createWizardPageInternal(final WizardPageContent page) throws IOException {
    // process layout
    JSONLayoutPage layout = new JSONLayoutPage();
    try {
        String lString = page.getLayoutInfo();
        if (StringUtils.isNotEmpty(lString)) {
            layout = getJSONLayoutFromSubnode(page.getPageNodeID(), page.getLayoutInfo());
        }
    } catch (IOException e) {
        throw new IOException("Layout for page could not be generated: " + e.getMessage(), e);
    }
    // process selection translators
    List<JSONSelectionTranslator> selectionTranslators = new ArrayList<JSONSelectionTranslator>();
    if (page.getHiLiteTranslators() != null) {
        for (HiLiteTranslator hiLiteTranslator : page.getHiLiteTranslators()) {
            if (hiLiteTranslator != null) {
                selectionTranslators.add(new JSONSelectionTranslator(hiLiteTranslator));
            }
        }
    }
    if (page.getHiliteManagers() != null) {
        for (HiLiteManager hiLiteManager : page.getHiliteManagers()) {
            if (hiLiteManager != null) {
                selectionTranslators.add(new JSONSelectionTranslator(hiLiteManager));
            }
        }
    }
    if (selectionTranslators.size() < 1) {
        selectionTranslators = null;
    }
    JSONWebNodePageConfiguration pageConfig = new JSONWebNodePageConfiguration(layout, null, selectionTranslators);
    Map<String, JSONWebNode> nodes = new HashMap<String, JSONWebNode>();
    for (Map.Entry<NodeIDSuffix, WizardPageNodeInfo> e : page.getInfoMap().entrySet()) {
        WizardPageNodeInfo pInfo = e.getValue();
        JSONWebNode jsonNode = new JSONWebNode();
        JSONWebNodeInfo info = new JSONWebNodeInfo();
        info.setNodeName(pInfo.getNodeName());
        info.setNodeAnnotation(pInfo.getNodeAnnotation());
        NodeContainerState state = pInfo.getNodeState();
        if (state.isIdle()) {
            info.setNodeState(JSONNodeState.IDLE);
        }
        if (state.isConfigured()) {
            info.setNodeState(JSONNodeState.CONFIGURED);
        }
        if (state.isExecutionInProgress() || state.isExecutingRemotely()) {
            info.setNodeState(JSONNodeState.EXECUTING);
        }
        if (state.isExecuted()) {
            info.setNodeState(JSONNodeState.EXECUTED);
        }
        NodeMessage message = pInfo.getNodeMessage();
        if (org.knime.core.node.workflow.NodeMessage.Type.ERROR.equals(message.getMessageType())) {
            info.setNodeErrorMessage(message.getMessage());
        }
        if (org.knime.core.node.workflow.NodeMessage.Type.WARNING.equals(message.getMessageType())) {
            info.setNodeWarnMessage(message.getMessage());
        }
        WizardNode<?, ?> wizardNode = page.getPageMap().get(e.getKey());
        if (wizardNode == null) {
            info.setDisplayPossible(false);
        } else {
            info.setDisplayPossible(true);
            WebTemplate template = WebResourceController.getWebTemplateFromJSObjectID(wizardNode.getJavascriptObjectID());
            List<String> jsList = new ArrayList<String>();
            List<String> cssList = new ArrayList<String>();
            for (WebResourceLocator locator : template.getWebResources()) {
                if (locator.getType() == WebResourceType.JAVASCRIPT) {
                    jsList.add(locator.getRelativePathTarget());
                } else if (locator.getType() == WebResourceType.CSS) {
                    cssList.add(locator.getRelativePathTarget());
                }
            }
            jsonNode.setJavascriptLibraries(jsList);
            jsonNode.setStylesheets(cssList);
            jsonNode.setNamespace(template.getNamespace());
            jsonNode.setInitMethodName(template.getInitMethodName());
            jsonNode.setValidateMethodName(template.getValidateMethodName());
            jsonNode.setSetValidationErrorMethodName(template.getSetValidationErrorMethodName());
            jsonNode.setGetViewValueMethodName(template.getPullViewContentMethodName());
            jsonNode.setViewRepresentation((JSONViewContent) wizardNode.getViewRepresentation());
            jsonNode.setViewValue((JSONViewContent) wizardNode.getViewValue());
        }
        jsonNode.setNodeInfo(info);
        nodes.put(e.getKey().toString(), jsonNode);
    }
    return new JSONWebNodePage(pageConfig, nodes);
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) HashMap(java.util.HashMap) JSONWebNodePageConfiguration(org.knime.js.core.JSONWebNodePageConfiguration) ArrayList(java.util.ArrayList) JSONWebNode(org.knime.js.core.JSONWebNode) HiLiteTranslator(org.knime.core.node.property.hilite.HiLiteTranslator) IOException(java.io.IOException) HiLiteManager(org.knime.core.node.property.hilite.HiLiteManager) JSONWebNodePage(org.knime.js.core.JSONWebNodePage) NodeContainerState(org.knime.core.node.workflow.NodeContainerState) WebResourceLocator(org.knime.core.node.web.WebResourceLocator) JSONWebNodeInfo(org.knime.js.core.JSONWebNodeInfo) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) WebTemplate(org.knime.core.node.web.WebTemplate) JSONSelectionTranslator(org.knime.js.core.selections.json.JSONSelectionTranslator) NodeMessage(org.knime.core.node.workflow.NodeMessage) HashMap(java.util.HashMap) Map(java.util.Map) WizardPageNodeInfo(org.knime.core.node.workflow.WebResourceController.WizardPageContent.WizardPageNodeInfo)

Aggregations

HiLiteManager (org.knime.core.node.property.hilite.HiLiteManager)3 HiLiteTranslator (org.knime.core.node.property.hilite.HiLiteTranslator)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)2 WizardPageNodeInfo (org.knime.core.node.workflow.WebResourceController.WizardPageContent.WizardPageNodeInfo)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 NodeModel (org.knime.core.node.NodeModel)1 HiLiteHandler (org.knime.core.node.property.hilite.HiLiteHandler)1 WebResourceLocator (org.knime.core.node.web.WebResourceLocator)1 WebTemplate (org.knime.core.node.web.WebTemplate)1 WizardNode (org.knime.core.node.wizard.WizardNode)1 NodeContainerState (org.knime.core.node.workflow.NodeContainerState)1 NodeMessage (org.knime.core.node.workflow.NodeMessage)1 JSONWebNode (org.knime.js.core.JSONWebNode)1 JSONWebNodeInfo (org.knime.js.core.JSONWebNodeInfo)1