Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » moving a popupDialog
moving a popupDialog [message #730459] Wed, 28 September 2011 08:55
mousa.alsulaimi is currently offline mousa.alsulaimi
Messages: 18
Registered: June 2011
Junior Member
hi all how can i move a PopUpDialog is there a way to achieve that ,
i have tried to create a mouse listener , when the mouse is down i will create a MouseMoveListener and in the MouseMoveListener i will change the position of the dialogs shell , then the mouse is up i well remove the MouseMoveListener ... however this does not seem to work where Nither MouseDownEvent nor MouseMoveListener is triggered , can some one please help me with this :
code
package froms.dialogs;

import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseListener;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.TableWrapLayout;

import forms.layout.FormLayoutFactory;
import forms.layout.SearchLayoutFactory;
import froms.blocks.AddressBlock;

public class AddressBlockDialog extends PopupDialog{

	private Composite main;
	private ScrolledForm form;
	private Point fAnchor; 

	public AddressBlockDialog(Shell parent , Point fAnchor) {
		super(parent, SWT.None,true, true, true, true, true, null, "info");
		this.fAnchor=fAnchor;
		// TODO Auto-generated constructor stub
	}
	protected Control createContents(Composite parent) {
		getShell().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
		//initializeBounds();
	
		
		return createDialogArea(parent);
	}
	
	
	protected Control createDialogArea(Composite parent) {
		
		this.main = (Composite) super.createDialogArea(parent);
		FormToolkit toolkit = new FormToolkit(main.getDisplay()) ; 
		main.setLayout(SearchLayoutFactory.createLayout(1, false)) ; 
		this.main.setLayoutData(SearchLayoutFactory.createLayoutData(SWT.FILL, SWT.FILL,true, true, 1,1));
		 form = toolkit.createScrolledForm(main);
		// this.fillDialogMenu(tool);
		 form.setLayoutData(SearchLayoutFactory.createLayoutData(SWT.FILL, SWT.FILL,true, true, 1,1));
		 toolkit.paintBordersFor(form);
		//toolkit.decorateFormHeading(form.getForm());

		// set title and image
	

		// add a Close button to the toolbar
		

		
		form.getBody().setLayout(FormLayoutFactory.createGridLayout(1, false));
		Composite composite = toolkit.createComposite(form.getBody()) ;
		toolkit.paintBordersFor(composite) ; 
		composite.setLayout(FormLayoutFactory.createGridLayout(1, false)) ; 
		composite.setLayoutData(FormLayoutFactory.createGridData(SWT.FILL, SWT.FILL,true, true, 1,1)) ; 

		AddressBlock addressBlock = new AddressBlock(toolkit, composite, "address section ", true,this) ;  
		// this.adjustBounds() ; 
	//	this.adjustBounds() ;
		 
		System.out.println(main.getSize());
		System.out.println(form.getBody().getSize());
		System.out.println(composite.getSize());
		main.layout(true) ; 
		main.redraw() ; 
		
		form.pack();
		getShell().addMouseListener(new MouseListener() {
			private MouseMoveListener mouseMove = null ; 
			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub
				System.out.println("removeremove");
				if(this.mouseMove!=null) AddressBlockDialog.this.getShell().removeMouseMoveListener(this.mouseMove) ; 
			}
			
			@Override
			public void mouseDown(MouseEvent e) {
				System.out.println("herehrehrhe");
				// TODO Auto-generated method stub
AddressBlockDialog.this.getShell().addMouseMoveListener(this.mouseMove=new MouseMoveListener() {
					
					@Override
					public void mouseMove(MouseEvent e) {
						// TODO Auto-generated method stub
						System.out.println("mouse move ");
						AddressBlockDialog.this.getShell().setLocation(Display.getCurrent().getCursorLocation()) ; 
					}
				}) ; 
			}
			
			@Override
			public void mouseDoubleClick(MouseEvent e) {
				// TODO Auto-generated method stub
				System.out.println("double click");
			}
		}) ; 
		return form ; 
	}
	
	@Override
//	protected void adjustBounds() {
//		// TODO Auto-generated method stub
//		System.out.println(main);
//		System.out.println(main.getSize());
//		System.out.println(getShell().getSize());
//		getShell().setSize(main.getSize()) ; 
//		System.out.println(getShell().getSize());
//		 
//	}
	
	
	protected Point getInitialLocation(Point size) {
		if (fAnchor == null) {
			return super.getInitialLocation(size);
		}
		Point point = fAnchor;
		Rectangle monitor = getShell().getMonitor().getClientArea();
		if (monitor.width < point.x + size.x) {
			point.x = Math.max(0, point.x - size.x);
		}
		if (monitor.height < point.y + size.y) {
			point.y = Math.max(0, point.y - size.y);
		}
		return point;
	}
	
	
	@Override
	protected Control getFocusControl() {
		// TODO Auto-generated method stub
		return form;
	}

}



im defining the listeners in createDialogArea() :

getShell().addMouseListener(new MouseListener() {
			private MouseMoveListener mouseMove = null ; 
			@Override
			public void mouseUp(MouseEvent e) {
				// TODO Auto-generated method stub
				System.out.println("removeremove");
				if(this.mouseMove!=null) AddressBlockDialog.this.getShell().removeMouseMoveListener(this.mouseMove) ; 
			}
			
			@Override
			public void mouseDown(MouseEvent e) {
				System.out.println("herehrehrhe");
				// TODO Auto-generated method stub
AddressBlockDialog.this.getShell().addMouseMoveListener(this.mouseMove=new MouseMoveListener() {
					
					@Override
					public void mouseMove(MouseEvent e) {
						// TODO Auto-generated method stub
						System.out.println("mouse move ");
						AddressBlockDialog.this.getShell().setLocation(Display.getCurrent().getCursorLocation()) ; 
					}
				}) ; 
			}
			
			@Override
			public void mouseDoubleClick(MouseEvent e) {
				// TODO Auto-generated method stub
				System.out.println("double click");
			}
		}) ; 


thanks in advance
Previous Topic:Sharing Data between plugins
Next Topic:org.eclipse.core.runtime.AssertionFailedException: null argument:
Goto Forum:
  


Current Time: Fri Aug 22 23:53:20 EDT 2014

Powered by FUDForum. Page generated in 0.02036 seconds