Project

General

Profile

Download (5.7 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2018 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.preference.wizard;
10

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.HashSet;
14
import java.util.List;
15
import java.util.Map;
16
import java.util.Set;
17
import java.util.UUID;
18

    
19
import org.apache.commons.lang.StringUtils;
20
import org.eclipse.jface.viewers.CheckStateChangedEvent;
21
import org.eclipse.jface.viewers.CheckboxTableViewer;
22
import org.eclipse.jface.viewers.ICheckStateListener;
23
import org.eclipse.jface.viewers.StyledString.Styler;
24
import org.eclipse.jface.viewers.ViewerComparator;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.graphics.TextStyle;
27
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.Composite;
30
import org.eclipse.swt.widgets.Display;
31

    
32
import eu.etaxonomy.cdm.api.service.IVocabularyService;
33
import eu.etaxonomy.cdm.model.common.CdmBase;
34
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
35
import eu.etaxonomy.cdm.model.common.TermType;
36
import eu.etaxonomy.cdm.model.common.TermVocabulary;
37
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
38
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
39
import eu.etaxonomy.taxeditor.editor.definedterm.VocabularyContentProvider;
40
import eu.etaxonomy.taxeditor.editor.definedterm.VocabularyLabelProvider;
41
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
42
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
43
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
44
import eu.etaxonomy.taxeditor.store.CdmStore;
45

    
46
/**
47
 * @author k.luther
48
 * @since 04.06.2018
49
 *
50
 */
51
public class AvailableAreaVocabulariesPage  extends AbstractTermSelectionWizardPage implements ICdmEntitySessionEnabled{
52

    
53
    CdmPreference pref;
54
    String featureTitle;
55
    /**
56
     * @param pageName
57
     */
58
    public AvailableAreaVocabulariesPage(String pageName, boolean localPref, CdmPreference pref, String featureTitle) {
59
        super(pageName, TermType.NamedArea);
60
        this.localPref = localPref;
61
        this.pref = pref;
62
        this.featureTitle = featureTitle;
63

    
64
    }
65

    
66
     /**
67
     * {@inheritDoc}
68
     */
69
    @Override
70
    public void createControl(Composite parent) {
71
        String vocString = null;
72
        if (localPref){
73
            vocString = PreferencesUtil.getPreferredVocabulariesForDistributionEditor(localPref);
74
        }else if (pref != null){
75
            vocString = pref.getValue();
76
        }
77
        setTitle("Select Vocabularies for "+ featureTitle);
78
        setDescription("In order to be able to modify and see the "+ featureTitle +" of taxa,\n"
79
                + "you have to select the vocabularies to select the areas from.");
80
        Composite composite = new Composite(parent, SWT.NULL);
81
        composite.setLayout(new GridLayout());
82
        setViewer(CheckboxTableViewer.newCheckList(composite, SWT.NULL));
83
        ((CheckboxTableViewer)getViewer()).getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
84

    
85
        Styler styler = new Styler() {
86
            @Override
87
            public void applyStyles(TextStyle textStyle) {
88
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
89
            }
90
        };
91
        getViewer().setContentProvider(new VocabularyContentProvider());
92
        getViewer().setLabelProvider(new VocabularyLabelProvider(styler));
93
        getViewer().setComparator(new ViewerComparator());
94
        ((CheckboxTableViewer)getViewer()).addCheckStateListener(new ICheckStateListener() {
95

    
96
            private boolean ignoreCheckEvent = false;
97

    
98
            @Override
99
            public void checkStateChanged(CheckStateChangedEvent event) {
100

    
101

    
102
                if (ignoreCheckEvent ) {
103
                    return;
104
                }
105

    
106
                ignoreCheckEvent = true;
107

    
108
                try {
109

    
110

    
111
                }
112
                finally {
113
                    ignoreCheckEvent = false;
114
                }
115

    
116
            }
117
        });
118
        rememberCheckedValues(vocString, null);
119
        ((CheckboxTableViewer)getViewer()).setCheckedElements(listCheckedTerms.toArray());
120
        setControl(composite);
121

    
122
    }
123

    
124
    /**
125
     * {@inheritDoc}
126
     */
127
    @Override
128
    public ICdmEntitySession getCdmEntitySession() {
129
        return null;
130
    }
131

    
132
    /**
133
     * {@inheritDoc}
134
     */
135
    @Override
136
    public <T extends CdmBase> Collection<T> getRootEntities() {
137
        return null;
138
    }
139

    
140
    /**
141
     * {@inheritDoc}
142
     */
143
    @Override
144
    public Map<Object, List<String>> getPropertyPathsMap() {
145
        return null;
146
    }
147

    
148
    @Override
149
    protected  List<TermVocabulary<DefinedTermBase>> getVocabulariesFromPreference(){
150
        List<TermVocabulary<DefinedTermBase>> vocs = new ArrayList();
151

    
152
        if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null ){
153
            vocs = CdmStore.getService(IVocabularyService.class).findByTermType(
154
                    type, null);
155
        }else{
156
            String vocString = PreferencesUtil.getPreferenceStore().getString(PreferencesUtil.DISTRIBUTION_VOCABULARIES);
157

    
158
            String[] arrayVocs = vocString.split(";");
159

    
160
            Set<UUID> uuidVocs = new HashSet();
161
            for (String voc: arrayVocs){
162
                if (!StringUtils.isBlank(voc)){
163
                    uuidVocs.add(UUID.fromString(voc));
164
                }
165
            }
166
            List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
167
            for (TermVocabulary voc: tempVocs){
168
                vocs.add(voc);
169
            }
170

    
171
        }
172
        return vocs;
173
    }
174

    
175
}
(4-4/13)