3 * Copyright (C) 2014 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.
10 package eu
.etaxonomy
.taxeditor
.ui
.dialog
;
13 import java
.io
.FileInputStream
;
14 import java
.io
.FileOutputStream
;
15 import java
.io
.IOException
;
16 import java
.util
.Properties
;
18 import org
.eclipse
.jface
.dialogs
.IMessageProvider
;
19 import org
.eclipse
.jface
.dialogs
.TitleAreaDialog
;
20 import org
.eclipse
.swt
.SWT
;
21 import org
.eclipse
.swt
.custom
.CCombo
;
22 import org
.eclipse
.swt
.custom
.CLabel
;
23 import org
.eclipse
.swt
.events
.SelectionEvent
;
24 import org
.eclipse
.swt
.events
.SelectionListener
;
25 import org
.eclipse
.swt
.layout
.GridData
;
26 import org
.eclipse
.swt
.layout
.GridLayout
;
27 import org
.eclipse
.swt
.widgets
.Composite
;
28 import org
.eclipse
.swt
.widgets
.Control
;
29 import org
.eclipse
.swt
.widgets
.Shell
;
31 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
40 public class DefaultLanguageDialog
extends TitleAreaDialog
{
47 public DefaultLanguageDialog(Shell parentShell
) {
52 protected void configureShell(Shell shell
) {
53 super.configureShell(shell
);
57 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
60 protected Control
createDialogArea(Composite parent
) {
61 // TODO Auto-generated method stub
62 setTitle("Select your default Language");
63 setMessage("This is will set your default langauge once.\n You will be able to change this in the prefrence menue at any time.", IMessageProvider
.INFORMATION
);
64 Composite composite
= (Composite
)super.createDialogArea(parent
);
65 Composite container
= new Composite(parent
, SWT
.NONE
);
66 container
.setLayoutData(new GridData(SWT
.TOP
));
68 GridLayout layout
= new GridLayout(1, false);
69 container
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.TOP
, true, true));
70 container
.setLayout(layout
);
72 final CLabel titleLabel
= new CLabel(container
, SWT
.NONE
);
73 titleLabel
.setText("After this the editor will restart, " +
74 "with your selection loaded. ");
77 createComboElement(container
);
86 private void createComboElement(Composite parent
) {
87 Composite container1
= new Composite(parent
, SWT
.NONE
);
88 container1
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
90 GridLayout layout1
= new GridLayout(2, false);
91 container1
.setLayoutData(new GridData(SWT
.RIGHT
, SWT
.RIGHT
, true, true));
92 container1
.setLayout(layout1
);
95 final CLabel comboLabel
= new CLabel(container1
, SWT
.NONE
);
96 comboLabel
.setText("Please choose your default language: ");
98 GridData oneLine
= new GridData();
99 oneLine
.grabExcessHorizontalSpace
= true;
100 oneLine
.horizontalAlignment
= GridData
.FILL
;
102 combo
= new CCombo(container1
, SWT
.NONE
);
103 combo
.setLayoutData(oneLine
);
105 combo
.add(Language
.GERMAN
.getLabel(), 0);
106 combo
.add(Language
.ENGLISH
.getLabel(), 1);
108 combo
.addSelectionListener(new SelectionListener() {
111 public void widgetSelected(SelectionEvent e
) {
113 writeConfigAndRestart(combo
.getSelectionIndex());
114 } catch (IOException e1
) {
115 e1
.printStackTrace();
120 public void widgetDefaultSelected(SelectionEvent e
) {
121 // TODO Auto-generated method stub
128 protected void okPressed() {
130 writeConfigAndRestart(combo
.getSelectionIndex());
131 } catch (IOException e
) {
138 private void writeConfigAndRestart(int setLanguage
) throws IOException
{
139 File file
= org
.eclipse
.core
.runtime
.preferences
.ConfigurationScope
.INSTANCE
.getLocation().toFile();
140 Properties properties
= load(file
.getAbsolutePath()+"/config.ini");
143 properties
.setProperty("osgi.nl", "de");
144 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "de");
147 properties
.setProperty("osgi.nl", "en");
148 PreferencesUtil
.getPreferenceStore().setValue(IPreferenceKeys
.DEFAULT_LANGUAGE_EDITOR
, "en");
153 save(file
+"/config.ini", properties
);
156 private Properties
load(String filename
) throws IOException
{
157 FileInputStream in
= new FileInputStream(filename
);
158 Properties prop
= new Properties();
164 private void save(String filename
, Properties properties
) throws IOException
{
165 FileOutputStream fos
= new FileOutputStream(filename
);
166 properties
.store(fos
, "");
170 private enum Language
{
172 GERMAN("Deutsch"), ENGLISH("English");
173 private String label
;
174 private Language(String label
){
181 public String
getLabel() {
185 private static final GridLayout
GRID_LAYOUT (int columns
, boolean equalwidth
){
186 GridLayout layout
= new GridLayout();
187 layout
.marginTop
= 0;
188 layout
.marginRight
= 0;
189 layout
.marginBottom
= 0;
190 layout
.marginLeft
= 0;
191 layout
.numColumns
= columns
;
192 layout
.makeColumnsEqualWidth
= equalwidth
;