72cbe43789bc8095b3e5aec2272184cb564e7c04
[taxeditor.git] / taxeditor-store / src / main / java / eu / etaxonomy / taxeditor / preference / RankMenuPreferences.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 import java.util.SortedSet;
14
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.name.Rank;
25 import eu.etaxonomy.taxeditor.store.CdmStore;
26
27 /**
28 * Allows the user to choose which <code>Rank</code>s to display in the
29 * <code>PropertySheet</code> drop-down menu for <code>TaxonNameBase</code>.
30 *
31 * @author p.ciardelli
32 * @created 17.09.2008
33 * @version 1.0
34 */
35 public class RankMenuPreferences extends PreferencePage implements
36 IWorkbenchPreferencePage {
37
38 public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.ranks";
39
40 private Map<Rank, Button> rankButtons;
41
42 public RankMenuPreferences() {
43 super();
44 setDescription("Choose which ranks to display in the property sheet drop-down menu.");
45 }
46
47
48 /**
49 * Create contents of the preference page
50 * @param parent
51 */
52 @Override
53 public Control createContents(Composite parent) {
54
55 rankButtons = new HashMap<Rank, Button>();
56
57 Composite container = new Composite(parent, SWT.NULL);
58 final GridLayout gridLayout = new GridLayout();
59 gridLayout.numColumns = 3;
60 container.setLayout(gridLayout);
61
62 CdmStore.getDefault();
63 SortedSet<Rank> ranks = CdmStore.getRanks();
64
65 for (Rank rank : ranks) {
66
67 Button button = new Button(container, SWT.CHECK);
68 button.setText(rank.getLabel());
69 rankButtons.put(rank, button);
70
71 if (PreferencesUtil.getRankPreference(rank)) {
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(PreferencesUtil.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 : rankButtons.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 (Rank rank : rankButtons.keySet()) {
104 Button button = rankButtons.get(rank);
105 PreferencesUtil.setRankPreference(rank, button.getSelection());
106 }
107
108 return true;
109 }
110 }