Project

General

Profile

Download (4.18 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.preference;
11

    
12
import java.util.List;
13

    
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.events.SelectionAdapter;
16
import org.eclipse.swt.events.SelectionEvent;
17
import org.eclipse.swt.layout.GridLayout;
18
import org.eclipse.swt.layout.RowLayout;
19
import org.eclipse.swt.widgets.Button;
20
import org.eclipse.swt.widgets.Combo;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Label;
24

    
25
import eu.etaxonomy.cdm.model.common.Language;
26
import eu.etaxonomy.taxeditor.preference.menu.CdmPreferencePage;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29
/**
30
 * @author n.hoffmann
31
 * @created Dec 3, 2010
32
 * @version 1.0
33
 */
34
public class LanguageRepresentationPreferencePage extends CdmPreferencePage{
35

    
36
	private boolean isMultilanguageTextEditingCapability;
37
	private Language globalLanguage;
38

    
39
//	private Composite createComposite(Composite parent){
40
//		Composite composite = new Composite(parent, SWT.NULL);
41
//		composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
42
//		composite.setLayout(new RowLayout(SWT.HORIZONTAL));
43
//		return composite;
44
//	}
45

    
46
	@Override
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

    
52
		createSetDefaultLanguage(container);
53

    
54
		createSetMultiLanguageTextEditingCapability(container);
55

    
56
		return container;
57

    
58

    
59
	}
60

    
61
	private void createSetDefaultLanguage(Composite parent) {
62
		globalLanguage = PreferencesUtil.getGlobalLanguage();
63

    
64
		if(globalLanguage == null) {
65
		    return;
66
		}
67

    
68
		int curentSelectionIndex = 0;
69

    
70
		final Composite composite = createComposite(parent);
71
		composite.setLayout(new RowLayout(1));
72

    
73
		final Label label = new Label(composite, SWT.NONE);
74
		label.setText("Choose the global language that will be used throughout the editor to get representations in.");
75

    
76
		final Combo combo_globalLanguage = new Combo(composite, SWT.NONE);
77

    
78
		List<Language> preferredLanguages = CdmStore.getTermManager().getPreferredTerms(Language.class);
79

    
80
		for(int i = 0; i < preferredLanguages.size(); i++){
81
			Language language = preferredLanguages.get(i);
82
			combo_globalLanguage.add(language.getLabel(), i);
83
			if(language.equals(globalLanguage)){
84
				curentSelectionIndex = i;
85
			}
86
		}
87

    
88
		combo_globalLanguage.select(curentSelectionIndex);
89

    
90
		combo_globalLanguage.addSelectionListener(new SelectionAdapter() {
91
			/* (non-Javadoc)
92
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
93
			 */
94
			@Override
95
			public void widgetSelected(SelectionEvent e) {
96
			    setApply(true);
97
				int selectionIndex = combo_globalLanguage.getSelectionIndex();
98
				globalLanguage = CdmStore.getCurrentApplicationConfiguration().getTermService().getLanguageByLabel(combo_globalLanguage.getItem(selectionIndex));
99
			}
100
		});
101
	}
102

    
103
	private void createSetMultiLanguageTextEditingCapability(Composite parent) {
104
		isMultilanguageTextEditingCapability = getPreferenceStore().getBoolean(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY);
105

    
106
		final Composite composite = createComposite(parent);
107

    
108
		final Button button_toggle = new Button(composite, SWT.CHECK);
109

    
110

    
111
		button_toggle.setText("Enable Multiple Language Editing Capability");
112

    
113
		button_toggle.setSelection(isMultilanguageTextEditingCapability);
114

    
115

    
116
		button_toggle.addSelectionListener(new SelectionAdapter(){
117
			/* (non-Javadoc)
118
			 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
119
			 */
120
			@Override
121
			public void widgetSelected(SelectionEvent e) {
122
			    setApply(true);
123
				isMultilanguageTextEditingCapability = button_toggle.getSelection();
124
			}
125
		});
126
	}
127

    
128
	@Override
129
	public boolean performOk() {
130
		getPreferenceStore().setValue(IPreferenceKeys.MULTILANGUAGE_TEXT_EDITING_CAPABILITY, isMultilanguageTextEditingCapability);
131
		PreferencesUtil.setGlobalLanguage(globalLanguage);
132

    
133
		return super.performOk();
134
	}
135
}
(13-13/31)