use of org.eclipse.core.resources.mapping.ModelStatus in project knime-core by knime.
the class MoveModelProvider method validateChange.
/**
* Checks if a KNIIME workflow project is intended to be renamed. The reason
* is, that at the moment the KNIME core saves an absolute path for storage
* reasons. If renamed save actions would fail.
*
* @see org.eclipse.core.resources.mapping.ModelProvider#
* validateChange(org.eclipse.core.resources.IResourceDelta,
* org.eclipse.core.runtime.IProgressMonitor)
*/
@Override
public IStatus validateChange(final IResourceDelta delta, final IProgressMonitor monitor) {
try {
// check whether this is a knime project
IProject project = null;
IFile workflowFile = null;
for (IResourceDelta affectedChild : delta.getAffectedChildren()) {
project = affectedChild.getResource().getProject();
workflowFile = project.getFile(WorkflowPersistor.WORKFLOW_FILE);
// break if we found the project with a knime workflow
if (workflowFile.exists()) {
break;
}
}
// check whether this is a move delta
IResourceDelta[] deltas = delta.getAffectedChildren();
boolean moveAction = false;
for (IResourceDelta curDelta : deltas) {
if ((curDelta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
moveAction = true;
break;
}
}
if (workflowFile.exists() && moveAction) {
// check if an editor is opened on this resource
boolean editorOpen = false;
IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows();
for (IWorkbenchWindow window : windows) {
IWorkbenchPage[] pages = window.getPages();
for (IWorkbenchPage page : pages) {
IEditorPart editorPart = page.findEditor(new FileEditorInput(workflowFile));
if (editorPart != null) {
editorOpen = true;
break;
}
}
}
if (editorOpen) {
return new ModelStatus(IStatus.WARNING, ResourcesPlugin.PI_RESOURCES, getModelProviderId(), "Renaming " + project.getName() + " may have undesirable side effects " + "since this workflow is currently open." + " You may loose some or all of your " + "data if you continue (although the " + "settings will" + " not be affected). Consider closing the " + "workflow before renaming it.");
}
}
} catch (Exception e) {
// do nothing
}
// else performe the default behavior
return super.validateChange(delta, monitor);
}
Aggregations