Search in sources :

Example 1 with JSONLayoutRow

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

use of org.knime.js.core.layout.bs.JSONLayoutRow 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 3 with JSONLayoutRow

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

Example 4 with JSONLayoutRow

use of org.knime.js.core.layout.bs.JSONLayoutRow 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 5 with JSONLayoutRow

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

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 JSONLayoutPage (org.knime.js.core.layout.bs.JSONLayoutPage)5 JSONLayoutRow (org.knime.js.core.layout.bs.JSONLayoutRow)5 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)3 IOException (java.io.IOException)3 Point (org.eclipse.swt.graphics.Point)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonLocation (com.fasterxml.jackson.core.JsonLocation)1 ArrayList (java.util.ArrayList)1 Color (org.eclipse.swt.graphics.Color)1 JSONLayoutColumn (org.knime.js.core.layout.bs.JSONLayoutColumn)1 JSONLayoutContent (org.knime.js.core.layout.bs.JSONLayoutContent)1