Project

General

Profile

Download (3.92 KB) Statistics
| Branch: | Tag: | Revision:
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.common.Representation;
18
import eu.etaxonomy.cdm.model.common.TermBase;
19
import eu.etaxonomy.cdm.model.common.TermType;
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
    /**
49
     * @param cdmFormFactory
50
     * @param parentElement
51
     * @param term
52
     * @param textHeight
53
     * @param style
54
     */
55
    public TranslatableRepresentationElement(CdmFormFactory cdmFormFactory, ICdmFormElement parentElement,
56
            TermBase term, int textHeight, int style, boolean fill) {
57
        super(cdmFormFactory, parentElement, term, textHeight, style, fill);
58
    }
59

    
60

    
61
    private class OpenTranslationWizard extends SelectionAdapter {
62

    
63
        public OpenTranslationWizard() {
64
            super();
65
        }
66

    
67
        /*
68
         * (non-Javadoc)
69
         *
70
         * @see
71
         * org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse
72
         * .swt.events.SelectionEvent)
73
         */
74
        @Override
75
        public void widgetSelected(SelectionEvent e) {
76
            TermBase term = getTerm();
77

    
78
            if (term == null){
79
                MessagingUtils.warningDialog("No term to translate", getClass(), "The term is empty and therefore can not be translated");
80
            }
81

    
82
            TermTranslationWizard wizard = new TermTranslationWizard(term);
83
            WizardDialog dialog = new WizardDialog(getLayoutComposite()
84
                    .getShell(), wizard);
85

    
86
            if (dialog.open() == Window.OK) {
87
                combo_language.setTerms(getLanguages());
88
                updateControls();
89
            }
90
            
91
            firePropertyChangeEvent( e);
92

    
93
        }
94
    }
95
    @Override
96
    protected void createRepresentationEditingElements(ICdmFormElement formElement, int style) {
97
        super.createRepresentationEditingElements(formElement, style );
98
        button = formFactory.createButton(getLayoutComposite(),
99
                "Open In Translation Editor", SWT.PUSH);
100
        addControl(button);
101
        button.setLayoutData(LayoutConstants.RIGHT());
102
        button.addSelectionListener(new OpenTranslationWizard());
103

    
104
    }
105

    
106
    @Override
107
    public void setTerm(
108
            TermBase term, boolean update) {
109
        super.setTerm(term, update);
110
        if (PreferencesUtil.isMultilanguageTextEditingCapability()) {
111
        	button.setEnabled(false);
112
        }
113
        updateControls();
114
    }
115

    
116

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

    
129
    }
130

    
131

    
132
}
(43-43/44)