implementation and generalization of a form framework to be used in the tabbed proper...
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / forms / EditorFormToolkit.java
1 /**
2 *
3 */
4 package eu.etaxonomy.taxeditor.forms;
5
6 import java.net.URI;
7
8 import org.eclipse.swt.graphics.Font;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Display;
11 import org.eclipse.ui.forms.FormColors;
12 import org.eclipse.ui.forms.IFormColors;
13 import org.eclipse.ui.forms.widgets.FormToolkit;
14 import org.eclipse.ui.forms.widgets.Section;
15 import org.eclipse.ui.internal.forms.widgets.FormFonts;
16
17 import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
18 import eu.etaxonomy.cdm.model.common.Annotation;
19 import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
20 import eu.etaxonomy.cdm.model.common.Language;
21 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
22 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
23 import eu.etaxonomy.taxeditor.forms.entitysections.AnnotationComposite;
24 import eu.etaxonomy.taxeditor.forms.entitysections.AnnotationSection;
25 import eu.etaxonomy.taxeditor.forms.entitysections.DescriptionElementSourceComposite;
26 import eu.etaxonomy.taxeditor.forms.entitysections.OriginalSourceSection;
27 import eu.etaxonomy.taxeditor.forms.selectioncomposites.TaxonSelectionComposite;
28 import eu.etaxonomy.taxeditor.forms.termcombos.LanguageComboComposite;
29
30 /**
31 * @author nho
32 *
33 */
34 public class EditorFormToolkit extends FormToolkit{
35
36 private BoldFontHolder2 boldFontHolder2;
37
38 /**
39 * @param display
40 */
41 public EditorFormToolkit(Display display) {
42 super(display);
43 init();
44 }
45
46 /**
47 *
48 */
49 private void init() {
50 boldFontHolder2 = new BoldFontHolder2();
51 }
52
53 /**
54 * @param display
55 */
56 public EditorFormToolkit(FormColors colors) {
57 super(colors);
58 init();
59 }
60
61 /**
62 *
63 * @param parent
64 * @param style
65 * @return
66 */
67 public Container createContainer(Composite parent, int style){
68 return new Container(parent, style);
69
70 }
71
72 /**
73 *
74 * @param parent
75 * @param labelString
76 * @param textHeight
77 * @param style
78 * @return
79 */
80 public MultilineTextWithLabel createMultilineTextWithLabel(Composite parent, String labelString, int textHeight, int style){
81 return new MultilineTextWithLabel(parent, labelString, "", textHeight, style);
82 }
83
84 /**
85 *
86 * @param parent
87 * @param source
88 * @param style
89 * @return
90 */
91 public DescriptionElementSourceComposite createDescriptionElementSourceComposite(Composite parent, DescriptionElementSource source, int style){
92 return new DescriptionElementSourceComposite(parent, source, style);
93 }
94
95 /**
96 *
97 * @param parent
98 * @param labelString
99 * @param initialText
100 * @param style
101 * @return
102 */
103 public TextWithLabelComposite createTextWithLabelComposite(Composite parent, String labelString, String initialText, int style){
104 return new TextWithLabelComposite(parent, labelString, initialText, style);
105 }
106
107 /**
108 *
109 * @param parent
110 * @param labelString
111 * @param selection
112 * @param style
113 * @return
114 */
115 public LanguageComboComposite createLanguageComboComposite(Composite parent, String labelString, Language selection, int style){
116 return new LanguageComboComposite(parent, labelString, selection, style);
117 }
118
119 /**
120 *
121 * @param parent
122 * @param imageUri
123 * @param style
124 * @return
125 */
126 public ImageComposite createImageComposite(Composite parent, URI imageUri, int style){
127 return new ImageComposite(parent, imageUri, style);
128 }
129
130 /**
131 *
132 * @param parent
133 * @param labelString
134 * @param initialText
135 * @param style
136 * @return
137 */
138 public TextActionComposite createTextActionComposite(Composite parent, String labelString, String initialText, int style){
139 return new TextActionComposite(parent, labelString, initialText, style);
140 }
141
142 /**
143 *
144 * @param parent
145 * @param annotation
146 * @param style
147 * @return
148 */
149 public AnnotationComposite createAnnotationComposite(Composite parent, Annotation annotation, int style) {
150 return new AnnotationComposite(parent, annotation, style);
151 }
152
153 /**
154 *
155 * @param parent
156 * @param selection
157 * @param style
158 * @return
159 */
160 public TaxonSelectionComposite createTaxonSelectionComposite(Composite parent, TaxonBase selection, int style) {
161 return new TaxonSelectionComposite(parent, "Taxon", selection, style);
162 }
163
164 /**
165 *
166 * @param parent
167 * @param annotatableEntity
168 * @param style
169 * @return
170 */
171 public AnnotationSection createAnnotationSection(Composite parent, AnnotatableEntity annotatableEntity, int style){
172 return new AnnotationSection(parent, annotatableEntity, style);
173 }
174
175 /**
176 *
177 * @param parent
178 * @param entity
179 * @param style
180 * @return
181 */
182 public OriginalSourceSection createOriginalSourceSection(Composite parent, DescriptionElementBase entity, int style){
183 return new OriginalSourceSection(parent, entity, style);
184 }
185
186
187 /**
188 * Creates a section as a part of the form.
189 *
190 * @param parent
191 * the section parent
192 * @param sectionStyle
193 * the section style
194 * @return the section widget
195 */
196 public Section adapt(AbstractEditorFormSection section) {
197 section.setMenu(section.getParent().getMenu());
198 adapt(section, true, true);
199 if (section.getToggle() != null) {
200 section.getToggle().setHoverDecorationColor(getColors()
201 .getColor(IFormColors.TB_TOGGLE_HOVER));
202 section.getToggle().setDecorationColor(getColors()
203 .getColor(IFormColors.TB_TOGGLE));
204 }
205
206 section.setFont(boldFontHolder2.getBoldFont(section.getParent().getFont()));
207
208 // if ((section.getStyle() & Section.TITLE_BAR) != 0
209 // || (section.getStyle() & Section.SHORT_TITLE_BAR) != 0) {
210 getColors().initializeSectionToolBarColors();
211 section.setTitleBarBackground(getColors().getColor(IFormColors.TB_BG));
212 section.setTitleBarBorderColor(getColors()
213 .getColor(IFormColors.TB_BORDER));
214 // }
215 // call setTitleBarForeground regardless as it also sets the label color
216 section.setTitleBarForeground(getColors()
217 .getColor(IFormColors.TB_TOGGLE));
218 return section;
219 }
220
221 private class BoldFontHolder2 {
222 private Font normalFont;
223
224 private Font boldFont;
225
226 public BoldFontHolder2() {
227 }
228
229 public Font getBoldFont(Font font) {
230 createBoldFont(font);
231 return boldFont;
232 }
233
234 private void createBoldFont(Font font) {
235 if (normalFont == null || !normalFont.equals(font)) {
236 normalFont = font;
237 dispose();
238 }
239 if (boldFont == null) {
240 boldFont = FormFonts.getInstance().getBoldFont(getColors().getDisplay(),
241 normalFont);
242 }
243 }
244
245 public void dispose() {
246 if (boldFont != null) {
247 FormFonts.getInstance().markFinished(boldFont);
248 boldFont = null;
249 }
250 }
251 }
252
253
254 }