Project

General

Profile

Revision a3c56b93

IDa3c56b93813fa25a19da96969a694c22af7f0c30
Parent 244ab5da
Child eebb08aa

Added by Patrick Plitzner over 1 year ago

ref #7887 Use DTOs in term editor

View differences:

eu.etaxonomy.taxeditor.bulkeditor/src/main/java/eu/etaxonomy/taxeditor/bulkeditor/e4/BulkEditorE4.java
236 236
    }
237 237

  
238 238
    @Override
239
    public boolean postOperation(CdmBase objectAffectedByOperation) {
239
    public boolean postOperation(Object objectAffectedByOperation) {
240 240
        return false;
241 241
    }
242 242

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/AreasSelectionDialog.java
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.editor.descriptiveDataSet;
10

  
11
import java.util.Arrays;
12
import java.util.Collection;
13
import java.util.Collections;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17
import java.util.stream.Collectors;
18

  
19
import org.eclipse.jface.dialogs.Dialog;
20
import org.eclipse.jface.layout.GridLayoutFactory;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Shell;
26

  
27
import eu.etaxonomy.cdm.api.service.IVocabularyService;
28
import eu.etaxonomy.cdm.model.common.TermType;
29
import eu.etaxonomy.cdm.model.common.TermVocabulary;
30
import eu.etaxonomy.cdm.model.location.NamedArea;
31
import eu.etaxonomy.cdm.persistence.dto.TermDto;
32
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
33
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
34
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36

  
37
/**
38
 * @author pplitzner
39
 * @since Oct 29, 2018
40
 *
41
 */
42
public class AreasSelectionDialog extends Dialog{
43

  
44
    private CheckBoxTreeComposite treeComposite;
45

  
46
    private Set<TermDto> selectedAreas = new HashSet<>();
47

  
48
    private Collection<TermVocabulary<NamedArea>> areaVocabularies;
49

  
50

  
51
    protected AreasSelectionDialog(Shell parentShell, Set<TermDto> selectedAreas) {
52
        super(parentShell);
53
        this.selectedAreas = selectedAreas;
54
        this.areaVocabularies = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null);
55
    }
56

  
57
    @Override
58
    protected Control createDialogArea(Composite parent) {
59
        parent.setLayout(new GridLayout());
60
        treeComposite = new CheckBoxTreeComposite(parent, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT.NONE);
61
        treeComposite.getViewer().setInput(areaVocabularies);
62
        treeComposite.setCheckedElements(selectedAreas.toArray());
63
        GridLayoutFactory.fillDefaults().applyTo(treeComposite);
64
        return treeComposite;
65
    }
66

  
67
    @Override
68
    protected void configureShell(Shell newShell) {
69
        super.configureShell(newShell);
70
        newShell.setText("Choose areas");
71
        newShell.setSize(400, 600);
72
    }
73

  
74
    @Override
75
    protected void okPressed() {
76
        selectedAreas.clear();
77
        List<Object> checkedElements = Arrays.asList(treeComposite.getViewer().getCheckedElements());
78
        checkedElements = checkedElements.stream().filter(element->element instanceof TermDto).collect(Collectors.toList());
79
        Collections.sort(checkedElements, (o1, o2)->((TermDto)o1).getOrderIndex()-((TermDto)o2).getOrderIndex());
80
        selectedAreas = new HashSet(checkedElements);
81
        super.okPressed();
82
    }
83

  
84
    @Override
85
    protected boolean isResizable() {
86
        return true;
87
    }
88

  
89
    public Set<TermDto> getSelectedAreas(){
90
        return selectedAreas;
91
    }
92
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetComposite.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet;
10 10

  
11
import java.util.HashSet;
12
import java.util.Set;
13
import java.util.stream.Collectors;
14

  
11 15
import org.eclipse.jface.viewers.TreeViewer;
12 16
import org.eclipse.swt.SWT;
13 17
import org.eclipse.swt.layout.GridData;
......
20 24

  
21 25
import eu.etaxonomy.cdm.model.common.TermType;
22 26
import eu.etaxonomy.cdm.model.description.FeatureTree;
23
import eu.etaxonomy.cdm.model.location.NamedArea;
24 27
import eu.etaxonomy.cdm.model.name.Rank;
28
import eu.etaxonomy.cdm.persistence.dto.TermDto;
29
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
25 30
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
26 31
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditorComposite;
27 32
import eu.etaxonomy.taxeditor.model.ImageResources;
......
40 45
    private TermUuidComboViewer comboRankMax;
41 46
    private FeatureTreeEditorComposite featureTreeEditorComposite;
42 47
    private TreeViewer taxonNodeTree;
43
    private NamedArea area;
48
    private Set<TermDto> areas = new HashSet<>();
44 49
    private Text textAreaText;
45 50
    private Button btnChooseArea;
46
    private Button btnRemoveArea;
47 51
    private Button btnRemoveRankMin;
48 52
    private Button btnRemoveRankMax;
49 53

  
......
115 119

  
116 120
        Composite composite = new Composite(this, SWT.NONE);
117 121
        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 1, 1));
118
        GridLayout gl_composite = new GridLayout(3, false);
122
        GridLayout gl_composite = new GridLayout(2, false);
119 123
        gl_composite.horizontalSpacing = 0;
120 124
        gl_composite.verticalSpacing = 0;
121 125
        gl_composite.marginHeight = 0;
......
130 134
        btnChooseArea = new Button(composite, SWT.NONE);
131 135
        btnChooseArea.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
132 136

  
133
        btnRemoveArea = new Button(composite, SWT.NONE);
134
        btnRemoveArea.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
135

  
136 137
        featureTreeEditorComposite = new FeatureTreeEditorComposite(this, SWT.NONE);
137 138
        featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
138 139
    }
......
173 174
    public TreeViewer getTaxonNodeTree() {
174 175
        return taxonNodeTree;
175 176
    }
176

  
177
    public NamedArea getArea(){
178
        return area;
177
    public Set<TermDto> getAreas() {
178
        return areas;
179 179
    }
180
    public void setArea(NamedArea area) {
181
        this.area = area;
182
        textAreaText.setText(area.getLabel());
183
    }
184
    public void removeArea() {
185
        this.area = null;
186
        textAreaText.setText(""); //$NON-NLS-1$
180
    public void setAreas(Set<TermDto> areas) {
181
        this.areas = areas;
182
        textAreaText.setText(areas.stream().map(area->{
183
            area.localize(new TermRepresentation_L10n());
184
            return area.getRepresentation_L10n();
185
        }).collect(Collectors.joining(", ")));
187 186
    }
188 187
    public Button getBtnChooseArea() {
189 188
        return btnChooseArea;
190 189
    }
191
    public Button getBtnRemoveArea() {
192
        return btnRemoveArea;
193
    }
194 190
    public Button getBtnRemoveRankMin() {
195 191
        return btnRemoveRankMin;
196 192
    }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetEditor.java
17 17
import java.util.Map;
18 18
import java.util.Set;
19 19
import java.util.UUID;
20
import java.util.stream.Collectors;
20 21

  
21 22
import javax.annotation.PostConstruct;
22 23
import javax.annotation.PreDestroy;
......
36 37
import org.eclipse.jface.viewers.IStructuredSelection;
37 38
import org.eclipse.jface.viewers.StructuredSelection;
38 39
import org.eclipse.jface.viewers.Viewer;
40
import org.eclipse.jface.window.Window;
39 41
import org.eclipse.swt.SWT;
40 42
import org.eclipse.swt.dnd.DND;
41 43
import org.eclipse.swt.dnd.Transfer;
......
63 65
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
64 66
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
65 67
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
68
import eu.etaxonomy.cdm.persistence.dto.TermDto;
66 69
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
67 70
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
68 71
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
......
72 75
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
73 76
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
74 77
import eu.etaxonomy.taxeditor.store.CdmStore;
75
import eu.etaxonomy.taxeditor.ui.dialog.selection.NamedAreaSelectionDialog;
76 78
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
77 79
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart;
78 80

  
......
152 154

  
153 155
            @Override
154 156
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
155
                NamedArea area = NamedAreaSelectionDialog.select(shell, null, null);
156
                if(area!=null){
157
                    composite.setArea(area);
157
                AreasSelectionDialog areasSelectionDialog = new AreasSelectionDialog(composite.getShell(), composite.getAreas());
158
                if(areasSelectionDialog.open()==Window.OK){
159
                    Set<TermDto> selectedAreas = areasSelectionDialog.getSelectedAreas();
160
                    if(selectedAreas!=null){
161
                        composite.setAreas(selectedAreas);
162
                        dirty.setDirty(true);
163
                    }
158 164
                }
159
                dirty.setDirty(true);
160
            }
161
        });
162
        composite.getBtnRemoveArea().addSelectionListener(new SelectionAdapter() {
163

  
164
            @Override
165
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
166
                composite.removeArea();
167
                dirty.setDirty(true);
168 165
            }
169 166
        });
170 167

  
......
207 204
        }
208 205
        Set<NamedArea> geoFilter = descriptiveDataSet.getGeoFilter();
209 206
        if(geoFilter!=null && !geoFilter.isEmpty()){
210
            composite.setArea(geoFilter.iterator().next());
207
            Set<TermDto> terms = geoFilter.stream().map(filter->new TermDto(
208
                    filter.getUuid(),
209
                    filter.getRepresentations(),
210
                    filter.getPartOf()!=null?filter.getPartOf().getUuid():null,
211
                    filter.getVocabulary().getUuid(),
212
                    filter.getOrderIndex())).collect(Collectors.toSet());
213
            composite.setAreas(terms);
211 214
        }
212 215
        Set<TaxonNode> taxonSubtreeFilter = descriptiveDataSet.getTaxonSubtreeFilter();
213 216
        if(taxonSubtreeFilter!=null){
......
271 274
    @Persist
272 275
    @Override
273 276
    public void save(IProgressMonitor monitor) {
274
        NamedArea area = composite.getArea();
275
        Set<NamedArea> areas = new HashSet<>();
276
        if(area!=null){
277
            areas.add(area);
278
        }
277
        Set<TermDto> areas = composite.getAreas();
279 278
        Object input = composite.getTaxonNodeTree().getInput();
280 279
        if(input!=null){
281 280
            descriptiveDataSet.setTaxonSubtreeFilter(new HashSet<>());//clear existing filter
......
308 307
        descriptiveDataSet.setMaxRank(rankMax);
309 308
        descriptiveDataSet.setMinRank(rankMin);
310 309
        descriptiveDataSet.setDescriptiveSystem(characters);
311
        descriptiveDataSet.setGeoFilter(areas);
310
        List<DefinedTermBase> terms = CdmStore.getService(ITermService.class)
311
                .load(areas.stream().map(area -> area.getUuid()).collect(Collectors.toList()), null);
312
        Set<NamedArea> areaTerms = new HashSet<>();
313
        terms.forEach(term->areaTerms.add((NamedArea) term));
314
        descriptiveDataSet.setGeoFilter(areaTerms);
312 315

  
313 316
        conversation.commit();
314 317
        CdmStore.getService(IDescriptiveDataSetService.class).merge(descriptiveDataSet, true);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/e4/AbstractGraphKeyEditorE4.java
26 26
import org.eclipse.zest.layouts.algorithms.TreeLayoutAlgorithm;
27 27

  
28 28
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
29
import eu.etaxonomy.cdm.model.common.CdmBase;
30 29
import eu.etaxonomy.cdm.model.description.IIdentificationKey;
31 30
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
32 31
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
......
157 156
	}
158 157

  
159 158
	@Override
160
	public boolean postOperation(CdmBase objectAffectedByOperation) {
159
	public boolean postOperation(Object objectAffectedByOperation) {
161 160
		setDirty(true);
162 161
		refresh();
163 162

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/key/polytomous/e4/PolytomousKeyListEditorE4.java
42 42
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
43 43
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
44 44
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
45
import eu.etaxonomy.cdm.model.common.CdmBase;
46 45
import eu.etaxonomy.cdm.model.description.PolytomousKey;
47 46
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
48 47
import eu.etaxonomy.cdm.model.taxon.Taxon;
......
314 313
    }
315 314

  
316 315
	@Override
317
	public boolean postOperation(CdmBase objectAffectedByOperation) {
316
	public boolean postOperation(Object objectAffectedByOperation) {
318 317
		viewer.refresh();
319 318

  
320 319
		if (objectAffectedByOperation != null) {
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java
313 313
	}
314 314

  
315 315
	@Override
316
    public boolean postOperation(CdmBase objectAffectedByOperation) {
316
    public boolean postOperation(Object objectAffectedByOperation) {
317 317

  
318 318
		changed(objectAffectedByOperation);
319 319

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/container/AbstractGroupE4.java
24 24
import org.eclipse.ui.forms.widgets.TableWrapData;
25 25
import org.eclipse.ui.forms.widgets.TableWrapLayout;
26 26

  
27
import eu.etaxonomy.cdm.model.common.CdmBase;
28 27
import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
29 28
import eu.etaxonomy.taxeditor.editor.name.e4.IDropTargetableE4;
30 29
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
......
150 149

  
151 150
	/** {@inheritDoc} */
152 151
	@Override
153
    public boolean postOperation(CdmBase objectAffectedByOperation) {
152
    public boolean postOperation(Object objectAffectedByOperation) {
154 153
		editor.changed(objectAffectedByOperation);
155 154
		redraw();
156 155
		return true;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/ChangeSynonymToAcceptedTaxonHandlerE4.java
26 26
import org.eclipse.jface.viewers.IStructuredSelection;
27 27
import org.eclipse.swt.widgets.Shell;
28 28

  
29
import eu.etaxonomy.cdm.model.common.CdmBase;
30 29
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
31 30
import eu.etaxonomy.cdm.model.name.TaxonName;
32 31
import eu.etaxonomy.cdm.model.taxon.Synonym;
......
108 107

  
109 108
	/** {@inheritDoc} */
110 109
	@Override
111
    public boolean postOperation(CdmBase objectAffectedByOperation) {
110
    public boolean postOperation(Object objectAffectedByOperation) {
112 111

  
113 112
		// Redraw existing editor
114 113
		((IPostOperationEnabled) editor).postOperation(null);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/DeleteTaxonBaseHandlerE4.java
25 25
import eu.etaxonomy.cdm.api.service.config.SynonymDeletionConfigurator;
26 26
import eu.etaxonomy.cdm.api.service.config.TaxonBaseDeletionConfigurator;
27 27
import eu.etaxonomy.cdm.api.service.config.TaxonDeletionConfigurator;
28
import eu.etaxonomy.cdm.model.common.CdmBase;
29 28
import eu.etaxonomy.cdm.model.taxon.Synonym;
30 29
import eu.etaxonomy.cdm.model.taxon.Taxon;
31 30
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
......
167 166
    }
168 167

  
169 168
	@Override
170
	public boolean postOperation(CdmBase objectAffectedByOperation) {
169
	public boolean postOperation(Object objectAffectedByOperation) {
171 170
	    editor.redraw();
172 171
		return true;
173 172
	}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/MoveSynonymToAnotherAcceptedTaxonHandlerE4.java
20 20
import org.eclipse.jface.viewers.IStructuredSelection;
21 21
import org.eclipse.swt.widgets.Shell;
22 22

  
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24 23
import eu.etaxonomy.cdm.model.taxon.Synonym;
25 24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
26 25
import eu.etaxonomy.taxeditor.editor.EditorUtil;
......
108 107
    }
109 108

  
110 109
	@Override
111
	public boolean postOperation(CdmBase objectAffectedByOperation) {
110
	public boolean postOperation(Object objectAffectedByOperation) {
112 111
	    editor.redraw();
113 112
		return false;
114 113
	}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/handler/SwapSynonymAndAcceptedHandlerE4.java
24 24
import org.eclipse.swt.widgets.Display;
25 25
import org.eclipse.swt.widgets.Shell;
26 26

  
27
import eu.etaxonomy.cdm.model.common.CdmBase;
28 27
import eu.etaxonomy.cdm.model.taxon.Synonym;
29 28
import eu.etaxonomy.cdm.model.taxon.Taxon;
30 29
import eu.etaxonomy.taxeditor.editor.EditorUtil;
......
92 91
    }
93 92

  
94 93
    @Override
95
    public boolean postOperation(CdmBase objectAffectedByOperation) {
94
    public boolean postOperation(Object objectAffectedByOperation) {
96 95
        // Redraw existing editor
97 96
        // ((IPostOperationEnabled) editor).postOperation(null);
98 97

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java
49 49
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
50 50
import eu.etaxonomy.cdm.api.service.ITaxonService;
51 51
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
52
import eu.etaxonomy.cdm.model.common.CdmBase;
53 52
import eu.etaxonomy.cdm.model.molecular.SingleRead;
54 53
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
55 54
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
......
466 465
    }
467 466

  
468 467
    @Override
469
    public boolean postOperation(CdmBase objectAffectedByOperation) {
468
    public boolean postOperation(Object objectAffectedByOperation) {
470 469
        refreshTree();
471 470
        if(objectAffectedByOperation!=null){
472 471
            changed(objectAffectedByOperation);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionElementsHandlerE4.java
37 37

  
38 38
import eu.etaxonomy.cdm.api.service.IDescriptionService;
39 39
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
40
import eu.etaxonomy.cdm.model.common.CdmBase;
41 40
import eu.etaxonomy.cdm.model.description.DescriptionBase;
42 41
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
43 42
import eu.etaxonomy.cdm.model.description.TaxonDescription;
......
187 186

  
188 187
    /** {@inheritDoc} */
189 188
    @Override
190
    public boolean postOperation(CdmBase objectAffectedByOperation) {
189
    public boolean postOperation(Object objectAffectedByOperation) {
191 190

  
192 191
        editor.getConversationHolder().bind();
193 192
        editor.getConversationHolder().commit(true);
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/MoveDescriptionToOtherTaxonHandlerE4.java
28 28
import org.eclipse.swt.widgets.Display;
29 29
import org.eclipse.swt.widgets.Shell;
30 30

  
31
import eu.etaxonomy.cdm.model.common.CdmBase;
32 31
import eu.etaxonomy.cdm.model.description.DescriptionBase;
33 32
import eu.etaxonomy.cdm.model.description.TaxonDescription;
34 33
import eu.etaxonomy.cdm.model.taxon.Classification;
......
154 153

  
155 154
    /** {@inheritDoc} */
156 155
    @Override
157
    public boolean postOperation(CdmBase objectAffectedByOperation) {
156
    public boolean postOperation(Object objectAffectedByOperation) {
158 157
        Display.getDefault().asyncExec(new Runnable(){
159 158

  
160 159
            @Override
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/uses/e4/UsesViewPartE4.java
20 20
import org.eclipse.swt.widgets.Composite;
21 21
import org.eclipse.swt.widgets.Tree;
22 22

  
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24 23
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
25 24
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDragListener;
26 25
import eu.etaxonomy.taxeditor.editor.view.descriptive.DescriptionElementDropAdapter;
......
80 79

  
81 80
    /** {@inheritDoc} */
82 81
    @Override
83
    public boolean postOperation(CdmBase objectAffectedByOperation) {
82
    public boolean postOperation(Object objectAffectedByOperation) {
84 83
        viewer.refresh();
85 84
        return super.postOperation(objectAffectedByOperation);
86 85
    }
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/key/polytomous/e4/PolytomousKeyViewPartE4.java
47 47
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
48 48
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
49 49
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
50
import eu.etaxonomy.cdm.model.common.CdmBase;
51 50
import eu.etaxonomy.cdm.model.description.PolytomousKey;
52 51
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
53 52
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
......
262 261
    }
263 262

  
264 263
    @Override
265
    public boolean postOperation(CdmBase objectAffectedByOperation) {
264
    public boolean postOperation(Object objectAffectedByOperation) {
266 265
        getConversationHolder().bind();
267 266
        getConversationHolder().commit(true);
268 267
        viewer.refresh();
eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/e4/TaxonNavigatorE4.java
499 499

  
500 500
	/** {@inheritDoc} */
501 501
	@Override
502
	public boolean postOperation(CdmBase objectAffectedByOperation) {
502
	public boolean postOperation(Object objectAffectedByOperation) {
503 503
	    viewer.refresh();
504 504
		return true;
505 505
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermSorter.java
10 10
package eu.etaxonomy.taxeditor.editor.definedterm;
11 11

  
12 12
import org.eclipse.jface.viewers.Viewer;
13
import org.eclipse.jface.viewers.ViewerSorter;
13
import org.eclipse.jface.viewers.ViewerComparator;
14 14

  
15 15
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
16
import eu.etaxonomy.cdm.persistence.dto.TermDto;
16 17

  
17 18
/**
18 19
 * @author pplitzner
19 20
 * @date 13.02.2018
20 21
 *
21 22
 */
22
public class DefinedTermSorter extends ViewerSorter {
23
public class DefinedTermSorter extends ViewerComparator {
23 24

  
24 25
    @Override
25 26
    public int compare(Viewer viewer, Object e1, Object e2) {
26
        // the comparison value in this method determines the
27
     // the comparison value in this method determines the
27 28
        // location <-> add term method used in the MoveDefinedTermOperation
28 29
        // execute call
30
        //FIXME: remove this when all viewer are changed to use DTOs
29 31
        if(e1 instanceof OrderedTermBase && e2 instanceof OrderedTermBase) {
30 32
            OrderedTermBase otbe1 = (OrderedTermBase)e1;
31 33
            OrderedTermBase otbe2 = (OrderedTermBase)e2;
......
36 38
            } else{
37 39
                return 1;
38 40
            }
39
        } else {
41
        }
42
        else if(e1 instanceof TermDto && e2 instanceof TermDto) {
43
            TermDto termDto1 = (TermDto)e1;
44
            TermDto termDto2 = (TermDto)e2;
45
            if(termDto1.getOrderIndex() == termDto2.getOrderIndex()) {
46
                return 0;
47
            } else if (termDto1.getOrderIndex() < termDto2.getOrderIndex()){
48
                return -1;
49
            } else{
50
                return 1;
51
            }
52
        }
53
        else {
40 54
            return super.compare(viewer, e1, e2);
41 55
        }
42 56
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermBasePropertyTester.java
1 1
/**
2 2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy 
3
* European Distributed Institute of Taxonomy
4 4
* http://www.e-taxonomy.eu
5
* 
5
*
6 6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7 7
* See LICENSE.TXT at the top of this package for the full license terms.
8 8
*/
......
11 11
import org.eclipse.core.expressions.PropertyTester;
12 12
import org.eclipse.jface.viewers.IStructuredSelection;
13 13

  
14
import eu.etaxonomy.cdm.api.service.IVocabularyService;
14 15
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15 16
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
16 17
import eu.etaxonomy.cdm.model.common.Marker;
17 18
import eu.etaxonomy.cdm.model.common.MarkerType;
18 19
import eu.etaxonomy.cdm.model.common.TermBase;
19 20
import eu.etaxonomy.cdm.model.common.TermVocabulary;
21
import eu.etaxonomy.cdm.persistence.dto.TermDto;
22
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
23
import eu.etaxonomy.taxeditor.store.CdmStore;
20 24

  
21 25
/**
22 26
 * @author l.morris
......
26 30
public class TermBasePropertyTester extends PropertyTester {
27 31

  
28 32
	private static final String IS_MODIFIABLE = "isModifiable";
29
	
33

  
30 34

  
31 35
	/* (non-Javadoc)
32 36
	 * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
......
34 38
	@Override
35 39
	public boolean test(Object receiver, String property, Object[] args,
36 40
			Object expectedValue) {
37
		
41

  
38 42
		IStructuredSelection selection = (IStructuredSelection) receiver;
39 43
		Object selectedElement = selection.getFirstElement();
40 44
		if (selectedElement != null && HibernateProxyHelper.isInstanceOf(selectedElement, TermBase.class)){
......
44 48
				return isModifiable(term);
45 49
			}
46 50
		}
47
		
51

  
48 52
		return false;
49 53
	}
50 54

  
51 55

  
52 56
	/**
53 57
	 * Checks whether there is a {@link Marker} with the type {@link MarkerType#MODIFIABLE()} and if there is then return its value.
54
	 * 
55
	 * @return The markers value if it exists 
58
	 *
59
	 * @return The markers value if it exists
56 60
	 */
57
	public static boolean isModifiable(TermBase termBase) {
58
		if (termBase == null){
61
	public static boolean isModifiable(Object object) {
62
		if (object == null){
59 63
			return true;
60 64
		}
61
		
65

  
62 66
		TermVocabulary vocabulary = null;
63
		
64
		if(termBase instanceof DefinedTermBase){
65
			vocabulary = ((DefinedTermBase) termBase).getVocabulary();
66
		}else if(termBase instanceof TermVocabulary){
67
			vocabulary = (TermVocabulary) termBase;
68
		}
69
		
67

  
68
		if(object instanceof DefinedTermBase){
69
			vocabulary = ((DefinedTermBase) object).getVocabulary();
70
		}else if(object instanceof TermVocabulary){
71
			vocabulary = (TermVocabulary) object;
72
		}else if(object instanceof TermDto){
73
            vocabulary = CdmStore.getService(IVocabularyService.class).load(((TermDto) object).getVocabularyUuid());
74
        }else if(object instanceof TermVocabularyDto){
75
            vocabulary = CdmStore.getService(IVocabularyService.class).load(((TermVocabularyDto) object).getUuid());
76
        }
77

  
70 78
		if(vocabulary == null){
71 79
			return true;
72 80
		}
73
		
81

  
74 82
		for(Marker vocabularyMarker : vocabulary.getMarkers()){
75 83
			if(vocabularyMarker.getMarkerType().equals(MarkerType.MODIFIABLE())){
76
				return vocabularyMarker.getValue();			
84
				return vocabularyMarker.getValue();
77 85
			}
78 86
		}
79
				
87

  
80 88
		return true;
81 89
	}
82 90

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoContentProvider.java
1
/**
2
* Copyright (C) 2009 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.editor.definedterm;
10

  
11
import java.util.Collection;
12
import java.util.HashSet;
13
import java.util.UUID;
14

  
15
import org.eclipse.jface.viewers.TreeNodeContentProvider;
16

  
17
import eu.etaxonomy.cdm.api.service.IVocabularyService;
18
import eu.etaxonomy.cdm.persistence.dto.TermDto;
19
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

  
22
/**
23
 *
24
 * @author pplitzner
25
 * @since Oct 29, 2018
26
 *
27
 */
28
public class TermDtoContentProvider extends TreeNodeContentProvider {
29

  
30
	@Override
31
	public Object[] getElements(Object inputElement) {
32
		Collection<TermVocabularyDto> inputElements = (Collection<TermVocabularyDto>) inputElement;
33
		return inputElements.toArray();
34
	}
35

  
36
	@Override
37
	public Object[] getChildren(Object parentElement) {
38
	    Collection<Object> children = new HashSet<>();
39
	    if(parentElement instanceof TermVocabularyDto){
40
	        children.addAll(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(((TermVocabularyDto)parentElement).getUuid()));
41
	    } else if(parentElement instanceof TermDto){
42
	            if(((TermDto) parentElement).getIncludes()!=null){
43
	                children.addAll(((TermDto) parentElement).getIncludes());
44
	            }
45
                if(((TermDto) parentElement).getGeneralizationOf()!=null){
46
                    children.addAll(((TermDto) parentElement).getGeneralizationOf());
47
                }
48
	    }
49
	    return children.toArray();
50
	}
51

  
52
	@Override
53
	public Object getParent(Object element) {
54
		if(element instanceof TermDto){
55
		    UUID partOfUuid = ((TermDto) element).getPartOfUuid();
56
		    if(partOfUuid==null){
57
		        return CdmStore.getService(IVocabularyService.class).load(((TermDto) element).getVocabularyUuid());
58
		    }
59
		    return new TermDto(partOfUuid, null, null);
60
		}
61
		return null;
62

  
63
	}
64

  
65
	@Override
66
	public boolean hasChildren(Object element) {
67
	    if(element instanceof TermVocabularyDto){
68
	        //performance optimization
69
	        return true;
70
	    }
71
		if (getChildren(element) != null){
72
			return getChildren(element).length > 0;
73
		}
74
		return false;
75
	}
76

  
77
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoLabelProvider.java
1
/**
2
 * Copyright (C) 2009 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.editor.definedterm;
10

  
11
import org.eclipse.jface.viewers.StyledCellLabelProvider;
12
import org.eclipse.jface.viewers.StyledString;
13
import org.eclipse.jface.viewers.StyledString.Styler;
14
import org.eclipse.jface.viewers.ViewerCell;
15
import org.eclipse.swt.SWT;
16
import org.eclipse.swt.custom.StyleRange;
17
import org.eclipse.swt.graphics.Color;
18
import org.eclipse.swt.graphics.TextStyle;
19
import org.eclipse.swt.widgets.Display;
20

  
21
import eu.etaxonomy.cdm.common.CdmUtils;
22
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermDto;
24
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
25
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
26

  
27
/**
28
 *
29
 * @author pplitzner
30
 * @since Oct 29, 2018
31
 *
32
 */
33
public class TermDtoLabelProvider extends StyledCellLabelProvider {
34

  
35
    private static Color vocColor = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE);
36
    private static Color kindOfColor = Display.getCurrent().getSystemColor(SWT.COLOR_DARK_GRAY);
37
    private Styler vocStyler;
38
    private Styler kindOfStyler;
39

  
40
    public TermDtoLabelProvider() {
41
    }
42

  
43
    public TermDtoLabelProvider(Styler vocStyler){
44
        this.vocStyler = vocStyler;
45
    }
46

  
47
    @Override
48
    public void update(ViewerCell cell) {
49
        Object element = cell.getElement();
50

  
51
        String text = getText(element);
52
        cell.setText(text);
53

  
54
        Styler styler = null;
55
        if (element instanceof TermVocabularyDto && text != null) {
56
            styler = getVocabularyStyler();
57
        }
58
        else if(element instanceof TermDto && ((TermDto) element).getKindOfUuid()!=null){
59
            styler = getKindOfStyler();
60
        }
61
        if(styler!=null){
62
            StyledString styledString = new StyledString(text, styler);
63
            StyleRange[] styleRanges;
64
            styleRanges = styledString.getStyleRanges();
65
            cell.setStyleRanges(styleRanges);
66
        }
67
        super.update(cell);
68
    }
69

  
70
    public String getText(Object element) {
71
        String label = null;
72
        if(element instanceof AbstractTermDto){
73
            AbstractTermDto termDto = (AbstractTermDto)element;
74
            termDto.localize(new TermRepresentation_L10n());
75
            label = termDto.getRepresentation_L10n();
76

  
77
            if(element instanceof TermDto && ((TermDto) termDto).getIdInVocabulary()!=null){
78
                label = CdmUtils.concat(" : ", ((TermDto) termDto).getIdInVocabulary(), label);
79
            }
80
        }
81
        // TODO add fallback for label
82
        if(label==null){
83
            label = element.toString();
84
        }
85
        return label;
86
    }
87

  
88
    protected Styler getVocabularyStyler() {
89
        if (vocStyler == null) {
90
            vocStyler = new Styler() {
91
                @Override
92
                public void applyStyles(TextStyle textStyle) {
93
                    textStyle.foreground = vocColor;
94
                }
95
            };
96
        }
97
        return vocStyler;
98
    }
99

  
100
    protected Styler getKindOfStyler() {
101
        if (kindOfStyler == null) {
102
            kindOfStyler = new Styler() {
103
                @Override
104
                public void applyStyles(TextStyle textStyle) {
105
                    textStyle.foreground = kindOfColor;
106
                }
107
            };
108
        }
109
        return kindOfStyler;
110
    }
111

  
112
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermLabelProvider.java
41 41
    private Styler kindOfStyler;
42 42

  
43 43
    public TermLabelProvider() {
44
        this.vocStyler = new Styler() {
45
            @Override
46
            public void applyStyles(TextStyle textStyle) {
47
                textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
48
            }
49
        };
44 50
    }
45 51

  
46 52
    public TermLabelProvider(Styler vocStyler){
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermDragListenerE4.java
8 8
*/
9 9
package eu.etaxonomy.taxeditor.editor.definedterm.e4;
10 10

  
11
import java.util.ArrayList;
12 11
import java.util.List;
13 12

  
13
import org.eclipse.jface.util.LocalSelectionTransfer;
14 14
import org.eclipse.jface.viewers.IStructuredSelection;
15 15
import org.eclipse.jface.viewers.Viewer;
16 16
import org.eclipse.swt.dnd.DragSourceAdapter;
17 17
import org.eclipse.swt.dnd.DragSourceEvent;
18 18

  
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
19
import eu.etaxonomy.cdm.persistence.dto.TermDto;
21 20

  
22 21
/**
23 22
 *
......
38 37
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
39 38
	    List list = selection.toList();
40 39
	    for (Object object : list) {
41
            if(!(object instanceof DefinedTermBase)){
40
            if(!(object instanceof TermDto)){
42 41
                event.doit = false;
43 42
                return;
44 43
            }
......
48 47

  
49 48
	@Override
50 49
	public void dragSetData(DragSourceEvent event) {
50
	    IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
51
        if (LocalSelectionTransfer.getTransfer().isSupportedType(event.dataType)) {
52
            LocalSelectionTransfer.getTransfer().setSelection(selection);
53
        }
51 54

  
52
		IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
53
		List<DefinedTermBase> definedTerms = new ArrayList<DefinedTermBase>();
54

  
55
		for (Object object : selection.toList()){
56
				definedTerms.add((DefinedTermBase)object);
57
			}
58

  
59
		if (TermTransfer.getInstance().isSupportedType(
60
				event.dataType)) {
61
			event.data = definedTerms.toArray(new DefinedTermBase[definedTerms.size()]);
62
		}
63 55
	}
64 56

  
65 57
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermDropAdapterE4.java
14 14
import javax.inject.Inject;
15 15

  
16 16
import org.eclipse.e4.ui.di.UISynchronize;
17
import org.eclipse.jface.util.LocalSelectionTransfer;
18
import org.eclipse.jface.viewers.IStructuredSelection;
17 19
import org.eclipse.jface.viewers.StructuredSelection;
18
import org.eclipse.swt.dnd.DND;
19
import org.eclipse.swt.dnd.DropTargetEvent;
20 20
import org.eclipse.swt.dnd.TransferData;
21 21

  
22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
24
import eu.etaxonomy.cdm.model.common.TermBase;
25
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
22
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
23
import eu.etaxonomy.cdm.persistence.dto.TermDto;
26 24
import eu.etaxonomy.taxeditor.editor.definedterm.operation.MoveDefinedTermOperation;
25
import eu.etaxonomy.taxeditor.model.AbstractUtility;
27 26
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
28 27
import eu.etaxonomy.taxeditor.store.StoreUtil;
29 28
import eu.etaxonomy.taxeditor.ui.EditViewerDropAdapter;
......
49 48

  
50 49
	@Override
51 50
	public boolean performDrop(Object data) {
52

  
53
		TermBase target = (TermBase) getCurrentTarget();//can be vocab
51
	    if(editor.checkDirty()){
52
	        return false;
53
	    }
54
		AbstractTermDto target = (AbstractTermDto) getCurrentTarget();//can be vocab
54 55
		int currentLocation = getCurrentLocation();
55
		Object[] droppedTerms = (Object[]) data;
56
		Collection<DefinedTermBase> sourceTerms = new ArrayList<DefinedTermBase>(); //Arrays.asList(droppedElements)
56
		IStructuredSelection droppedTerms = (IStructuredSelection) data;
57
		Collection<TermDto> sourceTerms = new ArrayList<>(); //Arrays.asList(droppedElements)
57 58

  
58
		for (Object droppedTerm : droppedTerms) {
59
			DefinedTermBase term = (DefinedTermBase) droppedTerm;
59
		for (Object droppedTerm : droppedTerms.toList()) {
60
		    TermDto term = (TermDto) droppedTerm;
60 61
			sourceTerms.add(term);
61 62
		}
62 63

  
......
66 67
		        sourceTerms,
67 68
		        editor,
68 69
		        currentLocation);
69
		//TODO: implement execute
70
		StoreUtil.executeOperation(operation, sync);
70
		AbstractUtility.executeOperation(operation, sync);
71 71
		// select the newly moved objects
72
		editor.getViewer().setSelection(new StructuredSelection(sourceTerms.toArray(new TermBase[sourceTerms.size()])));
72
		editor.getViewer().setSelection(new StructuredSelection(sourceTerms));
73 73

  
74 74
		return true;
75 75
	}
......
77 77
	@Override
78 78
	public boolean validateDrop(Object target, int operation,
79 79
			TransferData transferType) {
80
		boolean transferDataIsSupported = TermTransfer.getInstance().isSupportedType(transferType);
81
		// maybe don't need this - they will be all TermBase anyway
82
		return target instanceof TermBase && transferDataIsSupported;
83
	}
84

  
85
	@Override
86
	public void dragOver(DropTargetEvent event) {
87
	    super.dragOver(event);
88
	    TermBase target = (TermBase) getCurrentTarget();
89
	    if(!(target instanceof OrderedTermBase)) {
90
	        // this is to only disable insert between items
91
	        event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
92
	    }
93

  
94

  
80
        return LocalSelectionTransfer.getTransfer().isSupportedType(transferType) && target instanceof AbstractTermDto;
95 81
	}
96 82

  
97 83
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermEditorE4.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.editor.definedterm.e4;
10 10

  
11
import java.util.ArrayList;
12
import java.util.List;
13

  
11 14
import javax.annotation.PostConstruct;
12 15
import javax.annotation.PreDestroy;
13 16
import javax.inject.Inject;
......
22 25
import org.eclipse.e4.ui.services.EMenuService;
23 26
import org.eclipse.e4.ui.workbench.modeling.EPartService;
24 27
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
28
import org.eclipse.jface.dialogs.MessageDialog;
29
import org.eclipse.jface.util.LocalSelectionTransfer;
25 30
import org.eclipse.jface.viewers.ISelectionChangedListener;
26 31
import org.eclipse.jface.viewers.StructuredSelection;
27 32
import org.eclipse.jface.viewers.TreeViewer;
......
35 40

  
36 41
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
37 42
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
38
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
39
import eu.etaxonomy.cdm.model.common.CdmBase;
43
import eu.etaxonomy.cdm.api.service.ITermService;
40 44
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
41 45
import eu.etaxonomy.cdm.model.common.TermVocabulary;
46
import eu.etaxonomy.cdm.persistence.dto.TermDto;
47
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
42 48
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
43 49
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter;
44
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider;
45
import eu.etaxonomy.taxeditor.editor.definedterm.TermLabelProvider;
46
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
50
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
51
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
47 52
import eu.etaxonomy.taxeditor.editor.definedterm.input.TermEditorInput;
48 53
import eu.etaxonomy.taxeditor.event.EventUtility;
49 54
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
55
import eu.etaxonomy.taxeditor.l10n.Messages;
50 56
import eu.etaxonomy.taxeditor.model.IContextListener;
51 57
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
52 58
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
......
65 71
public class DefinedTermEditorE4 implements IConversationEnabled, IDirtyMarkable, IPostOperationEnabled,
66 72
IPartContentHasDetails, IPartContentHasSupplementalData, IE4SavablePart, IContextListener {
67 73

  
68
	public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.store.openDefinedTermEditor";
74
	public static final String OPEN_COMMAND_ID = "eu.etaxonomy.taxeditor.store.openDefinedTermEditor"; //$NON-NLS-1$
69 75

  
70 76
	protected TreeViewer viewer;
71 77

  
......
85 91
    @Inject
86 92
    private MPart thisPart;
87 93

  
94
    private List<DefinedTermBase> changedTerms = new ArrayList<>();
95

  
88 96
	@Inject
89 97
	public DefinedTermEditorE4() {
90 98
	    CdmStore.getContextManager().addContextListener(this);
......
109 117
	    parent.setLayout(layout);
110 118
	    viewer = new TreeViewer(new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI));
111 119
	    viewer.getControl().setLayoutData(LayoutConstants.FILL());
112
	    viewer.setContentProvider(new TermContentProvider());
113
	    viewer.setLabelProvider(new TermLabelProvider());
114
	    viewer.setSorter(new DefinedTermSorter());
120
	    viewer.setContentProvider(new TermDtoContentProvider());
121
	    viewer.setLabelProvider(new TermDtoLabelProvider());
122
	    viewer.setComparator(new DefinedTermSorter());
115 123

  
116
	    Transfer[] transfers = new Transfer[] { TermTransfer.getInstance() };
124
	    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
117 125
	    viewer.addDragSupport(dndOperations, transfers, new DefinedTermDragListenerE4(viewer));
118 126
	    DefinedTermDropAdapterE4 dropListener = new DefinedTermDropAdapterE4(this);
119 127
	    ContextInjectionFactory.inject(dropListener, context);
......
124 132
	    viewer.addSelectionChangedListener(selectionChangedListener);
125 133

  
126 134
	    //create context menu
127
	    menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.termeditor");
135
	    menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.termeditor"); //$NON-NLS-1$
128 136

  
129 137
	}
130 138

  
131 139
	@Override
132
	public boolean postOperation(CdmBase objectAffectedByOperation) {
133
	    if(objectAffectedByOperation.isInstanceOf(DefinedTermBase.class)){
134
	        TermVocabulary vocabulary = HibernateProxyHelper.deproxy(objectAffectedByOperation, DefinedTermBase.class).getVocabulary();
135
	        viewer.refresh(vocabulary);
136
	    }
137
	    else{
138
	        viewer.refresh();
139
	    }
140

  
140
	public boolean postOperation(Object objectAffectedByOperation) {
141
	    viewer.refresh();
141 142
		if(objectAffectedByOperation != null){
142
			viewer.setSelection(new StructuredSelection(objectAffectedByOperation));
143
			StructuredSelection selection = new StructuredSelection(objectAffectedByOperation);
144
            viewer.setSelection(selection);
145
			viewer.expandToLevel(objectAffectedByOperation, 1);
143 146
		}
144
		setDirty(true);
145

  
146 147
		return true;
147 148
	}
148 149

  
......
154 155
        thisPart.setLabel(input.getName());
155 156
	}
156 157

  
158
    /**
159
     * Checks the dirty flag and, if set, prompts the user to optionally save
160
     * the editor
161
     *
162
     * @return <code>false</code> if the editor is not dirty anymore, either
163
     *         because it wasn't beforehand or because it has been saved.
164
     *         <code>true</code> otherwise
165
     */
166
	public boolean checkDirty(){
167
	    if (isDirty()){
168
	        boolean proceed = MessageDialog.openQuestion(null,
169
	                Messages.DefinedTermEditorE4_SAVE_TITLE, Messages.DefinedTermEditorE4_SAVE_MESSAGE);
170
	        if (proceed) {
171
	            save(null);
172
	            return false;
173
	        }
174
	        else{
175
	            return true;
176
	        }
177
	    }
178
	    else{
179
	        return false;
180
	    }
181
	}
182

  
157 183
	@Override
158 184
    @Persist
159 185
	public void save(IProgressMonitor monitor) {
160 186
		getConversationHolder().commit();
187
        changedTerms.forEach(term->CdmStore.getService(ITermService.class).merge(term));
188
        changedTerms.clear();
161 189
		input.merge();
162 190
		setDirty(false);
163 191
		input.initialiseVocabularies();
......
193 221

  
194 222
	@Override
195 223
	public void changed(Object element) {
224
	    if(element instanceof DefinedTermBase){
225
	        DefinedTermBase definedTermBase = (DefinedTermBase) element;
226
            TermDto termDto = new TermDto(definedTermBase.getUuid(),
227
	                definedTermBase.getRepresentations(),
228
	                null,
229
	                null,
230
	                null);
231
	        viewer.update(termDto, null);
232
	        changedTerms.add(definedTermBase);
233
	    }
234
	    else if(element instanceof TermVocabulary){
235
	        TermVocabulary vocabulary = (TermVocabulary)element;
236
	        TermVocabularyDto vocabularyDto = new TermVocabularyDto(vocabulary.getUuid(), vocabulary.getRepresentations());
237
	        viewer.update(vocabularyDto, null);
238
	    }
196 239
		setDirty(true);
197 240
		viewer.update(element, null);
198 241
	}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/CreateDefinedTermHandlerE4.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.editor.definedterm.e4.handler;
10 10

  
11
import java.util.UUID;
12

  
11 13
import javax.inject.Named;
12 14

  
13 15
import org.eclipse.core.commands.operations.IUndoContext;
......
19 21
import org.eclipse.e4.ui.services.IServiceConstants;
20 22
import org.eclipse.jface.viewers.IStructuredSelection;
21 23

  
22
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
23
import eu.etaxonomy.cdm.model.common.TermBase;
24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
24
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
25
import eu.etaxonomy.cdm.persistence.dto.TermDto;
26
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
25 27
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
26 28
import eu.etaxonomy.taxeditor.editor.definedterm.operation.CreateDefinedTermOperation;
27 29
import eu.etaxonomy.taxeditor.model.AbstractUtility;
28 30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
31
import eu.etaxonomy.taxeditor.store.AppModelId;
29 32
import eu.etaxonomy.taxeditor.store.StoreUtil;
30 33

  
31 34
/**
......
40 43
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
41 44
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MHandledMenuItem menuItem,
42 45
            UISynchronize sync) {
43

  
44 46
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
45

  
47
        if(termEditor.checkDirty()){
48
            return;
49
        }
46 50
        boolean addTermAsKindOf =
47
                menuItem.getCommand().getElementId().equals("eu.etaxonomy.taxeditor.editor.definedTerms.newKindOfTerm")?true:false;
51
                menuItem.getCommand().getElementId()
52
                .equals(AppModelId.COMMAND_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERMS_NEWKINDOFTERM)?true:false;
48 53

  
49 54
        String label = menuItem.getLocalizedLabel();
50 55
        IUndoContext undoContext = StoreUtil.getUndoContext();
51 56

  
57
        AbstractTermDto parent = (AbstractTermDto) selection.getFirstElement();
52 58
        AbstractPostOperation operation =
53 59
                new CreateDefinedTermOperation(label,
54 60
                        undoContext,
55
                        (TermBase) selection.getFirstElement(),
61
                        parent,
56 62
                        termEditor.getDefinedTermEditorInput(),
57 63
                        termEditor, addTermAsKindOf);
58 64
        AbstractUtility.executeOperation(operation, sync);
......
66 72
        Object firstElement = selection.getFirstElement();
67 73
        canExecute = selection.size()==1
68 74
                &&
69
                (firstElement instanceof DefinedTermBase
70
                        || firstElement instanceof TermVocabulary);
71
        TermVocabulary vocabulary = null;
75
                (firstElement instanceof TermDto
76
                        || firstElement instanceof TermVocabularyDto);
77
        UUID vocabularyUuid = null;
72 78

  
73
        if(firstElement instanceof DefinedTermBase){
74
            vocabulary = ((DefinedTermBase) firstElement).getVocabulary();
75
        }else if(firstElement instanceof TermVocabulary){
76
            vocabulary = (TermVocabulary) firstElement;
79
        if(firstElement instanceof TermDto){
80
            vocabularyUuid = ((TermDto) firstElement).getVocabularyUuid();
81
        }else if(firstElement instanceof TermVocabularyDto
82
                && !menuItem.getCommand().getElementId()
83
                .equals(AppModelId.COMMAND_EU_ETAXONOMY_TAXEDITOR_EDITOR_DEFINEDTERMS_NEWKINDOFTERM)){
84
            vocabularyUuid = ((TermVocabularyDto) firstElement).getUuid();
77 85
        }
78
        canExecute &= vocabulary!=null;
86
        canExecute &= vocabularyUuid!=null;
79 87
        menuItem.setVisible(canExecute);
80 88
        return canExecute;
81 89
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/CreateTermVocabularyHandlerE4.java
35 35
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
36 36
            MMenuItem menuItem,
37 37
            UISynchronize sync) {
38

  
39 38
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
40

  
39
        if(termEditor.checkDirty()){
40
            return;
41
        }
41 42
        String label = menuItem.getLocalizedLabel();
42 43
        IUndoContext undoContext = StoreUtil.getUndoContext();
43 44

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/handler/DeleteTermBaseHandlerE4.java
8 8
 */
9 9
package eu.etaxonomy.taxeditor.editor.definedterm.e4.handler;
10 10

  
11
import java.util.UUID;
12

  
11 13
import javax.inject.Named;
12 14

  
13 15
import org.eclipse.core.commands.operations.IUndoContext;
......
18 20
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19 21
import org.eclipse.e4.ui.model.application.ui.menu.MMenuItem;
20 22
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.jface.dialogs.MessageDialog;
22 23
import org.eclipse.jface.viewers.IStructuredSelection;
23 24

  
24
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
25
import eu.etaxonomy.cdm.model.common.TermBase;
26
import eu.etaxonomy.cdm.model.common.TermVocabulary;
25
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
26
import eu.etaxonomy.cdm.persistence.dto.TermDto;
27
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
27 28
import eu.etaxonomy.taxeditor.editor.definedterm.e4.DefinedTermEditorE4;
28 29
import eu.etaxonomy.taxeditor.editor.definedterm.operation.DeleteTermBaseOperation;
29 30
import eu.etaxonomy.taxeditor.model.AbstractUtility;
......
42 43
    public void execute(@Named(IServiceConstants.ACTIVE_PART) MPart activePart,
43 44
            @Named(IServiceConstants.ACTIVE_SELECTION) IStructuredSelection selection, MMenuItem menuItem,
44 45
            UISynchronize sync) {
45

  
46 46
        DefinedTermEditorE4 termEditor = (DefinedTermEditorE4) activePart.getObject();
47

  
48
        if (termEditor.isDirty()){
49
            boolean proceed = MessageDialog.openQuestion(null,
50
                    "Save changes", "You have made changes that must be saved before this query can be executed. Would you like to proceed?");
51
            if (proceed) {
52
                termEditor.save(null);
53
            } else {
54
                return;
55
            }
47
        if(termEditor.checkDirty()){
48
            return;
56 49
        }
57 50
        String label = menuItem.getLocalizedLabel();
58 51
        IUndoContext undoContext = StoreUtil.getUndoContext();
59 52
        AbstractPostOperation operation =
60 53
                new DeleteTermBaseOperation(label,
61 54
                        undoContext,
62
                        (TermBase) selection.getFirstElement(),
55
                        (AbstractTermDto) selection.getFirstElement(),
63 56
                        termEditor.getDefinedTermEditorInput(),
64 57
                        termEditor);
65 58
        AbstractUtility.executeOperation(operation, sync);
......
71 64
        boolean canExecute = false;
72 65
        Object firstElement = selection.getFirstElement();
73 66
        canExecute = selection.size()==1
74
                &&
75
                (firstElement instanceof DefinedTermBase
76
                        || firstElement instanceof TermVocabulary);
77
        TermVocabulary vocabulary = null;
78
        if(firstElement instanceof DefinedTermBase){
79
            vocabulary = ((DefinedTermBase) firstElement).getVocabulary();
80
        }else if(firstElement instanceof TermVocabulary){
81
            vocabulary = (TermVocabulary) firstElement;
67
                && (firstElement instanceof AbstractTermDto);
68
        UUID vocabularyUuid = null;
69
        if(firstElement instanceof TermDto){
70
            vocabularyUuid = ((TermDto) firstElement).getVocabularyUuid();
71
        }else if(firstElement instanceof TermVocabularyDto){
72
            vocabularyUuid = ((TermVocabularyDto) firstElement).getUuid();
82 73
        }
83
        canExecute &= vocabulary!=null;
74
        canExecute &= vocabularyUuid!=null;
84 75
        menuItem.setVisible(canExecute);
85 76
        return canExecute;
86 77
    }
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/input/TermEditorInput.java
16 16

  
17 17
import eu.etaxonomy.cdm.api.service.IVocabularyService;
18 18
import eu.etaxonomy.cdm.model.common.DefinedTerm;
19
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
20 19
import eu.etaxonomy.cdm.model.common.TermType;
21 20
import eu.etaxonomy.cdm.model.common.TermVocabulary;
22 21
import eu.etaxonomy.cdm.model.description.Feature;
23 22
import eu.etaxonomy.cdm.model.description.FeatureTree;
23
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
24 24
import eu.etaxonomy.taxeditor.store.CdmStore;
25 25
import eu.etaxonomy.taxeditor.store.TermStore;
26 26

  
......
34 34
public class TermEditorInput extends AbstractDefinedTermEditorInput<DefinedTerm> {
35 35

  
36 36
	private TermType termType;
37
	private Set<TermVocabulary<DefinedTermBase>> vocabularies;
37
	private Set<TermVocabularyDto> vocabularies;
38 38

  
39 39
	// FIXME: the default feature should be move to CdmApplicationState
40 40
	//        where it is a singleton instance variable
......
46 46

  
47 47
	public TermEditorInput(TermType termType) {
48 48
		this.termType = termType;
49
		vocabularies = new HashSet<TermVocabulary<DefinedTermBase>>();
49
		vocabularies = new HashSet<TermVocabularyDto>();
50 50
		initialiseVocabularies();
51 51
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)