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 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 List
<Feature
> features
=
64 CdmSessionDataRepository
.getDefault().getFeatures();
66 for (Feature feature
: features
) {
68 Button button
= new Button(container
, SWT
.CHECK
);
69 button
.setText(feature
.getLabel());
70 featureButtons
.put(feature
, button
);
72 if (PreferencesController
.getFeaturePreference(feature
)) {
73 button
.setSelection(true);
82 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
84 public void init(IWorkbench workbench
) {
85 setPreferenceStore(PreferencesController
.getPrefStore());
89 * @see org.eclipse.jface.preference.PreferencePage#performDefaults()
91 protected void performDefaults() {
93 // Set all buttons to show feature
94 for (Button button
: featureButtons
.values()) {
95 button
.setSelection(true);
100 * @see org.eclipse.jface.preference.PreferencePage#performOk()
102 public boolean performOk() {
104 for (Feature feature
: featureButtons
.keySet()) {
105 Button button
= featureButtons
.get(feature
);
106 PreferencesController
.setFeaturePreference(feature
, button
.getSelection());