Search in sources :

Example 6 with JSONLayoutPage

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

the class SubnodeLayoutJSONEditorPage method generateInitialJson.

private JSONLayoutPage generateInitialJson() {
    JSONLayoutPage page = m_layoutCreator.createDefaultLayoutStructure(m_viewNodes);
    ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    try {
        String initialJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(page);
        m_jsonDocument = initialJson;
        return page;
    } catch (JsonProcessingException e) {
        LOGGER.error("Could not create initial layout: " + e.getMessage(), e);
        return null;
    }
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 7 with JSONLayoutPage

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

the class SubnodeLayoutJSONEditorPage method getJsonDocument.

/**
 * @return the jsonDocument
 */
public String getJsonDocument() {
    ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    ObjectReader reader = mapper.readerForUpdating(new JSONLayoutPage());
    try {
        String json = isWindows() ? m_textArea.getText() : m_jsonDocument;
        JSONLayoutPage page = reader.readValue(json);
        String layoutString = mapper.writeValueAsString(page);
        return layoutString;
    } catch (IOException e) {
        LOGGER.error("Failed to retrieve JSON string from layout:" + e.getMessage(), e);
    }
    return "";
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 8 with JSONLayoutPage

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

the class SubnodeLayoutJSONEditorPage method setNodes.

/**
 * Sets all currently available view nodes on this editor page.
 *
 * @param manager the workflow manager
 * @param subnodeContainer the wrapped metanode container
 * @param viewNodes a map of all available view nodes
 */
public void setNodes(final WorkflowManager manager, final SubNodeContainer subnodeContainer, @SuppressWarnings("rawtypes") final Map<NodeIDSuffix, WizardNode> viewNodes) {
    m_wfManager = manager;
    m_subNodeContainer = subnodeContainer;
    m_viewNodes = viewNodes;
    JSONLayoutPage page = null;
    String layout = m_subNodeContainer.getLayoutJSONString();
    if (StringUtils.isNotEmpty(layout)) {
        try {
            ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
            page = mapper.readValue(layout, JSONLayoutPage.class);
            if (page.getRows() == null) {
                page = null;
            } else {
                m_jsonDocument = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(page);
            }
        } catch (IOException e) {
            LOGGER.error("Error parsing layout. Pretty printing not possible: " + e.getMessage(), e);
            m_jsonDocument = layout;
        }
    }
    if (page == null) {
        page = resetLayout();
    }
    List<JSONLayoutRow> rows = page.getRows();
    for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
        JSONLayoutRow row = rows.get(rowIndex);
        populateDocumentNodeIDs(row);
        processBasicLayoutRow(row, rowIndex);
    }
}
Also used : JSONLayoutPage(org.knime.js.core.layout.bs.JSONLayoutPage) JSONLayoutRow(org.knime.js.core.layout.bs.JSONLayoutRow) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Point(org.eclipse.swt.graphics.Point)

Example 9 with JSONLayoutPage

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

the class SubnodeLayoutJSONEditorPage method updateBasicLayout.

private void updateBasicLayout() {
    ObjectMapper mapper = JSONLayoutPage.getConfiguredObjectMapper();
    JSONLayoutPage page = new JSONLayoutPage();
    ObjectReader reader = mapper.readerForUpdating(page);
    try {
        page = reader.readValue(m_jsonDocument);
    } catch (Exception e) {
    /* do nothing, input needs to be validated beforehand */
    }
    m_basicMap.clear();
    m_basicPanelAvailable = true;
    List<JSONLayoutRow> rows = page.getRows();
    for (int rowIndex = 0; rowIndex < rows.size(); rowIndex++) {
        JSONLayoutRow row = rows.get(rowIndex);
        populateDocumentNodeIDs(row);
        processBasicLayoutRow(row, rowIndex);
    }
}
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) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Point(org.eclipse.swt.graphics.Point)

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