Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
af3
kernel
Commits
b3c69067
Commit
b3c69067
authored
10 years ago
by
Simon Barner
Browse files
Options
Downloads
Patches
Plain Diff
- Use EContentAdapter instead of manual management of non-recursive AdapterImpl
refs 1841
parent
0888161d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java
+18
-43
18 additions, 43 deletions
...oling/base/ui/annotation/view/AnnotationViewPartBase.java
with
18 additions
and
43 deletions
org.fortiss.tooling.base.ui/trunk/src/org/fortiss/tooling/base/ui/annotation/view/AnnotationViewPartBase.java
+
18
−
43
View file @
b3c69067
...
...
@@ -19,14 +19,13 @@ package org.fortiss.tooling.base.ui.annotation.view;
import
java.util.Collection
;
import
java.util.Comparator
;
import
java.util.HashSet
;
import
java.util.Set
;
import
java.util.TreeSet
;
import
org.eclipse.emf.common.notify.Adapter
;
import
org.eclipse.emf.common.notify.Notification
;
import
org.eclipse.emf.common.notify.impl.AdapterImpl
;
import
org.eclipse.emf.ecore.EObject
;
import
org.eclipse.emf.ecore.util.EContentAdapter
;
import
org.eclipse.gef.editparts.AbstractGraphicalEditPart
;
import
org.eclipse.jface.viewers.ISelection
;
import
org.eclipse.swt.widgets.Composite
;
...
...
@@ -59,19 +58,22 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
private
IModelElement
currentlySelectedObject
;
/**
*
Set of {@link IModelE
lement
}s
for which the {@link #changeListener} has been installed to
*
Root e
lement for which the {@link #changeListener} has been installed to
(recursively)
* watch for model changes (to trigger an update of this {@link AnnotationViewPartBase}).
*/
Set
<
EObject
>
watched
Model
Element
s
=
new
HashSet
<
EObject
>()
;
EObject
watchedElement
;
/**
* {@link Adapter} to watch for the addition, removal or value change of model elements
* to/from/in elements visible in this {@link AnnotationViewPartBase} (to trigger according
* updates).
*/
private
final
Adapter
changeListener
=
new
AdapterImpl
()
{
private
final
Adapter
changeListener
=
new
EContentAdapter
()
{
/** {@inheritDoc} */
@Override
public
void
notifyChanged
(
Notification
notification
)
{
super
.
notifyChanged
(
notification
);
if
(
notification
.
getEventType
()
==
Notification
.
ADD
||
notification
.
getEventType
()
==
Notification
.
REMOVE
||
notification
.
getEventType
()
==
Notification
.
SET
)
{
...
...
@@ -113,38 +115,6 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
}
}
/** Update registration of model listeners. */
private
void
updateChangeListener
(
EObject
rootElement
)
{
// Determine all IModelElements, and their specifications below the current root elements.
// Specifications must be watched, too, since the state of an editing support for a given
// specification can depend on the state of one or more other specifications.
Set
<
EObject
>
currentWatchedModelElements
=
new
HashSet
<
EObject
>();
for
(
EObject
modelElement
:
EcoreUtils
.
getChildrenWithType
(
rootElement
,
IModelElement
.
class
))
{
currentWatchedModelElements
.
add
(
modelElement
);
currentWatchedModelElements
.
addAll
(((
IModelElement
)
modelElement
).
getSpecifications
());
}
if
(
rootElement
instanceof
IModelElement
)
{
currentWatchedModelElements
.
add
(
rootElement
);
currentWatchedModelElements
.
addAll
(((
IModelElement
)
rootElement
).
getSpecifications
());
}
// Add change listeners to IModelElements that are about to appear in the view
Set
<
EObject
>
tmpWatchedModelElements
=
new
HashSet
<
EObject
>(
currentWatchedModelElements
);
tmpWatchedModelElements
.
removeAll
(
watchedModelElements
);
for
(
EObject
modelElement
:
tmpWatchedModelElements
)
{
modelElement
.
eAdapters
().
add
(
changeListener
);
}
// Remove change listeners IModelElements that are about to disappear from the view
tmpWatchedModelElements
=
new
HashSet
<
EObject
>(
watchedModelElements
);
tmpWatchedModelElements
.
removeAll
(
currentWatchedModelElements
);
for
(
EObject
modelElement
:
tmpWatchedModelElements
)
{
modelElement
.
eAdapters
().
remove
(
changeListener
);
}
watchedModelElements
=
currentWatchedModelElements
;
}
/**
* Update the {@link AnnotationViewPartBase}: delegate update of concrete view to
* {@link #update(Collection)}, and update model change listeners.
...
...
@@ -181,9 +151,15 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
annotationEntries
.
addAll
(
IAnnotationValueService
.
INSTANCE
.
getValues
(
childModelElement
));
}
// Update the view
and change listener registration
// Update the view
...
update
(
annotationEntries
);
updateChangeListener
(
rootElement
);
// ... and change listener registration
if
(
watchedElement
!=
null
)
{
watchedElement
.
eAdapters
().
remove
(
changeListener
);
}
watchedElement
=
rootElement
;
watchedElement
.
eAdapters
().
add
(
changeListener
);
}
/** Update concrete view */
...
...
@@ -205,11 +181,10 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
@Override
public
void
dispose
()
{
getSite
().
getWorkbenchWindow
().
getSelectionService
().
removeSelectionListener
(
this
);
for
(
EObject
modelElement
:
watchedModelElements
)
{
modelElement
.
eAdapters
().
remove
(
changeListener
)
;
if
(
watchedElement
!=
null
)
{
watchedElement
.
eAdapters
().
remove
(
changeListener
);
watchedElement
=
null
;
}
watchedModelElements
.
clear
();
super
.
dispose
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment