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
;
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
;
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
;
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 public FeaturePreferences() {
45 setDescription("Choose which features you would like to use for descriptive elements.");
50 * Create contents of the preference page
54 public Control
createContents(Composite parent
) {
56 featureButtons
= new HashMap
<Feature
, Button
>();
58 Composite container
= new Composite(parent
, SWT
.NULL
);
59 final GridLayout gridLayout
= new GridLayout();
60 gridLayout
.numColumns
= 3;
61 container
.setLayout(gridLayout
);
63 TermVocabulary
<Feature
> features
= CdmUtil
.getDescriptionService().
64 getDefaultFeatureVocabulary();
65 for (Feature feature
: features
) {
67 Button button
= new Button(container
, SWT
.CHECK
);
68 button
.setText(feature
.getLabel());
69 featureButtons
.put(feature
, button
);
71 if (UiUtil
.getFeaturePreference(feature
)) {
72 button
.setSelection(true);
81 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
83 public void init(IWorkbench workbench
) {
84 setPreferenceStore(UiUtil
.getPrefStore());
88 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
90 protected void performDefaults() {
92 // Set all buttons to show feature
93 for (Button button
: featureButtons
.values()) {
94 button
.setSelection(true);
99 * @see org.eclipse.jface.preference.PreferencePage#performOk()
101 public boolean performOk() {
103 for (Feature feature
: featureButtons
.keySet()) {
104 Button button
= featureButtons
.get(feature
);
105 UiUtil
.setFeaturePreference(feature
, button
.getSelection());