Override setPinState for TimeGraphViewer
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 27 Oct 2016 20:35:00 +0000 (16:35 -0400)
committerJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Fri, 11 Nov 2016 15:36:07 +0000 (10:36 -0500)
When pinned several features are disabled:

External and internal modification of bookmarks (markers)
Toolbar buttons
    - All except views alignment
Hide the horizontal scroll bar
Horizontal zoom
Horizontal scrolling
Marker menu

Pass the state to internal control. Each have specific pin behaviour.

Change-Id: I645e9f91de6abe7d4208b94d6ce35b67070bcb1f
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/TimeGraphViewer.java

index 7ea8ddceb0f820bc55bf9f8bda171872bec224af..db5e2f7908ce425005c803b3a99596bc8cb6eab3 100644 (file)
@@ -172,8 +172,13 @@ public class TimeGraphViewer extends TmfViewer implements ITimeDataProvider, IMa
     private Action fPreviousMarkerAction;
     private MenuManager fMarkersMenu;
 
+    /** Pin related state */
+    private boolean fMarkersUpdateEnabled = true;
+    private boolean fShowMarkerActionsEnabled = true;
+
     /** The list of bookmarks */
-    private final List<IMarkerEvent> fBookmarks = new ArrayList<>();
+    private final List<IMarkerEvent> fCurrentBookmark = new ArrayList<>();
+    private final List<IMarkerEvent> fSyncedBookmark = new ArrayList<>();
 
     /** The list of marker categories */
     private final List<String> fMarkerCategories = new ArrayList<>();
@@ -1412,9 +1417,16 @@ public class TimeGraphViewer extends TmfViewer implements ITimeDataProvider, IMa
      * @since 2.0
      */
     public void setBookmarks(List<IMarkerEvent> bookmarks) {
-        fBookmarks.clear();
+
+        fSyncedBookmark.clear();
+
         if (bookmarks != null) {
-            fBookmarks.addAll(bookmarks);
+            fSyncedBookmark.addAll(bookmarks);
+        }
+
+        if (fMarkersUpdateEnabled) {
+            fCurrentBookmark.clear();
+            fCurrentBookmark.addAll(fSyncedBookmark);
         }
         updateMarkerList();
         updateMarkerActions();
@@ -1427,7 +1439,7 @@ public class TimeGraphViewer extends TmfViewer implements ITimeDataProvider, IMa
      * @since 2.0
      */
     public List<IMarkerEvent> getBookmarks() {
-        return Collections.unmodifiableList(fBookmarks);
+        return Collections.unmodifiableList(fCurrentBookmark);
     }
 
     /**
@@ -2266,14 +2278,14 @@ public class TimeGraphViewer extends TmfViewer implements ITimeDataProvider, IMa
                             final String label = dialog.getValue();
                             final RGBA rgba = dialog.getColorValue();
                             IMarkerEvent bookmark = new MarkerEvent(null, time, duration, IMarkerEvent.BOOKMARKS, rgba, label, true);
-                            fBookmarks.add(bookmark);
+                            fCurrentBookmark.add(bookmark);
                             updateMarkerList();
                             updateMarkerActions();
                             getControl().redraw();
                             fireBookmarkAdded(bookmark);
                         }
                     } else {
-                        fBookmarks.remove(selectedBookmark);
+                        fCurrentBookmark.remove(selectedBookmark);
                         updateMarkerList();
                         updateMarkerActions();
                         getControl().redraw();
@@ -2501,7 +2513,7 @@ public class TimeGraphViewer extends TmfViewer implements ITimeDataProvider, IMa
     private IMarkerEvent getBookmarkAtSelection() {
         final long time = Math.min(fSelectionBegin, fSelectionEnd);
         final long duration = Math.max(fSelectionBegin, fSelectionEnd) - time;
-        for (IMarkerEvent bookmark : fBookmarks) {
+        for (IMarkerEvent bookmark : fCurrentBookmark) {
             if (bookmark.getTime() == time && bookmark.getDuration() == duration) {
                 return bookmark;
             }
@@ -2510,7 +2522,7 @@ public class TimeGraphViewer extends TmfViewer implements ITimeDataProvider, IMa
     }
 
     private void updateMarkerActions() {
-        boolean enabled = fTime0Bound != SWT.DEFAULT || fTime1Bound != SWT.DEFAULT;
+        boolean enabled = (fTime0Bound != SWT.DEFAULT || fTime1Bound != SWT.DEFAULT) && fShowMarkerActionsEnabled;
         if (fToggleBookmarkAction != null) {
             if (getBookmarkAtSelection() != null) {
                 fToggleBookmarkAction.setText(Messages.TmfTimeGraphViewer_BookmarkActionRemoveText);
@@ -2543,7 +2555,7 @@ public class TimeGraphViewer extends TmfViewer implements ITimeDataProvider, IMa
             }
         }
         if (!fHiddenMarkerCategories.contains(IMarkerEvent.BOOKMARKS)) {
-            markers.addAll(fBookmarks);
+            markers.addAll(fCurrentBookmark);
         }
         Collections.sort(markers, new MarkerComparator());
         fTimeGraphCtrl.setMarkers(markers);
@@ -2712,4 +2724,73 @@ public class TimeGraphViewer extends TmfViewer implements ITimeDataProvider, IMa
         fTimeAlignedComposite.layout();
     }
 
+    @Override
+    public synchronized void setPinned(boolean pinned) {
+        super.setPinned(pinned);
+        boolean enabled = !pinned;
+
+        fTimeGraphCtrl.setPinned(pinned);
+        fTimeScaleCtrl.setPinned(pinned);
+        fMarkerAxisCtrl.setPinned(pinned);
+
+        fHorizontalScrollBar.setEnabled(enabled);
+        fHorizontalScrollBar.setVisible(enabled);
+
+        fMouseWheelListeners.setHorizontalScrollEnabled(enabled);
+        fMouseWheelListeners.setZoomEnabled(enabled);
+
+        fKeyListeners.setAllEnabled(enabled);
+
+        fMarkersMenu.setVisible(enabled);
+
+        if (enabled) {
+            fCurrentBookmark.clear();
+            fCurrentBookmark.addAll(fSyncedBookmark);
+        }
+
+        if (fResetScaleAction != null) {
+            fResetScaleAction.setEnabled(enabled);
+        }
+        if (fShowLegendAction != null) {
+            fShowLegendAction.setEnabled(enabled);
+        }
+        if (fNextEventAction != null) {
+            fNextEventAction.setEnabled(enabled);
+        }
+        if (fPrevEventAction != null) {
+            fPrevEventAction.setEnabled(enabled);
+        }
+        if (fNextItemAction != null) {
+            fNextItemAction.setEnabled(enabled);
+        }
+        if (fPreviousItemAction != null) {
+            fPreviousItemAction.setEnabled(enabled);
+        }
+        if (fZoomInAction != null) {
+            fZoomInAction.setEnabled(enabled);
+        }
+        if (fZoomOutAction != null) {
+            fZoomOutAction.setEnabled(enabled);
+        }
+        if (fHideArrowsAction != null) {
+            fHideArrowsAction.setEnabled(enabled);
+        }
+        if (fFollowArrowFwdAction != null) {
+            fFollowArrowFwdAction.setEnabled(enabled);
+        }
+        if (fFollowArrowBwdAction != null) {
+            fFollowArrowBwdAction.setEnabled(enabled);
+        }
+        if (fShowFilterDialogAction != null) {
+            fShowFilterDialogAction.setEnabled(enabled);
+        }
+        if (fToggleBookmarkAction != null) {
+            fToggleBookmarkAction.setEnabled(enabled);
+        }
+
+        fShowMarkerActionsEnabled = enabled;
+        fMarkersUpdateEnabled = enabled;
+        updateMarkerActions();
+    }
+
 }
This page took 0.028123 seconds and 5 git commands to generate.