Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 327893
Collapse All | Expand All

(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/CursorInfo.java (+2 lines)
Lines 14-22 Link Here
14
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
14
import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
15
import org.eclipse.swt.graphics.Point;
15
import org.eclipse.swt.graphics.Point;
16
import org.eclipse.swt.graphics.Rectangle;
16
import org.eclipse.swt.graphics.Rectangle;
17
import org.eclipse.swt.widgets.Control;
17
18
18
class CursorInfo {
19
class CursorInfo {
19
	Point cursorPos;
20
	Point cursorPos;
21
	Control curCtrl;
20
	MUIElement curElement;
22
	MUIElement curElement;
21
	MPlaceholder curElementRef;
23
	MPlaceholder curElementRef;
22
	MUIElement itemElement;
24
	MUIElement itemElement;
(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDManager.java (+4 lines)
Lines 124-130 Link Here
124
		baseWindow = window;
124
		baseWindow = window;
125
125
126
		dragAgents.add(new PartDragAgent());
126
		dragAgents.add(new PartDragAgent());
127
		dragAgents.add(new ToolbarDragAgent());
127
		dropAgents.add(new StackDropAgent(window));
128
		dropAgents.add(new StackDropAgent(window));
129
		dropAgents.add(new ToolbarDropAgent());
128
130
129
		modelService = (EModelService) window.getContext().get(EModelService.class.getName());
131
		modelService = (EModelService) window.getContext().get(EModelService.class.getName());
130
		dropAgents.add(new SplitDropAgent(modelService));
132
		dropAgents.add(new SplitDropAgent(modelService));
Lines 189-194 Link Here
189
		baseShell.setCapture(true);
191
		baseShell.setCapture(true);
190
192
191
		try {
193
		try {
194
			dragAgent.dragStart(dragAgent.dragElement);
195
192
			// Run tracker until mouse up occurs or escape key pressed.
196
			// Run tracker until mouse up occurs or escape key pressed.
193
			boolean performDrop = tracker.open();
197
			boolean performDrop = tracker.open();
194
198
(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAgent.java (-1 lines)
Lines 109-115 Link Here
109
	 * semi-transparent window that will track with the cursor.
109
	 * semi-transparent window that will track with the cursor.
110
	 */
110
	 */
111
	public void createDragFeedback() {
111
	public void createDragFeedback() {
112
		dragHost = new DragHost(dragElement);
113
	}
112
	}
114
113
115
	/**
114
	/**
(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAndDropUtil.java (-3 / +3 lines)
Lines 29-40 Link Here
29
	public CursorInfo getCursorInfo() {
29
	public CursorInfo getCursorInfo() {
30
		CursorInfo info = new CursorInfo();
30
		CursorInfo info = new CursorInfo();
31
		info.cursorPos = display.getCursorLocation();
31
		info.cursorPos = display.getCursorLocation();
32
		Control curControl = display.getCursorControl();
32
		info.curCtrl = display.getCursorControl();
33
		if (curControl == null) {
33
		if (info.curCtrl == null) {
34
			return info;
34
			return info;
35
		}
35
		}
36
36
37
		MUIElement curElement = getModelElement(curControl);
37
		MUIElement curElement = getModelElement(info.curCtrl);
38
		if (curElement instanceof MPlaceholder) {
38
		if (curElement instanceof MPlaceholder) {
39
			info.curElement = ((MPlaceholder) curElement).getRef();
39
			info.curElement = ((MPlaceholder) curElement).getRef();
40
			info.curElementRef = (MPlaceholder) curElement;
40
			info.curElementRef = (MPlaceholder) curElement;
(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java (+3 lines)
Lines 43-48 Link Here
43
43
44
	@Override
44
	@Override
45
	public boolean canDrop(MUIElement dragElement, CursorInfo info) {
45
	public boolean canDrop(MUIElement dragElement, CursorInfo info) {
46
		if (!(dragElement instanceof MPart))
47
			return false;
48
46
		if (info.curElement == dragElement.getParent()) {
49
		if (info.curElement == dragElement.getParent()) {
47
			if (info.curElement != null && info.curElement == dragElement.getParent()) {
50
			if (info.curElement != null && info.curElement == dragElement.getParent()) {
48
				CTabFolder ctf = (CTabFolder) dragElement.getParent().getWidget();
51
				CTabFolder ctf = (CTabFolder) dragElement.getParent().getWidget();
(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDragAgent.java (+42 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.e4.ui.workbench.addons.dndaddon;
13
14
import org.eclipse.e4.ui.model.application.ui.MUIElement;
15
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
16
import org.eclipse.swt.widgets.ToolBar;
17
18
/**
19
 *
20
 */
21
public class ToolbarDragAgent extends DragAgent {
22
23
	@Override
24
	public MUIElement getElementToDrag(CursorInfo info) {
25
		if (info.curElement instanceof MToolBar) {
26
			if (info.curCtrl instanceof ToolBar) {
27
				if (info.curCtrl == info.curCtrl.getParent().getChildren()[0]) {
28
					dragElement = info.curElement;
29
					return info.curElement;
30
				}
31
			}
32
		}
33
		return null;
34
	}
35
36
	@Override
37
	public void dragStart(MUIElement element) {
38
		super.dragStart(element);
39
40
		element.setVisible(false);
41
	}
42
}
(-)src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDropAgent.java (+148 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.e4.ui.workbench.addons.dndaddon;
13
14
import org.eclipse.e4.ui.model.application.ui.MUIElement;
15
import org.eclipse.e4.ui.model.application.ui.SideValue;
16
import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar;
17
import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement;
18
import org.eclipse.e4.ui.model.application.ui.menu.MToolBar;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.events.DisposeEvent;
21
import org.eclipse.swt.events.DisposeListener;
22
import org.eclipse.swt.graphics.Cursor;
23
import org.eclipse.swt.graphics.Point;
24
import org.eclipse.swt.graphics.Rectangle;
25
import org.eclipse.swt.layout.FillLayout;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Control;
28
import org.eclipse.swt.widgets.Display;
29
import org.eclipse.swt.widgets.Shell;
30
31
/**
32
 *
33
 */
34
public class ToolbarDropAgent extends DropAgent {
35
	private Shell dragShell;
36
37
	public ToolbarDropAgent() {
38
	}
39
40
	@Override
41
	public boolean canDrop(MUIElement dragElement, CursorInfo info) {
42
		if (!(dragElement instanceof MToolBar) || info.curElement == null)
43
			return false;
44
45
		// We can only drop TB's onto a trim area
46
		if (info.curElement instanceof MTrimBar)
47
			return true;
48
49
		MUIElement parentElement = info.curElement.getParent();
50
		if (parentElement instanceof MTrimBar)
51
			return true;
52
53
		return false;
54
	}
55
56
	@Override
57
	public boolean drop(MUIElement dragElement, CursorInfo info) {
58
		MTrimBar theBar = (MTrimBar) ((info.curElement instanceof MTrimBar) ? info.curElement
59
				: info.curElement.getParent());
60
61
		// If we're over another trim element should we go before or after it ?
62
		int index = -1;
63
		if (info.curElement != theBar) {
64
			index = info.curElement.getParent().getChildren().indexOf(info.curElement);
65
			if (after(info))
66
				index++;
67
		}
68
69
		dragElement.getParent().getChildren().remove(dragElement);
70
		dragElement.setVisible(true);
71
		if (index == -1 || index > theBar.getChildren().size() - 1)
72
			theBar.getChildren().add((MTrimElement) dragElement);
73
		else
74
			theBar.getChildren().add(index, (MTrimElement) dragElement);
75
76
		if (dragShell != null)
77
			dragShell.dispose();
78
79
		return true;
80
	}
81
82
	private boolean after(CursorInfo info) {
83
		if (info.curElement instanceof MTrimBar)
84
			return false;
85
86
		MTrimBar theBar = (MTrimBar) ((MUIElement) info.curElement.getParent());
87
		boolean isHorizontal = theBar.getSide() == SideValue.TOP
88
				|| theBar.getSide() == SideValue.BOTTOM;
89
90
		MUIElement overElement = info.curElement;
91
		Control ctrl = (Control) overElement.getWidget();
92
		Rectangle bounds = ctrl.getBounds();
93
		bounds = ctrl.getDisplay().map(ctrl.getParent(), null, bounds);
94
95
		if (isHorizontal
96
				&& info.cursorPos.x - bounds.x >= (bounds.x + bounds.width) - info.cursorPos.x)
97
			return true;
98
		else if (!isHorizontal
99
				&& info.cursorPos.y - bounds.y >= (bounds.y + bounds.height) - info.cursorPos.y)
100
			return true;
101
102
		return false;
103
	}
104
105
	@Override
106
	public Rectangle getRectangle(MUIElement dragElement, CursorInfo info) {
107
		boolean needsOpen = false;
108
		if (dragShell == null) {
109
			dragShell = new Shell(SWT.NO_TRIM);
110
			dragShell.setAlpha(150);
111
			dragShell.setLayout(new FillLayout());
112
113
			Composite comp = new Composite(dragShell, SWT.BORDER);
114
			comp.setLayout(new FillLayout());
115
116
			dragShell.addDisposeListener(new DisposeListener() {
117
				public void widgetDisposed(DisposeEvent e) {
118
					dragShell = null;
119
				}
120
			});
121
			Control ctrl = (Control) dragElement.getWidget();
122
			ctrl.setParent(comp);
123
			dragShell.pack();
124
			needsOpen = true;
125
		}
126
127
		Point newLoc = new Point(info.cursorPos.x + 4, info.cursorPos.y + 4);
128
		dragShell.setLocation(newLoc);
129
130
		if (needsOpen)
131
			dragShell.open();
132
133
		MUIElement overElement = info.curElement;
134
		Control ctrl = (Control) overElement.getWidget();
135
		Rectangle bounds = ctrl.getBounds();
136
		bounds = ctrl.getDisplay().map(ctrl.getParent(), null, bounds);
137
		bounds.x = after(info) ? bounds.x + bounds.width : bounds.x;
138
		bounds.width = 5;
139
		bounds.x -= bounds.width / 2;
140
141
		return bounds;
142
	}
143
144
	@Override
145
	public Cursor getCursor(Display display, MUIElement dragElement, CursorInfo info) {
146
		return display.getSystemCursor(SWT.CURSOR_HAND);
147
	}
148
}

Return to bug 327893