Project

General

Profile

Download (3.93 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.cdm.model.common.TermType;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
23
import eu.etaxonomy.taxeditor.ui.section.vocabulary.TermTranslationWizard;
24

    
25
/**
26
 * @author k.luther
27
 * @date 23.06.2016
28
 *
29
 */
30
public class TranslatableRepresentationElement extends RepresentationElement {
31

    
32
    /**
33
     * @param formFactory
34
     * @param formElement
35
     * @param representation
36
     * @param term
37
     * @param textHeight
38
     * @param style
39
     * @param isTranslationWizard
40
     */
41
    public TranslatableRepresentationElement(CdmFormFactory formFactory, ICdmFormElement formElement,
42
            Representation representation, TermBase term, Integer textHeight, int style, boolean fill) {
43
        super(formFactory, formElement, representation, term, textHeight, style, fill);
44
        
45

    
46
    }
47

    
48

    
49
    /**
50
     * @param cdmFormFactory
51
     * @param parentElement
52
     * @param term
53
     * @param textHeight
54
     * @param style
55
     */
56
    public TranslatableRepresentationElement(CdmFormFactory cdmFormFactory, ICdmFormElement parentElement,
57
            TermBase term, int textHeight, int style, boolean fill) {
58
        super(cdmFormFactory, parentElement, term, textHeight, style, fill);
59
    }
60

    
61

    
62
    private class OpenTranslationWizard extends SelectionAdapter {
63

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

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

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

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

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

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

    
105
    }
106

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

    
117

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

    
130
    }
131

    
132

    
133
}
(43-43/44)