* 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;
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;
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
* @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$
}
/**
private boolean fDisposeOnClose;
+ private Menu fHeaderMenu;
+
+ private Menu fTablePopup;
+
+ private Menu fRawTablePopup;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
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);
column.setResizable(false);
} else {
column.setMoveable(true);
+ createHeaderMenuItem(fHeaderMenu, column);
}
column.addControlListener(new ControlAdapter() {
/*
}
});
+ 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) {
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
// ------------------------------------------------------------------------
* Create a pop-up menu.
*/
private void createPopupMenu() {
+ createResetHeaderMenuItem();
final IAction showTableAction = new Action(Messages.TmfEventsTable_ShowTableActionText) {
@Override
public void run() {
}
});
- 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);
}
/**
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);