Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 180959 Details for
Bug 327893
[UI] Implement DnD for Toolbars / TrimControls
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Initial implementation of DnD for toolbars
patch(327893) (text/plain), 11.98 KB, created by
Eric Moffatt
on 2010-10-15 10:11:18 EDT
(
hide
)
Description:
Initial implementation of DnD for toolbars
Filename:
MIME Type:
Creator:
Eric Moffatt
Created:
2010-10-15 10:11:18 EDT
Size:
11.98 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.e4.ui.workbench.addons.swt >Index: src/org/eclipse/e4/ui/workbench/addons/dndaddon/CursorInfo.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/CursorInfo.java,v >retrieving revision 1.2 >diff -u -r1.2 CursorInfo.java >--- src/org/eclipse/e4/ui/workbench/addons/dndaddon/CursorInfo.java 14 May 2010 19:39:13 -0000 1.2 >+++ src/org/eclipse/e4/ui/workbench/addons/dndaddon/CursorInfo.java 15 Oct 2010 14:10:03 -0000 >@@ -14,9 +14,11 @@ > import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; > import org.eclipse.swt.graphics.Point; > import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.widgets.Control; > > class CursorInfo { > Point cursorPos; >+ Control curCtrl; > MUIElement curElement; > MPlaceholder curElementRef; > MUIElement itemElement; >Index: src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDManager.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDManager.java,v >retrieving revision 1.7 >diff -u -r1.7 DnDManager.java >--- src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDManager.java 21 Jul 2010 21:57:30 -0000 1.7 >+++ src/org/eclipse/e4/ui/workbench/addons/dndaddon/DnDManager.java 15 Oct 2010 14:10:03 -0000 >@@ -124,7 +124,9 @@ > baseWindow = window; > > dragAgents.add(new PartDragAgent()); >+ dragAgents.add(new ToolbarDragAgent()); > dropAgents.add(new StackDropAgent(window)); >+ dropAgents.add(new ToolbarDropAgent()); > > modelService = (EModelService) window.getContext().get(EModelService.class.getName()); > dropAgents.add(new SplitDropAgent(modelService)); >@@ -189,6 +191,8 @@ > baseShell.setCapture(true); > > try { >+ dragAgent.dragStart(dragAgent.dragElement); >+ > // Run tracker until mouse up occurs or escape key pressed. > boolean performDrop = tracker.open(); > >Index: src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAgent.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAgent.java,v >retrieving revision 1.2 >diff -u -r1.2 DragAgent.java >--- src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAgent.java 21 Apr 2010 19:02:15 -0000 1.2 >+++ src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAgent.java 15 Oct 2010 14:10:03 -0000 >@@ -109,7 +109,6 @@ > * semi-transparent window that will track with the cursor. > */ > public void createDragFeedback() { >- dragHost = new DragHost(dragElement); > } > > /** >Index: src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAndDropUtil.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAndDropUtil.java,v >retrieving revision 1.5 >diff -u -r1.5 DragAndDropUtil.java >--- src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAndDropUtil.java 15 Jul 2010 15:37:32 -0000 1.5 >+++ src/org/eclipse/e4/ui/workbench/addons/dndaddon/DragAndDropUtil.java 15 Oct 2010 14:10:03 -0000 >@@ -29,12 +29,12 @@ > public CursorInfo getCursorInfo() { > CursorInfo info = new CursorInfo(); > info.cursorPos = display.getCursorLocation(); >- Control curControl = display.getCursorControl(); >- if (curControl == null) { >+ info.curCtrl = display.getCursorControl(); >+ if (info.curCtrl == null) { > return info; > } > >- MUIElement curElement = getModelElement(curControl); >+ MUIElement curElement = getModelElement(info.curCtrl); > if (curElement instanceof MPlaceholder) { > info.curElement = ((MPlaceholder) curElement).getRef(); > info.curElementRef = (MPlaceholder) curElement; >Index: src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java >=================================================================== >RCS file: /cvsroot/eclipse/e4/org.eclipse.e4.ui/bundles/org.eclipse.e4.ui.workbench.addons.swt/src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java,v >retrieving revision 1.8 >diff -u -r1.8 StackDropAgent.java >--- src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java 28 Sep 2010 20:18:44 -0000 1.8 >+++ src/org/eclipse/e4/ui/workbench/addons/dndaddon/StackDropAgent.java 15 Oct 2010 14:10:03 -0000 >@@ -43,6 +43,9 @@ > > @Override > public boolean canDrop(MUIElement dragElement, CursorInfo info) { >+ if (!(dragElement instanceof MPart)) >+ return false; >+ > if (info.curElement == dragElement.getParent()) { > if (info.curElement != null && info.curElement == dragElement.getParent()) { > CTabFolder ctf = (CTabFolder) dragElement.getParent().getWidget(); >Index: src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDragAgent.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDragAgent.java >diff -N src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDragAgent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDragAgent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 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.e4.ui.workbench.addons.dndaddon; >+ >+import org.eclipse.e4.ui.model.application.ui.MUIElement; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; >+import org.eclipse.swt.widgets.ToolBar; >+ >+/** >+ * >+ */ >+public class ToolbarDragAgent extends DragAgent { >+ >+ @Override >+ public MUIElement getElementToDrag(CursorInfo info) { >+ if (info.curElement instanceof MToolBar) { >+ if (info.curCtrl instanceof ToolBar) { >+ if (info.curCtrl == info.curCtrl.getParent().getChildren()[0]) { >+ dragElement = info.curElement; >+ return info.curElement; >+ } >+ } >+ } >+ return null; >+ } >+ >+ @Override >+ public void dragStart(MUIElement element) { >+ super.dragStart(element); >+ >+ element.setVisible(false); >+ } >+} >Index: src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDropAgent.java >=================================================================== >RCS file: src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDropAgent.java >diff -N src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDropAgent.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/e4/ui/workbench/addons/dndaddon/ToolbarDropAgent.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,148 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 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.e4.ui.workbench.addons.dndaddon; >+ >+import org.eclipse.e4.ui.model.application.ui.MUIElement; >+import org.eclipse.e4.ui.model.application.ui.SideValue; >+import org.eclipse.e4.ui.model.application.ui.basic.MTrimBar; >+import org.eclipse.e4.ui.model.application.ui.basic.MTrimElement; >+import org.eclipse.e4.ui.model.application.ui.menu.MToolBar; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.DisposeEvent; >+import org.eclipse.swt.events.DisposeListener; >+import org.eclipse.swt.graphics.Cursor; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.Rectangle; >+import org.eclipse.swt.layout.FillLayout; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Shell; >+ >+/** >+ * >+ */ >+public class ToolbarDropAgent extends DropAgent { >+ private Shell dragShell; >+ >+ public ToolbarDropAgent() { >+ } >+ >+ @Override >+ public boolean canDrop(MUIElement dragElement, CursorInfo info) { >+ if (!(dragElement instanceof MToolBar) || info.curElement == null) >+ return false; >+ >+ // We can only drop TB's onto a trim area >+ if (info.curElement instanceof MTrimBar) >+ return true; >+ >+ MUIElement parentElement = info.curElement.getParent(); >+ if (parentElement instanceof MTrimBar) >+ return true; >+ >+ return false; >+ } >+ >+ @Override >+ public boolean drop(MUIElement dragElement, CursorInfo info) { >+ MTrimBar theBar = (MTrimBar) ((info.curElement instanceof MTrimBar) ? info.curElement >+ : info.curElement.getParent()); >+ >+ // If we're over another trim element should we go before or after it ? >+ int index = -1; >+ if (info.curElement != theBar) { >+ index = info.curElement.getParent().getChildren().indexOf(info.curElement); >+ if (after(info)) >+ index++; >+ } >+ >+ dragElement.getParent().getChildren().remove(dragElement); >+ dragElement.setVisible(true); >+ if (index == -1 || index > theBar.getChildren().size() - 1) >+ theBar.getChildren().add((MTrimElement) dragElement); >+ else >+ theBar.getChildren().add(index, (MTrimElement) dragElement); >+ >+ if (dragShell != null) >+ dragShell.dispose(); >+ >+ return true; >+ } >+ >+ private boolean after(CursorInfo info) { >+ if (info.curElement instanceof MTrimBar) >+ return false; >+ >+ MTrimBar theBar = (MTrimBar) ((MUIElement) info.curElement.getParent()); >+ boolean isHorizontal = theBar.getSide() == SideValue.TOP >+ || theBar.getSide() == SideValue.BOTTOM; >+ >+ MUIElement overElement = info.curElement; >+ Control ctrl = (Control) overElement.getWidget(); >+ Rectangle bounds = ctrl.getBounds(); >+ bounds = ctrl.getDisplay().map(ctrl.getParent(), null, bounds); >+ >+ if (isHorizontal >+ && info.cursorPos.x - bounds.x >= (bounds.x + bounds.width) - info.cursorPos.x) >+ return true; >+ else if (!isHorizontal >+ && info.cursorPos.y - bounds.y >= (bounds.y + bounds.height) - info.cursorPos.y) >+ return true; >+ >+ return false; >+ } >+ >+ @Override >+ public Rectangle getRectangle(MUIElement dragElement, CursorInfo info) { >+ boolean needsOpen = false; >+ if (dragShell == null) { >+ dragShell = new Shell(SWT.NO_TRIM); >+ dragShell.setAlpha(150); >+ dragShell.setLayout(new FillLayout()); >+ >+ Composite comp = new Composite(dragShell, SWT.BORDER); >+ comp.setLayout(new FillLayout()); >+ >+ dragShell.addDisposeListener(new DisposeListener() { >+ public void widgetDisposed(DisposeEvent e) { >+ dragShell = null; >+ } >+ }); >+ Control ctrl = (Control) dragElement.getWidget(); >+ ctrl.setParent(comp); >+ dragShell.pack(); >+ needsOpen = true; >+ } >+ >+ Point newLoc = new Point(info.cursorPos.x + 4, info.cursorPos.y + 4); >+ dragShell.setLocation(newLoc); >+ >+ if (needsOpen) >+ dragShell.open(); >+ >+ MUIElement overElement = info.curElement; >+ Control ctrl = (Control) overElement.getWidget(); >+ Rectangle bounds = ctrl.getBounds(); >+ bounds = ctrl.getDisplay().map(ctrl.getParent(), null, bounds); >+ bounds.x = after(info) ? bounds.x + bounds.width : bounds.x; >+ bounds.width = 5; >+ bounds.x -= bounds.width / 2; >+ >+ return bounds; >+ } >+ >+ @Override >+ public Cursor getCursor(Display display, MUIElement dragElement, CursorInfo info) { >+ return display.getSystemCursor(SWT.CURSOR_HAND); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 327893
: 180959 |
185075