2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.preference
;
12 import java
.io
.IOException
;
13 import java
.util
.Locale
;
15 import org
.apache
.commons
.lang
.StringUtils
;
16 import org
.eclipse
.jface
.dialogs
.MessageDialog
;
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
.PlatformUI
;
28 import eu
.etaxonomy
.taxeditor
.l10n
.Messages
;
29 import eu
.etaxonomy
.taxeditor
.preference
.menu
.CdmPreferencePage
;
33 * @created Dec 3, 2010
36 public class LanguageEditorPreferencePage
extends CdmPreferencePage
{
39 PreferencesUtil preferencesUtil
= new PreferencesUtil();
40 private boolean isSelectionChanged
= false;
41 private int initalSelectionIndex
;
44 protected Control
createContents(Composite parent
) {
45 Composite container
= new Composite(parent
, SWT
.NULL
);
46 final GridLayout gridLayout
= new GridLayout();
47 container
.setLayout(gridLayout
);
48 createEditorDefaultLanguage(container
);
55 private void createEditorDefaultLanguage(Composite container
) {
56 // TODO Auto-generated method stub
57 final Label description
= new Label(container
, SWT
.NONE
);
58 description
.setText(Messages
.LanguageEditorPreferencePage_RestartRequired
);
60 final Label label
= new Label(container
, SWT
.NONE
);
61 label
.setText(Messages
.LanguageEditorPreferencePage_ChooseDefaultLanguage
);
63 GridData oneLine
= new GridData();
64 oneLine
.grabExcessHorizontalSpace
= true;
65 oneLine
.horizontalAlignment
= GridData
.FILL
;
67 combo
= new CCombo(container
, SWT
.NONE
);
68 combo
.setLayoutData(oneLine
);
70 combo
.add(Language
.GERMAN
.getLabel(), 0);
71 combo
.add(Language
.ENGLISH
.getLabel(), 1);
72 restoreSavedSelection();
74 combo
.addSelectionListener(new SelectionListener() {
77 public void widgetSelected(SelectionEvent e
) {
79 // preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
80 if(initalSelectionIndex
!= combo
.getSelectionIndex()) {
81 isSelectionChanged
= true;
83 isSelectionChanged
= false;
85 // } catch (IOException e1) {
86 // MessagingUtils.messageDialog("Failed to write Config.ini", LanguageEditorPreferencePage.class,
87 // "Language switch failed, because could not write to Folder. No writing permissions!", null);
92 public void widgetDefaultSelected(SelectionEvent e
) {
93 // TODO Auto-generated method stub
100 * TODO: This method is not taking advantages of the enum field yet
102 private void restoreSavedSelection() {
103 String rememberedValue
= PreferencesUtil
.getPreferenceStore().getString(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
);
104 if(StringUtils
.isNotEmpty(rememberedValue
)&& StringUtils
.isNotBlank(rememberedValue
)){
105 if(rememberedValue
.equalsIgnoreCase("en")){ //$NON-NLS-1$
106 initalSelectionIndex
= 1;
108 }else if(rememberedValue
.equalsIgnoreCase("de")){ //$NON-NLS-1$
109 initalSelectionIndex
= 0;
113 Locale locale
= Locale
.getDefault();
114 if(locale
.getLanguage().equals(new Locale("de").getLanguage())){
115 initalSelectionIndex
= 0;
117 }else if(locale
.getLanguage().equals(new Locale("en").getLanguage())){
118 initalSelectionIndex
= 1;
124 private enum Language
{
126 GERMAN("Deutsch"), ENGLISH("English"); //$NON-NLS-1$ //$NON-NLS-2$
127 private final String label
;
128 private Language(String label
){
135 public String
getLabel() {
141 public boolean performOk() {
143 if(isSelectionChanged
){
144 preferencesUtil
.writePropertyToConfigFile(combo
.getSelectionIndex());
145 boolean result
= MessageDialog
.openConfirm(getShell(), Messages
.LanguageEditorPreferencePage_PleaseRestart
, Messages
.LanguageEditorPreferencePage_EditorHasToRestart
);
148 PlatformUI
.getWorkbench().restart();
151 } catch (IOException e
) {
154 return super.performOk();