Skip to content

Commit

Permalink
Fix issue #199 (no scroll bar when only the tree column is visible)
Browse files Browse the repository at this point in the history
The root cause of this is because the scroll bar only appears if the
metric columns are also visible.
To ensure the scroll bar is visible, the width of tree column needs to
be adjusted to allow at least one metric column is visible.
  • Loading branch information
la5 committed May 16, 2022
1 parent 3e71328 commit 8928a24
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
69 changes: 60 additions & 9 deletions edu.rice.cs.hpctree/src/edu/rice/cs/hpctree/ScopeTreeTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import edu.rice.cs.hpcsetting.fonts.FontManager;
import edu.rice.cs.hpctree.action.IActionListener;
import edu.rice.cs.hpctree.internal.ColumnHeaderDataProvider;
import edu.rice.cs.hpctree.internal.ResizeListener;
import edu.rice.cs.hpctree.internal.ScopeTooltip;
import edu.rice.cs.hpctree.internal.ScopeTreeBodyLayerStack;
import edu.rice.cs.hpctree.internal.ScopeTreeDataProvider;
Expand Down Expand Up @@ -205,8 +206,8 @@ public ScopeTreeTable(Composite parent, int style, IScopeTreeData treeData) {
treeData.getMetricManager().addMetricListener(this);

// Fix issue #145: do not listen to table resizing
//resizeListener = new ResizeListener(this);
//parent.addControlListener(resizeListener);
// fix issue #199: resizing table should at least show 1 metric column
parent.addControlListener(new ResizeListener(this));
}


Expand Down Expand Up @@ -394,13 +395,7 @@ public void pack() {
// compute the size of the tree column
// if the total size is less than the display, we can use the percentage for the tree column
// otherwise we should specify explicitly the width
Rectangle area = natTable.getClientArea();
if (area.width < 10) {
area = natTable.getShell().getClientArea();
area.width -= 20;
}

int areaWidth = GUIHelper.convertHorizontalDpiToPixel(area.width);
int areaWidth = getTableWidth();

// tree column: the width is the max between
// - TREE_COLUMN_WIDTH,
Expand All @@ -427,6 +422,62 @@ public void pack() {
gc.dispose();
}


/*****
* Arrange the table so that it displays at least
* a certain number of metric columns
*
* @param numVisibleMetricColumns
* Number of metric columns to be visible
*/
public void pack(int numVisibleMetricColumns) {
DataLayer bodyDataLayer = bodyLayerStack.getBodyDataLayer();
int width = bodyDataLayer.getColumnWidthByPosition(0);

// compute the size of the tree column
// if the size is bigger than the table width, we need to
// reduce its width to fit the metric columns

int areaWidth = getTableWidth();

if (width < areaWidth)
return;

final GC gc = new GC(natTable.getDisplay());
final Font genericFont = FontManager.getFontGeneric();
gc.setFont(genericFont);

final Point columnSize = getMetricColumnSize();
final ColumnHideShowLayer hideShowLayer = bodyLayerStack.getColumnHideShowLayer();
int totalMetricColumnWidth = areaWidth;

for(int i=0; i<numVisibleMetricColumns; i++) {
// List of metrics is based on column position, while the current display is based on index.
// We need to convert from an index to a position.
int position = hideShowLayer.getColumnIndexByPosition(1+i);
if (position < 0)
continue;

String title = bodyDataProvider.getMetric(position).getDisplayName() + STRING_PADDING;
Point titleSize = gc.textExtent(title);

int colWidth = (int) Math.max(titleSize.x , columnSize.x);
totalMetricColumnWidth -= GUIHelper.convertHorizontalDpiToPixel(colWidth);
}
bodyDataLayer.setColumnWidthByPosition(0, totalMetricColumnWidth);
gc.dispose();
}


private int getTableWidth() {
Rectangle area = natTable.getClientArea();
if (area.width < 10) {
area = natTable.getShell().getClientArea();
area.width -= 20;
}

return GUIHelper.convertHorizontalDpiToPixel(area.width);
}

private Point getMetricColumnSize() {
final GC gc = new GC(natTable.getDisplay());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public void handleEvent(Event event) {
@Override
public void run() {
if ((lastEvent + 500) < System.currentTimeMillis() && mouse) {
table.pack();
// fix issue #199: at least one metric column is visible when resizing the app
table.pack(1);
} else {
Display.getDefault().timerExec(500, this);
}
Expand Down

0 comments on commit 8928a24

Please sign in to comment.