Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 79f3c09

Browse files
committed
Draft fix to adjust row heights for trace view
1 parent d4687b8 commit 79f3c09

File tree

4 files changed

+143
-5
lines changed

4 files changed

+143
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package edu.rice.cs.hpctraceviewer.ui.base;
2+
3+
import org.eclipse.jface.preference.PreferenceStore;
4+
import org.eclipse.jface.util.IPropertyChangeListener;
5+
import org.eclipse.jface.util.PropertyChangeEvent;
6+
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
7+
import org.eclipse.jface.viewers.TableViewer;
8+
import org.eclipse.swt.SWT;
9+
import org.eclipse.swt.events.DisposeEvent;
10+
import org.eclipse.swt.events.DisposeListener;
11+
import org.eclipse.swt.graphics.GC;
12+
import org.eclipse.swt.graphics.Point;
13+
import org.eclipse.swt.widgets.Composite;
14+
import org.eclipse.swt.widgets.Event;
15+
import org.eclipse.swt.widgets.Listener;
16+
import org.eclipse.swt.widgets.Table;
17+
18+
import edu.rice.cs.hpcsetting.fonts.FontManager;
19+
import edu.rice.cs.hpcsetting.preferences.PreferenceConstants;
20+
import edu.rice.cs.hpcsetting.preferences.ViewerPreferenceManager;
21+
22+
public abstract class AbstractBaseTableViewer
23+
extends TableViewer
24+
implements Listener, DisposeListener, IPropertyChangeListener
25+
{
26+
27+
private int tableRowHeight;
28+
29+
public AbstractBaseTableViewer(Composite parent, int style) {
30+
super(parent, SWT.SINGLE | SWT.READ_ONLY | SWT.FULL_SELECTION | style);
31+
computeCellBounds();
32+
33+
PreferenceStore pref = ViewerPreferenceManager.INSTANCE.getPreferenceStore();
34+
pref.addPropertyChangeListener(this);
35+
36+
final Table table = getTable();
37+
table.setLinesVisible(true);
38+
39+
table.addDisposeListener(this);
40+
table.addListener(SWT.MeasureItem, this);
41+
42+
ColumnViewerToolTipSupport.enableFor(this);
43+
}
44+
45+
@Override
46+
public void widgetDisposed(DisposeEvent e) {
47+
getTable().removeDisposeListener(this);
48+
getTable().removeListener(SWT.MeasureItem, this);
49+
50+
PreferenceStore pref = ViewerPreferenceManager.INSTANCE.getPreferenceStore();
51+
pref.removePropertyChangeListener(this);
52+
}
53+
54+
@Override
55+
public void handleEvent (Event event) {
56+
switch(event.type) {
57+
case SWT.MeasureItem:
58+
event.height = tableRowHeight;
59+
break;
60+
}
61+
}
62+
63+
@Override
64+
public void propertyChange(PropertyChangeEvent event) {
65+
66+
final String property = event.getProperty();
67+
68+
boolean need_to_refresh = (property.equals(PreferenceConstants.ID_FONT_GENERIC) ||
69+
property.equals(PreferenceConstants.ID_FONT_METRIC));
70+
71+
if (need_to_refresh) {
72+
computeCellBounds();
73+
refresh();
74+
}
75+
}
76+
77+
final String text = "|{[(/`,q";
78+
79+
private void computeCellBounds() {
80+
81+
GC gc = new GC(getControl());
82+
83+
gc.setFont(FontManager.getFontGeneric());
84+
Point extent1 = gc.stringExtent(text);
85+
86+
// check the height if we use generic font (tree column)
87+
// if this font is higher, we should use this height as the standard.
88+
89+
gc.setFont(FontManager.getMetricFont());
90+
Point extent2 = gc.stringExtent(text);
91+
92+
Point extent = new Point(Math.max(extent1.x, extent2.x),
93+
Math.max(extent1.y, extent2.y));
94+
95+
extent = computeCellBounds(gc, extent);
96+
97+
tableRowHeight = extent.y;
98+
99+
gc.dispose();
100+
}
101+
102+
/****
103+
* Called when it's necessary to recompute the cell bound
104+
* @param gc the graphic context. Implementer shouldn't dispose the gc.
105+
* @param Point the suggested bound
106+
*
107+
* @return Point final bound
108+
*/
109+
abstract protected Point computeCellBounds(GC gc, Point extent);
110+
}

edu.rice.cs.hpctraceviewer.ui/src/edu/rice/cs/hpctraceviewer/ui/base/AbstractItemViewWithTable.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,15 @@ public void createContent(ITracePart parentPart, IEclipseContext context, IEvent
7777
TableColumnLayout layout = new TableColumnLayout();
7878
tableComposite.setLayout(layout);
7979

80-
tableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.VIRTUAL |
80+
tableViewer = new AbstractBaseTableViewer(tableComposite, SWT.BORDER | SWT.VIRTUAL |
8181
SWT.RESIZE | SWT.READ_ONLY |
82-
SWT.H_SCROLL | SWT.V_SCROLL);
82+
SWT.H_SCROLL | SWT.V_SCROLL) {
83+
84+
@Override
85+
protected Point computeCellBounds(GC gc, Point extent) {
86+
return extent;
87+
}
88+
};
8389

8490
final Table table = tableViewer.getTable();
8591
table.setHeaderVisible(true);

edu.rice.cs.hpctraceviewer.ui/src/edu/rice/cs/hpctraceviewer/ui/callstack/CallStackViewer.java

+23-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.eclipse.core.commands.operations.IUndoableOperation;
99
import org.eclipse.core.commands.operations.OperationHistoryEvent;
1010
import org.eclipse.e4.core.services.events.IEventBroker;
11+
import org.eclipse.jface.util.PropertyChangeEvent;
1112
import org.eclipse.jface.viewers.ColumnLabelProvider;
1213
import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
1314
import org.eclipse.jface.viewers.IStructuredContentProvider;
@@ -19,6 +20,9 @@
1920
import org.eclipse.swt.events.DisposeEvent;
2021
import org.eclipse.swt.events.DisposeListener;
2122
import org.eclipse.swt.graphics.Color;
23+
import org.eclipse.swt.graphics.Font;
24+
import org.eclipse.swt.graphics.GC;
25+
import org.eclipse.swt.graphics.Point;
2226
import org.eclipse.swt.layout.GridData;
2327
import org.eclipse.swt.widgets.Composite;
2428
import org.eclipse.swt.widgets.Display;
@@ -32,6 +36,8 @@
3236
import edu.rice.cs.hpc.data.util.CallPath;
3337
import edu.rice.cs.hpc.data.util.Constants;
3438
import edu.rice.cs.hpc.data.util.string.StringUtil;
39+
import edu.rice.cs.hpcsetting.fonts.FontManager;
40+
import edu.rice.cs.hpctraceviewer.ui.base.AbstractBaseTableViewer;
3541
import edu.rice.cs.hpctraceviewer.ui.base.ITracePart;
3642
import edu.rice.cs.hpctraceviewer.ui.context.BaseTraceContext;
3743
import edu.rice.cs.hpctraceviewer.ui.internal.TraceEventData;
@@ -49,7 +55,7 @@
4955
/**************************************************
5056
* A viewer for CallStackSamples.
5157
*************************************************/
52-
public class CallStackViewer extends TableViewer
58+
public class CallStackViewer extends AbstractBaseTableViewer
5359
implements IOperationHistoryListener, DisposeListener
5460
{
5561
private final static String EMPTY_FUNCTION = "--------------";
@@ -132,6 +138,11 @@ public void handleEvent(Event event)
132138

133139
final ColumnLabelProvider myLableProvider = new ColumnLabelProvider() {
134140

141+
@Override
142+
public Font getFont(Object element) {
143+
return FontManager.getFontGeneric();
144+
}
145+
135146
public String getText(Object element)
136147
{
137148
if (element instanceof String)
@@ -372,4 +383,15 @@ public Color getBackground(Object element) {
372383

373384
}
374385

386+
387+
@Override
388+
public void propertyChange(PropertyChangeEvent event) {
389+
// TODO Auto-generated method stub
390+
391+
}
392+
393+
@Override
394+
protected Point computeCellBounds(GC gc, Point extent) {
395+
return extent;
396+
}
375397
}

edu.rice.cs.hpcviewer.ui/src/edu/rice/cs/hpcviewer/ui/internal/ScopeTreeViewer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ public ScopeTreeViewer(Composite parent, int style) {
6565
// hack: on Windows, we have to add SWT.FULL_SELECTION to allow users
6666
// to select a row in the table.
6767
super(parent, SWT.VIRTUAL | SWT.FULL_SELECTION | style);
68+
69+
computeIdealCellBound();
6870

6971
setUseHashlookup(true);
7072
getTree().setLinesVisible(true);
@@ -85,8 +87,6 @@ public void widgetDisposed(DisposeEvent e) {
8587
// Fix bug #25: tooltip is not wrapped on MacOS
8688
ColumnViewerToolTipSupport.enableFor(this, ToolTip.NO_RECREATE);
8789

88-
computeIdealCellBound();
89-
9090
getTree().addListener(SWT.MeasureItem, this);
9191
}
9292

0 commit comments

Comments
 (0)