Project

General

Profile

Revision 2fe68f38

ID2fe68f382e1e7da510d531d414f96a8a4393bbb2
Parent 1f1ad1bc
Child de69ffd8

Added by Patrick Plitzner over 1 year ago

ref #6794 Adapt taxeditor to model changes (feature tree/node generics)

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetComposite.java
23 23
import org.eclipse.swt.widgets.Tree;
24 24

  
25 25
import eu.etaxonomy.cdm.model.common.TermType;
26
import eu.etaxonomy.cdm.model.description.Character;
26 27
import eu.etaxonomy.cdm.model.description.FeatureTree;
27 28
import eu.etaxonomy.cdm.model.name.Rank;
28 29
import eu.etaxonomy.cdm.persistence.dto.TermDto;
......
43 44
    private Text txtDescriptiveDataSet;
44 45
    private TermUuidComboViewer comboRankMin;
45 46
    private TermUuidComboViewer comboRankMax;
46
    private FeatureTreeEditorComposite featureTreeEditorComposite;
47
    private FeatureTreeEditorComposite<Character> featureTreeEditorComposite;
47 48
    private TreeViewer taxonNodeTree;
48 49
    private List<TermDto> areas = new ArrayList<>();
49 50
    private Text textAreaText;
......
134 135
        btnChooseArea = new Button(composite, SWT.NONE);
135 136
        btnChooseArea.setImage(ImageResources.getImage(ImageResources.BROWSE_ICON));
136 137

  
137
        featureTreeEditorComposite = new FeatureTreeEditorComposite(this, SWT.NONE);
138
        featureTreeEditorComposite = new FeatureTreeEditorComposite<Character>(this, SWT.NONE);
138 139
        featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
139 140
    }
140 141

  
......
160 161
        comboRankMax.setElement(max);
161 162
    }
162 163

  
163
    public FeatureTreeEditorComposite getFeatureTreeEditorComposite() {
164
    public FeatureTreeEditorComposite<Character> getFeatureTreeEditorComposite() {
164 165
        return featureTreeEditorComposite;
165 166
    }
166 167

  
167
    public FeatureTree getCharacters(){
168
    public FeatureTree<Character> getCharacters(){
168 169
        return featureTreeEditorComposite.getFeatureTree();
169 170
    }
170
    public void setCharacters(FeatureTree characters) {
171
    public void setCharacters(FeatureTree<Character> characters) {
171 172
        featureTreeEditorComposite.setSelectedTree(characters);
172 173
    }
173 174

  
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/DescriptiveDataSetEditor.java
59 59
import eu.etaxonomy.cdm.api.service.ITermService;
60 60
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
61 61
import eu.etaxonomy.cdm.model.common.TermType;
62
import eu.etaxonomy.cdm.model.description.Character;
62 63
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
63 64
import eu.etaxonomy.cdm.model.description.FeatureTree;
64 65
import eu.etaxonomy.cdm.model.location.NamedArea;
......
288 289
                }
289 290
            }
290 291
        }
291
        FeatureTree characters = composite.getCharacters();
292
        FeatureTree<Character> characters = composite.getCharacters();
292 293
        if(characters!=null){
293 294
            //save characters because they can be modified in this editor
294 295
            characters.getDistinctFeatures().forEach(character->CdmStore.getService(ITermService.class).merge(character,true));
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/character/CharacterEditor.java
58 58
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
59 59
import eu.etaxonomy.cdm.api.service.ITermService;
60 60
import eu.etaxonomy.cdm.api.service.IVocabularyService;
61
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
61 62
import eu.etaxonomy.cdm.model.common.Representation;
62 63
import eu.etaxonomy.cdm.model.common.TermType;
63 64
import eu.etaxonomy.cdm.model.common.TermVocabulary;
......
95 96
public class CharacterEditor implements IFeatureTreeEditor,IConversationEnabled, ISelectionChangedListener,
96 97
        ModifyListener, IE4ViewerPart, IPartContentHasDetails, IPartContentHasSupplementalData, IDirtyMarkable {
97 98

  
98
    private FeatureTreeEditorComposite characterTreeEditorComposite;
99
    private FeatureTreeEditorComposite propertiesTreeEditorComposite;
100
    private FeatureTreeEditorComposite structuresTreeEditorComposite;
99
    private FeatureTreeEditorComposite<Character> characterTreeEditorComposite;
100
    private FeatureTreeEditorComposite<DefinedTermBase> propertiesTreeEditorComposite;
101
    private FeatureTreeEditorComposite<DefinedTermBase> structuresTreeEditorComposite;
101 102
    private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
102 103

  
103 104
    @Inject
......
228 229
                Collection<Character> characters = createCharacters((TreeSelection)structureTreeSelection, (TreeSelection)propertyTreeSelection);
229 230
                for (Character character : characters) {
230 231
                    //add new Character to feature tree
231
                    FeatureNode parent = ((FeatureTree) characterTreeEditorComposite.getViewer().getInput()).getRoot();
232
                    FeatureNode<Character> parent = ((FeatureTree<Character>) characterTreeEditorComposite.getViewer().getInput()).getRoot();
232 233
                    vocabulary.addTerm(character);
233 234
                    CdmStore.getService(IFeatureNodeService.class).createChildFeatureNode(parent, character);
234 235
                }
......
252 253

  
253 254
    }
254 255

  
255
    private FeatureTreeEditorComposite addFeatureTreeEditor(Composite composite_3) {
256
        FeatureTreeEditorComposite featureTreeEditorComposite = new FeatureTreeEditorComposite(composite_3, SWT.NONE);
256
    private <T extends DefinedTermBase> FeatureTreeEditorComposite<T> addFeatureTreeEditor(Composite composite_3) {
257
        FeatureTreeEditorComposite<T> featureTreeEditorComposite = new FeatureTreeEditorComposite<>(composite_3, SWT.NONE);
257 258
        featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
258 259
        return featureTreeEditorComposite;
259 260
    }
......
292 293
    public static Collection<Character> createCharacters(TreeSelection structureTreeSelection, TreeSelection propertyTreeSelection){
293 294
        Set<Character> characters = new HashSet<>();
294 295
        //get selected structures and properties
295
        Iterator<FeatureNode> structureIterator = structureTreeSelection.iterator();
296
        Iterator<FeatureNode<DefinedTermBase>> structureIterator = structureTreeSelection.iterator();
296 297

  
297 298
        //create all combinations of structures and properties
298 299
        while(structureIterator.hasNext()){
299
            FeatureNode structureNode = structureIterator.next();
300
            Iterator<FeatureNode> propertiesIterator = propertyTreeSelection.iterator();
300
            FeatureNode<DefinedTermBase> structureNode = structureIterator.next();
301
            Iterator<FeatureNode<DefinedTermBase>> propertiesIterator = propertyTreeSelection.iterator();
301 302
            while(propertiesIterator.hasNext()){
302
                FeatureNode propertyNode = propertiesIterator.next();
303
                FeatureNode<DefinedTermBase> propertyNode = propertiesIterator.next();
303 304
                Representation structureRepresentation = structureNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
304 305
                Representation propertyRepresentation = propertyNode.getTerm().getRepresentation(PreferencesUtil.getGlobalLanguage());
305 306
                String label = null;
......
328 329
        // commit the conversation and start a new transaction immediately
329 330
        conversation.commit(true);
330 331

  
331
        FeatureTree featureTree = characterTreeEditorComposite.getFeatureTree();
332
        FeatureTree<Character> featureTree = characterTreeEditorComposite.getFeatureTree();
332 333
        if(featureTree!=null){
333 334
            //save characters because they can be modified in this editor
334 335
            featureTree.getDistinctFeatures().forEach(character->CdmStore.getService(ITermService.class).merge(character,true));
......
382 383
    }
383 384

  
384 385
    @Override
385
    public List<FeatureTree> getRootEntities() {
386
        List<FeatureTree> root = new ArrayList<>();
386
    public List<FeatureTree<Character>> getRootEntities() {
387
        List<FeatureTree<Character>> root = new ArrayList<>();
387 388
        root.add(characterTreeEditorComposite.getFeatureTree());
388 389
        return root;
389 390
    }
......
423 424
        return (IStructuredSelection) characterTreeEditorComposite.getViewer().getSelection();
424 425
    }
425 426

  
426
    public FeatureTree getCharacterTree(){
427
    public FeatureTree<Character> getCharacterTree(){
427 428
        return characterTreeEditorComposite.getFeatureTree();
428 429
    }
429 430

  
......
435 436
    }
436 437

  
437 438
    private class FeatureTreeChooserListener extends SelectionAdapter{
438
        private FeatureTreeEditorComposite featureTreeEditorComposite;
439
        private FeatureTreeEditorComposite<?> featureTreeEditorComposite;
439 440
        private TermType termType;
440 441

  
441
        public FeatureTreeChooserListener(FeatureTreeEditorComposite featureTreeEditorComposite, TermType termType) {
442
        public FeatureTreeChooserListener(FeatureTreeEditorComposite<?> featureTreeEditorComposite, TermType termType) {
442 443
            super();
443 444
            this.featureTreeEditorComposite = featureTreeEditorComposite;
444 445
            this.termType = termType;
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/descriptiveDataSet/matrix/CharacterMatrix.java
98 98
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
99 99
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
100 100
import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor;
101
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
102
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
103 101
import eu.etaxonomy.cdm.model.description.Character;
104 102
import eu.etaxonomy.cdm.model.description.DescriptionBase;
105 103
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
......
271 269
        natTable.doCommand(new ClientAreaResizeCommand(natTable));
272 270
    }
273 271

  
274
    private List<Character> initCharacterList(FeatureNode node){
272
    private List<Character> initCharacterList(FeatureNode<Character> node){
275 273
        List<Character> characters = new ArrayList<>();
276 274
        node.getChildNodes().forEach(childNode->
277 275
                {
278
                    DefinedTermBase term = childNode.getTerm();
279
                    // FIXME #8146 this is currently checked via the termType of the tree
280
                    // in the init() method. This may be solved by adding generics to FeatureNode
281
                    // so that getTerm is typified. This would make this check obsolete
282
                    if(term.isInstanceOf(Character.class)){
283
                        characters.add(HibernateProxyHelper.deproxy(term, Character.class));
284
                    }
276
                    characters.add(childNode.getTerm());
285 277
                    characters.addAll(initCharacterList(childNode));
286 278
                });
287 279
        return characters;
......
290 282
    public void initDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
291 283
        this.descriptiveDataSet = descriptiveDataSet;
292 284
        //get features/columns stored in descriptive data set
293
        FeatureTree tree = descriptiveDataSet.getDescriptiveSystem();
285
        FeatureTree<Character> tree = descriptiveDataSet.getDescriptiveSystem();
294 286
        characters = initCharacterList(tree.getRoot());
295 287

  
296 288
        //init state data for categorical features
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/descriptive/e4/handler/DynamicFeatureMenuE4.java
60 60
        Object selectedElement = selection.getFirstElement();
61 61

  
62 62
        if (selectedElement instanceof DescriptionBase<?>) {
63
            FeatureTree featureTree = getFeatureTree((DescriptionBase<?>) selectedElement);
63
            FeatureTree<?> featureTree = getFeatureTree((DescriptionBase<?>) selectedElement);
64 64

  
65
            for (FeatureNode childNode : featureTree.getRootChildren()) {
65
            for (FeatureNode<?> childNode : featureTree.getRootChildren()) {
66 66
                createMenuItem(menu, childNode.getTerm(), globalLanguage);
67 67
            }
68 68
        } else if (selectedElement instanceof FeatureNodeContainer) {
69
            FeatureNode featureNode = ((FeatureNodeContainer) selectedElement)
69
            FeatureNode<?> featureNode = ((FeatureNodeContainer) selectedElement)
70 70
                    .getFeatureNode();
71 71

  
72 72
            // add the feature to the menu
73 73
            createMenuItem(menu, featureNode.getTerm(), globalLanguage);
74 74

  
75 75
            // add possible children to the menu
76
            for (FeatureNode childNode : featureNode.getChildNodes()) {
76
            for (FeatureNode<?> childNode : featureNode.getChildNodes()) {
77 77
                createMenuItem(menu, childNode.getTerm(), globalLanguage);
78 78
            }
79 79
        } else if (selectedElement instanceof DescriptionElementBase) {
......
122 122
	 * @param description
123 123
	 * @return
124 124
	 */
125
	private FeatureTree getFeatureTree(DescriptionBase description) {
126
		FeatureTree featureTree = null;
125
	private FeatureTree<?> getFeatureTree(DescriptionBase description) {
126
		FeatureTree<?> featureTree = null;
127 127

  
128 128
		// TODO change this to the feature tree associated with this taxon
129 129
		// description
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditorComposite.java
28 28
import org.eclipse.swt.widgets.Text;
29 29
import org.eclipse.swt.widgets.Tree;
30 30

  
31
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
31 32
import eu.etaxonomy.cdm.model.common.TermType;
32 33
import eu.etaxonomy.cdm.model.description.FeatureTree;
33 34
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer;
......
44 45
 * @since Jun 19, 2017
45 46
 *
46 47
 */
47
public class FeatureTreeEditorComposite extends Composite{
48
public class FeatureTreeEditorComposite <T extends DefinedTermBase> extends Composite{
48 49

  
49
    private FeatureTree featureTree;
50
    private FeatureTree<T> featureTree;
50 51

  
51 52
    private Label label_title;
52 53
    private Text text_title;
......
180 181
            btnOpenFeatureTree.addSelectionListener(new SelectionAdapter(){
181 182
                @Override
182 183
                public void widgetSelected(SelectionEvent e) {
183
                    FeatureTree tree = FeatureTreeSelectionDialog.select(getDisplay().getActiveShell(),
184
                    FeatureTree<T> tree = FeatureTreeSelectionDialog.select(getDisplay().getActiveShell(),
184 185
                            null, termType);
185 186
                    if(tree!=null){
186 187
                        setSelectedTree(tree);
......
193 194
        }
194 195
    }
195 196

  
196
    public void setSelectedTree(FeatureTree featureTree) {
197
    public void setSelectedTree(FeatureTree<T> featureTree) {
197 198
        this.featureTree = featureTree;
198 199

  
199 200
        viewer.setInput(featureTree);
......
208 209
        }
209 210
    }
210 211

  
211
    public FeatureTree getFeatureTree() {
212
    public FeatureTree<T> getFeatureTree() {
212 213
        return featureTree;
213 214
    }
214 215

  
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/FeatureNodeContainer.java
41 41

  
42 42

  
43 43

  
44
	private FeatureNode featureNode;
44
	private FeatureNode<Feature> featureNode;
45 45
	private List<FeatureNodeContainer> children = new ArrayList<FeatureNodeContainer>();
46 46
	private List<DescriptionElementBase> descriptionElements = new ArrayList<DescriptionElementBase>();
47 47

  
......
64 64
	 * @param description
65 65
	 * @return
66 66
	 */
67
	protected void findLeaves(FeatureNode featureNode) {
67
	protected void findLeaves(FeatureNode<Feature> featureNode) {
68 68
		if(featureNode.isLeaf()){
69 69
			buildLeaf(featureNode);
70 70
		}else{
71
			for(FeatureNode childNode : featureNode.getChildNodes()){
71
			for(FeatureNode<Feature> childNode : featureNode.getChildNodes()){
72 72
				findLeaves(childNode);
73 73
			}
74 74
		}
......
80 80
	 * @param description
81 81
	 * @return
82 82
	 */
83
	private void buildLeaf(FeatureNode featureNode){
84
		if(featureNode.getFeature() == null){
83
	private void buildLeaf(FeatureNode<Feature> featureNode){
84
		if(featureNode.getTerm() == null){
85 85
			throw new IllegalArgumentException("The given feature node does not have a feature.");
86 86
		}
87 87

  
88
		Feature feature = (Feature) HibernateProxyHelper.deproxy(featureNode.getFeature());
88
		Feature feature = HibernateProxyHelper.deproxy(featureNode.getTerm());
89 89

  
90 90
		// get feature node container for the given feature
91 91
		FeatureNodeContainer container = containerTree.getFeatureNodeContainer(feature);
......
140 140
	 */
141 141
	private void buildBranch(){
142 142
		if(getParent() == null){
143
			FeatureNode parentFeatureNode = getFeatureNode().getParent();
143
			FeatureNode<Feature> parentFeatureNode = getFeatureNode().getParent();
144 144

  
145 145
			if(parentFeatureNode.isRoot()){
146 146
				containerTree.getRoot().addChild(this);
......
277 277
	 *
278 278
	 * @param featureNode a {@link eu.etaxonomy.cdm.model.description.FeatureNode} object.
279 279
	 */
280
	public void setFeatureNode(FeatureNode featureNode) {
280
	public void setFeatureNode(FeatureNode<Feature> featureNode) {
281 281
		this.featureNode = featureNode;
282 282
	}
283 283

  
......
286 286
	 *
287 287
	 * @return a {@link eu.etaxonomy.cdm.model.description.FeatureNode} object.
288 288
	 */
289
	public FeatureNode getFeatureNode() {
289
	public FeatureNode<Feature> getFeatureNode() {
290 290
		return featureNode;
291 291
	}
292 292

  
......
297 297
	 */
298 298
	public Feature getFeature(){
299 299
		if(featureNode != null){
300
			return featureNode.getFeature();
300
			return featureNode.getTerm();
301 301
		}
302 302
		return null;
303 303
	}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)