c7d11ba6485c2225f29da757e3a9ccb9a1eb0996
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / preference / TaxonomicEditorGeneralPreferences.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.taxeditor.preference;
12
13 import org.eclipse.jface.preference.PreferencePage;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.custom.CLabel;
16 import org.eclipse.swt.events.ModifyEvent;
17 import org.eclipse.swt.events.ModifyListener;
18 import org.eclipse.swt.events.SelectionAdapter;
19 import org.eclipse.swt.events.SelectionEvent;
20 import org.eclipse.swt.layout.GridData;
21 import org.eclipse.swt.layout.GridLayout;
22 import org.eclipse.swt.layout.RowLayout;
23 import org.eclipse.swt.widgets.Button;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Control;
26 import org.eclipse.swt.widgets.Text;
27 import org.eclipse.ui.IWorkbench;
28 import org.eclipse.ui.IWorkbenchPreferencePage;
29
30 /**
31 * <p>TaxonomicEditorGeneralPreferences class.</p>
32 *
33 * @author n.hoffmann
34 * @created Sep 1, 2009
35 * @version 1.0
36 */
37 public class TaxonomicEditorGeneralPreferences extends PreferencePage implements
38 IWorkbenchPreferencePage {
39
40 boolean showUuidInSupplementalView;
41
42 private String editMapServiceAccessPoint;
43
44 private boolean shouldConnectAtStartup;
45
46 private boolean shouldExpandSectionWhenDataAvailable;
47
48 private boolean shouldShowExperimentalFeatures;
49
50
51 /* (non-Javadoc)
52 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
53 */
54 /** {@inheritDoc} */
55 @Override
56 protected Control createContents(Composite parent) {
57 Composite container = new Composite(parent, SWT.NULL);
58 final GridLayout gridLayout = new GridLayout();
59 container.setLayout(gridLayout);
60
61 createShowUuidInSupplementalView(container);
62 createMapServiceAccessPoint(container);
63 createShouldConnectAtStartUp(container);
64 createShouldExpandSectionWhenDataAvailable(container);
65
66 createShowExperimentalFeatures(container);
67
68 return container;
69 }
70
71
72 private void createShouldExpandSectionWhenDataAvailable(Composite container) {
73 shouldExpandSectionWhenDataAvailable = getPreferenceStore().getBoolean(IPreferenceKeys.SHOULD_EXPAND_SECTION_WHEN_DATA_AVAILABLE);
74
75 final Composite composite = createComposite(container);
76
77 final Button button = new Button(composite, SWT.CHECK);
78 button.setText("Should expand sections when data is available (Details View)");
79
80 button.setSelection(shouldExpandSectionWhenDataAvailable);
81
82 button.addSelectionListener(new SelectionAdapter(){
83 @Override
84 public void widgetSelected(SelectionEvent e) {
85 shouldExpandSectionWhenDataAvailable = button.getSelection();
86 }
87 });
88
89 }
90
91 private void createMapServiceAccessPoint(Composite composite) {
92 editMapServiceAccessPoint = PreferencesUtil.getMapServiceAccessPoint();
93
94 // Composite composite = createComposite(parent);
95
96 final CLabel label = new CLabel(composite, SWT.NULL);
97 label.setText("EDIT Map Service Access Point:");
98
99 final Text text = new Text(composite, SWT.BORDER);
100 text.setText(editMapServiceAccessPoint);
101 text.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
102
103 text.addModifyListener(new ModifyListener() {
104
105 public void modifyText(ModifyEvent e) {
106 editMapServiceAccessPoint = text.getText();
107 }
108 });
109 }
110
111
112
113 private void createShowUuidInSupplementalView(Composite parent){
114 showUuidInSupplementalView = getPreferenceStore().getBoolean(PreferencesUtil.SHOW_DEBUG_INFORMATION);
115
116 final Composite composite = createComposite(parent);
117
118 final Button button_toggle = new Button(composite, SWT.CHECK);
119
120
121 button_toggle.setText("Show UUID and object ID in supplemental data view.");
122
123 button_toggle.setSelection(showUuidInSupplementalView);
124
125
126 button_toggle.addSelectionListener(new SelectionAdapter(){
127 /* (non-Javadoc)
128 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
129 */
130 @Override
131 public void widgetSelected(SelectionEvent e) {
132 showUuidInSupplementalView = button_toggle.getSelection();
133 }
134 });
135
136 }
137
138 private void createShouldConnectAtStartUp(Composite parent){
139 shouldConnectAtStartup = getPreferenceStore().getBoolean(IPreferenceKeys.SHOULD_CONNECT_AT_STARTUP);
140
141 final Composite composite = createComposite(parent);
142
143 final Button button_toggle = new Button(composite, SWT.CHECK);
144
145
146 button_toggle.setText("Connect to last used datasource when launching.");
147
148 button_toggle.setSelection(shouldConnectAtStartup);
149
150
151 button_toggle.addSelectionListener(new SelectionAdapter(){
152 /* (non-Javadoc)
153 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
154 */
155 @Override
156 public void widgetSelected(SelectionEvent e) {
157 shouldConnectAtStartup = button_toggle.getSelection();
158 }
159 });
160 }
161
162 /**
163 * @param container
164 */
165 private void createShowExperimentalFeatures(Composite parent) {
166 shouldShowExperimentalFeatures = getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES);
167 final Composite composite = createComposite(parent);
168
169 final Button button_toggle = new Button(composite, SWT.CHECK);
170
171
172 button_toggle.setText("Show experimental features-");
173
174 button_toggle.setSelection(shouldShowExperimentalFeatures);
175
176
177 button_toggle.addSelectionListener(new SelectionAdapter(){
178 /* (non-Javadoc)
179 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
180 */
181 @Override
182 public void widgetSelected(SelectionEvent e) {
183 shouldShowExperimentalFeatures = button_toggle.getSelection();
184 }
185 });
186 }
187
188 private Composite createComposite(Composite parent){
189 Composite composite = new Composite(parent, SWT.NULL);
190 composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
191 composite.setLayout(new RowLayout(SWT.HORIZONTAL));
192 return composite;
193 }
194
195 /* (non-Javadoc)
196 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
197 */
198 /** {@inheritDoc} */
199 public void init(IWorkbench workbench) {
200 setPreferenceStore(PreferencesUtil.getPreferenceStore());
201 }
202
203 /** {@inheritDoc} */
204 @Override
205 public boolean performOk() {
206
207 getPreferenceStore().setValue(IPreferenceKeys.SHOW_DEBUG_INFORMATION, showUuidInSupplementalView);
208 getPreferenceStore().setValue(IPreferenceKeys.EDIT_MAP_SERVICE_ACCES_POINT, editMapServiceAccessPoint);
209 getPreferenceStore().setValue(IPreferenceKeys.SHOULD_CONNECT_AT_STARTUP, shouldConnectAtStartup);
210 getPreferenceStore().setValue(IPreferenceKeys.SHOULD_EXPAND_SECTION_WHEN_DATA_AVAILABLE, shouldExpandSectionWhenDataAvailable);
211 getPreferenceStore().setValue(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES, shouldShowExperimentalFeatures);
212
213 return super.performOk();
214 }
215
216 }