Project

General

Profile

« Previous | Next » 

Revision 736d82ea

Added by Katja Luther about 4 years ago

ref #8047: adapt column width to length of header label

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/CdmModernNatTableThemeConfiguration.java
1
/**
2
* Copyright (C) 2020 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.view.checklist.e4;
10

  
11
import org.eclipse.nebula.widgets.nattable.group.painter.ColumnGroupHeaderTextPainter;
12
import org.eclipse.nebula.widgets.nattable.group.painter.RowGroupHeaderTextPainter;
13
import org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter;
14
import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
15
import org.eclipse.nebula.widgets.nattable.painter.cell.VerticalTextPainter;
16
import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator;
17
import org.eclipse.nebula.widgets.nattable.sort.painter.SortIconPainter;
18
import org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter;
19
import org.eclipse.nebula.widgets.nattable.style.BorderStyle;
20
import org.eclipse.nebula.widgets.nattable.style.BorderStyle.LineStyleEnum;
21
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
22
import org.eclipse.nebula.widgets.nattable.style.theme.DefaultNatTableThemeConfiguration;
23
import org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter;
24
import org.eclipse.nebula.widgets.nattable.tree.painter.TreeImagePainter;
25
import org.eclipse.nebula.widgets.nattable.ui.util.CellEdgeEnum;
26
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.graphics.FontData;
29

  
30
/**
31
 * This is a class copied from ModernNatTableThemeConfiguration and adapted to the Cdm use case.
32
 *
33
 * @author k.luther
34
 * @since Mar 5, 2020
35
 */
36
public class CdmModernNatTableThemeConfiguration extends DefaultNatTableThemeConfiguration {
37
    {
38
    this.defaultHAlign = HorizontalAlignmentEnum.LEFT;
39
    this.defaultCellPainter =
40
            new BackgroundPainter(
41
                    new PaddingDecorator(
42
                            new TextPainter(false, false),
43
                            0,
44
                            5,
45
                            0,
46
                            5,
47
                            false));
48

  
49
    // column header styling
50
    this.cHeaderHAlign = HorizontalAlignmentEnum.LEFT;
51
    this.cHeaderFont = GUIHelper.DEFAULT_FONT;
52
    TextPainter painter = new TextPainter();
53
    painter.setCalculateByTextLength(true);
54
    painter.setWrapText(false);
55
    this.cHeaderCellPainter =
56
            new PaddingDecorator(
57
                   painter,
58
                    0,
59
                    5,
60
                    0,
61
                    5);
62

  
63
    // column header selection style
64
    this.cHeaderSelectionFont = GUIHelper.DEFAULT_FONT;
65
    this.cHeaderSelectionCellPainter =
66
            new BackgroundPainter(
67
                    new PaddingDecorator(
68
                            new TextPainter(false, false),
69
                            0,
70
                            5,
71
                            0,
72
                            5,
73
                            false));
74

  
75
    // row header styling
76
    this.rHeaderFont = GUIHelper.DEFAULT_FONT;
77

  
78
    // row header selection style
79
    this.rHeaderSelectionFont = GUIHelper.DEFAULT_FONT;
80
    this.rHeaderSelectionCellPainter = new TextPainter();
81

  
82
    // no alternate row styling
83
    this.evenRowBgColor = GUIHelper.COLOR_WHITE;
84
    this.oddRowBgColor = GUIHelper.COLOR_WHITE;
85

  
86
    // default selection style
87
    this.defaultSelectionBgColor = GUIHelper.COLOR_LIST_SELECTION;
88
    this.defaultSelectionFgColor = GUIHelper.COLOR_WHITE;
89
    this.defaultSelectionFont = GUIHelper.DEFAULT_FONT;
90

  
91
    // selection anchor
92
    this.selectionAnchorSelectionBgColor = GUIHelper.COLOR_LIST_SELECTION;
93
    this.selectionAnchorSelectionFgColor = GUIHelper.COLOR_WHITE;
94
    this.selectionAnchorBorderStyle = new BorderStyle(1, GUIHelper.COLOR_BLUE, LineStyleEnum.SOLID);
95

  
96
    // column/row group header style
97
    this.cGroupHeaderHAlign = HorizontalAlignmentEnum.CENTER;
98
    this.cGroupHeaderCellPainter = new ColumnGroupHeaderTextPainter();
99
    this.rGroupHeaderCellPainter =
100
            new BackgroundPainter(
101
                    new PaddingDecorator(
102
                            new RowGroupHeaderTextPainter(
103
                                    new VerticalTextPainter(false, false),
104
                                    CellEdgeEnum.BOTTOM,
105
                                    false,
106
                                    2,
107
                                    true),
108
                            0,
109
                            0,
110
                            2,
111
                            0,
112
                            false));
113

  
114
    // sort header styling
115
    this.sortHeaderCellPainter =
116
            new BackgroundPainter(
117
                    new PaddingDecorator(
118
                            new SortableHeaderTextPainter(
119
                                    new TextPainter(false, false),
120
                                    CellEdgeEnum.RIGHT,
121
                                    new SortIconPainter(false),
122
                                    false,
123
                                    0,
124
                                    false),
125
                            0,
126
                            2,
127
                            0,
128
                            5,
129
                            false));
130
    this.selectedSortHeaderCellPainter =
131
            new BackgroundPainter(
132
                    new PaddingDecorator(
133
                            new SortableHeaderTextPainter(
134
                                    new TextPainter(false, false),
135
                                    CellEdgeEnum.RIGHT,
136
                                    new SortIconPainter(false, true),
137
                                    false,
138
                                    0,
139
                                    false),
140
                            0,
141
                            2,
142
                            0,
143
                            5,
144
                            false));
145

  
146
    TreeImagePainter treeImagePainter =
147
            new TreeImagePainter(
148
                    false,
149
                    GUIHelper.getImage("right"), //$NON-NLS-1$
150
                    GUIHelper.getImage("right_down"), //$NON-NLS-1$
151
                    null);
152
    this.treeStructurePainter =
153
            new BackgroundPainter(
154
                    new PaddingDecorator(
155
                            new IndentedTreeImagePainter(
156
                                    10,
157
                                    null,
158
                                    CellEdgeEnum.LEFT,
159
                                    treeImagePainter,
160
                                    false,
161
                                    2,
162
                                    true),
163
                            0,
164
                            5,
165
                            0,
166
                            5,
167
                            false));
168

  
169
    TreeImagePainter treeSelectionImagePainter =
170
            new TreeImagePainter(
171
                    false,
172
                    GUIHelper.getImage("right_inv"), //$NON-NLS-1$
173
                    GUIHelper.getImage("right_down_inv"), //$NON-NLS-1$
174
                    null);
175
    this.treeStructureSelectionPainter =
176
            new BackgroundPainter(
177
                    new PaddingDecorator(
178
                            new IndentedTreeImagePainter(
179
                                    10,
180
                                    null,
181
                                    CellEdgeEnum.LEFT,
182
                                    treeSelectionImagePainter,
183
                                    false,
184
                                    2,
185
                                    true),
186
                            0,
187
                            5,
188
                            0,
189
                            5,
190
                            false));
191

  
192
    FontData summaryRowFontData = GUIHelper.DEFAULT_FONT.getFontData()[0];
193
    summaryRowFontData.setStyle(SWT.BOLD);
194
    this.summaryRowFont = GUIHelper.getFont(summaryRowFontData);
195
    this.summaryRowHAlign = HorizontalAlignmentEnum.RIGHT;
196
    this.summaryRowBgColor = GUIHelper.COLOR_WIDGET_LIGHT_SHADOW;
197

  
198
    this.summaryRowSelectionFont = GUIHelper.getFont(summaryRowFontData);
199
    this.summaryRowSelectionBgColor = GUIHelper.COLOR_WIDGET_DARK_SHADOW;
200

  
201
    this.renderCornerGridLines = true;
202
    this.renderColumnHeaderGridLines = true;
203
}
204
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/DistributionEditor.java
55 55
import org.eclipse.nebula.widgets.nattable.layer.AbstractLayer;
56 56
import org.eclipse.nebula.widgets.nattable.layer.DataLayer;
57 57
import org.eclipse.nebula.widgets.nattable.layer.ILayer;
58
import org.eclipse.nebula.widgets.nattable.layer.config.DefaultColumnHeaderStyleConfiguration;
59
import org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter;
60
import org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator;
58 61
import org.eclipse.nebula.widgets.nattable.selection.SelectionLayer;
59 62
import org.eclipse.nebula.widgets.nattable.sort.config.SingleClickSortConfiguration;
60
import org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum;
61
import org.eclipse.nebula.widgets.nattable.style.theme.ModernNatTableThemeConfiguration;
62 63
import org.eclipse.nebula.widgets.nattable.util.GUIHelper;
63 64
import org.eclipse.swt.SWT;
64 65
import org.eclipse.swt.events.SelectionAdapter;
......
297 298
    }
298 299

  
299 300
    private void applyStyles(){
300
        ModernNatTableThemeConfiguration configuration = new ModernNatTableThemeConfiguration();
301
        configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
301
        CdmModernNatTableThemeConfiguration configuration = new CdmModernNatTableThemeConfiguration();
302

  
303
//        configuration.summaryRowHAlign = HorizontalAlignmentEnum.CENTER;
302 304
        // NOTE: Getting the colors and fonts from the GUIHelper ensures that
303 305
        // they are disposed properly (required by SWT)
304 306
        configuration.cHeaderBgColor = GUIHelper.getColor(211, 211, 211);
......
314 316
         */
315 317
        natTable.setConfigRegistry(configRegistry);
316 318

  
317
        applyStyles();
319

  
318 320

  
319 321
        //add default configuration because autoconfigure is set to false in constructor
320 322
        natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
321 323

  
322 324

  
325
        natTable.addConfiguration(new DefaultColumnHeaderStyleConfiguration() {
326
            {
327
                TextPainter painter = new TextPainter();
328
                painter.setCalculateByTextLength(true);
329
                painter.setWrapText(false);
323 330

  
331
                cellPainter = new BeveledBorderDecorator(painter);
332

  
333
            }
334
        });
335
//        applyStyles();
324 336
        // override the default sort configuration and change the mouse bindings
325 337
        // to sort on a single click
326 338

  
......
334 346
        // add custom configuration for data conversion and add column labels to viewport layer
335 347
        topMostLayer.addConfiguration(new DistributionCellEditorDataConversionConfiguration(this));
336 348

  
349

  
350
        applyStyles();
337 351
        natTable.configure();
338 352
    }
339 353

  
......
450 464

  
451 465
        natTable.setLayer(gridLayer);
452 466

  
467

  
453 468
        topMostLayer = compositeFreezeLayer;
454 469

  
455 470

  

Also available in: Unified diff