]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/ColumnFactory.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / ColumnFactory.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.common;
13
14 import org.simantics.browsing.ui.Column;
15 import org.simantics.browsing.ui.Column.Align;
16
17 /**
18  * A factory for constructing new {@link Column} instances in chained
19  * initialization coding style. The same factory can be used to create any
20  * number of new {@link Column} instances.
21  * 
22  * @see Column
23  * 
24  * @author Tuukka Lehtonen
25  */
26 public class ColumnFactory {
27
28     String key;
29
30     String label;
31
32     Align alignment;
33
34     int    width;
35
36     String tooltip;
37
38     boolean grab = false;
39
40     private ColumnFactory(String key) {
41         this.key = key;
42         this.alignment = Align.LEFT;
43         this.width = Column.DEFAULT_CONTROL_WIDTH;
44         this.tooltip = "";
45     }
46
47     private ColumnFactory(String key, Align alignment, int width, String tooltip) {
48         this.key = key;
49         this.alignment = alignment;
50         this.width = width;
51         this.tooltip = tooltip;
52     }
53
54     public static ColumnFactory defaults(String key) {
55         return new ColumnFactory(key);
56     }
57
58     public static ColumnFactory get(Column c) {
59         return new ColumnFactory(c.getKey(), c.getAlignment(), c.getWidth(), c.getTooltip());
60     }
61
62     public ColumnFactory key(String key) {
63         this.key = key;
64         return this;
65     }
66
67     public ColumnFactory label(String label) {
68         this.label = label;
69         return this;
70     }
71
72     public ColumnFactory alignment(Align alignment) {
73         this.alignment = alignment;
74         return this;
75     }
76
77     public ColumnFactory width(int width) {
78         this.width = width;
79         return this;
80     }
81
82     public ColumnFactory tooltip(String tooltip) {
83         this.tooltip = tooltip;
84         return this;
85     }
86
87     public ColumnFactory grab() {
88         this.grab = true;
89         return this;
90     }
91
92     public Column toColumn() {
93         return new Column(key, label, alignment, width, tooltip, grab);
94     }
95
96 }