use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.
the class TestSubnodeView method testExecuteAndCreateSubnodeView.
/**
* Simple test if a combined view can succesfully be created and contains the layout and expected nodes for display
* @throws Exception
*/
@Test
public void testExecuteAndCreateSubnodeView() throws Exception {
initialExecute();
SinglePageWebResourceController spc = new SinglePageWebResourceController(getManager(), m_subnodeID);
assertTrue("Should have subnode view", spc.isSubnodeViewAvailable());
WizardPageContent page = spc.getWizardPage();
assertNotNull("Page content should be available", page);
@SuppressWarnings("rawtypes") Map<NodeIDSuffix, WizardNode> pageMap = page.getPageMap();
assertNotNull("Page map should be available", pageMap);
assertEquals("Page should contain three nodes", 3, pageMap.size());
String layout = page.getLayoutInfo();
assertNotNull("Page layout should be available", layout);
assertTrue("Layout should contain test string", layout.contains("testString"));
}
use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.
the class SubnodeLayoutJSONEditorPage method fillBasicComposite.
private void fillBasicComposite() {
if (!m_basicPanelAvailable) {
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = SWT.CENTER;
Label infoLabel = new Label(m_basicComposite, SWT.CENTER);
infoLabel.setText("A basic configuration of the layout is not possible. \nPlease use the \"Advanced\" tab.");
infoLabel.setLayoutData(gridData);
return;
}
m_basicComposite.setLayout(new GridLayout(7, false));
m_basicComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
Label titleLabel = new Label(m_basicComposite, SWT.LEFT);
FontData fontData = titleLabel.getFont().getFontData()[0];
Font boldFont = new Font(Display.getCurrent(), new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
titleLabel.setText("Node");
titleLabel.setFont(boldFont);
new Composite(m_basicComposite, SWT.NONE);
/* Warning placeholder */
Label rowLabel = new Label(m_basicComposite, SWT.CENTER);
rowLabel.setText("Row");
rowLabel.setFont(boldFont);
Label colLabel = new Label(m_basicComposite, SWT.CENTER);
colLabel.setText("Column");
colLabel.setFont(boldFont);
Label widthLabel = new Label(m_basicComposite, SWT.CENTER);
widthLabel.setText("Width");
widthLabel.setFont(boldFont);
new Composite(m_basicComposite, SWT.NONE);
/* More placeholder */
new Composite(m_basicComposite, SWT.NONE);
for (final Entry<NodeIDSuffix, BasicLayoutInfo> entry : m_basicMap.entrySet()) {
NodeIDSuffix suffix = entry.getKey();
BasicLayoutInfo layoutInfo = entry.getValue();
NodeID nodeID = suffix.prependParent(m_subNodeContainer.getWorkflowManager().getID());
NodeContainer nodeContainer = m_viewNodes.containsKey(suffix) ? m_wfManager.getNodeContainer(nodeID) : null;
createNodeLabelComposite(m_basicComposite, nodeID, nodeContainer);
final Label warningLabel = new Label(m_basicComposite, SWT.CENTER);
if (nodeContainer != null && m_viewNodes.get(suffix).isHideInWizard()) {
warningLabel.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/warning.png"));
warningLabel.setToolTipText("Node is set to 'Hide in Wizard'. It might not be displayed in the layout.");
}
GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
gridData.widthHint = 50;
final Spinner rowSpinner = createBasicPanelSpinner(m_basicComposite, layoutInfo.getRow(), 1, 999);
rowSpinner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
layoutInfo.setRow(rowSpinner.getSelection());
tryUpdateJsonFromBasic();
}
});
final Spinner colSpinner = createBasicPanelSpinner(m_basicComposite, layoutInfo.getCol(), 1, 99);
colSpinner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
layoutInfo.setCol(colSpinner.getSelection());
tryUpdateJsonFromBasic();
}
});
final Spinner widthSpinner = createBasicPanelSpinner(m_basicComposite, layoutInfo.getColWidth(), 1, 12);
widthSpinner.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
layoutInfo.setColWidth(widthSpinner.getSelection());
tryUpdateJsonFromBasic();
}
});
final Button advancedButton = new Button(m_basicComposite, SWT.PUSH | SWT.CENTER);
advancedButton.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/settings.png"));
advancedButton.setToolTipText("Additional layout settings");
if (nodeContainer == null) {
advancedButton.setEnabled(false);
} else {
advancedButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
JSONLayoutViewContent defaultViewContent = m_layoutCreator.getDefaultViewContentForNode(suffix, m_viewNodes.get(suffix));
ViewContentSettingsDialog settingsDialog = new ViewContentSettingsDialog(m_basicComposite.getShell(), layoutInfo.getView(), defaultViewContent);
if (settingsDialog.open() == Window.OK) {
layoutInfo.setView(settingsDialog.getViewSettings());
tryUpdateJsonFromBasic();
}
}
});
}
final Button removeButton = new Button(m_basicComposite, SWT.PUSH | SWT.CENTER);
removeButton.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/remove.png"));
removeButton.setToolTipText("Remove node from layout");
removeButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
if (nodeContainer != null) {
if (!MessageDialog.openConfirm(m_basicComposite.getShell(), "Confirm deletion", "Are you sure you want to delete node " + suffix + " from the layout?")) {
return;
}
}
m_basicMap.remove(suffix);
tryUpdateJsonFromBasic();
}
});
}
for (@SuppressWarnings("rawtypes") final Entry<NodeIDSuffix, WizardNode> entry : m_viewNodes.entrySet()) {
if (m_basicMap.containsKey(entry.getKey())) {
continue;
}
// Node not in layout
NodeID nodeID = entry.getKey().prependParent(m_subNodeContainer.getWorkflowManager().getID());
NodeContainer nodeContainer = m_wfManager.getNodeContainer(nodeID);
createNodeLabelComposite(m_basicComposite, nodeID, nodeContainer);
final Label warningLabel = new Label(m_basicComposite, SWT.CENTER);
if (nodeContainer != null && m_viewNodes.get(entry.getKey()).isHideInWizard()) {
warningLabel.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/warning.png"));
warningLabel.setToolTipText("Node is set to 'Hide in Wizard'. It might not be displayed in the layout.");
}
final Button addButton = new Button(m_basicComposite, SWT.PUSH | SWT.CENTER);
addButton.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/add.png"));
addButton.setToolTipText("Add node to layout");
addButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
int lastRow = 0;
for (BasicLayoutInfo basicLayoutInfo : m_basicMap.values()) {
lastRow = Math.max(lastRow, basicLayoutInfo.getRow());
}
BasicLayoutInfo newInfo = new BasicLayoutInfo();
newInfo.setRow(lastRow + 1);
newInfo.setCol(1);
newInfo.setColWidth(12);
newInfo.setView(m_layoutCreator.getDefaultViewContentForNode(entry.getKey(), entry.getValue()));
m_basicMap.put(entry.getKey(), newInfo);
tryUpdateJsonFromBasic();
}
});
GridData gridData = new GridData();
gridData.horizontalSpan = 4;
Label space = new Label(m_basicComposite, SWT.NONE);
space.setLayoutData(gridData);
}
GridData fillRow = new GridData();
fillRow.grabExcessHorizontalSpace = true;
fillRow.horizontalAlignment = SWT.CENTER;
fillRow.horizontalSpan = 7;
Button resetButton = new Button(m_basicComposite, SWT.PUSH | SWT.CENTER);
resetButton.setImage(ImageRepository.getIconImage(KNIMEEditorPlugin.PLUGIN_ID, "icons/layout/reset.png"));
resetButton.setText("Reset");
resetButton.setToolTipText("Reset layout to default according to currently available nodes.");
resetButton.setLayoutData(fillRow);
resetButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
if (!MessageDialog.openConfirm(m_basicComposite.getShell(), "Confirm reset", "Are you sure you want to reset the layout according to the currently available nodes?")) {
return;
}
resetLayout();
if (isWindows()) {
m_textArea.setText(m_jsonDocument);
} else {
m_text.setText(m_jsonDocument);
}
updateModelFromJson();
}
});
}
use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.
the class WebResourceController method validateViewValuesInternal.
/**
* Validates a given set of serialized view values for a given subnode.
*
* @param viewValues the values to validate
* @param subnodeID the id of the subnode containing the appropriate view nodes
* @param wizardNodeSet the set of view nodes that the view values correspond to.
* @return Null or empty map if validation succeeds, map of errors otherwise
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Map<String, ValidationError> validateViewValuesInternal(final Map<String, String> viewValues, final NodeID subnodeID, final Map<NodeID, WizardNode> wizardNodeSet) {
if (subnodeID == null) {
LOGGER.error("No node ID supplied for validating view values of wizard page");
return null;
}
WorkflowManager manager = m_manager;
assert manager.isLockedByCurrentThread();
Map<String, ValidationError> resultMap = new LinkedHashMap<String, ValidationError>();
for (Map.Entry<String, String> entry : viewValues.entrySet()) {
NodeID.NodeIDSuffix suffix = NodeID.NodeIDSuffix.fromString(entry.getKey());
NodeID id = suffix.prependParent(manager.getID());
CheckUtils.checkState(id.hasPrefix(subnodeID), "The wizard page content for ID %s (suffix %s) " + "does not belong to the current Wrapped Metanode (ID %s)", id, entry.getKey(), subnodeID);
WizardNode wizardNode = wizardNodeSet.get(id);
CheckUtils.checkState(wizardNode != null, "No wizard node with ID %s in Wrapped Metanode, valid IDs are: " + "%s", id, ConvenienceMethods.getShortStringFrom(wizardNodeSet.entrySet(), 10));
@SuppressWarnings("null") WebViewContent newViewValue = wizardNode.createEmptyViewValue();
if (newViewValue == null) {
// node has no view value
continue;
}
ValidationError validationError = null;
try {
newViewValue.loadFromStream(new ByteArrayInputStream(entry.getValue().getBytes(Charset.forName("UTF-8"))));
validationError = wizardNode.validateViewValue(newViewValue);
} catch (Exception e) {
resultMap.put(entry.getKey(), new ValidationError("Could not deserialize JSON value: " + entry.getValue() + ": \n" + e.getMessage()));
}
if (validationError != null) {
resultMap.put(entry.getKey(), validationError);
}
}
if (!resultMap.isEmpty()) {
return resultMap;
}
return Collections.emptyMap();
}
use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.
the class WebResourceController method loadValuesIntoPageInternal.
/**
* Tries to load a map of view values to all appropriate views contained in a given subnode.
*
* @param viewContentMap the values to load
* @param subnodeID the id fo the subnode containing the appropriate view nodes
* @param validate true, if validation is supposed to be done before applying the values, false otherwise
* @param useAsDefault true, if the given value map is supposed to be applied as new node defaults (overwrite node
* settings), false otherwise (apply temporarily)
* @return Null or empty map if validation succeeds, map of errors otherwise
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
protected Map<String, ValidationError> loadValuesIntoPageInternal(final Map<String, String> viewContentMap, final NodeID subnodeID, final boolean validate, final boolean useAsDefault) {
if (subnodeID == null) {
LOGGER.error("No node ID supplied for loading values into wizard page");
return null;
}
WorkflowManager manager = m_manager;
assert manager.isLockedByCurrentThread();
LOGGER.debugWithFormat("Loading view content into wizard nodes (%d)", viewContentMap.size());
SubNodeContainer subNodeNC = manager.getNodeContainer(subnodeID, SubNodeContainer.class, true);
Map<NodeID, WizardNode> wizardNodeSet = getWizardNodeSetForVerifiedID(subnodeID);
if (validate) {
Map<String, ValidationError> validationResult = validateViewValuesInternal(viewContentMap, subnodeID, wizardNodeSet);
if (!validationResult.isEmpty()) {
return validationResult;
}
}
// validation succeeded, reset subnode and apply
if (!subNodeNC.getInternalState().isExecuted()) {
// this used to be an error but see SRV-745
LOGGER.warnWithFormat("Wrapped metanode (%s) not fully executed on appyling new values -- " + "consider to change wrapped metanode layout to have self-contained executable units", subNodeNC.getNameWithID());
}
manager.resetSubnodeForViewUpdate(subnodeID, this);
for (Map.Entry<String, String> entry : viewContentMap.entrySet()) {
NodeID.NodeIDSuffix suffix = NodeID.NodeIDSuffix.fromString(entry.getKey());
NodeID id = suffix.prependParent(manager.getID());
WizardNode wizardNode = wizardNodeSet.get(id);
WebViewContent newViewValue = wizardNode.createEmptyViewValue();
if (newViewValue == null) {
// node has no view value
continue;
}
try {
newViewValue.loadFromStream(new ByteArrayInputStream(entry.getValue().getBytes(Charset.forName("UTF-8"))));
wizardNode.loadViewValue(newViewValue, useAsDefault);
if (useAsDefault) {
subNodeNC.getWorkflowManager().getNodeContainer(id, SingleNodeContainer.class, true).saveNodeSettingsToDefault();
}
} catch (Exception e) {
LOGGER.error("Failed to load view value into node \"" + id + "\" although validation succeeded", e);
}
}
manager.configureNodeAndSuccessors(subnodeID, true);
return Collections.emptyMap();
}
use of org.knime.core.node.wizard.WizardNode in project knime-core by knime.
the class WebResourceController method getWizardPageInternal.
/**
* Crates the wizard page for a given node id. Throws exception if no wizard page available.
*
* @param subnodeID the node id for the subnode to retrieve the wizard page for
* @return The wizard page for the given node id
*/
@SuppressWarnings("rawtypes")
protected WizardPageContent getWizardPageInternal(final NodeID subnodeID) {
if (subnodeID == null) {
LOGGER.error("No node ID supplied for creating wizard page");
return null;
}
final WorkflowManager manager = m_manager;
assert manager.isLockedByCurrentThread();
// int currentSubnodeIDSuffix = m_promptedSubnodeIDSuffixes.peek();
// final NodeID subNodeID = toNodeID(currentSubnodeIDSuffix);
SubNodeContainer subNC = manager.getNodeContainer(subnodeID, SubNodeContainer.class, true);
WorkflowManager subWFM = subNC.getWorkflowManager();
Map<NodeID, WizardNode> wizardNodeMap = subWFM.findNodes(WizardNode.class, NOT_HIDDEN_FILTER, false);
LinkedHashMap<NodeIDSuffix, WizardNode> resultMap = new LinkedHashMap<NodeIDSuffix, WizardNode>();
// LinkedHashMap<NodeIDSuffix, WizardNode> errorMap = new LinkedHashMap<NodeIDSuffix, WizardNode>();
LinkedHashMap<NodeIDSuffix, WizardPageNodeInfo> infoMap = new LinkedHashMap<NodeIDSuffix, WizardPageNodeInfo>();
Set<HiLiteHandler> initialHiliteHandlerSet = new HashSet<HiLiteHandler>();
for (Map.Entry<NodeID, WizardNode> entry : wizardNodeMap.entrySet()) {
NodeContainer nc = subWFM.getNodeContainer(entry.getKey());
if ((nc instanceof SingleNodeContainer) && ((SingleNodeContainer) nc).isInactive()) {
// skip nodes in inactive branches
continue;
}
NodeID.NodeIDSuffix idSuffix = NodeID.NodeIDSuffix.create(manager.getID(), entry.getKey());
WizardPageNodeInfo nodeInfo = new WizardPageNodeInfo();
nodeInfo.setNodeName(nc.getName());
nodeInfo.setNodeAnnotation(nc.getNodeAnnotation().toString());
nodeInfo.setNodeState(nc.getInternalState());
nodeInfo.setNodeMessage(nc.getNodeMessage());
infoMap.put(idSuffix, nodeInfo);
if (EXECUTED.equals(nc.getInternalState())) {
// regular viewable nodes need to be executed
resultMap.put(idSuffix, entry.getValue());
}
for (int i = 0; i < nc.getNrInPorts() - 1; i++) {
HiLiteHandler hiLiteHandler = ((NodeModel) entry.getValue()).getInHiLiteHandler(i);
if (hiLiteHandler != null) {
initialHiliteHandlerSet.add(hiLiteHandler);
}
}
}
NodeID.NodeIDSuffix pageID = NodeID.NodeIDSuffix.create(manager.getID(), subWFM.getID());
String pageLayout = subNC.getLayoutJSONString();
if (StringUtils.isEmpty(pageLayout)) {
try {
pageLayout = LayoutUtil.createDefaultLayout(resultMap);
} catch (IOException ex) {
LOGGER.error("Default page layout could not be created: " + ex.getMessage(), ex);
}
}
Set<HiLiteHandler> knownHiLiteHandlers = new HashSet<HiLiteHandler>();
Set<HiLiteTranslator> knownTranslators = new HashSet<HiLiteTranslator>();
Set<HiLiteManager> knownManagers = new HashSet<HiLiteManager>();
for (HiLiteHandler initialHandler : initialHiliteHandlerSet) {
getHiLiteTranslators(initialHandler, knownHiLiteHandlers, knownTranslators, knownManagers);
}
List<HiLiteTranslator> translatorList = knownTranslators.size() > 0 ? new ArrayList<HiLiteTranslator>(knownTranslators) : null;
List<HiLiteManager> managerList = knownManagers.size() > 0 ? new ArrayList<HiLiteManager>(knownManagers) : null;
WizardPageContent page = new WizardPageContent(pageID, resultMap, pageLayout, translatorList, managerList);
page.setInfoMap(infoMap);
return page;
}
Aggregations