fix name editor menu for synonyms and misapplications
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / databaseAdmin / preferencePage / ChecklistEditorGeneralPreference.java
1 /**
2 * Copyright (C) 2014 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.databaseAdmin.preferencePage;
10
11 import org.eclipse.swt.SWT;
12 import org.eclipse.swt.custom.CLabel;
13 import org.eclipse.swt.events.SelectionAdapter;
14 import org.eclipse.swt.events.SelectionEvent;
15 import org.eclipse.swt.layout.GridLayout;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Control;
19
20 import eu.etaxonomy.cdm.api.application.ICdmRepository;
21 import eu.etaxonomy.cdm.api.service.IPreferenceService;
22 import eu.etaxonomy.cdm.model.metadata.CdmPreference;
23 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
24 import eu.etaxonomy.taxeditor.l10n.Messages;
25 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
26 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
27 import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
28 import eu.etaxonomy.taxeditor.store.CdmStore;
29 import eu.etaxonomy.taxeditor.ui.element.CommandHandlerButton;
30
31 /**
32 * @author a.oppermann
33 * @date 21.07.2014
34 *
35 */
36 public class ChecklistEditorGeneralPreference extends CdmPreferencePage implements IE4AdminPreferencePage {
37
38 boolean isEditorActivated;
39 boolean isShowRank;
40 boolean isSortByVocabularyOrder;
41 boolean isShowSymbol;
42 boolean isShowIdInVocabulary;
43 Composite child ;
44
45 @Override
46 protected Control createContents(Composite parent) {
47
48 Composite composite = new Composite(parent, SWT.NULL);
49 composite.setLayout(new GridLayout());
50 CdmPreference pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.DistributionEditorActivated);
51 if (pref != null){
52 isEditorActivated = Boolean.valueOf(pref.getValue());
53 }else{
54 isEditorActivated = false;
55 }
56 final Button activateCheckButton = new Button(composite, SWT.CHECK);
57 activateCheckButton.setText(Messages.ChecklistEditorGeneralPreference_enable);
58 activateCheckButton.setSelection(isEditorActivated);
59 activateCheckButton.addSelectionListener(new SelectionAdapter(){
60 @Override
61 public void widgetSelected(SelectionEvent e) {
62 isEditorActivated = activateCheckButton.getSelection();
63
64 if(isEditorActivated){
65 child.setVisible(true);
66 child.setEnabled(true);
67 }else{
68 child.setVisible(false);
69 child.setEnabled(false);
70 }
71
72 }
73 });
74
75 child = new Composite(composite, SWT.NULL);
76 child.setLayout(new GridLayout());
77 child.setVisible(isEditorActivated);
78 final CLabel label = new CLabel(child, SWT.NULL);
79 label.setText(Messages.ChecklistEditorGeneralPreference_open_wizard + Messages.ChecklistEditorGeneralPreference_2);
80 final CommandHandlerButton button_openWizard = new CommandHandlerButton(child, SWT.PUSH,
81 Messages.ChecklistEditorGeneralPreference_3);
82
83 button_openWizard.setText(Messages.ChecklistEditorGeneralPreference_open_distribution_selection);
84 final Button showIdInVocabulary = new Button(child, SWT.CHECK);
85 pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowIdInVocabulary);
86 if (pref != null){
87 isShowIdInVocabulary = Boolean.valueOf(pref.getValue());
88 }else{
89 isShowIdInVocabulary = false;
90 }
91 showIdInVocabulary.setText(Messages.ChecklistEditorGeneralPreference_show_id_in_voc);
92 showIdInVocabulary.setSelection(isShowIdInVocabulary);
93 showIdInVocabulary.addSelectionListener(new SelectionAdapter(){
94 @Override
95 public void widgetSelected(SelectionEvent e) {
96 isShowIdInVocabulary = showIdInVocabulary.getSelection();
97
98 }
99 });
100
101 final Button showSymbol = new Button(child, SWT.CHECK);
102 pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowSymbol);
103 if (pref != null){
104 isShowSymbol = Boolean.valueOf(pref.getValue());
105 }else{
106 isShowSymbol = false;
107 }
108
109 showSymbol.setText(Messages.ChecklistEditorGeneralPreference_show_symbol);
110 showSymbol.setSelection(isShowSymbol);
111 showSymbol.addSelectionListener(new SelectionAdapter(){
112 @Override
113 public void widgetSelected(SelectionEvent e) {
114 isShowSymbol = showSymbol.getSelection();
115 }
116 });
117 // PreferencesUtil.recursiveSetEnabled(button_openWizard, CdmStore.isActive());
118 pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.ShowRankInDistributionEditor);
119 if (pref != null){
120 isShowRank = Boolean.valueOf(pref.getValue());
121 }else{
122 isShowRank = false;
123 }
124
125 final Button activateRankButton = new Button(child, SWT.CHECK);
126 activateRankButton.setText(Messages.ChecklistEditorGeneralPreference_show_rank);
127 activateRankButton.setSelection(isShowRank);
128 activateRankButton.addSelectionListener(new SelectionAdapter(){
129 @Override
130 public void widgetSelected(SelectionEvent e) {
131 isShowRank = activateRankButton.getSelection();
132 }
133 });
134 final Button sortNamedAreaByVocabularyOrder = new Button(child, SWT.CHECK);
135
136 pref = PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AreasSortedByIdInVocabulary);
137 if (pref != null){
138 isSortByVocabularyOrder = Boolean.valueOf(pref.getValue());
139 }else{
140 isSortByVocabularyOrder = false;
141 }
142
143 sortNamedAreaByVocabularyOrder.setText(Messages.ChecklistEditorGeneralPreference_sort_areas);
144 sortNamedAreaByVocabularyOrder.setSelection(isSortByVocabularyOrder);
145 sortNamedAreaByVocabularyOrder.addSelectionListener(new SelectionAdapter(){
146 @Override
147 public void widgetSelected(SelectionEvent e) {
148 isSortByVocabularyOrder = sortNamedAreaByVocabularyOrder.getSelection();
149 }
150 });
151
152 if(isEditorActivated){
153 child.setEnabled(true);
154 }else{
155 child.setEnabled(false);
156 }
157
158 return composite;
159 }
160
161 @Override
162 public boolean performOk() {
163 ICdmRepository controller = CdmStore.getCurrentApplicationConfiguration();
164 if (controller == null){
165 return false;
166 }
167 IPreferenceService service = controller.getPreferenceService();
168
169 CdmPreference pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.DistributionEditorActivated, Boolean.toString(isEditorActivated));
170 //ToDo
171 pref.setAllowOverride(false);
172 service.set(pref);
173
174 pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.ShowIdInVocabulary, Boolean.toString(isShowIdInVocabulary));
175 //ToDo
176 pref.setAllowOverride(false);
177 service.set(pref);
178
179 pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.ShowSymbol, Boolean.toString(isShowSymbol));
180 //ToDo
181 pref.setAllowOverride(false);
182 service.set(pref);
183
184 pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.ShowRankInDistributionEditor, Boolean.toString(isShowRank));
185 //ToDo
186 pref.setAllowOverride(false);
187 service.set(pref);
188 pref = CdmPreference.NewDatabaseInstance( PreferencePredicate.AreasSortedByIdInVocabulary, Boolean.toString(isSortByVocabularyOrder));
189 //ToDo
190 pref.setAllowOverride(false);
191 service.set(pref);
192
193 PreferencesUtil.getPreferenceStore().setValue(IPreferenceKeys.DISTRIBUTION_AREA_PREFRENCES_ACTIVE, isEditorActivated);
194 PreferencesUtil.setSortNamedAreasByOrderInVocabulary(isSortByVocabularyOrder);
195 PreferencesUtil.setShowRankInChecklistEditor(isShowRank);
196 PreferencesUtil.setShowSymbolInChecklistEditor(isShowSymbol);
197 PreferencesUtil.setShowIdInVocabularyInChecklistEditor(isShowIdInVocabulary);
198 return true;
199 }
200
201 }