import org.eclipse.swt.widgets.Display;
import org.eclipse.tracecompass.internal.tmf.ui.Activator;
import org.eclipse.tracecompass.internal.tmf.ui.editors.ITmfEventsEditorConstants;
+import org.eclipse.tracecompass.internal.tmf.ui.editors.TmfTableColumnUtils;
import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
-import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
import org.eclipse.tracecompass.tmf.core.event.aspect.ITmfEventAspect;
+import org.eclipse.tracecompass.tmf.core.event.aspect.TmfBaseAspects;
import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler;
import org.eclipse.tracecompass.tmf.core.signal.TmfTimestampFormatUpdateSignal;
import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
if (propId == IEditorPart.PROP_INPUT && getEditorInput() instanceof TmfEditorInput) {
if (fTrace != null) {
broadcast(new TmfTraceClosedSignal(this, fTrace));
- TmfTraceColumnManager.saveColumnOrder(fTrace.getTraceTypeId(), fEventsTable.getColumnOrder());
+ saveState();
}
fEventsTable.dispose();
fFile = ((TmfEditorInput) getEditorInput()).getFile();
}
}
+ private void loadState() {
+ final @Nullable String traceTypeId = fTrace.getTraceTypeId();
+ fEventsTable.setColumnOrder(TmfTableColumnUtils.loadColumnOrder(traceTypeId));
+ fEventsTable.setColumnWidth(TmfTableColumnUtils.loadColumnWidth(traceTypeId), TmfTableColumnUtils.loadColumnResizable(traceTypeId));
+ }
+
+ private void saveState() {
+ final @Nullable String traceTypeId = fTrace.getTraceTypeId();
+ TmfTableColumnUtils.saveColumnOrder(traceTypeId, fEventsTable.getColumnOrder());
+ TmfTableColumnUtils.saveColumnWidth(traceTypeId, fEventsTable.getColumnWidth());
+ TmfTableColumnUtils.saveColumnResizability(traceTypeId, fEventsTable.getColumnResizable());
+ }
+
@Override
public void createPartControl(final Composite parent) {
fParent = parent;
setPartName(fTrace.getName());
fEventsTable = createEventsTable(fParent, fTrace.getCacheSize());
fEventsTable.registerContextMenus(getSite());
- fEventsTable.setColumnOrder(TmfTraceColumnManager.loadColumnOrder(fTrace.getTraceTypeId()));
+ loadState();
fEventsTable.addSelectionChangedListener(this);
fEventsTable.setTrace(fTrace, true);
fEventsTable.refreshBookmarks(fFile);
if (fTrace != null) {
broadcast(new TmfTraceClosedSignal(this, fTrace));
if (fEventsTable != null) {
- TmfTraceColumnManager.saveColumnOrder(fTrace.getTraceTypeId(), fEventsTable.getColumnOrder());
+ saveState();
}
}
super.dispose();
fTable.setColumnOrder(order);
fColumnOrder = fTable.getColumnOrder();
}
+
+ @Override
+ public void controlResized(ControlEvent e) {
+ final int size = fTable.getColumns().length;
+ int[] width = new int[size];
+ boolean[] resizable = new boolean[size];
+ for (TableColumn column : fTable.getColumns()) {
+ int i = (int) column.getData(Key.INDEX);
+ resizable[i] = column.getResizable();
+ Object data = column.getData(Key.WIDTH);
+ if (data instanceof Integer) {
+ width[i] = resizable[i] ? column.getWidth() : (Integer) data;
+ } else {
+ width[i] = column.getWidth();
+ }
+ }
+ fColumnSize = width;
+ fColumnResizable = resizable;
+ super.controlResized(e);
+ }
}
private final class TableSelectionListener extends SelectionAdapter {
* @since 1.1
*/
String WIDTH = "$width"; //$NON-NLS-1$
+
+ /**
+ * The position of the column
+ *
+ * @since 2.1
+ */
+ String INDEX = "$index"; //$NON-NLS-1$
}
/**
* @author Patrick Tasse
*/
public static enum HeaderState {
- /** No search filter is applied
- * @since 2.0*/
+ /**
+ * No search filter is applied
+ *
+ * @since 2.0
+ */
NO_SEARCH,
/** A search filter is applied */
private MenuManager fTablePopupMenuManager;
private MenuManager fHeaderPopupMenuManager;
+ private boolean[] fColumnResizable;
+
+ private int[] fColumnSize;
+
// ------------------------------------------------------------------------
// Constructors
// ------------------------------------------------------------------------
for (ITmfEventAspect<?> aspect : aspects) {
if (aspect != null) {
fColumns.add(new TmfEventTableColumn(aspect));
+
}
}
fColumns.add(MARGIN_COLUMN_INDEX, collapseCol);
fHeaderMenu = new Menu(fTable);
+ int i = 0;
// Create the UI columns in the table
for (TmfEventTableColumn col : fColumns) {
TableColumn column = fTable.newTableColumn(SWT.LEFT);
column.setText(col.getHeaderName());
column.setToolTipText(col.getHeaderTooltip());
column.setData(Key.ASPECT, col.getEventAspect());
+ column.setData(Key.INDEX, i);
+ i++;
column.pack();
if (col instanceof TmfMarginColumn) {
column.setResizable(false);
// Handle the table item requests
fTable.addListener(SWT.SetData, new SetDataListener());
- fTable.addMenuDetectListener( event -> {
+ fTable.addMenuDetectListener(event -> {
fLastMenuCursorLocation = new Point(event.x, event.y);
Point pt = fTable.getDisplay().map(null, fTable, fLastMenuCursorLocation);
Rectangle clientArea = fTable.getClientArea();
* @param column
* the column
*/
- private static IAction createHeaderAction(final TableColumn column) {
+ private IAction createHeaderAction(final TableColumn column) {
final IAction columnMenuAction = new Action(column.getText(), IAction.AS_CHECK_BOX) {
@Override
public void run() {
- if (isChecked()) {
- column.setWidth((int) column.getData(Key.WIDTH));
+ boolean isChecked = isChecked();
+ int width = column.getWidth();
+ if (isChecked) {
+ int newWidth = (int) column.getData(Key.WIDTH);
+ column.setWidth(newWidth);
column.setResizable(true);
+ width = newWidth;
} else {
column.setData(Key.WIDTH, column.getWidth());
column.setWidth(0);
column.setResizable(false);
}
+ int pos = (int) column.getData(Key.INDEX);
+ fColumnSize[pos] = width;
+ fColumnResizable[pos] = isChecked;
}
};
columnMenuAction.setChecked(column.getResizable());
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();
- }
+ column.setWidth((Integer) widthVal);
+ 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();
}
+ int index = (int) column.getData(Key.INDEX);
+ fColumnSize[index] = column.getWidth();
+ fColumnResizable[index] = true;
}
}
}
final int selection = index + 1 + (eventFilter != null ? +1 : 0);
display.asyncExec(new Runnable() {
+
@Override
public void run() {
if (monitor.isCanceled()) {
}
});
return Status.OK_STATUS;
+
}
@Override
fSearchThread = null;
}
}
+
}
/**
/**
* Pack the columns.
*
- * @return
- * Whether or not a pack was done in this call. Otherwise, it was already done by a
- * previous call
+ * @return Whether or not a pack was done in this call. Otherwise, it was
+ * already done by a previous call
*
* @since 2.0
*/
private void packSingleColumn(int i, final TableColumn column) {
final int headerWidth = column.getWidth();
+ if (column.getWidth() <= 0) {
+ return;
+ }
column.pack();
/*
* Workaround for Linux which doesn't consider the image width of
return fColumnOrder;
}
+ /**
+ * Get column widths
+ *
+ * @return the current visual widths of the receiver's columns
+ * @since 2.1
+ */
+ public int[] getColumnWidth() {
+ return fColumnSize;
+ }
+
+ /**
+ * Get whether the columns are resizable
+ *
+ * @return an array stating if each column is resizable
+ * @since 2.1
+ */
+ public boolean[] getColumnResizable() {
+ return fColumnResizable;
+ }
+
/**
* Sets the order that the columns in the receiver should be displayed in to
* the given argument which is described in terms of the zero-relative
fColumnOrder = fTable.getColumnOrder();
}
+ /**
+ * Sets the column width and resizability
+ *
+ * @param width
+ * an array of widths
+ * @param resizable
+ * an array of bools saying if a column is resizable or not
+ * @since 2.1
+ */
+ public void setColumnWidth(int[] width, boolean[] resizable) {
+ int length = fTable.getColumns().length;
+ if (width == null || resizable == null || resizable.length != length || width.length != length) {
+ fColumnSize = null;
+ fColumnResizable = null;
+ return;
+ }
+ int i = 0;
+ for (TableColumn column : fTable.getColumns()) {
+ if (i != 0) {
+ column.setData(Key.WIDTH, width[i]);
+ column.setResizable(resizable[i]);
+ if (column.getResizable()) {
+ column.setWidth((int) column.getData(Key.WIDTH));
+ } else {
+ column.setWidth(0);
+ }
+ }
+ i++;
+ }
+ fColumnSize = width;
+ fColumnResizable = resizable;
+ }
+
/**
* Notify this table that is got the UI focus.
*/
* disposed
*/
public void setTrace(final ITmfTrace trace, final boolean disposeOnClose) {
+ setTrace(trace, disposeOnClose, null);
+ }
+
+ /**
+ * Assign a new trace to this event table.
+ *
+ * @param trace
+ * The trace to assign to this event table
+ * @param disposeOnClose
+ * true if the trace should be disposed when the table is
+ * disposed
+ * @param sizes
+ * the column widths
+ * @since 2.1
+ */
+ public void setTrace(final ITmfTrace trace, final boolean disposeOnClose, final int[] sizes) {
if ((fTrace != null) && fDisposeOnClose) {
fTrace.dispose();
}
fTrace = trace;
- fPackDone = false;
+ fPackDone = sizes != null;
fDisposeOnClose = disposeOnClose;
// Perform the updates on the UI thread
*/
private static final class TmfMarginColumn extends TmfEventTableColumn {
- private static final @NonNull ITmfEventAspect<String> MARGIN_ASPECT =
- new ITmfEventAspect<String>() {
+ private static final @NonNull ITmfEventAspect<String> MARGIN_ASPECT = new ITmfEventAspect<String>() {
@Override
public String getName() {
super(MARGIN_ASPECT);
}
}
-
-}
+}
\ No newline at end of file