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