Added FeaturePreferences to enable user to choose which Features to display in the...
[taxeditor.git] / eclipseprojects / eu.etaxonomy.taxeditor / src / eu / etaxonomy / taxeditor / preference / FeaturePreferences.java
1 /**
2 * Copyright (C) 2007 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.preference;
10
11 import java.util.HashMap;
12 import java.util.Map;
13
14 import org.apache.log4j.Logger;
15 import org.eclipse.jface.preference.PreferencePage;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.layout.GridLayout;
18 import org.eclipse.swt.widgets.Button;
19 import org.eclipse.swt.widgets.Composite;
20 import org.eclipse.swt.widgets.Control;
21 import org.eclipse.ui.IWorkbench;
22 import org.eclipse.ui.IWorkbenchPreferencePage;
23
24 import eu.etaxonomy.cdm.model.common.TermVocabulary;
25 import eu.etaxonomy.cdm.model.description.Feature;
26 import eu.etaxonomy.taxeditor.UiUtil;
27 import eu.etaxonomy.taxeditor.model.CdmUtil;
28
29 /**
30 * @author p.ciardelli
31 * @created 17.09.2008
32 * @version 1.0
33 */
34 public class FeaturePreferences extends PreferencePage implements
35 IWorkbenchPreferencePage {
36 private static final Logger logger = Logger
37 .getLogger(FeaturePreferences.class);
38
39 public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.feature";
40
41 private Map<Feature, Button> featureButtons;
42
43 public FeaturePreferences() {
44 super();
45 setDescription("Choose which features you would like to use for descriptive elements.");
46 }
47
48
49 /**
50 * Create contents of the preference page
51 * @param parent
52 */
53 @Override
54 public Control createContents(Composite parent) {
55
56 featureButtons = new HashMap<Feature, Button>();
57
58 Composite container = new Composite(parent, SWT.NULL);
59 final GridLayout gridLayout = new GridLayout();
60 gridLayout.numColumns = 3;
61 container.setLayout(gridLayout);
62
63 TermVocabulary<Feature> features = CdmUtil.getDescriptionService().
64 getDefaultFeatureVocabulary();
65 for (Feature feature : features) {
66
67 Button button = new Button(container, SWT.CHECK);
68 button.setText(feature.getLabel());
69 featureButtons.put(feature, button);
70
71 if (UiUtil.getFeaturePreference(feature)) {
72 button.setSelection(true);
73 }
74 }
75
76 return container;
77 }
78
79
80 /* (non-Javadoc)
81 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
82 */
83 public void init(IWorkbench workbench) {
84 setPreferenceStore(UiUtil.getPrefStore());
85 }
86
87 /* (non-Javadoc)
88 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
89 */
90 protected void performDefaults() {
91
92 // Set all buttons to show feature
93 for (Button button : featureButtons.values()) {
94 button.setSelection(true);
95 }
96 }
97
98 /* (non-Javadoc)
99 * @see org.eclipse.jface.preference.PreferencePage#performOk()
100 */
101 public boolean performOk() {
102
103 for (Feature feature : featureButtons.keySet()) {
104 Button button = featureButtons.get(feature);
105 UiUtil.setFeaturePreference(feature, button.getSelection());
106 }
107
108 return true;
109 }
110 }