From 02c921ed127fefe27f23830ee5bf158e9ca2efca Mon Sep 17 00:00:00 2001 From: Brian Clements Date: Mon, 5 May 2014 12:52:46 -0500 Subject: [PATCH] Issue #3076 added clear all to shared display sessions Former-commit-id: 1432aa1302a52d56027f01d3b32fa5dfd548c11d [formerly f545c548cc2a536f20fc7c3a8f9c8121ba85f8fa [formerly 9e4a518f2ecbe86fed87fbb6dac7fad08ffb33eb]] Former-commit-id: f545c548cc2a536f20fc7c3a8f9c8121ba85f8fa Former-commit-id: 729e717be1c63639ab82d3f8720f648d9e82038a --- .../CollaborationDrawingEvent.java | 3 +- .../CollaborationDrawingResource.java | 41 +++++++++- .../icons/clear_all.gif | Bin 0 -> 223 bytes .../ui/session/CollaborationSessionView.java | 72 ++++++++++++++++-- .../uf/viz/drawing/DrawingToolLayer.java | 35 ++++++--- 5 files changed, 130 insertions(+), 21 deletions(-) create mode 100644 cave/com.raytheon.uf.viz.collaboration.ui/icons/clear_all.gif diff --git a/cave/com.raytheon.uf.viz.collaboration.display/src/com/raytheon/uf/viz/collaboration/display/rsc/telestrator/CollaborationDrawingEvent.java b/cave/com.raytheon.uf.viz.collaboration.display/src/com/raytheon/uf/viz/collaboration/display/rsc/telestrator/CollaborationDrawingEvent.java index 0c138412c9..ec07161cbd 100644 --- a/cave/com.raytheon.uf.viz.collaboration.display/src/com/raytheon/uf/viz/collaboration/display/rsc/telestrator/CollaborationDrawingEvent.java +++ b/cave/com.raytheon.uf.viz.collaboration.display/src/com/raytheon/uf/viz/collaboration/display/rsc/telestrator/CollaborationDrawingEvent.java @@ -37,6 +37,7 @@ import com.vividsolutions.jts.geom.Coordinate; * ------------ ---------- ----------- -------------------------- * Apr 3, 2012 mnash Initial creation * Jan 30, 2014 2698 bclement changed UserId to VenueParticipant + * May 05, 2014 3076 bclement added DISPOSE_ALL * * * @@ -48,7 +49,7 @@ import com.vividsolutions.jts.geom.Coordinate; public class CollaborationDrawingEvent { public static enum CollaborationEventType { - DRAW, ERASE, REDO, UNDO, CLEAR, LOCK_USERS, UNLOCK_USERS, CLEAR_ALL, NEW_USER_ARRIVED; + DRAW, ERASE, REDO, UNDO, CLEAR, CLEAR_ALL, LOCK_USERS, UNLOCK_USERS, DISPOSE_ALL, NEW_USER_ARRIVED; } @DynamicSerializeElement diff --git a/cave/com.raytheon.uf.viz.collaboration.display/src/com/raytheon/uf/viz/collaboration/display/rsc/telestrator/CollaborationDrawingResource.java b/cave/com.raytheon.uf.viz.collaboration.display/src/com/raytheon/uf/viz/collaboration/display/rsc/telestrator/CollaborationDrawingResource.java index 48dd9259fe..e9cd38f8b7 100644 --- a/cave/com.raytheon.uf.viz.collaboration.display/src/com/raytheon/uf/viz/collaboration/display/rsc/telestrator/CollaborationDrawingResource.java +++ b/cave/com.raytheon.uf.viz.collaboration.display/src/com/raytheon/uf/viz/collaboration/display/rsc/telestrator/CollaborationDrawingResource.java @@ -19,6 +19,9 @@ **/ package com.raytheon.uf.viz.collaboration.display.rsc.telestrator; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -64,6 +67,8 @@ import com.vividsolutions.jts.geom.Coordinate; * Jan 30, 2014 2698 bclement changed UserId to VenueParticipant * Feb 13, 2014 2751 bclement VenueParticipant refactor * Mar 18, 2014 2895 njensen Fix concurrent mod exception on dispose + * May 05, 2014 3076 bclement old CLEAR_ALL is now DISPOSE_ALL, + * added clearLayers() and getAllDrawingLayers() * * * @@ -129,7 +134,7 @@ public class CollaborationDrawingResource extends CollaborationDrawingEvent event = new CollaborationDrawingEvent( resourceData.getDisplayId()); event.setUserName(myUser); - event.setType(CollaborationEventType.CLEAR_ALL); + event.setType(CollaborationEventType.DISPOSE_ALL); sendEvent(event); } @@ -205,6 +210,18 @@ public class CollaborationDrawingResource extends } } + /** + * Clear all drawing layers. Does not generate any collaboration events. + * This is not "undoable". + */ + private void clearLayers() { + synchronized (layerMap) { + for (DrawingToolLayer layer : layerMap.values()) { + layer.clearAllDrawingData(); + } + } + } + /** * @return the myUser */ @@ -249,6 +266,23 @@ public class CollaborationDrawingResource extends return null; } + /** + * A collection of drawing layers for resource + * + * @return empty collection if there are no layers + */ + public Collection getAllDrawingLayers() { + Collection rval; + if (layerMap != null) { + synchronized (layerMap) { + rval = new ArrayList(layerMap.values()); + } + } else { + rval = Collections.emptyList(); + } + return rval; + } + /* * (non-Javadoc) * @@ -377,9 +411,12 @@ public class CollaborationDrawingResource extends case UNDO: layer.undo(); break; - case CLEAR_ALL: + case DISPOSE_ALL: disposeLayers(); break; + case CLEAR_ALL: + clearLayers(); + break; case NEW_USER_ARRIVED: CollaborationDrawingToolLayer myLayer = (CollaborationDrawingToolLayer) getDrawingLayerFor(getMyUser()); InitialCollaborationData dataBundle = new InitialCollaborationData( diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/icons/clear_all.gif b/cave/com.raytheon.uf.viz.collaboration.ui/icons/clear_all.gif new file mode 100644 index 0000000000000000000000000000000000000000..3baa1c7a858fb5673ed4f2ff1f9e81019896f547 GIT binary patch literal 223 zcmZ?wbhEHb6krfwc+AJJhk@Z71H(NAhBpih|A2^>_rJ9Ce_7f8y1M`E?f?1u{`2?$ z9~=9B?b`ofp!iSFxhOTUBsE2$JhLQ2!QIn0fI;ym3nK#qKZ6bf5P%G3U@8A#yLd_H zv8dt~PiLl?@E$K&axlZoQHj+_Z0a`|mX*Toxq^!s4>@d5V4HS$fuRBi``*Q$x5e-X zbv`@P>8dxAgON$CqgAlqk@1%T3tvIS0*yp(rdNlo9!wTsU}ujl;YB$Y(vLJ&s09xKr+5i9m literal 0 HcmV?d00001 diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/CollaborationSessionView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/CollaborationSessionView.java index a27ce5e13c..a1b08ae7e0 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/CollaborationSessionView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/CollaborationSessionView.java @@ -21,6 +21,7 @@ package com.raytheon.uf.viz.collaboration.ui.session; **/ import java.util.Collection; +import java.util.Collections; import java.util.IdentityHashMap; import java.util.Map; @@ -101,6 +102,7 @@ import com.raytheon.viz.ui.input.EditableManager; * Mar 11, 2014 2865 lvenable Added null checks in threads * Mar 18, 2014 2895 njensen Fix lockAction enable/disable logic * Apr 15, 2014 2822 bclement only allow transfer leader if participant is using shared display + * May 05, 2014 3076 bclement added clear all action * * * @@ -140,6 +142,8 @@ public class CollaborationSessionView extends SessionView implements private ActionContributionItem lockAction; + private ActionContributionItem clearAllAction; + private ControlContribution noEditorAction; private ISharedDisplaySession session; @@ -181,6 +185,21 @@ public class CollaborationSessionView extends SessionView implements return null; } + /** + * @see CollaborationDrawingResource#getAllDrawingLayers() + * @return empty collection if no layers are found + */ + private Collection getAllLayers() { + Collection rval; + CollaborationDrawingResource resource = getCurrentDrawingResource(); + if (resource != null) { + rval = resource.getAllDrawingLayers(); + } else { + rval = Collections.emptyList(); + } + return rval; + } + /* * (non-Javadoc) * @@ -354,7 +373,15 @@ public class CollaborationSessionView extends SessionView implements lockAction.getAction().setImageDescriptor( IconUtil.getImageDescriptor(Activator.getDefault().getBundle(), "lock.gif")); - + clearAllAction = new ActionContributionItem(new Action("Clear All") { + @Override + public void run() { + clearAllDrawingLayers(); + } + }); + clearAllAction.getAction().setImageDescriptor( + IconUtil.getImageDescriptor(Activator.getDefault().getBundle(), + "clear_all.gif")); noEditorAction = new ControlContribution("noEditorAction") { @Override @@ -383,12 +410,30 @@ public class CollaborationSessionView extends SessionView implements mgr.insert(mgr.getSize() - 1, redoAction); mgr.insert(mgr.getSize() - 1, clearAction); mgr.insert(mgr.getSize() - 1, eraseAction); + mgr.insert(mgr.getSize() - 1, new Separator()); mgr.insert(mgr.getSize() - 1, lockAction); + mgr.insert(mgr.getSize() - 1, clearAllAction); mgr.insert(mgr.getSize() - 1, new Separator()); updateToolItems(); } + /** + * Clear all drawing layers and send clear all event + */ + private void clearAllDrawingLayers() { + for (DrawingToolLayer layer : getAllLayers()) { + layer.clearAllDrawingData(); + } + CollaborationDrawingResource resource = getCurrentDrawingResource(); + CollaborationDrawingEvent event = new CollaborationDrawingEvent( + resource.getResourceData().getDisplayId()); + event.setType(CollaborationEventType.CLEAR_ALL); + event.setUserName(resource.getMyUser()); + resource.sendEvent(event); + updateToolItems(); + } + private void toggleDrawMode(DrawMode mode) { if (mode != DrawMode.NONE) { CollaborationDrawingResource resource = getCurrentDrawingResource(); @@ -411,6 +456,20 @@ public class CollaborationSessionView extends SessionView implements } } + /** + * @return true if any drawing layer has been drawn on + */ + private boolean anyLayerHasDrawing() { + boolean anyCanClear = false; + for (DrawingToolLayer dtl : getAllLayers()) { + if (dtl.hasDrawing()) { + anyCanClear = true; + break; + } + } + return anyCanClear; + } + public void updateToolItems() { ToolBarManager mgr = (ToolBarManager) getViewSite().getActionBars() .getToolBarManager(); @@ -419,24 +478,21 @@ public class CollaborationSessionView extends SessionView implements mgr.insert(0, noEditorAction); } CollaborationDrawingResource currentResource = getCurrentDrawingResource(); - DrawingToolLayer layer = null; - if (currentResource != null) { - layer = currentResource.getDrawingLayerFor(currentResource - .getMyUser()); - } + DrawingToolLayer layer = getCurrentLayer(); if (layer != null && currentResource.isSessionLeader()) { lockAction.getAction().setEnabled(true); + clearAllAction.getAction().setEnabled(anyLayerHasDrawing()); } else { lockAction.getAction().setEnabled(false); + clearAllAction.getAction().setEnabled(false); } - // enable/disable toolbar buttons based on locked if (layer != null && (locked == false || currentResource.isSessionLeader())) { drawAction.getAction().setEnabled(true); undoAction.getAction().setEnabled(layer.canUndo()); redoAction.getAction().setEnabled(layer.canRedo()); - clearAction.getAction().setEnabled(layer.canClear()); + clearAction.getAction().setEnabled(layer.hasDrawing()); eraseAction.getAction().setEnabled(true); switch (layer.getDrawMode()) { case DRAW: diff --git a/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingToolLayer.java b/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingToolLayer.java index bd549a3665..8112d33860 100644 --- a/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingToolLayer.java +++ b/cave/com.raytheon.uf.viz.drawing/src/com/raytheon/uf/viz/drawing/DrawingToolLayer.java @@ -65,6 +65,8 @@ import com.vividsolutions.jts.geom.TopologyException; * May 23, 2012 mschenke Initial creation * May 23, 2012 2646 bsteffen Fix NPE in project. * Apr 03, 2014 2967 njensen Fix error when erasing the last part of a line + * May 05, 2014 3076 bclement added clearAllDrawingData() and disposeWireframeShape() + * renamed canClear() to hasDrawing() * * * @@ -331,15 +333,7 @@ public class DrawingToolLayer implements IRenderable { * Disposes the data in the layer */ public void dispose() { - synchronized (currentData) { - if (wireframeShape != null) { - wireframeShape.dispose(); - } - currentData.geometries.clear(); - currentDrawingLine = null; - undoStack.clear(); - redoStack.clear(); - } + clearAllDrawingData(); } /** @@ -503,7 +497,7 @@ public class DrawingToolLayer implements IRenderable { * * @return */ - public boolean canClear() { + public boolean hasDrawing() { return currentData.geometries.size() > 0 || redoStack.size() > 0; } @@ -535,6 +529,20 @@ public class DrawingToolLayer implements IRenderable { } } + /** + * Clears the current display and the undo and redo stacks. This operation + * is not "undoable" + */ + public void clearAllDrawingData() { + synchronized (currentData) { + disposeWireframeShape(); + currentData.geometries.clear(); + currentDrawingLine = null; + undoStack.clear(); + redoStack.clear(); + } + } + /** * Pushes currentData on pushStack and pops next frame from popStack and * puts in currentData @@ -568,6 +576,13 @@ public class DrawingToolLayer implements IRenderable { StackFrame oldData = new StackFrame(new ArrayList( currentData.geometries)); stack.push(oldData); + disposeWireframeShape(); + } + + /** + * disposes and sets wireframeShape to null if not already null + */ + private void disposeWireframeShape() { if (wireframeShape != null) { wireframeShape.dispose(); wireframeShape = null;