Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Child EditPart with Sliders
Child EditPart with Sliders [message #195823] Tue, 13 September 2005 16:28 Go to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
Hi,
Re: Child EditPart with Sliders [message #195831 is a reply to message #195823] Tue, 13 September 2005 16:41 Go to previous messageGo to next message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
I'm trying to create a UML2.0 StateDiagram.
I need to add Concurrent sub states to States.
In UML2 these concurrent sub states divide up the parent State into
contigous vertically tiled areas separated by a dotted line.
I wish to make these lines moveable so that the User can expand the sub
states.
The parent State might have something like a toolbar layout into which the
child substates are placed, but I need then to make the child sub states
non moveable but resizeable. Further the feedback needs to be a horizontal
bar without anchors, rather like Sashes in SWT.
Can anyone suggest a suitable example to start with, or at least a Layout
which will tiles the children horizontally and an accompanying EditPolicy
to allow them to be resized?

Thanks
Re: Child EditPart with Sliders [message #195913 is a reply to message #195831] Wed, 14 September 2005 09:51 Go to previous message
J F is currently offline J FFriend
Messages: 256
Registered: July 2009
Senior Member
The following example class shows an edit policy that works with a Layout
container to constrain children to move, resize in the vertical direction
with appropriate feedback.


package regionTestEditor.parts;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PrecisionRectangle;
import org.eclipse.gef.GraphicalEditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.handles.NonResizableHandleKit;
import org.eclipse.gef.handles.ResizableHandleKit;
import org.eclipse.gef.requests.ChangeBoundsRequest;

/**
* A Test example that shows an edit policy that constrains a figure to
move or resize
* in the vertical dimension only.

* The source is mostly copied from ResizeableEditPolicy, but only
* createSelectionHandles
* showChangeBoundsFeedback
* are changed
*
* A Better implementation would override ResizeableEditPolicy directly,
this was just a self learning exercise
*
* To use merely install on the layout container which wishes children to
be moved, resized vertically only.
*/
public class VerticalOnlyResizableEditPolicy extends NonResizableEditPolicy
{

private int directions = -1;

/**
* @see
org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#crea teSelectionHandles()
*/
protected List createSelectionHandles()
{
List list = new ArrayList();

if(directions == 0)
NonResizableHandleKit.addHandles((GraphicalEditPart) getHost(), list);
else if(directions != -1)
{
ResizableHandleKit.addMoveHandle((GraphicalEditPart) getHost(), list);
if((directions & PositionConstants.SOUTH) != 0)
ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list,
PositionConstants.SOUTH);
else
NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list,
PositionConstants.SOUTH);
if((directions & PositionConstants.NORTH) != 0)
ResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list,
PositionConstants.NORTH);
else
NonResizableHandleKit.addHandle((GraphicalEditPart) getHost(), list,
PositionConstants.NORTH);
}
else
ResizableHandleKit.addHandles((GraphicalEditPart) getHost(), list);

return list;
}

/**
* Dispatches erase requests to more specific methods.
*
* @see
org.eclipse.gef.EditPolicy#eraseSourceFeedback(org.eclipse.g ef.Request)
*/
public void eraseSourceFeedback(Request request)
{
if(REQ_RESIZE.equals(request.getType()))
{
System.out.println("Change bounds feed back y delta is " +
((ChangeBoundsRequest) request).getResizeDirection());
eraseChangeBoundsFeedback((ChangeBoundsRequest) request);
}
else
{
if(REQ_MOVE.equals(request.getType()))
{
System.out.println("Move feed back y delta is " +
((ChangeBoundsRequest) request).getMoveDelta().y);
}
super.eraseSourceFeedback(request);
}
}

/**
* @see org.eclipse.gef.EditPolicy#getCommand(org.eclipse.gef.Reques t)
*/
public Command getCommand(Request request)
{
if(REQ_RESIZE.equals(request.getType()))
return getResizeCommand((ChangeBoundsRequest) request);

return super.getCommand(request);
}

/**
* Returns the current resize directions integer that depicts which
handles
* can be resized on this object.
*
* @return handle directions that can be resized
*/
public int getResizeDirections()
{
return directions;
}

/**
* Returns the command contribution for the given resize request. By
* default, the request is redispatched to the host's parent as a {@link
* org.eclipse.gef.RequestConstants#REQ_RESIZE_CHILDREN}. The parent's
* editpolicies determine how to perform the resize based on the layout
* manager in use.
*
* @param request
* the resize request
* @return the command contribution obtained from the parent
*/
protected Command getResizeCommand(ChangeBoundsRequest request)
{
ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_RESIZE_CHILDREN);
req.setEditParts(getHost());

req.setMoveDelta(request.getMoveDelta());
req.setSizeDelta(request.getSizeDelta());
req.setLocation(request.getLocation());
req.setExtendedData(request.getExtendedData());
req.setResizeDirection(request.getResizeDirection());
return getHost().getParent().getCommand(req);
}

/**
* Sets the directions in which handles should allow resizing. Valid
values
* are bit-wise combinations of:
* <UL>
* <LI>{@link PositionConstants#NORTH}
* <LI>{@link PositionConstants#SOUTH}
* <LI>{@link PositionConstants#EAST}
* <LI>{@link PositionConstants#WEST}
* </UL>
*
* @param newDirections
* the direction in which resizing is allowed
*/
public void setResizeDirections(int newDirections)
{
directions = newDirections;
}

/**
* @see
org.eclipse.gef.EditPolicy#showSourceFeedback(org.eclipse.ge f.Request)
*/
public void showSourceFeedback(Request request)
{
if(REQ_RESIZE.equals(request.getType()))
showChangeBoundsFeedback((ChangeBoundsRequest) request);
else
super.showSourceFeedback(request);
}

/**
* @see
org.eclipse.gef.EditPolicy#understandsRequest(org.eclipse.ge f.Request)
*/
public boolean understandsRequest(Request request)
{
if(REQ_RESIZE.equals(request.getType()))
return true;
return super.understandsRequest(request);
}

protected void showChangeBoundsFeedback(ChangeBoundsRequest request)
{
IFigure feedback = getDragSourceFeedbackFigure();

PrecisionRectangle rect = new
PrecisionRectangle(getInitialFeedbackBounds().getCopy());
getHostFigure().translateToAbsolute(rect);
System.out.println("Feedback rectangle x=" + request.getMoveDelta().x +
", y=" + request.getMoveDelta().y);
Point verticallyConstrainedPoint = request.getMoveDelta();
verticallyConstrainedPoint.x = 0;
rect.translate(verticallyConstrainedPoint);
rect.resize(request.getSizeDelta());

feedback.translateToRelative(rect);
feedback.setBounds(rect);
}

}
Previous Topic:Open multiple editors and associating the editors with every figure
Next Topic:problems with reveal
Goto Forum:
  


Current Time: Fri Apr 19 12:57:53 GMT 2024

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

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

Back to the top