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;
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations