3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.preference
;
13 import java
.io
.IOException
;
15 import org
.apache
.commons
.lang
.StringUtils
;
16 import org
.eclipse
.jface
.preference
.PreferencePage
;
17 import org
.eclipse
.swt
.SWT
;
18 import org
.eclipse
.swt
.custom
.CCombo
;
19 import org
.eclipse
.swt
.events
.SelectionEvent
;
20 import org
.eclipse
.swt
.events
.SelectionListener
;
21 import org
.eclipse
.swt
.layout
.GridData
;
22 import org
.eclipse
.swt
.layout
.GridLayout
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Control
;
25 import org
.eclipse
.swt
.widgets
.Label
;
26 import org
.eclipse
.ui
.IWorkbench
;
27 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
31 * @created Dec 3, 2010
34 public class LanguageEditorPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage
{
37 PreferencesUtil preferencesUtil
= new PreferencesUtil();
40 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
43 protected Control
createContents(Composite parent
) {
44 Composite container
= new Composite(parent
, SWT
.NULL
);
45 final GridLayout gridLayout
= new GridLayout();
46 container
.setLayout(gridLayout
);
47 createEditorDefaultLanguage(container
);
54 private void createEditorDefaultLanguage(Composite container
) {
55 // TODO Auto-generated method stub
56 final Label description
= new Label(container
, SWT
.NONE
);
57 description
.setText("After changing the default language, a restart is required,\nin order for the new settings to take effect.");
59 final Label label
= new Label(container
, SWT
.NONE
);
60 label
.setText("Please choose your default language for the editor: ");
62 GridData oneLine
= new GridData();
63 oneLine
.grabExcessHorizontalSpace
= true;
64 oneLine
.horizontalAlignment
= GridData
.FILL
;
66 combo
= new CCombo(container
, SWT
.NONE
);
67 combo
.setLayoutData(oneLine
);
69 combo
.add(Language
.GERMAN
.getLabel(), 0);
70 combo
.add(Language
.ENGLISH
.getLabel(), 1);
71 restoreSavedSelection();
73 combo
.addSelectionListener(new SelectionListener() {
76 public void widgetSelected(SelectionEvent e
) {
78 preferencesUtil
.writePropertyToConfigFile(combo
.getSelectionIndex());
79 } catch (IOException e1
) {
85 public void widgetDefaultSelected(SelectionEvent e
) {
86 // TODO Auto-generated method stub
93 * TODO: This method is not taking advantages of the enum field yet
95 private void restoreSavedSelection() {
96 String rememberedValue
= PreferencesUtil
.getPreferenceStore().getString(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
);
97 if(StringUtils
.isNotEmpty(rememberedValue
)&& StringUtils
.isNotBlank(rememberedValue
)){
98 if(rememberedValue
.equalsIgnoreCase("en")){
100 }else if(rememberedValue
.equalsIgnoreCase("de")){
106 private enum Language
{
108 GERMAN("Deutsch"), ENGLISH("English");
109 private final String label
;
110 private Language(String label
){
117 public String
getLabel() {
123 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
126 public void init(IWorkbench workbench
) {
127 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
131 * @see org.eclipse.jface.preference.PreferencePage#performOk()
134 public boolean performOk() {
136 preferencesUtil
.writePropertyToConfigFile(combo
.getSelectionIndex());
137 } catch (IOException e
) {
140 return super.performOk();