Search in sources :

Example 1 with WebResourceLocator

use of org.knime.core.node.web.WebResourceLocator in project knime-core by knime.

the class WebResourceController method getWebTemplateFromJSObjectID.

/**
 * @param jsObjectID The JavaScript object ID used for locating the extension point.
 * @return A template object, being used to assamble views.
 */
public static WebTemplate getWebTemplateFromJSObjectID(final String jsObjectID) {
    LinkedHashSet<WebResourceLocator> webResList = new LinkedHashSet<WebResourceLocator>();
    IConfigurationElement jsComponentExtension = getConfigurationFromID(ID_JS_COMP, ATTR_JS_ID, jsObjectID);
    if (jsComponentExtension == null) {
        return getEmptyWebTemplate();
    }
    String bundleID = jsComponentExtension.getAttribute(ID_IMPL_BUNDLE);
    IConfigurationElement implementationExtension = getConfigurationFromID(ID_WEB_RES, ATTR_RES_BUNDLE_ID, bundleID);
    if (implementationExtension == null) {
        return getEmptyWebTemplate();
    }
    Set<WebResourceLocator> implementationRes = getResourcesFromExtension(implementationExtension);
    webResList.addAll(DEFAULT_RES);
    for (IConfigurationElement dependencyConf : jsComponentExtension.getChildren(ID_DEPENDENCY)) {
        String dependencyID = dependencyConf.getAttribute(ATTR_RES_BUNDLE_ID);
        IConfigurationElement dependencyExtension = getConfigurationFromID(ID_WEB_RES, ATTR_RES_BUNDLE_ID, dependencyID);
        if (dependencyExtension == null) {
            LOGGER.error("Web ressource dependency could not be found: " + dependencyID + ". This is most likely an implementation error.");
            continue;
        }
        Set<WebResourceLocator> dependencyRes = getResourcesFromExtension(dependencyExtension);
        webResList.addAll(dependencyRes);
    }
    webResList.addAll(implementationRes);
    String namespace = jsComponentExtension.getAttribute(ATTR_NAMESPACE);
    String initMethodName = jsComponentExtension.getAttribute(ATTR_INIT_METHOD_NAME);
    String validateMethodName = jsComponentExtension.getAttribute(ATTR_VALIDATE_METHOD_NAME);
    String valueMethodName = jsComponentExtension.getAttribute(ATTR_GETCOMPONENTVALUE_METHOD_NAME);
    String setValidationErrorMethodName = jsComponentExtension.getAttribute(ATTR_SETVALIDATIONERROR_METHOD_NAME);
    return new DefaultWebTemplate(webResList.toArray(new WebResourceLocator[0]), namespace, initMethodName, validateMethodName, valueMethodName, setValidationErrorMethodName);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) WebResourceLocator(org.knime.core.node.web.WebResourceLocator) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) DefaultWebTemplate(org.knime.core.node.web.DefaultWebTemplate)

Example 2 with WebResourceLocator

use of org.knime.core.node.web.WebResourceLocator in project knime-core by knime.

the class WebResourceController method getResourcesFromExtension.

private static Set<WebResourceLocator> getResourcesFromExtension(final IConfigurationElement resConfig) {
    if (resConfig == null) {
        return Collections.emptySet();
    }
    String pluginName = resConfig.getContributor().getName();
    LinkedHashSet<WebResourceLocator> locators = new LinkedHashSet<WebResourceLocator>();
    Map<String, String> resMap = getWebResources(resConfig);
    Set<String> imports = new HashSet<String>();
    // collect dependencies
    for (IConfigurationElement depElement : resConfig.getChildren(ID_DEPENDENCY)) {
        String dependencyID = depElement.getAttribute(ATTR_RES_BUNDLE_ID);
        IConfigurationElement depConfig = getConfigurationFromID(ID_WEB_RES, ATTR_RES_BUNDLE_ID, dependencyID);
        if (depConfig == null) {
            LOGGER.error("Web ressource dependency could not be found: " + dependencyID + ". This is most likely an implementation error.");
            continue;
        }
        locators.addAll(getResourcesFromExtension(depConfig));
    }
    // collect own import files
    for (IConfigurationElement resElement : resConfig.getChildren(ID_IMPORT_RES)) {
        String path = resElement.getAttribute(ATTR_PATH);
        String type = resElement.getAttribute(ATTR_TYPE);
        if (path != null && type != null) {
            WebResourceType resType = WebResourceType.FILE;
            if (type.equalsIgnoreCase("javascript")) {
                resType = WebResourceType.JAVASCRIPT;
            } else if (type.equalsIgnoreCase("css")) {
                resType = WebResourceType.CSS;
            }
            String parent = path.substring(0, path.lastIndexOf('/') + 1);
            String newParent = resMap.get(parent);
            String sourcePath;
            if (newParent != null) {
                sourcePath = path.replace(parent, newParent);
            } else {
                sourcePath = path;
            }
            locators.add(new WebResourceLocator(pluginName, sourcePath, path, resType));
            imports.add(sourcePath);
        }
    }
    /* for (Entry<String, String> entry :resMap.entrySet()) {
            String targetPath = entry.getKey();
            String sourcePath = entry.getValue();
            try {
                URL url = new URL("platform:/plugin/" + pluginName);
                File dir = new File(FileLocator.resolve(url).getFile());
                File file = new File(dir, sourcePath);
                if (file.exists()) {
                    addLocators(pluginName, locators, imports, file, sourcePath, targetPath);
                }
            } catch (Exception e) {
                LOGGER.warn("Could not resolve web resource " + sourcePath, e);
            }
        }*/
    return locators;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) WebResourceType(org.knime.core.node.web.WebResourceLocator.WebResourceType) WebResourceLocator(org.knime.core.node.web.WebResourceLocator) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with WebResourceLocator

use of org.knime.core.node.web.WebResourceLocator 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

WebResourceLocator (org.knime.core.node.web.WebResourceLocator)3 LinkedHashSet (java.util.LinkedHashSet)2 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 HiLiteManager (org.knime.core.node.property.hilite.HiLiteManager)1 HiLiteTranslator (org.knime.core.node.property.hilite.HiLiteTranslator)1 DefaultWebTemplate (org.knime.core.node.web.DefaultWebTemplate)1 WebResourceType (org.knime.core.node.web.WebResourceLocator.WebResourceType)1 WebTemplate (org.knime.core.node.web.WebTemplate)1 NodeContainerState (org.knime.core.node.workflow.NodeContainerState)1 NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)1 NodeMessage (org.knime.core.node.workflow.NodeMessage)1 WizardPageNodeInfo (org.knime.core.node.workflow.WebResourceController.WizardPageContent.WizardPageNodeInfo)1 JSONWebNode (org.knime.js.core.JSONWebNode)1 JSONWebNodeInfo (org.knime.js.core.JSONWebNodeInfo)1 JSONWebNodePage (org.knime.js.core.JSONWebNodePage)1