tmf.ui: make columns hideable.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 27 May 2015 21:37:10 +0000 (17:37 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Sat, 6 Jun 2015 02:02:35 +0000 (22:02 -0400)
Change-Id: Ia23182dc74f05fac21570a718758e050b8881155
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/48704
Reviewed-by: Hudson CI
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/Messages.java
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/internal/tmf/ui/messages.properties
org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/viewers/events/TmfEventsTable.java

index 2e70a8e11e9c36a63a355b416d23d49780b70519..bef1fd5e7c3a022e6fc0c0c7e762dbf3ea4efe96 100644 (file)
@@ -55,6 +55,8 @@ public class Messages extends NLS {
     public static String TmfEventsTable_RemoveBookmarkActionText;
     public static String TmfEventsTable_SearchHint;
     public static String TmfEventsTable_SearchingJobName;
+
+    public static String TmfEventsTable_showAll;
     public static String TmfEventsTable_ShowFilterBarActionText;
     public static String TmfEventsTable_ShowRawActionText;
     public static String TmfEventsTable_ShowSearchBarActionText;
index 1e35228ec5b22e66518bf294475a72a1c60f9914..aeffaeccacfa8494a7c590c6fcefedd664283ab5 100644 (file)
@@ -48,6 +48,7 @@ TmfEventsTable_ReferenceColumnHeader=File
 TmfEventsTable_RemoveBookmarkActionText=Remove Bookmark
 TmfEventsTable_SearchHint=<srch>
 TmfEventsTable_SearchingJobName=Searching...
+TmfEventsTable_showAll=Show all
 TmfEventsTable_ShowFilterBarActionText=Show Filter Bar
 TmfEventsTable_ShowRawActionText=Show Raw
 TmfEventsTable_ShowSearchBarActionText=Show Search Bar
index d8a711d099c770e5578ba9b9de083fd728dd1397..02a245ae3083dc1241335859749789f9f8847176 100644 (file)
@@ -13,6 +13,7 @@
  *   Ansgar Radermacher - Support navigation to model URIs (Bug 396956)
  *   Bernd Hufmann - Updated call site and model URI implementation
  *   Alexandre Montplaisir - Update to new column API
+ *   Matthew Khouzam - Add hide columns
  *******************************************************************************/
 
 package org.eclipse.tracecompass.tmf.ui.viewers.events;
@@ -107,6 +108,7 @@ import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.TableColumn;
@@ -214,7 +216,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
     private static final int EVENT_COLUMNS_START_INDEX = MARGIN_COLUMN_INDEX + 1;
 
     /**
-     * The events table search/filter keys
+     * The events table search/filter/data keys
      *
      * @version 1.0
      * @author Patrick Tasse
@@ -250,6 +252,13 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
          * @since 1.0
          */
         String STYLE_RANGES = "$style_ranges"; //$NON-NLS-1$
+
+        /**
+         * The width of a table item
+         *
+         * @since 1.0
+         */
+        String WIDTH = "$width"; //$NON-NLS-1$
     }
 
     /**
@@ -332,6 +341,12 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
 
     private boolean fDisposeOnClose;
 
+    private Menu fHeaderMenu;
+
+    private Menu fTablePopup;
+
+    private Menu fRawTablePopup;
+
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
@@ -436,6 +451,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         TmfMarginColumn collapseCol = new TmfMarginColumn();
         fColumns.add(MARGIN_COLUMN_INDEX, collapseCol);
 
+        fHeaderMenu = new Menu(fTable);
         // Create the UI columns in the table
         for (TmfEventTableColumn col : fColumns) {
             TableColumn column = fTable.newTableColumn(SWT.LEFT);
@@ -447,6 +463,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
                 column.setResizable(false);
             } else {
                 column.setMoveable(true);
+                createHeaderMenuItem(fHeaderMenu, column);
             }
             column.addControlListener(new ControlAdapter() {
                 /*
@@ -557,6 +574,16 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
             }
         });
 
+        fTable.addListener(SWT.MenuDetect, new Listener() {
+            @Override
+            public void handleEvent(Event event) {
+                Point pt = fTable.getDisplay().map(null, fTable, new Point(event.x, event.y));
+                Rectangle clientArea = fTable.getClientArea();
+                boolean header = clientArea.y <= pt.y && pt.y < (clientArea.y + fTable.getHeaderHeight());
+                fTable.setMenu(header ? fHeaderMenu : fTablePopup);
+            }
+        });
+
         fTable.addMouseListener(new MouseAdapter() {
             @Override
             public void mouseDoubleClick(final MouseEvent event) {
@@ -810,6 +837,67 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
         createPopupMenu();
     }
 
+    /**
+     * Checked menu creator to make columns visible or not.
+     *
+     * @param parent
+     *            the parent menu
+     * @param column
+     *            the column
+     */
+    private static void createHeaderMenuItem(Menu parent, final TableColumn column) {
+        final MenuItem columnMenuItem = new MenuItem(parent, SWT.CHECK);
+        columnMenuItem.setText(column.getText());
+        columnMenuItem.setSelection(column.getResizable());
+        columnMenuItem.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                if (columnMenuItem.getSelection()) {
+                    column.setWidth((int) column.getData(Key.WIDTH));
+                    column.setResizable(true);
+                } else {
+                    column.setData(Key.WIDTH, column.getWidth());
+                    column.setWidth(0);
+                    column.setResizable(false);
+                }
+            }
+        });
+    }
+
+    private void createResetHeaderMenuItem() {
+        final MenuItem resetMenu = new MenuItem(fHeaderMenu, SWT.PUSH);
+        resetMenu.setText(Messages.TmfEventsTable_showAll);
+        resetMenu.addSelectionListener(new SelectionAdapter() {
+            @Override
+            public void widgetSelected(SelectionEvent e) {
+                for (TableColumn column : fTable.getColumns()) {
+                    final Object widthVal = column.getData(Key.WIDTH);
+                    if (widthVal instanceof Integer) {
+                        Integer width = (Integer) widthVal;
+                        if (!column.getResizable()) {
+                            column.setWidth(width);
+                            column.setResizable(true);
+                            /*
+                             * This is because Linux always resizes the last
+                             * column to fill in the void, this means that
+                             * hiding a column resizes others and we can have 10
+                             * columns that are 1000 pixels wide by hiding the
+                             * last one progressively.
+                             */
+                            if (IS_LINUX) {
+                                column.pack();
+                            }
+                        }
+                    }
+                }
+                for (MenuItem menuItem : fHeaderMenu.getItems()) {
+                    menuItem.setSelection(true);
+                }
+
+            }
+        });
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -818,6 +906,7 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
      * Create a pop-up menu.
      */
     private void createPopupMenu() {
+        createResetHeaderMenuItem();
         final IAction showTableAction = new Action(Messages.TmfEventsTable_ShowTableActionText) {
             @Override
             public void run() {
@@ -1177,11 +1266,11 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
             }
         });
 
-        Menu menu = tablePopupMenu.createContextMenu(fTable);
-        fTable.setMenu(menu);
+        fTablePopup = tablePopupMenu.createContextMenu(fTable);
+        fTable.setMenu(fTablePopup);
 
-        menu = rawViewerPopupMenu.createContextMenu(fRawViewer);
-        fRawViewer.setMenu(menu);
+        fRawTablePopup = rawViewerPopupMenu.createContextMenu(fRawViewer);
+        fRawViewer.setMenu(fRawTablePopup);
     }
 
     /**
@@ -2213,7 +2302,9 @@ public class TmfEventsTable extends TmfComponent implements IGotoMarker, IColorS
             for (int i = 0; i < tableColumns.length; i++) {
                 final TableColumn column = tableColumns[i];
                 packSingleColumn(i, column);
+                column.setData(Key.WIDTH, column.getWidth());
             }
+
         } finally {
             // Make sure that redraw is always enabled.
             fTable.setRedraw(true);
This page took 0.031177 seconds and 5 git commands to generate.