Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrescobar2010-09-28 15:38:42 -0400
committerRyan D. Brooks2010-09-28 15:38:42 -0400
commita2a8552849527f522ca5ccfe4af4ca2c74f09047 (patch)
treeb1c181f6f4906bcec66e2183638c6a052732178f /plugins
parent5421a31419268921bd9d9a8f1dc256e7cce03ae4 (diff)
downloadorg.eclipse.osee-a2a8552849527f522ca5ccfe4af4ca2c74f09047.tar.gz
org.eclipse.osee-a2a8552849527f522ca5ccfe4af4ca2c74f09047.tar.xz
org.eclipse.osee-a2a8552849527f522ca5ccfe4af4ca2c74f09047.zip
bug: Fix WorldXViewerEventManager errors0.9.6.v201009281413_RC
Fix static class initialization Fix thread safety issues Improve performance of artifact event handling
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewerEventManager.java204
1 files changed, 113 insertions, 91 deletions
diff --git a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewerEventManager.java b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewerEventManager.java
index 890fcd3c8c..dc4901ac9c 100644
--- a/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewerEventManager.java
+++ b/plugins/org.eclipse.osee.ats/src/org/eclipse/osee/ats/world/WorldXViewerEventManager.java
@@ -10,7 +10,6 @@
*******************************************************************************/
package org.eclipse.osee.ats.world;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -37,117 +36,140 @@ import org.eclipse.osee.framework.ui.swt.Displays;
*
* @author Donald G. Dunne
*/
-public class WorldXViewerEventManager implements IArtifactEventListener {
+public class WorldXViewerEventManager {
- List<IWorldViewerEventHandler> handlers = new ArrayList<IWorldViewerEventHandler>();
- static WorldXViewerEventManager instance = new WorldXViewerEventManager();
+ private static final NotificationHandler notificationHandler = new NotificationHandler();
- public WorldXViewerEventManager() {
- OseeEventManager.addListener(this);
+ private WorldXViewerEventManager() {
+ // Static API Class
}
public static void add(IWorldViewerEventHandler iWorldEventHandler) {
- instance.handlers.add(iWorldEventHandler);
+ notificationHandler.add(iWorldEventHandler);
}
public static void remove(IWorldViewerEventHandler iWorldEventHandler) {
- instance.handlers.remove(iWorldEventHandler);
+ notificationHandler.remove(iWorldEventHandler);
}
- @Override
- public void handleArtifactEvent(final ArtifactEvent artifactEvent, Sender sender) {
- for (IWorldViewerEventHandler handler : new CopyOnWriteArrayList<IWorldViewerEventHandler>(handlers)) {
- if (handler.isDisposed()) {
- handlers.remove(handler);
- }
+ private static final class NotificationHandler implements IArtifactEventListener {
+ private final Collection<IWorldViewerEventHandler> handlers =
+ new CopyOnWriteArrayList<IWorldViewerEventHandler>();
+
+ public NotificationHandler() {
+ OseeEventManager.addListener(this);
}
- try {
- if (!artifactEvent.isForBranch(AtsUtil.getAtsBranch())) {
- return;
+
+ public void add(IWorldViewerEventHandler iWorldEventHandler) {
+ handlers.add(iWorldEventHandler);
+ }
+
+ public void remove(IWorldViewerEventHandler iWorldEventHandler) {
+ handlers.remove(iWorldEventHandler);
+ }
+
+ @Override
+ public void handleArtifactEvent(final ArtifactEvent artifactEvent, Sender sender) {
+ for (IWorldViewerEventHandler handler : handlers) {
+ if (handler.isDisposed()) {
+ handlers.remove(handler);
+ }
}
- } catch (OseeCoreException ex) {
- return;
+ try {
+ if (artifactEvent.isForBranch(AtsUtil.getAtsBranch())) {
+ Runnable runnable = createDisplayRunnable(artifactEvent, handlers);
+ Displays.ensureInDisplayThread(runnable);
+ }
+ } catch (OseeCoreException ex) {
+ // Do Nothing;
+ }
+ }
+
+ @Override
+ public List<? extends IEventFilter> getEventFilters() {
+ return AtsUtil.getAtsObjectEventFilters();
+ }
+
+ private Runnable createDisplayRunnable(ArtifactEvent artifactEvent, Collection<IWorldViewerEventHandler> handlers) {
+ Collection<Artifact> modifiedArts =
+ artifactEvent.getCacheArtifacts(EventModType.Modified, EventModType.Reloaded);
+ Collection<Artifact> relModifiedArts = artifactEvent.getRelCacheArtifacts();
+ Collection<EventBasicGuidArtifact> deletedPurgedArts =
+ artifactEvent.get(EventModType.Deleted, EventModType.Purged);
+ return new DisplayRunnable(modifiedArts, relModifiedArts, deletedPurgedArts, handlers);
}
- final Collection<Artifact> modifiedArts =
- artifactEvent.getCacheArtifacts(EventModType.Modified, EventModType.Reloaded);
- final Collection<Artifact> relModifiedArts = artifactEvent.getRelCacheArtifacts();
- final Collection<EventBasicGuidArtifact> deletedPurgedArts =
- artifactEvent.get(EventModType.Deleted, EventModType.Purged);
-
- Displays.ensureInDisplayThread(new Runnable() {
- @Override
- public void run() {
- if (!deletedPurgedArts.isEmpty()) {
- for (IWorldViewerEventHandler handler : handlers) {
- try {
- if (!handler.isDisposed()) {
- // allow handler to remove from model
- handler.removeItems(deletedPurgedArts);
- IContentProvider contentProvider = handler.getWorldXViewer().getContentProvider();
- // remove from UI
- if (contentProvider instanceof WorldContentProvider) {
- handler.getWorldXViewer().remove(
- deletedPurgedArts.toArray(new Object[deletedPurgedArts.size()]));
- }
+ }
+
+ private static final class DisplayRunnable implements Runnable {
+ private final Collection<Artifact> modifiedArts;
+ private final Collection<Artifact> relModifiedArts;
+ private final Collection<EventBasicGuidArtifact> deletedPurgedArts;
+ private final Collection<IWorldViewerEventHandler> handlers;
+
+ public DisplayRunnable(Collection<Artifact> modifiedArts, Collection<Artifact> relModifiedArts, Collection<EventBasicGuidArtifact> deletedPurgedArts, Collection<IWorldViewerEventHandler> handlers) {
+ super();
+ this.modifiedArts = modifiedArts;
+ this.relModifiedArts = relModifiedArts;
+ this.deletedPurgedArts = deletedPurgedArts;
+ this.handlers = handlers;
+ }
+
+ private void processArtifact(WorldXViewer worldViewer, Artifact artifact) {
+ try {
+ // Don't refresh deleted artifacts
+ if (!artifact.isDeleted()) {
+ if (artifact instanceof IWorldViewArtifact) {
+ worldViewer.refresh(artifact);
+ // If parent is loaded and child changed, refresh parent
+ if (artifact instanceof StateMachineArtifact) {
+ StateMachineArtifact smaArt = (StateMachineArtifact) artifact;
+ Artifact smaParent = smaArt.getParentAtsArtifact();
+ if (smaParent instanceof IWorldViewArtifact) {
+ worldViewer.refresh(smaParent);
}
- } catch (Exception ex) {
- OseeLog.log(AtsPlugin.class, Level.SEVERE,
- "Error processing event handler for deleted - " + handler, ex);
}
}
}
- for (IWorldViewerEventHandler handler : handlers) {
- try {
- if (!handler.isDisposed()) {
- for (Artifact artifact : modifiedArts) {
- try {
- // Don't refresh deleted artifacts
- if (artifact.isDeleted()) {
- continue;
- }
- if (artifact instanceof IWorldViewArtifact) {
- handler.getWorldXViewer().refresh(artifact);
- // If parent is loaded and child changed, refresh parent
- if (artifact instanceof StateMachineArtifact && ((StateMachineArtifact) artifact).getParentAtsArtifact() instanceof IWorldViewArtifact) {
- handler.getWorldXViewer().refresh(
- ((StateMachineArtifact) artifact).getParentAtsArtifact());
- }
- }
- } catch (OseeCoreException ex) {
- OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
- }
- }
+ } catch (OseeCoreException ex) {
+ OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
+ }
+ }
- for (Artifact art : relModifiedArts) {
- // Don't refresh deleted artifacts
- if (art.isDeleted()) {
- continue;
- }
- if (art instanceof IWorldViewArtifact) {
- handler.getWorldXViewer().refresh(art);
- // If parent is loaded and child changed, refresh parent
- try {
- if (art instanceof StateMachineArtifact && ((StateMachineArtifact) art).getParentAtsArtifact() instanceof IWorldViewArtifact) {
- handler.getWorldXViewer().refresh(((StateMachineArtifact) art).getParentAtsArtifact());
- }
- } catch (OseeCoreException ex) {
- OseeLog.log(AtsPlugin.class, Level.SEVERE, ex);
- }
- }
- }
- }
- } catch (Exception ex) {
- OseeLog.log(AtsPlugin.class, Level.SEVERE,
- "Error processing event handler for modified - " + handler, ex);
+ private void processPurged(WorldXViewer worldViewer, IWorldViewerEventHandler handler) {
+ if (!deletedPurgedArts.isEmpty()) {
+ try {
+ // allow handler to remove from model
+ handler.removeItems(deletedPurgedArts);
+ IContentProvider contentProvider = worldViewer.getContentProvider();
+ // remove from UI
+ if (contentProvider instanceof WorldContentProvider) {
+ worldViewer.remove(deletedPurgedArts.toArray(new Object[deletedPurgedArts.size()]));
}
+ } catch (Exception ex) {
+ OseeLog.log(AtsPlugin.class, Level.SEVERE, ex, "Error processing event handler for deleted - %s",
+ handler);
}
}
- });
- }
+ }
- @Override
- public List<? extends IEventFilter> getEventFilters() {
- return AtsUtil.getAtsObjectEventFilters();
+ @Override
+ public void run() {
+ for (IWorldViewerEventHandler handler : handlers) {
+ try {
+ if (!handler.isDisposed()) {
+ WorldXViewer worldViewer = handler.getWorldXViewer();
+ processPurged(worldViewer, handler);
+ for (Artifact artifact : modifiedArts) {
+ processArtifact(worldViewer, artifact);
+ }
+ for (Artifact artifact : relModifiedArts) {
+ processArtifact(worldViewer, artifact);
+ }
+ }
+ } catch (Exception ex) {
+ OseeLog.log(AtsPlugin.class, Level.SEVERE, ex, "Error processing event handler for - %s", handler);
+ }
+ }
+ }
}
-
}

Back to the top