2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.preference
;
11 import java
.util
.HashMap
;
12 import java
.util
.List
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.jface
.preference
.PreferencePage
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.layout
.GridLayout
;
19 import org
.eclipse
.swt
.widgets
.Button
;
20 import org
.eclipse
.swt
.widgets
.Composite
;
21 import org
.eclipse
.swt
.widgets
.Control
;
22 import org
.eclipse
.ui
.IWorkbench
;
23 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
25 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
26 import eu
.etaxonomy
.taxeditor
.controller
.PreferencesController
;
27 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
34 public class FeaturePreferences
extends PreferencePage
implements
35 IWorkbenchPreferencePage
{
36 private static final Logger logger
= Logger
37 .getLogger(FeaturePreferences
.class);
39 public static final String PLUGIN_ID
= "eu.etaxonomy.taxeditor.preferences.feature";
41 private Map
<Feature
, Button
> featureButtons
;
43 private Composite container
;
45 public FeaturePreferences() {
47 setDescription("Choose which features you would like to use for descriptive elements.");
52 * Create contents of the preference page
56 public Control
createContents(Composite parent
) {
58 featureButtons
= new HashMap
<Feature
, Button
>();
60 container
= new Composite(parent
, SWT
.NULL
);
61 final GridLayout gridLayout
= new GridLayout();
62 gridLayout
.numColumns
= 3;
63 container
.setLayout(gridLayout
);
65 List
<Feature
> features
=
66 CdmSessionDataRepository
.getDefault().getFeatures();
68 // Purpose of this code block:
69 // fill first column, then second, then third
70 Object
[] array
= features
.toArray();
71 int count
= features
.size();
72 int colheight
= count
/ 3;
76 for (int i
= 0; i
< colheight
; i
++) {
77 createButton((Feature
) array
[i
]);
78 if (i
+ colheight
< count
) {
79 createButton((Feature
) array
[i
+ colheight
]);
81 if (i
+ (colheight
* 2) < count
) {
82 createButton((Feature
) array
[i
+ (colheight
* 2)]);
92 private void createButton(Feature feature
) {
93 Button button
= new Button(container
, SWT
.CHECK
);
94 button
.setText(feature
.getLabel());
95 featureButtons
.put(feature
, button
);
97 if (PreferencesController
.getFeaturePreference(feature
)) {
98 button
.setSelection(true);
104 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
106 public void init(IWorkbench workbench
) {
107 setPreferenceStore(PreferencesController
.getPrefStore());
111 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
113 protected void performDefaults() {
115 // Set all buttons to show feature
116 for (Button button
: featureButtons
.values()) {
117 button
.setSelection(true);
122 * @see org.eclipse.jface.preference.PreferencePage#performOk()
124 public boolean performOk() {
126 for (Feature feature
: featureButtons
.keySet()) {
127 Button button
= featureButtons
.get(feature
);
128 PreferencesController
.setFeaturePreference(feature
, button
.getSelection());