Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuergen Haug2017-04-19 04:10:12 -0400
committerJuergen Haug2017-08-02 04:46:39 -0400
commit9f7b0a9d010b50f8455b9f478b7095f28183255d (patch)
tree42771f76c739f744e6042f1597879950d3a004d9
parentfb37813c37540fa744ddbb7bd6b3e040390de1f6 (diff)
downloadorg.eclipse.etrice-9f7b0a9d010b50f8455b9f478b7095f28183255d.tar.gz
org.eclipse.etrice-9f7b0a9d010b50f8455b9f478b7095f28183255d.tar.xz
org.eclipse.etrice-9f7b0a9d010b50f8455b9f478b7095f28183255d.zip
[ui] more robust SuperClassListener
-rw-r--r--plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SuperClassListener.java67
1 files changed, 36 insertions, 31 deletions
diff --git a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SuperClassListener.java b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SuperClassListener.java
index 61cac5f7d..20741c198 100644
--- a/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SuperClassListener.java
+++ b/plugins/org.eclipse.etrice.ui.common.base/src/org/eclipse/etrice/ui/common/base/editor/SuperClassListener.java
@@ -39,32 +39,34 @@ public class SuperClassListener implements IPartListener, ResourceSetListener, I
private List<TransactionalEditingDomain> domains;
private List<IXtextDocument> xtextDocuments;
private boolean changeInSuperClass;
-
+
public SuperClassListener(DiagramEditorBase diagramEditor, Object editorClass) {
this.diagramEditor = diagramEditor;
this.editorClass = editorClass;
domains = new ArrayList<TransactionalEditingDomain>();
xtextDocuments = new ArrayList<IXtextDocument>();
changeInSuperClass = false;
-
- assert(editorClass instanceof Class) : "Class expected";
+
+ assert (editorClass instanceof Class) : "Class expected";
}
-
+
public boolean isChangeInSuperClass() {
return changeInSuperClass;
}
- public void dispose(){
- for(TransactionalEditingDomain domain : domains){
- if(domain != null)
+ public void dispose() {
+ for (TransactionalEditingDomain domain : domains) {
+ if (domain != null)
domain.removeResourceSetListener(this);
}
- for(IXtextDocument document : xtextDocuments){
- if(document != null)
+ for (IXtextDocument document : xtextDocuments) {
+ if (document != null)
document.removeModelListener(this);
}
+ domains.clear();
+ xtextDocuments.clear();
}
-
+
// ---
// IPartListener
// ---
@@ -81,18 +83,22 @@ public class SuperClassListener implements IPartListener, ResourceSetListener, I
@Override
public void partClosed(IWorkbenchPart part) {
- if(part instanceof DiagramEditorBase){
- DiagramEditorBase editor = (DiagramEditorBase)part;
+ if (part == diagramEditor) {
+ dispose();
+ return;
+ }
+
+ if (part instanceof DiagramEditorBase) {
+ DiagramEditorBase editor = (DiagramEditorBase) part;
TransactionalEditingDomain toRemove = editor.getEditingDomain();
- if(toRemove != null){
+ if (toRemove != null) {
toRemove.removeResourceSetListener(this);
domains.remove(toRemove);
}
}
-
- if (((Class<?>)editorClass).isInstance(part)) {
+ if (((Class<?>) editorClass).isInstance(part)) {
IXtextDocument toRemove = ((XtextEditor) part).getDocument();
- if(toRemove != null){
+ if (toRemove != null) {
toRemove.removeModelListener(this);
xtextDocuments.remove(toRemove);
}
@@ -101,43 +107,43 @@ public class SuperClassListener implements IPartListener, ResourceSetListener, I
@Override
public void partDeactivated(IWorkbenchPart part) {
- if(part == diagramEditor)
+ if (part == diagramEditor)
changeInSuperClass = false;
}
@Override
public void partOpened(IWorkbenchPart part) {
// initial
- if(part==diagramEditor){
+ if (part == diagramEditor) {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
for (IEditorReference editorRef : activePage.getEditorReferences()) {
IEditorPart editor = editorRef.getEditor(false);
- if (editor != null && editor!=diagramEditor)
+ if (editor != null && editor != diagramEditor)
partOpened(editor);
}
return;
}
-
- if(part instanceof DiagramEditorBase){
- DiagramEditorBase editor = (DiagramEditorBase)part;
+
+ if (part instanceof DiagramEditorBase) {
+ DiagramEditorBase editor = (DiagramEditorBase) part;
TransactionalEditingDomain domain = editor.getEditingDomain();
- if(!domains.contains(domain) && diagramEditor.registerSuperClassListener(editor)){
+ if (!domains.contains(domain) && diagramEditor.registerSuperClassListener(editor)) {
domain.addResourceSetListener(this);
domains.add(domain);
}
}
-
- if (((Class<?>)editorClass).isInstance(part)) {
+
+ if (((Class<?>) editorClass).isInstance(part)) {
XtextEditor editor = (XtextEditor) part;
IXtextDocument document = editor.getDocument();
-
- if(!xtextDocuments.contains(document) && diagramEditor.registerSuperClassListener(editor)){
+
+ if (!xtextDocuments.contains(document) && diagramEditor.registerSuperClassListener(editor)) {
editor.getDocument().addModelListener(this);
xtextDocuments.add(document);
}
}
}
-
+
// ---
// ResourceSetListener
// ---
@@ -148,8 +154,7 @@ public class SuperClassListener implements IPartListener, ResourceSetListener, I
}
@Override
- public Command transactionAboutToCommit(ResourceSetChangeEvent event)
- throws RollbackException {
+ public Command transactionAboutToCommit(ResourceSetChangeEvent event) throws RollbackException {
return null;
}
@@ -173,7 +178,7 @@ public class SuperClassListener implements IPartListener, ResourceSetListener, I
public boolean isPostcommitOnly() {
return true;
}
-
+
// ---
// IXtextModelListener
// ---

Back to the top