Project

General

Profile

Revision 0634d71b

ID0634d71b15e650141d6eefd36042831e3575c3c1
Parent a904e4d0
Child 04cb966e

Added by Patrick Plitzner over 3 years ago

ref #7011 Migrate dnd

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/CdmAuthorityTableDropTargetListener.java
1 1
/**
2 2
* Copyright (C) 2007 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
*/
9 9
package eu.etaxonomy.taxeditor.dnd;
10 10

  
11
import java.util.Iterator;
12

  
13
import org.eclipse.jface.util.LocalSelectionTransfer;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.TreeSelection;
11 16
import org.eclipse.swt.dnd.DropTargetEvent;
12 17
import org.eclipse.swt.dnd.DropTargetListener;
13 18

  
14 19
import eu.etaxonomy.cdm.model.common.CdmBase;
15
import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
16 20
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityComposite;
17 21
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityCompositeViewer;
18 22

  
19 23
/**
20 24
 * Drop listener for the {@link CdmAuthorityComposite}.
21
 * 
25
 *
22 26
 * @author cmathew
23 27
 * @created Mar 28, 2013
24 28
 *
......
26 30
public class CdmAuthorityTableDropTargetListener implements DropTargetListener {
27 31

  
28 32
	private CdmAuthorityCompositeViewer viewer;
29
	
30
	
33

  
34

  
31 35
	public CdmAuthorityTableDropTargetListener(CdmAuthorityCompositeViewer viewer) {
32 36
		this.viewer = viewer;
33 37
	}
34 38

  
35 39
	@Override
36
	public void dragEnter(DropTargetEvent event) {				
40
	public void dragEnter(DropTargetEvent event) {
37 41
	}
38 42

  
39 43
	@Override
......
50 54

  
51 55
	@Override
52 56
	public void drop(DropTargetEvent dtevent) {
53
		if(TaxonNodeTransfer.getInstance().isSupportedType(dtevent.currentDataType)) {
54
			Object[] selectedCdmBases = (Object[])dtevent.data;
55
			
56
			for (Object cdmBase : selectedCdmBases){
57
				if(CdmBase.class.isAssignableFrom(cdmBase.getClass()) ) {
58
					viewer.addCdmAuthority((CdmBase)cdmBase);					
59
				}
60
			}
61
		}		
57
	    ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
58
        if (selection instanceof TreeSelection) {
59

  
60
            Iterator<?> selectionIterator = ((TreeSelection) selection).iterator();
61

  
62
            while (selectionIterator.hasNext()){
63
                Object next = selectionIterator.next();
64
                if(CdmBase.class.isAssignableFrom(next.getClass()) ) {
65
                    viewer.addCdmAuthority((CdmBase)next);
66
                }
67
            }
68
		}
62 69
	}
63 70

  
64 71
	@Override
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityComposite.java
1 1
/**
2 2
* Copyright (C) 2007 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
*/
9 9
package eu.etaxonomy.taxeditor.ui.group.grantedauthority;
10 10

  
11
import org.eclipse.jface.util.LocalSelectionTransfer;
11 12
import org.eclipse.nebula.widgets.compositetable.CompositeTable;
12 13
import org.eclipse.nebula.widgets.compositetable.IRowContentProvider;
13 14
import org.eclipse.swt.SWT;
14
import org.eclipse.swt.custom.ScrolledComposite;
15 15
import org.eclipse.swt.dnd.DND;
16 16
import org.eclipse.swt.dnd.DropTarget;
17 17
import org.eclipse.swt.dnd.Transfer;
18 18
import org.eclipse.swt.events.DisposeEvent;
19 19
import org.eclipse.swt.events.DisposeListener;
20
import org.eclipse.swt.events.SelectionAdapter;
21
import org.eclipse.swt.events.SelectionEvent;
20 22
import org.eclipse.swt.layout.GridData;
21 23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.widgets.Button;
22 25
import org.eclipse.swt.widgets.Composite;
23 26
import org.eclipse.swt.widgets.Control;
24 27
import org.eclipse.swt.widgets.Display;
......
26 29
import org.eclipse.ui.forms.widgets.FormToolkit;
27 30

  
28 31
import eu.etaxonomy.taxeditor.dnd.CdmAuthorityTableDropTargetListener;
29
import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
30
import org.eclipse.swt.widgets.Button;
31
import org.eclipse.swt.events.SelectionAdapter;
32
import org.eclipse.swt.events.SelectionEvent;
33 32

  
34 33
/**
35 34
 * Composite class which consists of a {@link CompositeTable} built specifically
36 35
 * for creating / editing CDM Authority objects
37
 * 
36
 *
38 37
 * @author cmathew
39 38
 * @created Mar 28, 2013
40 39
 *
......
44 43

  
45 44
	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
46 45
	private CompositeTable table;
47
	
46

  
48 47
	private int numOfInitialCdmAuthorities;
49
	
48

  
50 49
	private CdmAuthorityCompositeViewer viewer;
51
	
50

  
52 51
	private CdmAuthorityTableHeader cdmAuthorityTableHeader;
53
	
52

  
54 53

  
55 54
	/**
56 55
	 * Creates the composite using the given parent, style and associated viewer.
57
	 * 
56
	 *
58 57
	 * @param parent composite to use as parent of this composite
59
	 * @param style 
58
	 * @param style
60 59
	 * @param viewer viewer representing the model
61 60
	 */
62 61
	public CdmAuthorityComposite(Composite parent, int style, final CdmAuthorityCompositeViewer viewer) {
63 62
		super(parent, SWT.NONE);
64 63
		addDisposeListener(new DisposeListener() {
65
			public void widgetDisposed(DisposeEvent e) {
64
			@Override
65
            public void widgetDisposed(DisposeEvent e) {
66 66
				toolkit.dispose();
67 67
			}
68 68
		});
69
		
69

  
70 70
		this.viewer = viewer;
71
				
71

  
72 72
		numOfInitialCdmAuthorities = viewer.getCdmAuthorities().size();
73 73
		setLayout(new GridLayout(2, false));
74 74
		setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
75
	    Transfer[] transfers = new Transfer[] { TaxonNodeTransfer.getInstance() };	   
76
	    
75
	    Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
76

  
77 77
	    toolkit.adapt(this);
78 78
		toolkit.paintBordersFor(this);
79 79
		new Label(this, SWT.NONE);
80
		
80

  
81 81
		final Button cbShowUUIDheader = new Button(this, SWT.CHECK);
82 82
		cbShowUUIDheader.addSelectionListener(new SelectionAdapter() {
83 83
			@Override
......
96 96
		table.setLayoutData(gd_table);
97 97
		cdmAuthorityTableHeader = new CdmAuthorityTableHeader(table, SWT.NULL);
98 98
		CdmAuthorityRow cdmAuthorityRow = new CdmAuthorityRow(table, SWT.NULL);
99
		
99

  
100 100
		table.setRunTime(true);
101 101
		table.setNumRowsInCollection(numOfInitialCdmAuthorities);
102
		table.setLinesVisible(true); 
103
		
102
		table.setLinesVisible(true);
103

  
104 104
		DropTarget dropTarget = new DropTarget(table, DND.DROP_MOVE);
105 105
		dropTarget.setTransfer(transfers);
106 106
		dropTarget.addDropListener(new CdmAuthorityTableDropTargetListener(viewer));
107
		
108
		
107

  
108

  
109 109
		table.addRowContentProvider(new IRowContentProvider() {
110
			public void refresh(CompositeTable sender, int currentObjectOffset, Control rowControl) {
111
				CdmAuthorityRow row = (CdmAuthorityRow) rowControl;		
110
			@Override
111
            public void refresh(CompositeTable sender, int currentObjectOffset, Control rowControl) {
112
				CdmAuthorityRow row = (CdmAuthorityRow) rowControl;
112 113
				// add the newly created authority objects first and then the already existing ones.
113 114
				// this ensures the newly 'dragged' in objects always remain at the top
114
				if(currentObjectOffset < viewer.getNewCdmAuthorities().size()) {			
115
					row.setRowCdmAuthority(viewer, 
116
							viewer.getNewCdmAuthorities().get(currentObjectOffset), 
115
				if(currentObjectOffset < viewer.getNewCdmAuthorities().size()) {
116
					row.setRowCdmAuthority(viewer,
117
							viewer.getNewCdmAuthorities().get(currentObjectOffset),
117 118
							true,
118 119
							cbShowUUIDheader.getSelection());
119 120
				} else {
120
					row.setRowCdmAuthority(viewer, 
121
							viewer.getCdmAuthorities().get(currentObjectOffset - viewer.getNewCdmAuthorities().size()), 
121
					row.setRowCdmAuthority(viewer,
122
							viewer.getCdmAuthorities().get(currentObjectOffset - viewer.getNewCdmAuthorities().size()),
122 123
							false,
123 124
							cbShowUUIDheader.getSelection());
124
				}										
125
				}
125 126
			}
126 127
		});
127
	}	
128
	}
128 129

  
129 130
	/**
130 131
	 * Refreshes the table with underlying data
131 132
	 */
132
	public void refresh() {			
133
		numOfInitialCdmAuthorities = viewer.getNewCdmAuthorities().size() + viewer.getCdmAuthorities().size();			    	    
134
	    table.setNumRowsInCollection(numOfInitialCdmAuthorities);	  
133
	public void refresh() {
134
		numOfInitialCdmAuthorities = viewer.getNewCdmAuthorities().size() + viewer.getCdmAuthorities().size();
135
	    table.setNumRowsInCollection(numOfInitialCdmAuthorities);
135 136
	    table.refreshAllRows();
136 137
	}
137 138
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)