#4018 let the right side of the translation wizard empty, fix the save problem for...
[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.preference.PreferencesUtil;
22 import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermTranslationWizard;
23
24 /**
25 * @author k.luther
26 * @date 23.06.2016
27 *
28 */
29 public class TranslatableRepresentationElement extends RepresentationElement {
30
31 /**
32 * @param formFactory
33 * @param formElement
34 * @param representation
35 * @param term
36 * @param textHeight
37 * @param style
38 * @param isTranslationWizard
39 */
40 public TranslatableRepresentationElement(CdmFormFactory formFactory, ICdmFormElement formElement,
41 Representation representation, TermBase term, Integer textHeight, int style, boolean fill) {
42 super(formFactory, formElement, representation, term, textHeight, style, fill);
43
44 }
45
46
47 /**
48 * @param cdmFormFactory
49 * @param parentElement
50 * @param term
51 * @param textHeight
52 * @param style
53 */
54 public TranslatableRepresentationElement(CdmFormFactory cdmFormFactory, ICdmFormElement parentElement,
55 TermBase term, int textHeight, int style, boolean fill) {
56 super(cdmFormFactory, parentElement, term, textHeight, style, fill);
57 }
58
59
60 private class OpenTranslationWizard extends SelectionAdapter {
61
62 public OpenTranslationWizard() {
63 super();
64 }
65
66 /*
67 * (non-Javadoc)
68 *
69 * @see
70 * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
71 * .swt.events.SelectionEvent)
72 */
73 @Override
74 public void widgetSelected(SelectionEvent e) {
75 TermBase term = getTerm();
76
77 if (term == null){
78 MessagingUtils.warningDialog("No term to translate", getClass(), "The term is empty and therefore can not be translated");
79 }
80
81 TermTranslationWizard wizard = new TermTranslationWizard(term);
82 WizardDialog dialog = new WizardDialog(getLayoutComposite()
83 .getShell(), wizard);
84
85 if (dialog.open() == Window.OK) {
86 combo_language.setTerms(getLanguages());
87 updateControls();
88 }
89
90 firePropertyChangeEvent( e);
91
92 }
93 }
94 @Override
95 protected void createRepresentationEditingElements(ICdmFormElement formElement, int style) {
96 super.createRepresentationEditingElements(formElement, style);
97 button = formFactory.createButton(getLayoutComposite(),
98 "Open In Translation Editor", SWT.PUSH);
99 addControl(button);
100 button.setLayoutData(LayoutConstants.RIGHT());
101 button.addSelectionListener(new OpenTranslationWizard());
102
103 }
104
105 @Override
106 public void setTerm(
107 TermBase term, boolean update) {
108 super.setTerm(term, update);
109 if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
110 button.setEnabled(false);
111 }
112 updateControls();
113 }
114
115
116 /**
117 *
118 */
119 @Override
120 protected void updateControls() {
121 super.updateControls();
122 if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
123 button.setEnabled(true);
124 combo_language.setTerms(getLanguages());
125 combo_language.setSelection(selectedRepresentation.getLanguage());
126 }
127
128 }
129
130
131 }