Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » EditPart Policy and Figure Mouse Listener Conflict(EditPart Policy and Figure Mouse Listener Conflict)
EditPart Policy and Figure Mouse Listener Conflict [message #1406563] Sun, 10 August 2014 12:30 Go to next message
Juan Ting is currently offline Juan TingFriend
Messages: 3
Registered: August 2014
Junior Member
Hello,

I am facing a very weird problem. I dont know why the selection Policy of my EditPart stops working when I add to the associated figure of the EditPart a MouseListener.

Basically, I am installing for my EditPart a Selection Policy FeedBack to let the GraphicViewer highlight and select my EditPart, as well as to notify the property view with the new selection. So far so good, However, when I add to my Figure a Mouse listener to drag and move the figure. The GraphicViewer stops selecting the EditPart and notifying the Property View. I dont understand why. I try to install also a EditPolicy.Layout_Role to the RootEditPart to move my figures. It works, however the way of moving the figure using EditPolity.Layout_Role it is not what I am looking for. I dont like the way of moving the figures in this way because I cannot see the figure moving under the mouse, only the shadow of the moving figure. I dont get the same effect as using the Mouse Listener associated to the figure.


Could anyone tell me what I am doing wrong? I dont understand why the EditPart Selection stops working after addition the Mouse listener to the figure.

Thanks in advance.

Here you have the code that I am using.

MyRootEditPart
public class MyRootEditPart extends AbstractGraphicalEditPart 
{		

.... code here ....

	protected void createEditPolicies() 
	{
		// If this editpart is the root content of the viewer, then disallow
		// removal
		if (getParent() instanceof RootEditPart) {
			installEditPolicy(EditPolicy.COMPONENT_ROLE, new RootComponentEditPolicy());
			
		}
		
		// Handle Resize and Move the Children		
		installEditPolicy(EditPolicy.LAYOUT_ROLE, new MoveEditLayoutPolicy());
			
	}

.... code here ....
}


MyEditPart
public class MyEditPart extends AbstractGraphicalEditPart implements PropertyChangeListener
{
.... code here ....

    @Override
    protected void createEditPolicies()
    {                 
       
       	// Policy to Highlight the Figure when the mouse is hovering or then the EditPart
	// has been selected.
	installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, new HighLightEditPolicy((BlockNodeFigure)this.getFigure()));	        
       
    }

.... code here ....

}


MyBlockFigure
public class MyBlockFigure extends RoundedRectangle 
{

.... code here ....

	public MyBlockFigure(MyEditPart editpart) 
	{
                .... code here ....

		// Instantiate the Drag&Move Listener
		new DragAndMoveFigureMouseListener(this);						
	}

.... code here ....

}



MoveEditLayoutPolicy
public class MoveEditLayoutPolicy extends XYLayoutEditPolicy
{

	@Override
	protected Command createChangeConstraintCommand(EditPart child, Object constraint)
	{
		AbstractLayoutCommand command = null;
		if(child instanceof BlockModelEditPart)
		{
			command = new BlockModelLayoutCommand();
			command.setModel((BlockModel)child.getModel());
			command.setConstraint((Rectangle)constraint);		
		}
		
		return command;
	}

	
	
	@Override
	protected Command getCreateCommand(CreateRequest request) 
	{	
		return null;
	}

}


HighLightEditPolicy
public class HighLightEditPolicy extends SelectionEditPolicy 
{
	
	/** BlockModel Figure to be handled for this policy to be 
	 * highlighted or selected */ 
	MyBlockFigure figBlock = null;
	
	
	public HighLightEditPolicy(MyBlockFigure figure) 
	{
		super();
		this.figBlock = figure;
	}
	
	
	@Override
	protected void showSelection() 
	{
		figBlock.select();
	}

	
	@Override
	protected void hideSelection() 
	{	
		figBlock.deSelect();
	}
	
	
	@Override
	public void showTargetFeedback(Request request) 
	{
		figBlock.activateHighLight();
	}

	
	@Override
	public void eraseTargetFeedback(Request request)
	{		
		figBlock.deactiveHighLight();		
	}
		
}



MyBlockFigure
/** This Listener implements drag and drop for Draw2D Figure */
public class DragAndMoveFigureMouseListener implements MouseListener, MouseMotionListener{
	   

	/** */
	private Figure figure;
	
	/** */
	private Point location;

	/** Instance the Logger */
	private final static Logger LOGGER = Logger.getLogger(DragAndMoveFigureMouseListener.class.getName()); 
	

	/**
	 * constructor save reference to figure, then add listeners
	 * @param figure
	 */
	public DragAndMoveFigureMouseListener(Figure figure) 
	{
		this.figure = figure;
		figure.addMouseListener(this);	    
		figure.addMouseMotionListener(this);	    
	}


	@Override
	public void mousePressed(MouseEvent me) 
	{
		location = me.getLocation();
		me.consume();
	}


	@Override
	public void mouseReleased(MouseEvent me) 
	{
		if( location==null )
			return;

		location = null;

		me.consume();
	}
	
	public void mouseDragged(MouseEvent event) 
	{
		if (location == null)
			return;
		Point newLocation = event.getLocation();
		if (newLocation == null)
			return;
		Dimension offset = newLocation.getDifference(location);
		if (offset.width == 0 && offset.height == 0)
			return;
		location = newLocation;

		UpdateManager updateMgr = figure.getUpdateManager();
		LayoutManager layoutMgr = figure.getParent().getLayoutManager();
		Rectangle bounds = figure.getBounds();
		updateMgr.addDirtyRegion(figure.getParent(), bounds);
		bounds = bounds.getCopy().translate(offset.width, offset.height);
		layoutMgr.setConstraint(figure, bounds);
		figure.translate(offset.width, offset.height);
		updateMgr.addDirtyRegion(figure.getParent(), bounds);
		event.consume();
				
	}


	@Override
	public void mouseEntered(MouseEvent me) { }		  


	@Override
	public void mouseExited(MouseEvent me) { }


	@Override
	public void mouseHover(MouseEvent me) { }


	@Override
	public void mouseMoved(MouseEvent me) { }


	@Override
	public void mouseDoubleClicked(MouseEvent me) { }
}
Re: EditPart Policy and Figure Mouse Listener Conflict [message #1406672 is a reply to message #1406563] Sun, 10 August 2014 20:40 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
Could you try to remove the calls to 'me.consume()'?
Re: EditPart Policy and Figure Mouse Listener Conflict [message #1406693 is a reply to message #1406672] Sun, 10 August 2014 21:56 Go to previous message
Juan Ting is currently offline Juan TingFriend
Messages: 3
Registered: August 2014
Junior Member
Hello Alexander,

Thank your for your fast reply.

I commented all the "me.consume()" at the DragAndMoveFigureMouseListener, then the selection starts working but... the moving the Figure didnt work even I applied the DragAndMoveFigureMouseListener to it.


I noticed that is the me.consume() at the DragAndMoveFigureMouseListener.mousePressed() the one that generates the conflict.

Any solution? I really dont understand why this is happening.

Thanks
Previous Topic:[ZEST] Program Speed
Next Topic: HELP! SELECTIO FIGURE (SHAPE)
Goto Forum:
  


Current Time: Wed Apr 24 15:49:31 GMT 2024

Powered by FUDForum. Page generated in 0.03733 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top