1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 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
|
|
11
|
package eu.etaxonomy.taxeditor.preference;
|
12
|
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.eclipse.jface.preference.PreferencePage;
|
16
|
import org.eclipse.swt.SWT;
|
17
|
import org.eclipse.swt.events.SelectionAdapter;
|
18
|
import org.eclipse.swt.events.SelectionEvent;
|
19
|
import org.eclipse.swt.layout.GridData;
|
20
|
import org.eclipse.swt.layout.GridLayout;
|
21
|
import org.eclipse.swt.layout.RowLayout;
|
22
|
import org.eclipse.swt.widgets.Button;
|
23
|
import org.eclipse.swt.widgets.Combo;
|
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
|
|
30
|
import eu.etaxonomy.cdm.model.common.Language;
|
31
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
32
|
|
33
|
/**
|
34
|
* @author n.hoffmann
|
35
|
* @created Dec 3, 2010
|
36
|
* @version 1.0
|
37
|
*/
|
38
|
public class LanguagePreferencePage extends PreferencePage implements IWorkbenchPreferencePage{
|
39
|
|
40
|
private boolean isMultilanguageTextEditingCapability;
|
41
|
private Language globalLanguage;
|
42
|
|
43
|
private Composite createComposite(Composite parent){
|
44
|
Composite composite = new Composite(parent, SWT.NULL);
|
45
|
composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
|
46
|
composite.setLayout(new RowLayout(SWT.HORIZONTAL));
|
47
|
return composite;
|
48
|
}
|
49
|
|
50
|
/* (non-Javadoc)
|
51
|
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
|
52
|
*/
|
53
|
@Override
|
54
|
protected Control createContents(Composite parent) {
|
55
|
Composite container = new Composite(parent, SWT.NULL);
|
56
|
final GridLayout gridLayout = new GridLayout();
|
57
|
container.setLayout(gridLayout);
|
58
|
|
59
|
createSetDefaultLanguage(container);
|
60
|
|
61
|
createSetMultiLanguageTextEditingCapability(container);
|
62
|
|
63
|
return container;
|
64
|
|
65
|
|
66
|
}
|
67
|
|
68
|
/**
|
69
|
* @param container
|
70
|
*/
|
71
|
private void createSetDefaultLanguage(Composite parent) {
|
72
|
globalLanguage = PreferencesUtil.getGlobalLanguage();
|
73
|
|
74
|
int curentSelectionIndex = 0;
|
75
|
|
76
|
final Composite composite = createComposite(parent);
|
77
|
composite.setLayout(new RowLayout(1));
|
78
|
|
79
|
final Label label = new Label(composite, SWT.NONE);
|
80
|
label.setText("Choose the global language that will be used throughout the editor to get representations in.");
|
81
|
|
82
|
final Combo combo_globalLanguage = new Combo(composite, SWT.NONE);
|
83
|
|
84
|
List<Language> preferredLanguages = CdmStore.getTermManager().getPreferredTerms(Language.class);
|
85
|
|
86
|
for(int i = 0; i < preferredLanguages.size(); i++){
|
87
|
Language language = preferredLanguages.get(i);
|
88
|
combo_globalLanguage.add(language.getLabel(), i);
|
89
|
if(language.equals(globalLanguage)){
|
90
|
curentSelectionIndex = i;
|
91
|
}
|
92
|
}
|
93
|
|
94
|
combo_globalLanguage.select(curentSelectionIndex);
|
95
|
|
96
|
combo_globalLanguage.addSelectionListener(new SelectionAdapter() {
|
97
|
/* (non-Javadoc)
|
98
|
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
|
99
|
*/
|
100
|
@Override
|
101
|
public void widgetSelected(SelectionEvent e) {
|
102
|
int selectionIndex = combo_globalLanguage.getSelectionIndex();
|
103
|
globalLanguage = Language.getLanguageByLabel(combo_globalLanguage.getItem(selectionIndex));
|
104
|
}
|
105
|
});
|
106
|
}
|
107
|
|
108
|
/**
|
109
|
*
|
110
|
*/
|
111
|
private void createSetMultiLanguageTextEditingCapability(Composite parent) {
|
112
|
isMultilanguageTextEditingCapability = getPreferenceStore().getBoolean(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
|
113
|
|
114
|
final Composite composite = createComposite(parent);
|
115
|
|
116
|
final Button button_toggle = new Button(composite, SWT.CHECK);
|
117
|
|
118
|
|
119
|
button_toggle.setText("Enable Multiple Language Editing Capability");
|
120
|
|
121
|
button_toggle.setSelection(isMultilanguageTextEditingCapability);
|
122
|
|
123
|
|
124
|
button_toggle.addSelectionListener(new SelectionAdapter(){
|
125
|
/* (non-Javadoc)
|
126
|
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
|
127
|
*/
|
128
|
@Override
|
129
|
public void widgetSelected(SelectionEvent e) {
|
130
|
isMultilanguageTextEditingCapability = button_toggle.getSelection();
|
131
|
}
|
132
|
});
|
133
|
}
|
134
|
|
135
|
/* (non-Javadoc)
|
136
|
* @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
137
|
*/
|
138
|
@Override
|
139
|
public void init(IWorkbench workbench) {
|
140
|
setPreferenceStore(PreferencesUtil.getPreferenceStore());
|
141
|
}
|
142
|
|
143
|
/* (non-Javadoc)
|
144
|
* @see org.eclipse.jface.preference.PreferencePage#performOk()
|
145
|
*/
|
146
|
@Override
|
147
|
public boolean performOk() {
|
148
|
getPreferenceStore().setValue(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY, isMultilanguageTextEditingCapability);
|
149
|
PreferencesUtil.setGlobalLanguage(globalLanguage);
|
150
|
|
151
|
return super.performOk();
|
152
|
}
|
153
|
}
|