diff options
author | Christian W. Damus | 2013-10-10 15:54:39 +0000 |
---|---|---|
committer | Christian W. Damus | 2013-10-10 15:54:39 +0000 |
commit | 5e28ce8977b3dc20201e246dcf463ce149811355 (patch) | |
tree | b4ac59e1af78b3fe4fc45b3ebe0f33e98c87b1a6 | |
parent | bb411ffa1e3f263c6ce42687359cca331b075bad (diff) | |
download | org.eclipse.uml2-5e28ce8977b3dc20201e246dcf463ce149811355.tar.gz org.eclipse.uml2-5e28ce8977b3dc20201e246dcf463ce149811355.tar.xz org.eclipse.uml2-5e28ce8977b3dc20201e246dcf463ce149811355.zip |
[268444] Update ApplyStereotypeAction to select a resource locationbugs/268444
https://bugs.eclipse.org/bugs/show_bug.cgi?id=268444
Address code review comments on commit a5da73c.
- fix exception on attempt to load newly created resource
- fix exception on attempt to refresh disposed viewer when
closing the UML editor
2 files changed, 104 insertions, 78 deletions
diff --git a/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/actions/ApplyStereotypeAction.java b/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/actions/ApplyStereotypeAction.java index 52b3106d6..27d92a066 100644 --- a/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/actions/ApplyStereotypeAction.java +++ b/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/actions/ApplyStereotypeAction.java @@ -410,6 +410,12 @@ public class ApplyStereotypeAction .createResource( selectedURI, ContentHandler.UNSPECIFIED_CONTENT_TYPE); + if (resource != null) { + // poke the new resource to mark it as + // loaded so that we won't attempt to + // load it from non-existent storage + resource.getContents().clear(); + } } } catch (Exception e) { MessageDialog diff --git a/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/presentation/UMLEditor.java b/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/presentation/UMLEditor.java index 6580c9e6b..4a56e855d 100644 --- a/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/presentation/UMLEditor.java +++ b/plugins/org.eclipse.uml2.uml.editor/src/org/eclipse/uml2/uml/editor/presentation/UMLEditor.java @@ -30,6 +30,7 @@ import org.eclipse.emf.common.util.BasicDiagnostic; import org.eclipse.emf.common.util.Diagnostic; import org.eclipse.emf.common.util.TreeIterator; +import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notification; @@ -592,6 +593,95 @@ public class UMLEditor } }; + // an adapter that reacts to load/unload of resources that may contain + // stereotype applications to update the elements that they extend + private Adapter stereotypeApplicationsResourceAdapter = new AdapterImpl() { + + private volatile Runnable pendingRefresh; + + @Override + public void notifyChanged(Notification msg) { + if (!msg.isTouch() && (getViewer() != null) + && !getViewer().getControl().isDisposed()) { + if (msg.getNotifier() instanceof Resource) { + if (msg.getFeatureID(Resource.class) == Resource.RESOURCE__IS_LOADED) { + refreshViewer(); + } + } else if (msg.getNotifier() instanceof ResourceSet) { + if (msg.getFeatureID(ResourceSet.class) == ResourceSet.RESOURCE_SET__RESOURCES) { + switch (msg.getEventType()) { + case Notification.ADD : + handleResource((Resource) msg.getNewValue()); + break; + case Notification.ADD_MANY : + for (Object next : (Iterable<?>) msg + .getNewValue()) { + handleResource((Resource) next); + } + break; + case Notification.SET : + if (msg.getNewValue() != null) { + handleResource((Resource) msg.getNewValue()); + } + break; + } + } + } + } + } + + private void handleResource(Resource resource) { + if (!resource.eAdapters().contains(this)) { + resource.eAdapters().add(this); + } + + if (resource.isLoaded()) { + // already loaded? Refresh now + refreshViewer(); + } + } + + private void refreshViewer() { + if ((pendingRefresh == null) && (currentViewer != null) + && (currentViewer.getControl() != null)) { + + Runnable refreshRunnable = new Runnable() { + + public void run() { + pendingRefresh = null; + if (!currentViewer.getControl().isDisposed()) { + currentViewer.refresh(); + } + } + }; + currentViewer.getControl().getDisplay() + .asyncExec(refreshRunnable); + pendingRefresh = refreshRunnable; + } + } + + @Override + public void setTarget(Notifier newTarget) { + super.setTarget(newTarget); + + if (newTarget instanceof ResourceSet) { + // listen for resource unload/load + for (Resource next : ((ResourceSet) newTarget).getResources()) { + next.eAdapters().add(this); + } + } + } + + @Override + public void unsetTarget(Notifier oldTarget) { + if (oldTarget instanceof ResourceSet) { + for (Resource next : ((ResourceSet) oldTarget).getResources()) { + next.eAdapters().remove(this); + } + } + } + }; + /** * Handles activation of the editor or it's associated views. * @generated @@ -1061,84 +1151,7 @@ public class UMLEditor // listen for loading of new resources, to refresh in case they bring in // new stereotype applications (and unloading to remove them) - resourceSet.eAdapters().add(new AdapterImpl() { - - private volatile Runnable pendingRefresh; - - @Override - public void notifyChanged(Notification msg) { - if (!msg.isTouch()) { - if (msg.getNotifier() instanceof Resource) { - if (msg.getFeatureID(Resource.class) == Resource.RESOURCE__IS_LOADED) { - refreshViewer(); - } - } else if (msg.getNotifier() instanceof ResourceSet) { - if (msg.getFeatureID(ResourceSet.class) == ResourceSet.RESOURCE_SET__RESOURCES) { - switch (msg.getEventType()) { - case Notification.ADD : - handleResource((Resource) msg.getNewValue()); - break; - case Notification.ADD_MANY : - for (Object next : (Iterable<?>) msg - .getNewValue()) { - handleResource((Resource) next); - } - break; - case Notification.SET : - if (msg.getNewValue() != null) { - handleResource((Resource) msg - .getNewValue()); - } - break; - } - } - } - } - } - - private void handleResource(Resource resource) { - if (!resource.eAdapters().contains(this)) { - resource.eAdapters().add(this); - } - - if (resource.isLoaded()) { - // already loaded? Refresh now - refreshViewer(); - } - } - - private void refreshViewer() { - if ((pendingRefresh == null) && (currentViewer != null) - && (currentViewer.getControl() != null)) { - - Runnable refreshRunnable = new Runnable() { - - public void run() { - pendingRefresh = null; - if (!currentViewer.getControl().isDisposed()) { - currentViewer.refresh(); - } - } - }; - currentViewer.getControl().getDisplay() - .asyncExec(refreshRunnable); - pendingRefresh = refreshRunnable; - } - } - - @Override - public void setTarget(Notifier newTarget) { - super.setTarget(newTarget); - - if (newTarget instanceof ResourceSet) { - // listen for resource unload/load - for (Resource next : ((ResourceSet) newTarget) - .getResources()) { - next.eAdapters().add(this); - } - } - } - }); + resourceSet.eAdapters().add(stereotypeApplicationsResourceAdapter); } /** @@ -1934,6 +1947,13 @@ public class UMLEditor @Override public void dispose() { + if (stereotypeApplicationsResourceAdapter != null + && editingDomain != null) { + + editingDomain.getResourceSet().eAdapters() + .remove(stereotypeApplicationsResourceAdapter); + } + if (commandStackListener != null && editingDomain != null) { editingDomain.getCommandStack().removeCommandStackListener( commandStackListener); |