Project

General

Profile

Download (3.76 KB) Statistics
| Branch: | Tag: | Revision:
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) {
42
        super(formFactory, formElement, representation, term, textHeight, style);
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) {
56
        super(cdmFormFactory, parentElement, term, textHeight, style);
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
        }
91
    }
92
    @Override
93
    protected void createRepresentationEditingElements(ICdmFormElement formElement, int style) {
94
        super.createRepresentationEditingElements(formElement, style);
95
        button = formFactory.createButton(getLayoutComposite(),
96
                "Open In Translation Editor", SWT.PUSH);
97
        addControl(button);
98
        button.setLayoutData(LayoutConstants.RIGHT());
99
        button.addSelectionListener(new OpenTranslationWizard());
100

    
101
    }
102

    
103
    @Override
104
    public void setTerm(
105
            TermBase term) {
106
        super.setTerm(term);
107
        if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
108
        	button.setEnabled(false);
109
        }
110
        updateControls();
111
    }
112

    
113

    
114
    /**
115
     *
116
     */
117
    @Override
118
    protected void updateControls() {
119
       super.updateControls();
120
       if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
121
    	   button.setEnabled(true);
122
    	   combo_language.setTerms(getLanguages());
123
    	   combo_language.setSelection(selectedRepresentation.getLanguage());
124
       }
125

    
126
    }
127

    
128

    
129
}
(43-43/44)