Skip to content
Snippets Groups Projects
Commit 233116a3 authored by Simon Barner's avatar Simon Barner
Browse files

- Add AnnotationViewPartBase.setUpdateEnabled() and .isUpdateEnabled() that...

- Add AnnotationViewPartBase.setUpdateEnabled() and .isUpdateEnabled() that allows to control if AnnotationView is updated
parent 98da7829
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,9 @@ import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParent ...@@ -24,7 +24,9 @@ import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getParent
import java.util.Collection; import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.eclipse.emf.common.notify.Adapter; import org.eclipse.emf.common.notify.Adapter;
...@@ -85,6 +87,18 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect ...@@ -85,6 +87,18 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
/** Flag to prevent nested calls of {@link #selectionChanged(IWorkbenchPart, ISelection)}. */ /** Flag to prevent nested calls of {@link #selectionChanged(IWorkbenchPart, ISelection)}. */
private boolean processingSectionChanged = false; private boolean processingSectionChanged = false;
/** Flag if update of {@link AnnotationViewPartBase} views is enabled. */
private static boolean isUpdateEnabled = true;
/** Active instances of {@link AnnotationViewPartBase} views. */
private static Set<AnnotationViewPartBase> activeInstances =
new HashSet<AnnotationViewPartBase>();
/** Constructs a new {@link AnnotationViewPartBase}. */
public AnnotationViewPartBase() {
activeInstances.add(this);
}
/** /**
* {@link Adapter} to watch for the addition, removal or value change of model elements * {@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 * to/from/in elements visible in this {@link AnnotationViewPartBase} (to trigger according
...@@ -94,6 +108,10 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect ...@@ -94,6 +108,10 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void notifyChanged(Notification notification) { public void notifyChanged(Notification notification) {
if(!isUpdateEnabled) {
return;
}
// Required to actually watch child elements (behavior of EContentAdapter) // Required to actually watch child elements (behavior of EContentAdapter)
super.notifyChanged(notification); super.notifyChanged(notification);
...@@ -198,7 +216,8 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect ...@@ -198,7 +216,8 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
*/ */
private void addAnnotationEntry(Collection<AnnotationEntry> annotationEntries, private void addAnnotationEntry(Collection<AnnotationEntry> annotationEntries,
IModelElement modelElement) { IModelElement modelElement) {
AnnotationEntry entry = IAnnotationValueService.getInstance().getAnnotationEntry(modelElement); AnnotationEntry entry =
IAnnotationValueService.getInstance().getAnnotationEntry(modelElement);
if(!entry.isEmpty()) { if(!entry.isEmpty()) {
annotationEntries.add(entry); annotationEntries.add(entry);
...@@ -266,6 +285,9 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect ...@@ -266,6 +285,9 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
/** Update concrete view */ /** Update concrete view */
protected abstract void update(Collection<AnnotationEntry> annotationEntries); protected abstract void update(Collection<AnnotationEntry> annotationEntries);
/** Triggers an update of the view to refresh its last state. */
public abstract void update();
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void createPartControl(Composite parent) { public void createPartControl(Composite parent) {
...@@ -280,7 +302,7 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect ...@@ -280,7 +302,7 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void dispose() { public synchronized void dispose() {
// Unregister listeners // Unregister listeners
getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this); getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this);
if(watchedElement != null) { if(watchedElement != null) {
...@@ -289,5 +311,27 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect ...@@ -289,5 +311,27 @@ public abstract class AnnotationViewPartBase extends ViewPart implements ISelect
} }
super.dispose(); super.dispose();
activeInstances.remove(this);
}
/** Sets {@link #isUpdateEnabled}. If the update is re-enabled, the view is refreshed. */
public static synchronized void setUpdateEnabled(boolean isUpdateEnabled) {
AnnotationViewPartBase.isUpdateEnabled = isUpdateEnabled;
if(isUpdateEnabled) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
for(AnnotationViewPartBase avp : activeInstances) {
avp.update();
}
}
});
}
}
/** Returns {@link #isUpdateEnabled}. */
public synchronized static boolean isUpdateEnabled() {
return isUpdateEnabled;
} }
} }
...@@ -156,7 +156,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -156,7 +156,8 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
return annotationFilter; return annotationFilter;
} }
/** Updates the table after a filter change */ /** {@inheritDoc} */
@Override
public void update() { public void update() {
// Full update, i.e. including reconstructions of columns is always required due to the // Full update, i.e. including reconstructions of columns is always required due to the
// following scenario: // following scenario:
...@@ -164,6 +165,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -164,6 +165,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
// - Filter scope is changed to component names -> annotation filter needs to be undone // - Filter scope is changed to component names -> annotation filter needs to be undone
// - Filter is based on annotation entry type // - Filter is based on annotation entry type
// - Filter is set to current level / current sub model // - Filter is set to current level / current sub model
// - Update of view as been disabled using setUpdateEnable(boolean) is re-enabled now
if(lastAnnotationEntries != null) { if(lastAnnotationEntries != null) {
update(lastAnnotationEntries); update(lastAnnotationEntries);
} }
...@@ -172,6 +174,10 @@ public class GenericAnnotationView extends AnnotationViewPartBase { ...@@ -172,6 +174,10 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected void update(Collection<AnnotationEntry> annotationEntries) { protected void update(Collection<AnnotationEntry> annotationEntries) {
if(!isUpdateEnabled()) {
return;
}
// Update row filter with currently selected element // Update row filter with currently selected element
annotationFilter.setCurrentySelectedModelElement(getCurrentlySelectedObject()); annotationFilter.setCurrentySelectedModelElement(getCurrentlySelectedObject());
boolean contentRequiresUpdate = boolean contentRequiresUpdate =
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment