Skip to content
Snippets Groups Projects
Commit b7009286 authored by Simon Barner's avatar Simon Barner
Browse files

- Automatically adjust column width (within a range of 125..150 points)

- Cache column width (possibly manually adjusted by the user)
refs 1841
parent f44a04e3
No related branches found
No related tags found
No related merge requests found
......@@ -20,7 +20,9 @@ package org.fortiss.tooling.base.ui.annotation.view;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
......@@ -100,6 +102,12 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
/** Number of fixed columns shown for every model element (e.g., name, comment). */
int fixedColumnCount;
/** Map used to preserve column width during update of the view. */
Map<String, Integer> columnWidthCache;
/** Default width of columns */
static final int COLUMN_DEFAULT_WIDTH = 125;
/**
* Data required to identify a column displaying a particular {@link IAnnotatedSpecification} in
* a column of the {@link GenericAnnotationView}. Used to sort columns (see
......@@ -726,7 +734,9 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
* hold the model elements' names and comments.
*/
while(tableViewer.getTable().getColumnCount() > fixedColumnCount) {
tableViewer.getTable().getColumn(fixedColumnCount).dispose();
TableColumn column = tableViewer.getTable().getColumn(fixedColumnCount);
columnWidthCache.put(column.getText(), column.getWidth());
column.dispose();
}
// Aggregate required columns. Column order is defined by ColumnHandle.compareTo().
......@@ -798,6 +808,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
table.setLayout(new FillLayout(SWT.VERTICAL));
fixedColumnCount = createFixedModelElementColumns();
columnWidthCache = new HashMap<String, Integer>();
tableViewer.setComparator(new HierarchicalNameComparator());
......@@ -817,7 +828,7 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
EditingSupport editingSupport) {
TableViewerColumn column = new TableViewerColumn(tableViewer, SWT.NONE);
column.getColumn().setText(label);
column.getColumn().setWidth(100);
column.getColumn().setWidth(COLUMN_DEFAULT_WIDTH);
tableViewer.setContentProvider(new ArrayContentProvider());
column.setLabelProvider(labelProvider);
......@@ -883,7 +894,20 @@ public class GenericAnnotationView extends AnnotationViewPartBase {
}
if(tableColumn != null) {
tableColumn.setWidth(125);
Integer width = columnWidthCache.get(tableColumn.getText());
if(width != null) {
// If possible, use cached with (possibly adjusted by the user)
tableColumn.setWidth(width);
} else {
// Otherwise, calculate width for new columns
tableColumn.pack();
width = tableColumn.getWidth();
if(width < COLUMN_DEFAULT_WIDTH) {
tableColumn.setWidth(COLUMN_DEFAULT_WIDTH);
} else if(width > 1.2f * COLUMN_DEFAULT_WIDTH) {
tableColumn.setWidth(Math.round(1.2f * COLUMN_DEFAULT_WIDTH));
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment