Search in sources :

Example 1 with ModelStatus

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);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IFile(org.eclipse.core.resources.IFile) IEditorPart(org.eclipse.ui.IEditorPart) IProject(org.eclipse.core.resources.IProject) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ModelStatus(org.eclipse.core.resources.mapping.ModelStatus) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Aggregations

IFile (org.eclipse.core.resources.IFile)1 IProject (org.eclipse.core.resources.IProject)1 IResourceDelta (org.eclipse.core.resources.IResourceDelta)1 ModelStatus (org.eclipse.core.resources.mapping.ModelStatus)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1