Project

General

Profile

Download (2.01 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.molecular.io.wizard;
10

    
11

    
12
import org.eclipse.core.databinding.validation.IValidator;
13
import org.eclipse.core.databinding.validation.ValidationStatus;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
16
import org.eclipse.swt.events.SelectionAdapter;
17
import org.eclipse.swt.events.SelectionEvent;
18
import org.eclipse.swt.widgets.Button;
19

    
20

    
21

    
22
/**
23
 * Validator to make sure a non-empty consensus sequence name is provided. It must be registered as a selection listener
24
 * of the export consensus sequence check box of the wizard page in order to work properly.
25
 *
26
 * @author Ben Stöver
27
 * @date 16.11.2016
28
 */
29
public class ConsensusSequenceLabelValidator extends SelectionAdapter implements IValidator {
30
    private boolean exportConsensusSequence = true;
31
    private ISWTObservableValue checkBoxObersable;
32

    
33

    
34
    public ConsensusSequenceLabelValidator(ISWTObservableValue checkBoxObersable) {
35
        super();
36
        this.checkBoxObersable = checkBoxObersable;
37
    }
38

    
39

    
40
    /**
41
     * {@inheritDoc}
42
     */
43
    @Override
44
    public IStatus validate(Object value) {
45
        if (exportConsensusSequence && ((value == null) || ((String)value).isEmpty())) {
46
            return ValidationStatus.error("The consensus sequence label must not be empty.");  //TODO multi language
47
        }
48
        else {
49
            return ValidationStatus.ok();
50
        }
51
    }
52

    
53

    
54
    /**
55
     * {@inheritDoc}
56
     */
57
    @Override
58
    public void widgetSelected(SelectionEvent event) {
59
        exportConsensusSequence = ((Button)event.getSource()).getSelection();
60

    
61
        // Trigger validation of label:
62
        Object value = checkBoxObersable.getValue();
63
        checkBoxObersable.setValue("");
64
        checkBoxObersable.setValue(value);
65
    }
66
}
(1-1/6)