Search in sources :

Example 1 with JSONLayoutPage

use of org.knime.js.core.layout.bs.JSONLayoutPage in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method isJSONValid.

/**
 * @return true, if current JSON layout structure is valid
 */
protected boolean isJSONValid() {
    ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    ObjectReader reader = mapper.readerForUpdating(new JSONLayoutPage());
    try {
        String json = isWindows() ? m_textArea.getText() : m_jsonDocument;
        JSONLayoutPage page = reader.readValue(json);
        m_documentNodeIDs.clear();
        if (page.getRows() != null) {
            for (JSONLayoutRow row : page.getRows()) {
                populateDocumentNodeIDs(row);
            }
            compareNodeIDs();
        }
        return true;
    } catch (IOException | NumberFormatException e) {
        String errorMessage;
        if (e instanceof JsonProcessingException) {
            JsonProcessingException jsonException = (JsonProcessingException) e;
            Throwable cause = null;
            Throwable newCause = jsonException.getCause();
            while (newCause instanceof JsonProcessingException) {
                if (cause == newCause) {
                    break;
                }
                cause = newCause;
                newCause = cause.getCause();
            }
            if (cause instanceof JsonProcessingException) {
                jsonException = (JsonProcessingException) cause;
            }
            errorMessage = jsonException.getOriginalMessage().split("\n")[0];
            JsonLocation location = jsonException.getLocation();
            if (location != null) {
                errorMessage += " at line: " + (location.getLineNr() + 1) + " column: " + location.getColumnNr();
            }
        } else {
            String message = e.getMessage();
            errorMessage = message;
        }
        if (m_statusLine != null && !m_statusLine.isDisposed()) {
            m_statusLine.setForeground(new Color(Display.getCurrent(), 255, 0, 0));
            m_statusLine.setText(errorMessage);
            int textWidth = isWindows() ? m_textArea.getSize().width : m_text.getSize().x;
            Point newSize = m_statusLine.computeSize(textWidth, m_statusLine.getSize().y, true);
            m_statusLine.setSize(newSize);
        }
    }
    return false;
}
Also used : JsonLocation(com.fasterxml.jackson.core.JsonLocation) JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) Color(org.eclipse.swt.graphics.Color) IOException(java.io.IOException) Point(org.eclipse.swt.graphics.Point) JSONLayoutRow(org.knime.js.core.layout.bs.JSONLayoutRow) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with JSONLayoutPage

use of org.knime.js.core.layout.bs.JSONLayoutPage in project knime-core by knime.

the class TestSubnodeView method validateJSONPage.

private void validateJSONPage(final JSONWebNodePage page) {
    assertNotNull("Page should have config object", page.getWebNodePageConfiguration());
    assertNotNull("Page should have map of nodes", page.getWebNodes());
    assertNotNull("Page should have layout information", page.getWebNodePageConfiguration().getLayout());
    JSONLayoutPage layout = page.getWebNodePageConfiguration().getLayout();
    assertNotNull("Layout should contain list of rows", layout.getRows());
    assertEquals("Layout should contain four rows", 4, layout.getRows().size());
    assertEquals("Page should contain three nodes", 3, page.getWebNodes().size());
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage)

Example 3 with JSONLayoutPage

use of org.knime.js.core.layout.bs.JSONLayoutPage 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)

Example 4 with JSONLayoutPage

use of org.knime.js.core.layout.bs.JSONLayoutPage in project knime-core by knime.

the class AbstractPageManager method getJSONLayoutFromSubnode.

private JSONLayoutPage getJSONLayoutFromSubnode(final NodeIDSuffix pageID, final String layoutInfo) throws IOException {
    ObjectMapper mapper = JSONLayoutPage.getConfiguredVerboseObjectMapper();
    ObjectReader reader = mapper.readerForUpdating(new JSONLayoutPage());
    JSONLayoutPage page = reader.readValue(layoutInfo);
    if (page != null && page.getRows() != null) {
        for (JSONLayoutRow row : page.getRows()) {
            setNodeIDInContent(row, pageID);
        }
    }
    return page;
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) JSONLayoutRow(org.knime.js.core.layout.bs.JSONLayoutRow) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with JSONLayoutPage

use of org.knime.js.core.layout.bs.JSONLayoutPage in project knime-core by knime.

the class SubnodeLayoutJSONEditorPage method basicLayoutToJson.

private void basicLayoutToJson() throws Exception {
    JSONLayoutPage page = new JSONLayoutPage();
    List<JSONLayoutRow> rows = new ArrayList<JSONLayoutRow>();
    for (BasicLayoutInfo basicLayoutInfo : m_basicMap.values()) {
        while (rows.size() < basicLayoutInfo.getRow()) {
            rows.add(new JSONLayoutRow());
        }
        JSONLayoutRow row = rows.get(basicLayoutInfo.getRow() - 1);
        if (row.getColumns() == null) {
            row.setColumns(new ArrayList<JSONLayoutColumn>());
        }
        List<JSONLayoutColumn> columns = row.getColumns();
        while (columns.size() < basicLayoutInfo.getCol()) {
            columns.add(new JSONLayoutColumn());
        }
        JSONLayoutColumn column = columns.get(basicLayoutInfo.getCol() - 1);
        column.setWidthMD(basicLayoutInfo.getColWidth());
        List<JSONLayoutContent> contentList = column.getContent();
        if (contentList == null) {
            contentList = new ArrayList<JSONLayoutContent>(1);
        }
        contentList.add(basicLayoutInfo.getView());
        column.setContent(contentList);
    }
    page.setRows(rows);
    ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(page);
    m_jsonDocument = json;
    if (isWindows()) {
        m_textArea.setText(m_jsonDocument);
    } else {
        m_text.setText(m_jsonDocument);
    }
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) ArrayList(java.util.ArrayList) JSONLayoutContent(org.knime.js.core.layout.bs.JSONLayoutContent) JSONLayoutRow(org.knime.js.core.layout.bs.JSONLayoutRow) JSONLayoutColumn(org.knime.js.core.layout.bs.JSONLayoutColumn) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JSONLayoutPage (org.knime.js.core.layout.bs.JSONLayoutPage)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 IOException (java.io.IOException)5 JSONLayoutRow (org.knime.js.core.layout.bs.JSONLayoutRow)5 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 Point (org.eclipse.swt.graphics.Point)3 ArrayList (java.util.ArrayList)2 JsonLocation (com.fasterxml.jackson.core.JsonLocation)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Color (org.eclipse.swt.graphics.Color)1 HiLiteManager (org.knime.core.node.property.hilite.HiLiteManager)1 HiLiteTranslator (org.knime.core.node.property.hilite.HiLiteTranslator)1 WebResourceLocator (org.knime.core.node.web.WebResourceLocator)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