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
.editor
.description
;
13 import java
.util
.ArrayList
;
14 import java
.util
.List
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.jface
.dialogs
.Dialog
;
18 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
19 import org
.eclipse
.jface
.dialogs
.InputDialog
;
20 import org
.eclipse
.jface
.window
.Window
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.custom
.CCombo
;
23 import org
.eclipse
.swt
.events
.SelectionAdapter
;
24 import org
.eclipse
.swt
.events
.SelectionEvent
;
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
.Label
;
30 import org
.eclipse
.swt
.widgets
.Shell
;
32 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
33 import eu
.etaxonomy
.taxeditor
.controller
.GlobalController
;
34 import eu
.etaxonomy
.taxeditor
.model
.CdmSessionDataRepository
;
35 import eu
.etaxonomy
.taxeditor
.model
.LanguageUtil
;
42 public class LanguageDialog
extends InputDialog
{
43 private static final Logger logger
= Logger
.getLogger(LanguageDialog
.class);
45 private String message
;
47 private Language language
;
48 protected Language languageTemp
;
51 * Language selected last time the dialog was used.
53 private static Language lastLanguage
;
57 private List
<Language
> languages
;
63 * @param dialogMessage
65 public LanguageDialog(Shell shell
, String dialogTitle
, String dialogMessage
) {
66 super(shell
, dialogTitle
,
67 dialogMessage
, null, null);
69 message
= dialogMessage
;
71 // Set selection menu to language chosen last time Dialog was opened
72 if (lastLanguage
!= null) {
73 language
= lastLanguage
;
84 protected Control
createDialogComposite(Composite parent
) {
85 // create a composite with standard margins and spacing
86 Composite composite
= new Composite(parent
, SWT
.NONE
);
87 GridLayout layout
= new GridLayout();
88 layout
.marginHeight
= convertVerticalDLUsToPixels(IDialogConstants
.VERTICAL_MARGIN
);
89 layout
.marginWidth
= convertHorizontalDLUsToPixels(IDialogConstants
.HORIZONTAL_MARGIN
);
90 layout
.verticalSpacing
= convertVerticalDLUsToPixels(IDialogConstants
.VERTICAL_SPACING
);
91 layout
.horizontalSpacing
= convertHorizontalDLUsToPixels(IDialogConstants
.HORIZONTAL_SPACING
);
92 composite
.setLayout(layout
);
93 composite
.setLayoutData(new GridData(GridData
.FILL_BOTH
));
94 applyDialogFont(composite
);
99 * (non-Javadoc) Method declared on Dialog.
101 protected Control
createDialogArea(Composite parent
) {
103 Composite composite
= (Composite
) createDialogComposite(parent
);
105 if (message
!= null) {
106 Label label
= new Label(composite
, SWT
.WRAP
);
107 label
.setText(message
);
108 GridData data
= new GridData(GridData
.GRAB_HORIZONTAL
109 | GridData
.GRAB_VERTICAL
| GridData
.HORIZONTAL_ALIGN_FILL
110 | GridData
.VERTICAL_ALIGN_CENTER
);
111 data
.widthHint
= convertHorizontalDLUsToPixels(IDialogConstants
.MINIMUM_MESSAGE_AREA_WIDTH
);
112 label
.setLayoutData(data
);
113 label
.setFont(parent
.getFont());
116 combo
= new CCombo(composite
, SWT
.BORDER
);
117 combo
.setLayoutData(new GridData(GridData
.GRAB_HORIZONTAL
118 | GridData
.HORIZONTAL_ALIGN_FILL
));
119 combo
.addSelectionListener(new SelectionAdapter() {
121 public void widgetSelected(SelectionEvent e
) {
122 int i
= combo
.getSelectionIndex();
123 languageTemp
= languages
.get(i
);
129 applyDialogFont(composite
);
136 private void populateLanguages() {
137 languages
= new ArrayList
<Language
>();
140 for (Language language
: CdmSessionDataRepository
.getDefault().getLanguages()) {
142 combo
.add(LanguageUtil
.getDescription(language
));
143 languages
.add(language
);
145 if (this.language
!= null && this.language
.equals(language
)) {
156 private Language
getLanguage() {
162 * @param dialogMessage
165 public static Language
getLanguage(String dialogTitle
,
166 String dialogMessage
) {
167 LanguageDialog dialog
= new LanguageDialog(GlobalController
.getShell(),
170 if (dialog
.open() == Window
.CANCEL
) {
173 return dialog
.getLanguage();
176 protected void createButtonsForButtonBar(Composite parent
) {
177 createButton(parent
, IDialogConstants
.OK_ID
,
178 IDialogConstants
.OK_LABEL
, true);
179 createButton(parent
, IDialogConstants
.CANCEL_ID
,
180 IDialogConstants
.CANCEL_LABEL
, false);
183 protected void buttonPressed(int buttonId
) {
184 if (IDialogConstants
.OK_ID
== buttonId
) {
186 } else if (IDialogConstants
.CANCEL_ID
== buttonId
) {
191 protected void okPressed() {
192 language
= getLanguageSelection();
193 lastLanguage
= language
;
197 protected void cancelPressed() {
199 super.cancelPressed();
202 private Language
getLanguageSelection() {
203 int i
= combo
.getSelectionIndex();
204 return languages
.get(i
);