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