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
;
31 import eu
.etaxonomy
.taxeditor
.Messages
;
35 * @created Dec 3, 2010
38 public class LanguageEditorPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage
{
41 PreferencesUtil preferencesUtil
= new PreferencesUtil();
44 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
47 protected Control
createContents(Composite parent
) {
48 Composite container
= new Composite(parent
, SWT
.NULL
);
49 final GridLayout gridLayout
= new GridLayout();
50 container
.setLayout(gridLayout
);
51 createEditorDefaultLanguage(container
);
58 private void createEditorDefaultLanguage(Composite container
) {
59 // TODO Auto-generated method stub
60 final Label description
= new Label(container
, SWT
.NONE
);
61 description
.setText(Messages
.LanguageEditorPreferencePage_RestartRequired
);
63 final Label label
= new Label(container
, SWT
.NONE
);
64 label
.setText(Messages
.LanguageEditorPreferencePage_ChooseDefaultLanguage
);
66 GridData oneLine
= new GridData();
67 oneLine
.grabExcessHorizontalSpace
= true;
68 oneLine
.horizontalAlignment
= GridData
.FILL
;
70 combo
= new CCombo(container
, SWT
.NONE
);
71 combo
.setLayoutData(oneLine
);
73 combo
.add(Language
.GERMAN
.getLabel(), 0);
74 combo
.add(Language
.ENGLISH
.getLabel(), 1);
75 restoreSavedSelection();
77 combo
.addSelectionListener(new SelectionListener() {
80 public void widgetSelected(SelectionEvent e
) {
82 preferencesUtil
.writePropertyToConfigFile(combo
.getSelectionIndex());
83 } catch (IOException e1
) {
89 public void widgetDefaultSelected(SelectionEvent e
) {
90 // TODO Auto-generated method stub
97 * TODO: This method is not taking advantages of the enum field yet
99 private void restoreSavedSelection() {
100 String rememberedValue
= PreferencesUtil
.getPreferenceStore().getString(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
);
101 if(StringUtils
.isNotEmpty(rememberedValue
)&& StringUtils
.isNotBlank(rememberedValue
)){
102 if(rememberedValue
.equalsIgnoreCase("en")){ //$NON-NLS-1$
104 }else if(rememberedValue
.equalsIgnoreCase("de")){ //$NON-NLS-1$
110 private enum Language
{
112 GERMAN("Deutsch"), ENGLISH("English"); //$NON-NLS-1$ //$NON-NLS-2$
113 private final String label
;
114 private Language(String label
){
121 public String
getLabel() {
127 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
130 public void init(IWorkbench workbench
) {
131 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
135 * @see org.eclipse.jface.preference.PreferencePage#performOk()
138 public boolean performOk() {
140 preferencesUtil
.writePropertyToConfigFile(combo
.getSelectionIndex());
141 boolean result
= MessageDialog
.openConfirm(getShell(), Messages
.LanguageEditorPreferencePage_PleaseRestart
, Messages
.LanguageEditorPreferencePage_EditorHasToRestart
);
144 PlatformUI
.getWorkbench().restart();
146 } catch (IOException e
) {
149 return super.performOk();