Search in sources :

Example 1 with JSONLayoutColumn

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

the class SubnodeLayoutJSONEditorPage method processBasicLayoutRow.

/**
 * Processes one layout row, creates {@link BasicLayoutInfo} for each contained node and determines if basic layout
 * is available. Some advanced configurations (additional styles or classes, HTML content or nested layouts) can not
 * be represented in a basic layout.
 *
 * @param row the row to process
 * @param rowIndex the index of the row as it appears in the layout
 */
private void processBasicLayoutRow(final JSONLayoutRow row, final int rowIndex) {
    if (listNotNullOrEmpty(row.getAdditionalStyles()) || listNotNullOrEmpty(row.getAdditionalClasses())) {
        // basic layout not possible, show only advanced tab
        m_basicPanelAvailable = false;
        return;
    }
    List<JSONLayoutColumn> columns = row.getColumns();
    for (int colIndex = 0; colIndex < columns.size(); colIndex++) {
        JSONLayoutColumn column = columns.get(colIndex);
        if (listNotNullOrEmpty(column.getAdditionalStyles()) || listNotNullOrEmpty(column.getAdditionalClasses())) {
            // basic layout not possible, show only advanced tab
            m_basicPanelAvailable = false;
            return;
        }
        List<JSONLayoutContent> content = column.getContent();
        if (content != null) {
            for (JSONLayoutContent jsonLayoutContent : content) {
                if (jsonLayoutContent != null) {
                    if (jsonLayoutContent instanceof JSONLayoutViewContent) {
                        JSONLayoutViewContent viewContent = (JSONLayoutViewContent) jsonLayoutContent;
                        if (listNotNullOrEmpty(viewContent.getAdditionalStyles()) || listNotNullOrEmpty(viewContent.getAdditionalClasses())) {
                            // basic layout not possible, show only advanced tab
                            m_basicPanelAvailable = false;
                            return;
                        }
                        BasicLayoutInfo basicInfo = new BasicLayoutInfo();
                        basicInfo.setRow(rowIndex + 1);
                        basicInfo.setCol(colIndex + 1);
                        basicInfo.setColWidth(column.getWidthMD());
                        basicInfo.setView(viewContent);
                        NodeIDSuffix id = NodeIDSuffix.fromString(viewContent.getNodeID());
                        m_basicMap.put(id, basicInfo);
                    } else {
                        // basic layout not possible, show only advanced tab
                        m_basicPanelAvailable = false;
                        return;
                    }
                }
            }
        }
    }
}
Also used : JSONLayoutContent(org.knime.js.core.layout.bs.JSONLayoutContent) NodeIDSuffix(org.knime.core.node.workflow.NodeID.NodeIDSuffix) JSONLayoutColumn(org.knime.js.core.layout.bs.JSONLayoutColumn) JSONLayoutViewContent(org.knime.js.core.layout.bs.JSONLayoutViewContent) Point(org.eclipse.swt.graphics.Point)

Example 2 with JSONLayoutColumn

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

JSONLayoutColumn (org.knime.js.core.layout.bs.JSONLayoutColumn)2 JSONLayoutContent (org.knime.js.core.layout.bs.JSONLayoutContent)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayList (java.util.ArrayList)1 Point (org.eclipse.swt.graphics.Point)1 NodeIDSuffix (org.knime.core.node.workflow.NodeID.NodeIDSuffix)1 JSONLayoutPage (org.knime.js.core.layout.bs.JSONLayoutPage)1 JSONLayoutRow (org.knime.js.core.layout.bs.JSONLayoutRow)1 JSONLayoutViewContent (org.knime.js.core.layout.bs.JSONLayoutViewContent)1