blob: 26b229bd94e3b6d782ded2fa1160af59e475824e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*******************************************************************************
* Copyright (c) 2001, 2009 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.design.editpolicies;
import java.util.List;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartViewer;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.tools.DragEditPartsTracker;
import org.eclipse.wst.xsd.ui.internal.adt.design.editparts.BaseEditPart;
public class GraphNodeDragTracker extends DragEditPartsTracker
{
protected EditPart editPart;
public GraphNodeDragTracker(EditPart editPart)
{
super(editPart);
this.editPart = editPart;
}
protected Command getCommand()
{
Request request = getTargetRequest();
return editPart.getCommand(request);
}
protected void performSelection()
{
performAdditionalSelection();
super.performSelection();
}
protected void performAdditionalSelection()
{
EditPartViewer viewer = getCurrentViewer();
// This code selects the fields in-between the last selected field and the newly
// selected field, if the shift key is held down. Note that the selection logic
// can be improved so that already selected but, a) incompatible edit part figures, or b)
// like-edit part figures from other parents, should be unselected.
if (getCurrentInput().isShiftKeyDown())
{
// This list contains the fields
List list = editPart.getParent().getChildren();
// Get the index of the current selection
int currentIndex = list.indexOf(editPart);
// List of all the currently selected edit parts
List currentSelected = viewer.getSelectedEditParts();
int size = currentSelected.size();
if (size > 0)
{
Object lastSelected = currentSelected.get(size - 1);
if (lastSelected instanceof BaseEditPart)
{
// Here, we determine the upper and lower limit of the indices
int lowerIndex = -1, upperIndex = -1;
int lastSelectedIndex = list.indexOf(lastSelected);
if (lastSelectedIndex >= 0 && lastSelectedIndex < currentIndex)
{
lowerIndex = lastSelectedIndex;
upperIndex = currentIndex;
}
else if (lastSelectedIndex >= 0 && lastSelectedIndex > currentIndex)
{
lowerIndex = currentIndex;
upperIndex = lastSelectedIndex;
}
if (lowerIndex >= 0 && upperIndex >= 0)
{
for (int i = lowerIndex; i < upperIndex; i++)
{
viewer.appendSelection((EditPart) list.get(i));
}
}
}
}
}
}
}
|