Project

General

Profile

Download (6.19 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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.menu;
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.Set;
16
import java.util.UUID;
17

    
18
import javax.inject.Inject;
19

    
20
import org.apache.commons.lang3.StringUtils;
21
import org.eclipse.e4.core.services.events.IEventBroker;
22
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.custom.CLabel;
24
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.Combo;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29

    
30
import eu.etaxonomy.cdm.api.service.ITermService;
31
import eu.etaxonomy.cdm.api.service.IVocabularyService;
32
import eu.etaxonomy.cdm.model.common.CdmClass;
33
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
34
import eu.etaxonomy.cdm.model.term.TermType;
35
import eu.etaxonomy.cdm.persistence.dto.TermDto;
36
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
37
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter;
38
import eu.etaxonomy.taxeditor.editor.definedterm.FeatureDtoContentProvider;
39
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
40
import eu.etaxonomy.taxeditor.l10n.Messages;
41
import eu.etaxonomy.taxeditor.preference.GeneralTermPreferencePage;
42
import eu.etaxonomy.taxeditor.preference.LocalOrDefaultEnum;
43
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
44
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite;
45
import eu.etaxonomy.taxeditor.store.CdmStore;
46

    
47
/**
48
 * @author k.luther
49
 * @since 14.05.2019
50
 *
51
 */
52
public class NameFeatureMenuPreference extends GeneralTermPreferencePage {
53
    /** Constant <code>PLUGIN_ID="eu.etaxonomy.taxeditor.preferences.feat"{trunked}</code> */
54
    public static final String PLUGIN_ID = "eu.etaxonomy.taxeditor.preferences.nameFeature"; //$NON-NLS-1$
55

    
56
    @Inject
57
    private IEventBroker eventBroker;
58
    /**
59
     * <p>Constructor for NameFeatureMenuPreference.</p>
60
     */
61
    public NameFeatureMenuPreference() {
62
        super();
63
        setPredicate(PreferencePredicate.NameFeatures);
64
        type = TermType.Feature;
65
    }
66

    
67
    @Override
68
    protected Control createContents(Composite parent) {
69
        Composite container = new Composite(parent, SWT.NULL);
70
        getPreferenceValues();
71
        if (isLocalPref() && !allowOverride){
72
            final CLabel description = new CLabel(parent, SWT.NULL);
73
            description.setText(Messages.NameDetailsViewConfiguration_description_not_available);
74
            this.setDefaultButtonActivated(false);
75
            return parent;
76

    
77
        }
78
        final GridLayout gridLayout = new GridLayout();
79
        gridLayout.numColumns = 2;
80
        container.setLayout(gridLayout);
81
        parent.setLayout(new GridLayout());
82
        useLocalOrAdmin = new Combo(parent, SWT.BORDER | SWT.READ_ONLY);
83
        if (!isAdminPreference){
84
            useLocalOrAdmin.add(LocalOrDefaultEnum.Default.getLabel(), 0);
85
            useLocalOrAdmin.add(LocalOrDefaultEnum.Local.getLabel(), 1);
86

    
87
        }else{
88
            useLocalOrAdmin.add(LocalOrDefaultEnum.AllowOverride.getLabel(), 0);
89
            useLocalOrAdmin.add(LocalOrDefaultEnum.Database.getLabel(), 1);
90
        }
91

    
92

    
93
        treeComposite = new CheckBoxTreeComposite(container, new FeatureDtoContentProvider(false, true, false), new TermDtoLabelProvider(), SWT.SCROLL_PAGE);
94
        treeComposite.getViewer().setComparator(new DefinedTermSorter());
95
        rememberCheckedValues(getCheckedValuesFromPreferences());
96

    
97
        if (isLocalPref()){
98
            if (isOverride){
99
                useLocalOrAdmin.select(1);
100
            }else{
101
                useLocalOrAdmin.select(0);
102
                if (treeComposite.getViewer().getTree() != null && treeComposite.getViewer().getTree().getTopItem() != null) {
103
                    treeComposite.getViewer().getTree().setSelection(treeComposite.getViewer().getTree().getTopItem());
104
                }
105
                treeComposite.setEnabled(false);
106

    
107
                //treeComposite.getViewer().getTree().getVerticalBar().setEnabled(true);
108
            }
109
        }else{
110
            if (allowOverride){
111
                useLocalOrAdmin.select(0);
112
            }else{
113
                useLocalOrAdmin.select(1);
114
            }
115
        }
116
        useLocalOrAdmin.addSelectionListener(this);
117

    
118
        GridData data = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
119
        data.heightHint = 300;
120
        treeComposite.setLayoutData(data);
121
        treeComposite.getViewer().addSelectionChangedListener(this);
122

    
123
        return container;
124

    
125
    }
126

    
127

    
128
    @Override
129
    public boolean performOk(){
130
        if (isApply()){
131
            boolean result = super.performOk();
132
            if (result){
133
                PreferencesUtil.getPreferredFeatureTreeForNameDescription(true);
134
            }
135
        }
136
        return true;
137

    
138
    }
139

    
140
    @Override
141
    protected void initialiseVocabularies() {
142

    
143
        if (getVocabularies() != null) {
144
            getVocabularies().clear();
145
        }
146
        List<TermVocabularyDto> vocs = new ArrayList<>();
147
        Set<CdmClass> availableFor = new HashSet<>();
148
        availableFor.add(CdmClass.TAXON_NAME);
149
        vocs = CdmStore.getService(IVocabularyService.class).findFeatureVocabularyDtoByTermTypes(availableFor);
150

    
151
        setVocabularies(vocs);
152
    }
153

    
154
    @Override
155
    protected List<TermDto> getTermsFromStringValues(List<String> listValue) {
156
        Collection<TermDto> termlist = new ArrayList<>();
157
        ITermService termService = CdmStore.getService(ITermService.class);
158
        List<UUID> uuidList = new ArrayList();
159
        for (String s : listValue) {
160
            if (!StringUtils.isBlank(s)){
161
                UUID uuid = UUID.fromString(s);
162
                uuidList.add(uuid);
163
            }
164
        }
165
        if (!uuidList.isEmpty()){
166
            termlist = termService.findFeatureByUUIDsAsDto(uuidList);
167
        }
168

    
169
        if (listValue == null || listValue.isEmpty() ){
170
            termlist = termService.findFeatureByTitleAsDto("");
171

    
172
        }
173

    
174
        return new ArrayList(termlist);
175
    }
176

    
177

    
178
}
(12-12/21)