#5908: fix that the combo box on the left hand side contains only available languages
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / element / TranslatableRepresentationElement.java
1 // $Id$
2 /**
3 * Copyright (C) 2016 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.element;
11
12 import org.eclipse.jface.window.Window;
13 import org.eclipse.jface.wizard.WizardDialog;
14 import org.eclipse.swt.SWT;
15 import org.eclipse.swt.events.SelectionAdapter;
16 import org.eclipse.swt.events.SelectionEvent;
17
18 import eu.etaxonomy.cdm.model.common.Representation;
19 import eu.etaxonomy.cdm.model.common.TermBase;
20 import eu.etaxonomy.taxeditor.model.MessagingUtils;
21 import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermTranslationWizard;
22
23 /**
24 * @author k.luther
25 * @date 23.06.2016
26 *
27 */
28 public class TranslatableRepresentationElement extends RepresentationElement {
29
30 /**
31 * @param formFactory
32 * @param formElement
33 * @param representation
34 * @param term
35 * @param textHeight
36 * @param style
37 * @param isTranslationWizard
38 */
39 public TranslatableRepresentationElement(CdmFormFactory formFactory, ICdmFormElement formElement,
40 Representation representation, TermBase term, Integer textHeight, int style) {
41 super(formFactory, formElement, representation, term, textHeight, style);
42
43 }
44
45
46 /**
47 * @param cdmFormFactory
48 * @param parentElement
49 * @param term
50 * @param textHeight
51 * @param style
52 */
53 public TranslatableRepresentationElement(CdmFormFactory cdmFormFactory, ICdmFormElement parentElement,
54 TermBase term, int textHeight, int style) {
55 super(cdmFormFactory, parentElement, term, textHeight, style);
56 }
57
58
59 private class OpenTranslationWizard extends SelectionAdapter {
60
61 public OpenTranslationWizard() {
62 super();
63 }
64
65 /*
66 * (non-Javadoc)
67 *
68 * @see
69 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
70 * .swt.events.SelectionEvent)
71 */
72 @Override
73 public void widgetSelected(SelectionEvent e) {
74 TermBase term = getTerm();
75
76 if (term == null){
77 MessagingUtils.warningDialog("No term to translate", getClass(), "The term is empty and therefore can not be translated");
78 }
79
80 TermTranslationWizard wizard = new TermTranslationWizard(term);
81 WizardDialog dialog = new WizardDialog(getLayoutComposite()
82 .getShell(), wizard);
83
84 if (dialog.open() == Window.OK) {
85 combo_language.setTerms(getLanguages());
86 updateControls();
87 }
88
89 }
90 }
91 @Override
92 protected void createRepresentationEditingElements(ICdmFormElement formElement, int style) {
93 super.createRepresentationEditingElements(formElement, style);
94 button = formFactory.createButton(getLayoutComposite(),
95 "Open In Translation Editor", SWT.PUSH);
96 addControl(button);
97 button.setLayoutData(LayoutConstants.RIGHT());
98 button.addSelectionListener(new OpenTranslationWizard());
99
100 }
101
102 @Override
103 public void setTerm(
104 TermBase term) {
105 super.setTerm(term);
106 button.setEnabled(false);
107 updateControls();
108 }
109
110
111 /**
112 *
113 */
114 @Override
115 protected void updateControls() {
116 super.updateControls();
117 button.setEnabled(true);
118 combo_language.setTerms(getLanguages());
119 combo_language.setSelection(selectedRepresentation.getLanguage());
120
121 }
122
123
124 }