Skip to content

Commit

Permalink
TEIIDDES-2349 added checks when processing project REMOVE/MOVE events to
Browse files Browse the repository at this point in the history
prevent reloading of diagram editor for closed or removed model.
  • Loading branch information
blafond committed Dec 9, 2014
1 parent fe72e50 commit 7d98eb7
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
Expand Down Expand Up @@ -1357,16 +1358,40 @@ public void run() {
refreshDiagramSafe();
} // endif -- diagram not null
} else if (stillValid && eventType == ModelResourceEvent.CHANGED) // Check Readonly status
updateReadOnlyState();
updateReadOnlyState();
else if (stillValid && eventType == ModelResourceEvent.ADDED) {
// file should not be represented in the diagram, since it is new.
// how do we find if we need to refresh?
} else if (stillValid && (eventType == ModelResourceEvent.REMOVED || eventType == ModelResourceEvent.MOVED)) // if moved or
// removed:
if (currentDiagram != null) {
final IDiagramType idt = DiagramUiPlugin.getDiagramTypeManager().getDiagram(currentDiagram.getType());
if (idt.dependsOnResource(currentModel, event.getResource())) // redisplay contents:
refreshDiagramSafe();
} else if (stillValid && (eventType == ModelResourceEvent.REMOVED || eventType == ModelResourceEvent.MOVED)) { // if moved or removed:
if (currentDiagram != null) {
final ModelResource editorMR = ModelUtilities.getModelResourceForModelObject(getDiagram());

// During Project and model closing or deleting, the open model editor may be "stale", so if NOT OPEN, then just return since
// The editor should close
if( ! editorMR.isOpen() ) {
return;
}

// If we get here, check if removed project that the project is the same project as the open model's project
if( event.getResource() instanceof IProject ) {
IProject eventProj = (IProject)event.getResource();
// get resource from diagram.
IProject editorProject = ModelUtilities.getProject(editorMR);

if( editorProject == eventProj) {
return;
}
}

// If we get here do a refresh if there's a dependency
final IDiagramType idt = DiagramUiPlugin.getDiagramTypeManager().getDiagram(currentDiagram.getType());
// Note the following dependsOntResource() will re-load/register EMF resources, so need make sure (above) that the model/resource
// isn't being removed

if (idt.dependsOnResource(currentModel, event.getResource())) {
refreshDiagramSafe(); // redisplay contents:
}
}
} // endif -- diagram not null
}

Expand Down

0 comments on commit 7d98eb7

Please sign in to comment.