1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2014 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.ui.dialog;
|
11
|
|
12
|
import java.io.IOException;
|
13
|
|
14
|
import org.eclipse.jface.dialogs.IMessageProvider;
|
15
|
import org.eclipse.jface.dialogs.TitleAreaDialog;
|
16
|
import org.eclipse.swt.SWT;
|
17
|
import org.eclipse.swt.custom.CCombo;
|
18
|
import org.eclipse.swt.custom.CLabel;
|
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.Shell;
|
26
|
|
27
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
28
|
|
29
|
|
30
|
/**
|
31
|
* @author alex
|
32
|
* @date 19.08.2014
|
33
|
*
|
34
|
*/
|
35
|
public class DefaultLanguageDialog extends TitleAreaDialog{
|
36
|
|
37
|
|
38
|
private CCombo combo;
|
39
|
final PreferencesUtil preferencesUtil = new PreferencesUtil();
|
40
|
|
41
|
/**
|
42
|
* @param parentShell
|
43
|
*/
|
44
|
public DefaultLanguageDialog(Shell parentShell) {
|
45
|
super(parentShell);
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
protected void configureShell(Shell shell) {
|
50
|
super.configureShell(shell);
|
51
|
}
|
52
|
|
53
|
/* (non-Javadoc)
|
54
|
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
|
55
|
*/
|
56
|
@Override
|
57
|
protected Control createDialogArea(Composite parent) {
|
58
|
// TODO Auto-generated method stub
|
59
|
setTitle("Select your default Language");
|
60
|
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);
|
61
|
Composite composite = (Composite)super.createDialogArea(parent);
|
62
|
Composite container = new Composite(parent, SWT.NONE);
|
63
|
container.setLayoutData(new GridData(SWT.TOP));
|
64
|
|
65
|
GridLayout layout = new GridLayout(1, false);
|
66
|
container.setLayoutData(new GridData(SWT.CENTER, SWT.TOP, true, true));
|
67
|
container.setLayout(layout);
|
68
|
|
69
|
final CLabel titleLabel = new CLabel(container, SWT.NONE);
|
70
|
titleLabel.setText("After this the editor will restart, " +
|
71
|
"with your selection loaded. ");
|
72
|
|
73
|
|
74
|
createComboElement(container);
|
75
|
|
76
|
return composite;
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
*
|
81
|
* @param parent
|
82
|
*/
|
83
|
private void createComboElement(Composite parent) {
|
84
|
Composite container1 = new Composite(parent, SWT.NONE);
|
85
|
container1.setLayoutData(new GridData(GridData.FILL_BOTH));
|
86
|
|
87
|
GridLayout layout1 = new GridLayout(2, false);
|
88
|
container1.setLayoutData(new GridData(SWT.RIGHT, SWT.RIGHT, true, true));
|
89
|
container1.setLayout(layout1);
|
90
|
|
91
|
|
92
|
final CLabel comboLabel = new CLabel(container1, SWT.NONE);
|
93
|
comboLabel.setText("Please choose your default language: ");
|
94
|
|
95
|
GridData oneLine = new GridData();
|
96
|
oneLine.grabExcessHorizontalSpace = true;
|
97
|
oneLine.horizontalAlignment = GridData.FILL;
|
98
|
|
99
|
combo = new CCombo(container1, SWT.NONE);
|
100
|
combo.setLayoutData(oneLine);
|
101
|
|
102
|
combo.add(Language.GERMAN.getLabel(), 0);
|
103
|
combo.add(Language.ENGLISH.getLabel(), 1);
|
104
|
combo.select(1);
|
105
|
combo.addSelectionListener(new SelectionListener() {
|
106
|
|
107
|
@Override
|
108
|
public void widgetSelected(SelectionEvent e) {
|
109
|
try {
|
110
|
preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
|
111
|
} catch (IOException e1) {
|
112
|
e1.printStackTrace();
|
113
|
}
|
114
|
}
|
115
|
|
116
|
@Override
|
117
|
public void widgetDefaultSelected(SelectionEvent e) {
|
118
|
}
|
119
|
});
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
protected void okPressed() {
|
124
|
try {
|
125
|
preferencesUtil.writePropertyToConfigFile(combo.getSelectionIndex());
|
126
|
} catch (IOException e) {
|
127
|
e.printStackTrace();
|
128
|
}
|
129
|
super.okPressed();
|
130
|
}
|
131
|
|
132
|
private enum Language{
|
133
|
|
134
|
GERMAN("Deutsch"), ENGLISH("English");
|
135
|
private String label;
|
136
|
private Language(String label){
|
137
|
this.label = label;
|
138
|
}
|
139
|
|
140
|
/**
|
141
|
* @return the label
|
142
|
*/
|
143
|
public String getLabel() {
|
144
|
return label;
|
145
|
}
|
146
|
}
|
147
|
}
|