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
.dialogs
.MessageDialog
;
17 import org
.eclipse
.jface
.preference
.PreferencePage
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.custom
.CCombo
;
20 import org
.eclipse
.swt
.events
.SelectionEvent
;
21 import org
.eclipse
.swt
.events
.SelectionListener
;
22 import org
.eclipse
.swt
.layout
.GridData
;
23 import org
.eclipse
.swt
.layout
.GridLayout
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.Control
;
26 import org
.eclipse
.swt
.widgets
.Label
;
27 import org
.eclipse
.ui
.IWorkbench
;
28 import org
.eclipse
.ui
.IWorkbenchPreferencePage
;
29 import org
.eclipse
.ui
.PlatformUI
;
33 * @created Dec 3, 2010
36 public class LanguageEditorPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage
{
39 PreferencesUtil preferencesUtil
= new PreferencesUtil();
42 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
45 protected Control
createContents(Composite parent
) {
46 Composite container
= new Composite(parent
, SWT
.NULL
);
47 final GridLayout gridLayout
= new GridLayout();
48 container
.setLayout(gridLayout
);
49 createEditorDefaultLanguage(container
);
56 private void createEditorDefaultLanguage(Composite container
) {
57 // TODO Auto-generated method stub
58 final Label description
= new Label(container
, SWT
.NONE
);
59 description
.setText("After changing the default language, a restart is required,\nin order for the new settings to take effect.");
61 final Label label
= new Label(container
, SWT
.NONE
);
62 label
.setText("Please choose your default language for the editor: ");
64 GridData oneLine
= new GridData();
65 oneLine
.grabExcessHorizontalSpace
= true;
66 oneLine
.horizontalAlignment
= GridData
.FILL
;
68 combo
= new CCombo(container
, SWT
.NONE
);
69 combo
.setLayoutData(oneLine
);
71 combo
.add(Language
.GERMAN
.getLabel(), 0);
72 combo
.add(Language
.ENGLISH
.getLabel(), 1);
73 restoreSavedSelection();
75 combo
.addSelectionListener(new SelectionListener() {
78 public void widgetSelected(SelectionEvent e
) {
80 preferencesUtil
.writePropertyToConfigFile(combo
.getSelectionIndex());
81 } catch (IOException e1
) {
87 public void widgetDefaultSelected(SelectionEvent e
) {
88 // TODO Auto-generated method stub
95 * TODO: This method is not taking advantages of the enum field yet
97 private void restoreSavedSelection() {
98 String rememberedValue
= PreferencesUtil
.getPreferenceStore().getString(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
);
99 if(StringUtils
.isNotEmpty(rememberedValue
)&& StringUtils
.isNotBlank(rememberedValue
)){
100 if(rememberedValue
.equalsIgnoreCase("en")){
102 }else if(rememberedValue
.equalsIgnoreCase("de")){
108 private enum Language
{
110 GERMAN("Deutsch"), ENGLISH("English");
111 private final String label
;
112 private Language(String label
){
119 public String
getLabel() {
125 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
128 public void init(IWorkbench workbench
) {
129 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
133 * @see org.eclipse.jface.preference.PreferencePage#performOk()
136 public boolean performOk() {
138 preferencesUtil
.writePropertyToConfigFile(combo
.getSelectionIndex());
139 boolean result
= MessageDialog
.openConfirm(getShell(), "Please Restart", "The Taxonomic Editor has to restart now, in order to complete the language switch.\nDo you want to restart now?");
142 PlatformUI
.getWorkbench().restart();
144 } catch (IOException e
) {
147 return super.performOk();