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
.util
.List
;
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
;
30 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
31 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 * @created Dec 3, 2010
38 public class LanguageRepresentationPreferencePage
extends PreferencePage
implements IWorkbenchPreferencePage
{
40 private boolean isMultilanguageTextEditingCapability
;
41 private Language globalLanguage
;
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
));
51 * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
54 protected Control
createContents(Composite parent
) {
55 Composite container
= new Composite(parent
, SWT
.NULL
);
56 final GridLayout gridLayout
= new GridLayout();
57 container
.setLayout(gridLayout
);
59 createSetDefaultLanguage(container
);
61 createSetMultiLanguageTextEditingCapability(container
);
71 private void createSetDefaultLanguage(Composite parent
) {
72 globalLanguage
= PreferencesUtil
.getGlobalLanguage();
74 if(globalLanguage
== null) {
78 int curentSelectionIndex
= 0;
80 final Composite composite
= createComposite(parent
);
81 composite
.setLayout(new RowLayout(1));
83 final Label label
= new Label(composite
, SWT
.NONE
);
84 label
.setText("Choose the global language that will be used throughout the editor to get representations in.");
86 final Combo combo_globalLanguage
= new Combo(composite
, SWT
.NONE
);
88 List
<Language
> preferredLanguages
= CdmStore
.getTermManager().getPreferredTerms(Language
.class);
90 for(int i
= 0; i
< preferredLanguages
.size(); i
++){
91 Language language
= preferredLanguages
.get(i
);
92 combo_globalLanguage
.add(language
.getLabel(), i
);
93 if(language
.equals(globalLanguage
)){
94 curentSelectionIndex
= i
;
98 combo_globalLanguage
.select(curentSelectionIndex
);
100 combo_globalLanguage
.addSelectionListener(new SelectionAdapter() {
102 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
105 public void widgetSelected(SelectionEvent e
) {
106 int selectionIndex
= combo_globalLanguage
.getSelectionIndex();
107 globalLanguage
= Language
.getLanguageByLabel(combo_globalLanguage
.getItem(selectionIndex
));
115 private void createSetMultiLanguageTextEditingCapability(Composite parent
) {
116 isMultilanguageTextEditingCapability
= getPreferenceStore().getBoolean(IPreferenceKeys
.MULTILANGUAGE_TEXT_EDITING_CAPABILITY
);
118 final Composite composite
= createComposite(parent
);
120 final Button button_toggle
= new Button(composite
, SWT
.CHECK
);
123 button_toggle
.setText("Enable Multiple Language Editing Capability");
125 button_toggle
.setSelection(isMultilanguageTextEditingCapability
);
128 button_toggle
.addSelectionListener(new SelectionAdapter(){
130 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
133 public void widgetSelected(SelectionEvent e
) {
134 isMultilanguageTextEditingCapability
= button_toggle
.getSelection();
140 * @see org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
143 public void init(IWorkbench workbench
) {
144 setPreferenceStore(PreferencesUtil
.getPreferenceStore());
148 * @see org.eclipse.jface.preference.PreferencePage#performOk()
151 public boolean performOk() {
152 getPreferenceStore().setValue(IPreferenceKeys
.MULTILANGUAGE_TEXT_EDITING_CAPABILITY
, isMultilanguageTextEditingCapability
);
153 PreferencesUtil
.setGlobalLanguage(globalLanguage
);
155 return super.performOk();