Project

General

Profile

« Previous | Next » 

Revision b599010f

Added by Patrick Plitzner about 5 years ago

ref #7887 Avoid moving a term onto itself or its children

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/e4/DefinedTermDropAdapterE4.java
36 36
 */
37 37
public class DefinedTermDropAdapterE4 extends EditViewerDropAdapter {
38 38

  
39
    private static final String MOVE_FAILED = "Move failed";
40

  
41
    private static final String MOVE_FAILED_MESSAGE = "Cannot move term onto itself or its children";
42

  
39 43
	private final DefinedTermEditorE4 editor;
40 44

  
41 45
	@Inject
......
61 65
		    TermDto term = (TermDto) droppedTerm;
62 66
			sourceTerms.add(term);
63 67
		}
64
        // cannot drop a feature node onto itself
68
        // cannot drop a term onto itself or at its own children
65 69
        for (Object droppedObject : sourceTerms) {
66 70
            if(droppedObject==null){
67
                MessagingUtils.warningDialog("Move failed", this.getClass(),
71
                MessagingUtils.warningDialog(MOVE_FAILED, this.getClass(),
68 72
                        "Moving the feature node failed. Try saving before.");
69 73
                return false;
70 74
            }
71 75
            if (droppedObject.equals(target)) {
76
                MessagingUtils.warningDialog(MOVE_FAILED, this.getClass(),
77
                        MOVE_FAILED_MESSAGE);
72 78
                return false;
73 79
            }
80
            // check if target is a child of the dropped term
81
            if(target instanceof TermDto){
82
                TermDto parentTerm = (TermDto)target;
83
                TermDto partOfDto = parentTerm.getPartOfDto();
84
                while(partOfDto!=null){
85
                    if(partOfDto.equals(droppedObject)){
86
                        MessagingUtils.warningDialog(MOVE_FAILED, this.getClass(),
87
                                MOVE_FAILED_MESSAGE);
88
                        return false;
89
                    }
90
                    partOfDto = partOfDto.getPartOfDto();
91
                }
92
                TermDto kindOfDto = parentTerm.getKindOfDto();
93
                while(kindOfDto!=null){
94
                    if(kindOfDto.equals(droppedObject)){
95
                        MessagingUtils.warningDialog(MOVE_FAILED, this.getClass(),
96
                                MOVE_FAILED_MESSAGE);
97
                        return false;
98
                    }
99
                    kindOfDto = kindOfDto.getKindOfDto();
100
                }
101
            }
74 102
        }
75 103
		AbstractPostOperation operation = new MoveDefinedTermOperation("Move Descriptions",
76 104
		        StoreUtil.getUndoContext(),

Also available in: Unified diff