use of org.knime.js.core.layout.bs.JSONLayoutContent 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;
}
}
}
}
}
}
use of org.knime.js.core.layout.bs.JSONLayoutContent 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);
}
}
Aggregations