Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2012 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.basic.MTrimElement;
 import  org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
 import  org.eclipse.e4.ui.widgets.ImageBasedFrame;
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.graphics.Rectangle;
 import  org.eclipse.swt.widgets.Shell;

 
 public class IBFDragAgent extends DragAgent {
 
 	private ImageBasedFrame frame;
 	private Shell ds;

Parameters:
manager
 
 	public IBFDragAgent(DnDManager manager) {
 		super(manager);
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see
 	 * org.eclipse.e4.ui.workbench.addons.dndaddon.DragAgent#getElementToDrag(org.eclipse.e4.ui.
 	 * workbench.addons.dndaddon.DnDInfo)
 	 */
 	public MUIElement getElementToDrag(DnDInfo info) {
 		if (!(info.curCtrl instanceof ImageBasedFrame))
 			return null;
 
 		if (!(info.curElement instanceof MTrimElement))
 			return null;
 
 		ImageBasedFrame frame = (ImageBasedFrame) info.curCtrl;
 		Rectangle handleRect = frame.getHandleRect();
 		handleRect = frame.getDisplay().map(framenullhandleRect);
 
 		if (handleRect.contains(info.cursorPos)) {
 			 = info.curElement;
 			return info.curElement;
 		}
 
 		return null;
 	}
 
 	/*
 	 * (non-Javadoc)
 	 * 
 	 * @see
 	 * org.eclipse.e4.ui.workbench.addons.dndaddon.DragAgent#dragStart(org.eclipse.e4.ui.workbench
 	 * .addons.dndaddon.DnDInfo)
 	 */
 	public void dragStart(DnDInfo info) {
 		super.dragStart(info);
 
 		if ( instanceof MToolControl) {
 			MToolControl tc = (MToolControl) ;
 			if (tc.getObject() instanceof TrimStack) {
 				TrimStack ts = (TrimStacktc.getObject();
 				ts.showStack(false);
 			}
 		}
 
 		if ( == null)
 	}
 
 	private void attachToCursor(DnDInfo info) {
 		 = (ImageBasedFrame) .getWidget();
 		.setVisible(false);
 		.getTags().add("LockVisibility");
 
 		if ( == null)
 			 = new Shell(.getDragShell(), SWT.NO_TRIM);
 
 		.setParent();
 		.setLocation(0, 0);
 		.setSize(.getSize());
 		.setLocation(info.cursorPos.x - 5, info.cursorPos.y - 5);
		.open();
		info.update();
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.e4.ui.workbench.addons.dndaddon.DragAgent#track(org.eclipse.e4.ui.workbench.addons
	 * .dndaddon.DnDInfo)
	 */
	public void track(DnDInfo info) {
		super.track(info);
		if ( != null &&  != null && !.isDisposed() && .getChildren().length == 0) {
			.dispose();
			 = null;
		}
		if ( == null)
		if ( != null)
			.setLocation(info.cursorPos.x - 5, info.cursorPos.y - 5);
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.e4.ui.workbench.addons.dndaddon.DragAgent#dragFinished(boolean,
	 * org.eclipse.e4.ui.workbench.addons.dndaddon.DnDInfo)
	 */
	public void dragFinished(boolean performDropDnDInfo info) {
		.getTags().remove("LockVisibility");
		.setVisible(true);
		super.dragFinished(performDropinfo);
		// NOTE: the dragElement should no longer be a child of the shell
		if ( != null && !.isDisposed())
			.dispose();
		 = null;
	}
New to GrepCode? Check out our FAQ X