use of org.knime.core.node.workflow.NodeContainerState 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.workflow.NodeContainerState in project knime-core by knime.
the class WorkflowEditor method saveTo.
/**
* Save workflow to resource.
*
* @param fileResource .. the resource, usually m_fileResource or m_autoSaveFileResource or soon-to-be
* m_fileResource (for save-as)
* @param monitor ...
* @param saveWithData ... save data also
* @param newContext a new workflow context for the saved workflow; if this is non-<code>null</code>, a "save as" is
* performed
*/
private void saveTo(final URI fileResource, final IProgressMonitor monitor, final boolean saveWithData, final WorkflowContext newContext) {
LOGGER.debug("Saving workflow " + getWorkflowManager().get().getNameWithID());
// Exception messages from the inner thread
final StringBuilder exceptionMessage = new StringBuilder();
if (fileResource == null && m_parentEditor != null) {
m_parentEditor.doSave(monitor);
m_isDirty = false;
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
firePropertyChange(IEditorPart.PROP_DIRTY);
}
});
return;
}
// attach editor properties with the workflow manager - for all sub editors too
saveEditorSettingsToWorkflowManager();
/* TODO: EditorSettings should be saved on all child editors too. But this triggers them dirty. And they stay
* dirty even after save (and setting them clean!). The dirty flag is a mess. Needs to be cleaned up!
* And after that, we may not inherit the zoom level (in metanodes) from the parent anymore
* (see #applyEditorSettingsFromWorkflowManager).
* for (IEditorPart subEditor : getSubEditors()) {
* ((WorkflowEditor)subEditor).saveEditorSettingsToWorkflowManager();
* }
*/
// to be sure to mark dirty and inform the user about running nodes
// we ask for the state BEFORE saving
// this flag is evaluated at the end of this method
boolean wasInProgress = false;
try {
final File workflowDir = new File(fileResource);
AbstractSaveRunnable saveRunnable;
if (newContext != null) {
saveRunnable = new SaveAsRunnable(this, exceptionMessage, monitor, newContext);
} else {
WorkflowSaveHelper saveHelper = new WorkflowSaveHelper(saveWithData, false);
saveRunnable = new InplaceSaveRunnable(this, exceptionMessage, saveHelper, monitor, workflowDir);
}
IWorkbench wb = PlatformUI.getWorkbench();
IProgressService ps = wb.getProgressService();
NodeContainerState state = m_manager.getNodeContainerState();
wasInProgress = state.isExecutionInProgress() && !state.isExecutingRemotely();
ps.run(true, false, saveRunnable);
// this code is usually (always?) run in the UI thread but in case it's not we schedule in UI thread
// (SVG export always in UI thread)
final File svgFile = new File(workflowDir, WorkflowPersistor.SVG_WORKFLOW_FILE);
svgFile.delete();
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
if (m_manager.isProject()) {
saveSVGImage(svgFile);
}
}
});
// mark command stack (no undo beyond this point)
getCommandStack().markSaveLocation();
} catch (Exception e) {
LOGGER.error("Could not save workflow: " + exceptionMessage, e);
// inform the user
if (exceptionMessage.length() > 0) {
showInfoMessage("Workflow could not be saved ...", exceptionMessage.toString());
}
throw new OperationCanceledException("Workflow was not saved: " + exceptionMessage.toString());
}
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (!Display.getDefault().isDisposed() && (m_manager != null)) {
// mark all sub editors as saved
for (IEditorPart subEditor : getSubEditors()) {
final WorkflowEditor editor = (WorkflowEditor) subEditor;
((WorkflowEditor) subEditor).setIsDirty(false);
editor.firePropertyChange(IEditorPart.PROP_DIRTY);
}
}
}
});
monitor.done();
// or simply saves (Ctrl+S)
if (wasInProgress) {
markDirty();
final Pointer<Boolean> abortPointer = new Pointer<Boolean>();
abortPointer.set(Boolean.FALSE);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
boolean abort = false;
Shell sh = Display.getDefault().getActiveShell();
String title = "Workflow in execution";
String message = "Executing nodes are not saved!";
if (m_isClosing) {
abort = !MessageDialog.openQuestion(sh, title, message + " Exit anyway?");
// user canceled close
m_isClosing = !abort;
} else {
IPreferenceStore prefStore = KNIMEUIPlugin.getDefault().getPreferenceStore();
String toogleMessage = "Don't warn me again";
if (prefStore.getBoolean(PreferenceConstants.P_CONFIRM_EXEC_NODES_NOT_SAVED)) {
MessageDialogWithToggle.openInformation(sh, title, message, toogleMessage, false, prefStore, PreferenceConstants.P_CONFIRM_EXEC_NODES_NOT_SAVED);
}
}
abortPointer.set(Boolean.valueOf(abort));
}
});
if (abortPointer.get()) {
throw new OperationCanceledException("Closing workflow canceled on user request.");
}
}
}
use of org.knime.core.node.workflow.NodeContainerState in project knime-core by knime.
the class SubworkflowFigure method setStateFromNC.
/**
* {@inheritDoc}
* Only reflects three different states: idle, executing, executed.
*/
@Override
public void setStateFromNC(final NodeContainerUI nc) {
NodeContainerState state = nc.getNodeContainerState();
Image image;
if (state.isExecuted()) {
image = EXECUTED_STATE;
} else if (state.isExecutionInProgress()) {
image = EXECUTING_STATE;
} else {
image = IDLE_STATE;
}
((NodeContainerFigure.SymbolFigure) getSymbolFigure()).setIcon(image);
revalidate();
}
Aggregations