1
|
/**
|
2
|
* Copyright (C) 2016 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
|
package eu.etaxonomy.taxeditor.ui.element;
|
10
|
|
11
|
import org.eclipse.jface.window.Window;
|
12
|
import org.eclipse.jface.wizard.WizardDialog;
|
13
|
import org.eclipse.swt.SWT;
|
14
|
import org.eclipse.swt.events.SelectionAdapter;
|
15
|
import org.eclipse.swt.events.SelectionEvent;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.term.Representation;
|
18
|
import eu.etaxonomy.cdm.model.term.TermBase;
|
19
|
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
|
20
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
21
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
22
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
23
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
24
|
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermTranslationWizard;
|
25
|
|
26
|
/**
|
27
|
* @author k.luther
|
28
|
* @date 23.06.2016
|
29
|
*
|
30
|
*/
|
31
|
public class TranslatableRepresentationElement extends RepresentationElement {
|
32
|
|
33
|
/**
|
34
|
* @param formFactory
|
35
|
* @param formElement
|
36
|
* @param representation
|
37
|
* @param term
|
38
|
* @param textHeight
|
39
|
* @param style
|
40
|
* @param isTranslationWizard
|
41
|
*/
|
42
|
public TranslatableRepresentationElement(CdmFormFactory formFactory, ICdmFormElement formElement,
|
43
|
Representation representation, TermBase term, Integer textHeight, int style, boolean fill) {
|
44
|
super(formFactory, formElement, representation, term, textHeight, style, fill);
|
45
|
|
46
|
|
47
|
}
|
48
|
|
49
|
public TranslatableRepresentationElement(CdmFormFactory formFactory, ICdmFormElement formElement,
|
50
|
Representation representation, AbstractTermDto term, Integer textHeight, int style, boolean fill) {
|
51
|
super(formFactory, formElement, representation, term, textHeight, style, fill);
|
52
|
|
53
|
|
54
|
}
|
55
|
|
56
|
|
57
|
/**
|
58
|
* @param cdmFormFactory
|
59
|
* @param parentElement
|
60
|
* @param term
|
61
|
* @param textHeight
|
62
|
* @param style
|
63
|
*/
|
64
|
public TranslatableRepresentationElement(CdmFormFactory cdmFormFactory, ICdmFormElement parentElement,
|
65
|
TermBase term, int textHeight, int style, boolean fill) {
|
66
|
super(cdmFormFactory, parentElement, term, textHeight, style, fill);
|
67
|
}
|
68
|
|
69
|
|
70
|
private class OpenTranslationWizard extends SelectionAdapter {
|
71
|
|
72
|
public OpenTranslationWizard() {
|
73
|
super();
|
74
|
}
|
75
|
|
76
|
/*
|
77
|
* (non-Javadoc)
|
78
|
*
|
79
|
* @see
|
80
|
* org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
|
81
|
* .swt.events.SelectionEvent)
|
82
|
*/
|
83
|
@Override
|
84
|
public void widgetSelected(SelectionEvent e) {
|
85
|
TermBase term = getTerm();
|
86
|
AbstractTermDto termDto = getTermDto();
|
87
|
|
88
|
|
89
|
if (term == null && termDto == null){
|
90
|
MessagingUtils.warningDialog("No term to translate", getClass(), "The term is empty and therefore can not be translated");
|
91
|
}
|
92
|
TermTranslationWizard wizard;
|
93
|
if (term != null) {
|
94
|
wizard = new TermTranslationWizard(term);
|
95
|
}else {
|
96
|
wizard = new TermTranslationWizard(termDto);
|
97
|
}
|
98
|
WizardDialog dialog = new WizardDialog(getLayoutComposite()
|
99
|
.getShell(), wizard);
|
100
|
|
101
|
if (dialog.open() == Window.OK) {
|
102
|
combo_language.setTerms(getLanguages());
|
103
|
updateControls();
|
104
|
}
|
105
|
|
106
|
firePropertyChangeEvent( e);
|
107
|
|
108
|
}
|
109
|
}
|
110
|
@Override
|
111
|
protected void createRepresentationEditingElements(ICdmFormElement formElement, int style) {
|
112
|
super.createRepresentationEditingElements(formElement, style );
|
113
|
button = formFactory.createButton(getLayoutComposite(),
|
114
|
"Open In Translation Editor", SWT.PUSH);
|
115
|
addControl(button);
|
116
|
button.setLayoutData(LayoutConstants.RIGHT());
|
117
|
button.addSelectionListener(new OpenTranslationWizard());
|
118
|
|
119
|
}
|
120
|
|
121
|
@Override
|
122
|
public void setTerm(
|
123
|
TermBase term, boolean update) {
|
124
|
super.setTerm(term, update);
|
125
|
if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
|
126
|
button.setEnabled(false);
|
127
|
}
|
128
|
updateControls();
|
129
|
}
|
130
|
|
131
|
|
132
|
/**
|
133
|
*
|
134
|
*/
|
135
|
@Override
|
136
|
protected void updateControls() {
|
137
|
super.updateControls();
|
138
|
if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
|
139
|
button.setEnabled(true);
|
140
|
combo_language.setTerms(getLanguages());
|
141
|
if (selectedRepresentation != null){
|
142
|
combo_language.setSelection(selectedRepresentation.getLanguage());
|
143
|
}else {
|
144
|
combo_language.setSelection(CdmStore.getDefaultLanguage());
|
145
|
}
|
146
|
}
|
147
|
|
148
|
}
|
149
|
@Override
|
150
|
public void setEnabled(boolean isEnabled){
|
151
|
super.setEnabled(isEnabled);
|
152
|
if (combo_language != null){
|
153
|
combo_language.setEnabled(isEnabled);
|
154
|
}
|
155
|
if (button != null){
|
156
|
button.setEnabled(isEnabled);
|
157
|
}
|
158
|
|
159
|
}
|
160
|
|
161
|
|
162
|
|
163
|
}
|