use of org.knime.core.node.web.WebTemplate in project knime-core by knime.
the class AbstractPageManager method createWizardPageInternal.
/**
* Performs a transformation from {@link WizardPageContent} to {@link JSONWebNodePage} which can be used for serialization.
* @param page the {@link WizardPageContent} to transform
* @return the transformed {@link JSONWebNodePage}
* @throws IOException if layout of page can not be generated
*/
protected JSONWebNodePage createWizardPageInternal(final WizardPageContent page) throws IOException {
// process layout
JSONLayoutPage layout = new JSONLayoutPage();
try {
String lString = page.getLayoutInfo();
if (StringUtils.isNotEmpty(lString)) {
layout = getJSONLayoutFromSubnode(page.getPageNodeID(), page.getLayoutInfo());
}
} catch (IOException e) {
throw new IOException("Layout for page could not be generated: " + e.getMessage(), e);
}
// process selection translators
List<JSONSelectionTranslator> selectionTranslators = new ArrayList<JSONSelectionTranslator>();
if (page.getHiLiteTranslators() != null) {
for (HiLiteTranslator hiLiteTranslator : page.getHiLiteTranslators()) {
if (hiLiteTranslator != null) {
selectionTranslators.add(new JSONSelectionTranslator(hiLiteTranslator));
}
}
}
if (page.getHiliteManagers() != null) {
for (HiLiteManager hiLiteManager : page.getHiliteManagers()) {
if (hiLiteManager != null) {
selectionTranslators.add(new JSONSelectionTranslator(hiLiteManager));
}
}
}
if (selectionTranslators.size() < 1) {
selectionTranslators = null;
}
JSONWebNodePageConfiguration pageConfig = new JSONWebNodePageConfiguration(layout, null, selectionTranslators);
Map<String, JSONWebNode> nodes = new HashMap<String, JSONWebNode>();
for (Map.Entry<NodeIDSuffix, WizardPageNodeInfo> e : page.getInfoMap().entrySet()) {
WizardPageNodeInfo pInfo = e.getValue();
JSONWebNode jsonNode = new JSONWebNode();
JSONWebNodeInfo info = new JSONWebNodeInfo();
info.setNodeName(pInfo.getNodeName());
info.setNodeAnnotation(pInfo.getNodeAnnotation());
NodeContainerState state = pInfo.getNodeState();
if (state.isIdle()) {
info.setNodeState(JSONNodeState.IDLE);
}
if (state.isConfigured()) {
info.setNodeState(JSONNodeState.CONFIGURED);
}
if (state.isExecutionInProgress() || state.isExecutingRemotely()) {
info.setNodeState(JSONNodeState.EXECUTING);
}
if (state.isExecuted()) {
info.setNodeState(JSONNodeState.EXECUTED);
}
NodeMessage message = pInfo.getNodeMessage();
if (org.knime.core.node.workflow.NodeMessage.Type.ERROR.equals(message.getMessageType())) {
info.setNodeErrorMessage(message.getMessage());
}
if (org.knime.core.node.workflow.NodeMessage.Type.WARNING.equals(message.getMessageType())) {
info.setNodeWarnMessage(message.getMessage());
}
WizardNode<?, ?> wizardNode = page.getPageMap().get(e.getKey());
if (wizardNode == null) {
info.setDisplayPossible(false);
} else {
info.setDisplayPossible(true);
WebTemplate template = WebResourceController.getWebTemplateFromJSObjectID(wizardNode.getJavascriptObjectID());
List<String> jsList = new ArrayList<String>();
List<String> cssList = new ArrayList<String>();
for (WebResourceLocator locator : template.getWebResources()) {
if (locator.getType() == WebResourceType.JAVASCRIPT) {
jsList.add(locator.getRelativePathTarget());
} else if (locator.getType() == WebResourceType.CSS) {
cssList.add(locator.getRelativePathTarget());
}
}
jsonNode.setJavascriptLibraries(jsList);
jsonNode.setStylesheets(cssList);
jsonNode.setNamespace(template.getNamespace());
jsonNode.setInitMethodName(template.getInitMethodName());
jsonNode.setValidateMethodName(template.getValidateMethodName());
jsonNode.setSetValidationErrorMethodName(template.getSetValidationErrorMethodName());
jsonNode.setGetViewValueMethodName(template.getPullViewContentMethodName());
jsonNode.setViewRepresentation((JSONViewContent) wizardNode.getViewRepresentation());
jsonNode.setViewValue((JSONViewContent) wizardNode.getViewValue());
}
jsonNode.setNodeInfo(info);
nodes.put(e.getKey().toString(), jsonNode);
}
return new JSONWebNodePage(pageConfig, nodes);
}
use of org.knime.core.node.web.WebTemplate in project knime-core by knime.
the class WizardNodeView method retrieveCurrentValueFromView.
/**
* {@inheritDoc}
*/
@Override
protected String retrieveCurrentValueFromView() {
WizardViewCreator<REP, VAL> creator = getViewCreator();
WebTemplate template = creator.getWebTemplate();
String pullMethod = template.getPullViewContentMethodName();
String ns = creator.getNamespacePrefix();
String jsonString = null;
if (ns != null && !ns.isEmpty() && pullMethod != null && !pullMethod.isEmpty()) {
String evalCode = creator.wrapInTryCatch("if (typeof " + ns.substring(0, ns.length() - 1) + " != 'undefined') { return JSON.stringify(" + ns + pullMethod + "());}");
jsonString = (String) m_browser.evaluate(evalCode);
}
return jsonString;
}
use of org.knime.core.node.web.WebTemplate in project knime-core by knime.
the class WizardNodeView method validateCurrentValueInView.
/**
* {@inheritDoc}
*/
@Override
protected boolean validateCurrentValueInView() {
boolean valid = true;
WizardViewCreator<REP, VAL> creator = getViewCreator();
WebTemplate template = creator.getWebTemplate();
String validateMethod = template.getValidateMethodName();
if (validateMethod != null && !validateMethod.isEmpty()) {
String evalCode = creator.wrapInTryCatch("return JSON.stringify(" + creator.getNamespacePrefix() + validateMethod + "());");
String jsonString = (String) m_browser.evaluate(evalCode);
valid = Boolean.parseBoolean(jsonString);
}
return valid;
}
use of org.knime.core.node.web.WebTemplate in project knime-core by knime.
the class WizardNodeView method showValidationErrorInView.
/**
* {@inheritDoc}
*/
@Override
protected void showValidationErrorInView(final String error) {
WizardViewCreator<REP, VAL> creator = getViewCreator();
WebTemplate template = creator.getWebTemplate();
String showErrorMethod = template.getSetValidationErrorMethodName();
String escapedError = error.replace("\\", "\\\\").replace("'", "\\'").replace("\n", " ");
String showErrorCall = creator.wrapInTryCatch(creator.getNamespacePrefix() + showErrorMethod + "('" + escapedError + "');");
m_browser.execute(showErrorCall);
}
Aggregations