Project

General

Profile

Revision 24b8f2f1

ID24b8f2f1ab3aa3fc2ab32e0b883bba6a6878973c
Parent 19c6a52f
Child 860316c8

Added by Patrick Plitzner about 3 years ago

ref #6595 migrate drag and drop functionality

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/TaxonNameEditorE4.java
34 34
import org.eclipse.jface.viewers.ISelection;
35 35
import org.eclipse.jface.viewers.ISelectionProvider;
36 36
import org.eclipse.jface.viewers.StructuredSelection;
37
import org.eclipse.swt.dnd.DND;
38
import org.eclipse.swt.dnd.DropTarget;
39
import org.eclipse.swt.dnd.Transfer;
37 40
import org.eclipse.swt.graphics.Color;
38 41
import org.eclipse.swt.widgets.Composite;
39 42
import org.eclipse.ui.ISelectionListener;
......
56 59
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
57 60
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
58 61
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
62
import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
59 63
import eu.etaxonomy.taxeditor.editor.ISecuredEditor;
60 64
import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
61 65
import eu.etaxonomy.taxeditor.editor.e4.TaxonEditorInputE4;
......
67 71
import eu.etaxonomy.taxeditor.editor.name.e4.container.ContainerFactoryE4;
68 72
import eu.etaxonomy.taxeditor.editor.name.e4.container.HomotypicalSynonymGroupE4;
69 73
import eu.etaxonomy.taxeditor.editor.name.e4.container.MisappliedGroupE4;
74
import eu.etaxonomy.taxeditor.editor.name.e4.dnd.NameEditorDropTargetListenerE4;
70 75
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
71 76
import eu.etaxonomy.taxeditor.model.AbstractUtility;
72 77
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
......
90 95
 */
91 96
public class TaxonNameEditorE4 implements IConversationEnabled, IDirtyMarkable, IPartContentHasDetails,
92 97
        IPartContentHasSupplementalData, IPartContentHasMedia, IPartContentHasFactualData, IPartChangeListener,
93
        ISelectionListener, ISecuredEditor, IPostOperationEnabled, IE4SavablePart, ITaxonEditor {
98
        ISelectionListener, ISecuredEditor, IPostOperationEnabled, IE4SavablePart, ITaxonEditor, IDropTargetableE4 {
94 99

  
95 100
	private Taxon taxon;
96 101

  
......
107 112
	private List<HomotypicalSynonymGroupE4> heterotypicSynonymGroups = new ArrayList<>();
108 113
	private MisappliedGroupE4 misappliedGroup;
109 114

  
110
	//FIXME E4 migrate dnd
111
//	private DropTarget target;
115
	private DropTarget target;
112 116

  
113 117
	private TaxonBase objectAffectedByLastOperation;
114 118

  
......
393 397

  
394 398
        setFocus();
395 399

  
400
        createDragSupport();
401

  
396 402
        setPartName();
397 403
	}
398 404

  
399
	//FIXME E4 migrate drag support
400
//   private void createDragSupport() {
401
//       // Listen for names being dragged outside of existing homotypic groups -
402
//       // user wants to create a new group
403
//       Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() };
404
//       int operations = DND.DROP_MOVE;
405
//       if (target == null) {
406
//           target = new DropTarget(parent, operations);
407
//           target.setTransfer(types);
408
//           target.addDropListener(new NameEditorDropTargetListener(this));
409
//       }
405
   private void createDragSupport() {
406
       // Listen for names being dragged outside of existing homotypic groups -
407
       // user wants to create a new group
408
       Transfer[] types = new Transfer[] { CdmDataTransfer.getInstance() };
409
       int operations = DND.DROP_MOVE;
410
       if (target == null) {
411
           target = new DropTarget(parent, operations);
412
           target.setTransfer(types);
413
           target.addDropListener(new NameEditorDropTargetListenerE4(this));
414
       }
415
   }
410 416

  
411 417
	public AcceptedNameContainerE4 getAcceptedNameContainer() {
412 418
		return getAcceptedGroup().getAcceptedNameContainer();
......
504 510
				: getAcceptedNameContainer();
505 511
	}
506 512

  
507
	//FIXME E4 migrate drag n drop
508
//    @Override
509
//    public void dragEntered() {
510
//        // TODO change this
511
//        getControl().setBackground(
512
//                AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER));
513
//    }
514
//
515
//    @Override
516
//    public void dragLeft() {
517
//        getControl().setBackground(
518
//                AbstractUtility.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
519
//    }
513
    @Override
514
    public void dragEntered() {
515
        // TODO change this
516
        getControl().setBackground(
517
                AbstractUtility.getColor(Resources.COLOR_DRAG_ENTER));
518
    }
519

  
520
    @Override
521
    public void dragLeft() {
522
        getControl().setBackground(
523
                AbstractUtility.getColor(Resources.COLOR_COMPOSITE_BACKGROUND));
524
    }
520 525

  
521 526

  
522 527
	public void setMisapplicationsGroup(MisappliedGroupE4 misappliedGroup) {
......
652 657
        return undoContext;
653 658
    }
654 659

  
660
    @Override
655 661
    public Composite getControl(){
656 662
        return managedForm.getForm().getBody();
657 663
    }
......
677 683
        return input;
678 684
    }
679 685

  
686
    /**
687
     * {@inheritDoc}
688
     */
689
    @Override
690
    public TaxonNameEditorE4 getEditor() {
691
        return this;
692
    }
693

  
680 694
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/container/AbstractGroupedContainerE4.java
15 15

  
16 16
import org.apache.commons.lang.StringUtils;
17 17
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
19 18
import org.eclipse.jface.dialogs.Dialog;
20 19
import org.eclipse.jface.text.IDocument;
21 20
import org.eclipse.jface.text.Position;
......
60 59
import eu.etaxonomy.taxeditor.editor.name.container.LineBreakListener;
61 60
import eu.etaxonomy.taxeditor.editor.name.container.LineWrapSupport;
62 61
import eu.etaxonomy.taxeditor.editor.name.container.NameViewer;
62
import eu.etaxonomy.taxeditor.editor.name.dnd.NameEditorDragSourceEffect;
63 63
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
64
import eu.etaxonomy.taxeditor.editor.name.e4.dnd.NameEditorDragListenerE4;
64 65
import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInNewGroupOperation;
65 66
import eu.etaxonomy.taxeditor.model.AbstractUtility;
66 67
import eu.etaxonomy.taxeditor.model.IElementHasDetails;
......
682 683
						operations);
683 684
				dragSource.setTransfer(types);
684 685

  
685
				//FIXME E4 migrate dnd
686
//				dragSource.addDragListener(new NameEditorDragListener(this));
687
//				dragSource.setDragSourceEffect(new NameEditorDragSourceEffect(
688
//						control));
686
				dragSource.addDragListener(new NameEditorDragListenerE4(this));
687
				dragSource.setDragSourceEffect(new NameEditorDragSourceEffect(
688
						control));
689 689
			}
690 690
		}
691 691
	}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDragListenerE4.java
1
/**
2
 *
3
 */
4
package eu.etaxonomy.taxeditor.editor.name.e4.dnd;
5

  
6
import org.eclipse.swt.dnd.DND;
7
import org.eclipse.swt.dnd.DragSourceAdapter;
8
import org.eclipse.swt.dnd.DragSourceEvent;
9
import org.eclipse.ui.forms.ManagedForm;
10

  
11
import eu.etaxonomy.cdm.model.common.ICdmBase;
12
import eu.etaxonomy.taxeditor.editor.CdmDataTransfer;
13
import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractGroupedContainerE4;
14

  
15
/**
16
 *
17
 * @author pplitzner
18
 * @date 04.09.2017
19
 *
20
 */
21
public class NameEditorDragListenerE4 extends DragSourceAdapter {
22

  
23
	private AbstractGroupedContainerE4 container;
24

  
25
	public NameEditorDragListenerE4(AbstractGroupedContainerE4 container){
26
		this.container = container;
27
	}
28

  
29
	/** {@inheritDoc} */
30
	@Override
31
    public void dragFinished(DragSourceEvent event) {
32
		if(!event.doit) {
33
            return;
34
        }
35
		if(event.detail == DND.DROP_MOVE){
36
			ManagedForm managedForm = container.getGroup().getEditor().getManagedForm();
37
			container.getGroup().remove(container);
38
			managedForm.reflow(true);
39
		}
40

  
41
	};
42

  
43
	/** {@inheritDoc} */
44
	@Override
45
	public void dragSetData(DragSourceEvent event) {
46
		ICdmBase[] cdmBaseObjects = new ICdmBase[]{container.getData()};
47
		if(CdmDataTransfer.getInstance().isSupportedType(event.dataType)){
48
			event.data = cdmBaseObjects;
49
		}
50
	}
51

  
52
	/** {@inheritDoc} */
53
	@Override
54
	public void dragStart(DragSourceEvent event) {
55
		event.doit = container.getData() != null;
56
	}
57
}
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/e4/dnd/NameEditorDropTargetListenerE4.java
10 10

  
11 11
import eu.etaxonomy.cdm.model.common.ICdmBase;
12 12
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
13
import eu.etaxonomy.cdm.model.taxon.Synonym;
14
import eu.etaxonomy.cdm.model.taxon.Taxon;
13 15
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
14
import eu.etaxonomy.taxeditor.editor.EditorUtil;
16
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
15 17
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
16
import eu.etaxonomy.taxeditor.editor.name.TaxonNameEditor;
17
import eu.etaxonomy.taxeditor.editor.name.container.AbstractHomotypicalGroupContainer;
18 18
import eu.etaxonomy.taxeditor.editor.name.e4.IDropTargetableE4;
19 19
import eu.etaxonomy.taxeditor.editor.name.e4.TaxonNameEditorE4;
20
import eu.etaxonomy.taxeditor.editor.name.e4.container.AbstractHomotypicalGroupContainerE4;
21
import eu.etaxonomy.taxeditor.editor.name.e4.container.MisappliedGroupE4;
22
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptRelationshipTypeOperation;
23
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation;
24
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation;
25
import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToMisapplicationOperation;
26
import eu.etaxonomy.taxeditor.editor.name.operation.MoveSynonymToAnotherAcceptedTaxonOperation;
27
import eu.etaxonomy.taxeditor.event.EventUtility;
20 28
import eu.etaxonomy.taxeditor.model.AbstractUtility;
21 29
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22 30
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
......
72 80
			AbstractUtility.executeOperation(operation);
73 81
		}
74 82
		target.getEditor().getConversationHolder().commit();
75
		if (!target.equals(EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor())){
76
			((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).redraw();
77
			((TaxonNameEditor)EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor()).getConversationHolder().commit();
83
		if (!target.equals(EventUtility.getEditor())){
84
			((TaxonNameEditorE4)EventUtility.getEditor()).redraw();
85
			((TaxonNameEditorE4)EventUtility.getEditor()).getConversationHolder().commit();
78 86

  
79 87
		}
80 88
		target.getEditor().redraw();
......
83 91

  
84 92
	private AbstractPostOperation createOperation(TaxonBase taxonBase) {
85 93

  
86
	    //FIXME E4 migrate dnd
87

  
88
//		if(taxonBase instanceof Synonym){
89
//			Synonym synonym = (Synonym) taxonBase;
90
//
91
//			if(target instanceof AbstractHomotypicalGroupContainer){
92
//				HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainer) target).getGroup();
93
//
94
//				return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
95
//						getEditor().getTaxon(), synonym, homotypicalGroup, target);
96
//			}
97
//			else if(target instanceof MisappliedGroup){
98
//				return new ChangeSynonymToMisapplicationOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM_TO_MISAPP, getEditor().getUndoContext(),
99
//						getEditor().getTaxon(), synonym, target);
100
//			}
101
//			else if(target instanceof TaxonNameEditor){
102
//				if (target.equals(getEditor())){
103
//					return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
104
//						getEditor().getTaxon(), synonym, null, target);
105
//				} else{
106
//					getEditor().getConversationHolder().commit();
107
//					((TaxonNameEditor) target).getConversationHolder().commit();
108
//
109
//					return new MoveSynonymToAnotherAcceptedTaxonOperation(Messages.NameEditorDropTargetListener_CHANGE_ACC_TAXON, getEditor().getUndoContext(), getEditor().getTaxon().getUuid(), synonym.getUuid(), ((TaxonNameEditor) target).getTaxon(), null );
110
//
111
//				}
112
//			}
113
//
114
//		}else if(taxonBase instanceof Taxon){
115
//			Taxon concept = (Taxon) taxonBase;
116
//
117
//			if(target instanceof AbstractHomotypicalGroupContainer){
118
//				HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainer) target).getGroup();
119
//
120
//				return new ChangeConceptToSynonymOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM, getEditor().getUndoContext(),
121
//						getEditor().getTaxon(), concept, homotypicalGroup, target);
122
//			}
123
//			else if(target instanceof MisappliedGroup ){
124
//				return new ChangeConceptRelationshipTypeOperation(Messages.NameEditorDropTargetListener_CHANGE, getEditor().getUndoContext(),
125
//						getEditor().getTaxon(), concept, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), target);
126
//			}
127
//		}
94
		if(taxonBase instanceof Synonym){
95
			Synonym synonym = (Synonym) taxonBase;
96

  
97
			if(target instanceof AbstractHomotypicalGroupContainerE4){
98
				HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainerE4) target).getGroup();
99

  
100
				return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
101
						getEditor().getTaxon(), synonym, homotypicalGroup, target);
102
			}
103
			else if(target instanceof MisappliedGroupE4){
104
				return new ChangeSynonymToMisapplicationOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM_TO_MISAPP, getEditor().getUndoContext(),
105
						getEditor().getTaxon(), synonym, target);
106
			}
107
			else if(target instanceof TaxonNameEditorE4){
108
				if (target.equals(getEditor())){
109
					return new ChangeHomotypicGroupOperation(Messages.NameEditorDropTargetListener_CHANGE_HOMOTYPICAL_GROUP, getEditor().getUndoContext(),
110
						getEditor().getTaxon(), synonym, null, target);
111
				} else{
112
					getEditor().getConversationHolder().commit();
113
					((TaxonNameEditorE4) target).getConversationHolder().commit();
114

  
115
					return new MoveSynonymToAnotherAcceptedTaxonOperation(Messages.NameEditorDropTargetListener_CHANGE_ACC_TAXON, getEditor().getUndoContext(), getEditor().getTaxon().getUuid(), synonym.getUuid(), ((TaxonNameEditorE4) target).getTaxon(), null );
116

  
117
				}
118
			}
119

  
120
		}else if(taxonBase instanceof Taxon){
121
			Taxon concept = (Taxon) taxonBase;
122

  
123
			if(target instanceof AbstractHomotypicalGroupContainerE4){
124
				HomotypicalGroup homotypicalGroup = ((AbstractHomotypicalGroupContainerE4) target).getGroup();
125

  
126
				return new ChangeConceptToSynonymOperation(Messages.NameEditorDropTargetListener_CHANGE_SYNONYM, getEditor().getUndoContext(),
127
						getEditor().getTaxon(), concept, homotypicalGroup, target);
128
			}
129
			else if(target instanceof MisappliedGroupE4){
130
				return new ChangeConceptRelationshipTypeOperation(Messages.NameEditorDropTargetListener_CHANGE, getEditor().getUndoContext(),
131
						getEditor().getTaxon(), concept, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), target);
132
			}
133
		}
128 134

  
129 135

  
130 136
		return null;
......
138 144

  
139 145

  
140 146
	private HomotypicalGroup getHomotypicalGroup() {
141
		if(target instanceof AbstractHomotypicalGroupContainer){
142
			return ((AbstractHomotypicalGroupContainer) target).getGroup();
147
		if(target instanceof AbstractHomotypicalGroupContainerE4){
148
			return ((AbstractHomotypicalGroupContainerE4) target).getGroup();
143 149
		}
144 150
		return null;
145 151
	}
......
157 163
	}
158 164

  
159 165
	private TaxonNameEditorE4 getEditor() {
160
		return (TaxonNameEditorE4) EditorUtil.getActiveMultiPageTaxonEditor().getActiveEditor();
166
		return (TaxonNameEditorE4) EventUtility.getEditor();
161 167
	}
162 168
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)