Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Create a special figure
Create a special figure [message #167488] Wed, 09 February 2005 09:04 Go to next message
Eclipse UserFriend
Originally posted by: no.mail.please

Hi !

I need to create a figure for my application which would allow the user
to extend only EAST or SOUTH (or SOUTH_EAST).

So I would like to have handles only on two sides (EAST and SOUTH) and
on the lower right corner.

How can I make that ? (I need to have an image inside the figure, so
till now I worked with ImageFigure).

TIA

--
Arnaud
Re: Create a special figure [message #167515 is a reply to message #167488] Wed, 09 February 2005 12:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wjancz.\/\/asko.pl(change \/\/ with w)

> Hi !
>
> I need to create a figure for my application which would allow the user
> to extend only EAST or SOUTH (or SOUTH_EAST).
>
> So I would like to have handles only on two sides (EAST and SOUTH) and
> on the lower right corner.
>
> How can I make that ? (I need to have an image inside the figure, so
> till now I worked with ImageFigure).

Try installing a ResizableEditPolicy for children in your layout policy and
setResizeDirection to SOUTH_EAST:


protected EditPolicy createChildEditPolicy(EditPart child) {
ResizableEditPolicy policy = new ResizableEditPolicy();
policy.setResizeDirections(PositionConstants.SOUTH_EAST);
return policy;
}

this should help....

...::WojT::..
Re: Create a special figure [message #167546 is a reply to message #167515] Wed, 09 February 2005 17:15 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: no.mail.please

Thanks, but it doesn't work and I don't understand why (it keeps showing
me all the handles ).

I tried creating a subclass of ResizableEditPolicy and creating handles
only in the given directions, but it keeps showing me all the handles too.

I finally tried to prevent figure to be moved, but then again it fails
( I added :
understandsRequest(Request request) {
if(REQ_MOVE.equals(request.getType()))
return false;
in the layoueditpolicie)

The rules I put don't seem to be respected.
What do I miss ?

Please, have a look at my code below.

TIA

--
Arnaud

my editpart model is :
DiagramEditPart containing one or more BeanBoxEditPart itself containing
one or more ShapeEditPart.

------------------------------------------------------------ ---------------
DiagramEditPart : where I tried your solution
------------------------------------------------------------ ---------------
class DiagramEditPart extends AbstractGraphicalEditPart
implements PropertyChangeListener {

/**
* Upon activation, attach to the model element as a property change
listener.
*/
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
}
}

/**
* Upon deactivation, detach from the model element as a property
change listener.
*/
public void deactivate() {
if (isActive()) {
super.deactivate();
((ModelElement) getModel()).removePropertyChangeListener(this);
}
}

/* (non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicie s()
*/
protected void createEditPolicies() {
// disallows the removal of this edit part from its parent
installEditPolicy(EditPolicy.COMPONENT_ROLE, new
RootComponentEditPolicy());
// handles constraint changes (e.g. moving and/or resizing) of model
elements
// and creation of new model elements
XYLayout layout = (XYLayout) getContentPane().getLayoutManager();
installEditPolicy(EditPolicy.LAYOUT_ROLE, new
BeanBoxXYLayoutEditPolicy(layout));
// disable selection feedback for this edit part
installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, null);
}

/* (non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFi gure()
*/
protected IFigure createFigure() {
FreeformLayer f = new FreeformLayer();
f.setLayoutManager(new FreeformLayout());
f.setOpaque(true);
f.setBackgroundColor(ColorConstants.red);
return f;
}



private ShapesDiagram getCastedModel() {
return (ShapesDiagram) getModel();
}

/* (non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren( )
*/
protected List getModelChildren() {
return getCastedModel().getChildren(); // return a list of shapes
}

/* (non-Javadoc)
* @see
java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt) {
String prop = evt.getPropertyName();
// these properties are fired when Shapes are added into or removed from
// the ShapeDiagram instance and must cause a call of refreshChildren()
// to update the diagram's contents.
if (ShapesDiagram.CHILD_ADDED_PROP.equals(prop)
|| ShapesDiagram.CHILD_REMOVED_PROP.equals(prop)) {
refreshChildren();
}
}

/**
* EditPolicy for the Figure used by this edit part.
* Children of XYLayoutEditPolicy can be used in Figures with XYLayout.
* @author Elias Volanakis
*/
private class BeanBoxXYLayoutEditPolicy extends XYLayoutEditPolicy {

/**
* Create a new instance of this edit policy.
* @param layout a non-null XYLayout instance. This should be the
layout of the editpart's
* figure where this instance is installed.
* @throws IllegalArgumentException if layout is null
* @see DiagramEditPart#createEditPolicies()
*/
BeanBoxXYLayoutEditPolicy(XYLayout layout) {
if (layout == null) {
throw new IllegalArgumentException();
}
setXyLayout(layout);
}

/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateAddCommand(org.eclipse.gef.EditPart,
java.lang.Object)
*/
protected Command createAddCommand(EditPart child, Object constraint) {
// not used in this example
return null;
}


/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateChangeConstraintCommand(org.eclipse.gef.requests.ChangeBo undsRequest,
org.eclipse.gef.EditPart, java.lang.Object)
*/
protected Command createChangeConstraintCommand(ChangeBoundsRequest request,
EditPart child, Object constraint) {
/*if (child instanceof BeanBoxEditPart && constraint instanceof
Rectangle) {
// return a command that can move and/or resize a Shape
return new BeanBoxSetConstraintCommand(
(BeanBox) child.getModel(), request, (Rectangle) constraint);
}
return super.createChangeConstraintCommand(request, child, constraint);*/
return null;
}

/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateChangeConstraintCommand(org.eclipse.gef.EditPart,
java.lang.Object)
*/
protected Command createChangeConstraintCommand(EditPart child,
Object constraint) {
// not used in this example
return null;
}

/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateComma nd(org.eclipse.gef.requests.CreateRequest)
*/
protected Command getCreateCommand(CreateRequest request) {
Object childClass = request.getNewObjectType();
if (childClass == BeanBox.class) {
// return a command that can add a Shape to a ShapesDiagram
return new BeanBoxCreateCommand(DiagramEditPart.this.getCastedModel(),
request);
}
return null;
}

/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.LayoutEditPolicy#getDeleteDepen dantCommand(org.eclipse.gef.Request)
*/
protected Command getDeleteDependantCommand(Request request) {
// not used in this example
return null;
}

/*
* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.LayoutEditPolicy#createChildEdi tPolicy(org.eclipse.gef.EditPart)
*/
protected EditPolicy createChildEditPolicy(EditPart child) {
ResizableEditPolicy policy = new ResizableEditPolicy();
policy.setResizeDirections(PositionConstants.SOUTH_EAST);
return policy;
}

}

}


------------------------------------------------------------ ----------------
BeanBoxEditPart : where I tried to create handles on south and east side
------------------------------------------------------------ ----------------
class BeanBoxEditPart extends AbstractGraphicalEditPart
implements PropertyChangeListener {

private IFigure contentPane;

/**
* Upon activation, attach to the model element as a property change
listener.
*/
public void activate() {
if (!isActive()) {
super.activate();
((ModelElement) getModel()).addPropertyChangeListener(this);
}
}

/**
* Upon deactivation, detach from the model element as a property
change listener.
*/
public void deactivate() {
if (isActive()) {
super.deactivate();
((ModelElement) getModel()).removePropertyChangeListener(this);
}
}

/* (non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicie s()
*/
protected void createEditPolicies() {
// allow removal of the associated model element
//installEditPolicy(EditPolicy.COMPONENT_ROLE, new
ShapeComponentEditPolicy());
// handles constraint changes (e.g. moving and/or resizing) of model
elements
// and creation of new model elements
XYLayout layout = (XYLayout) getContentPane().getLayoutManager();
installEditPolicy(EditPolicy.LAYOUT_ROLE, new
ShapesXYLayoutEditPolicy(layout));
}

/*(non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFi gure()
*/
protected IFigure createFigure() {
IFigure f = new RectangleFigure();
XYLayout layout = new XYLayout();
f.setLayoutManager(layout);
f.setOpaque(true);
f.setBackgroundColor(ColorConstants.lightBlue);

contentPane = new RectangleFigure();
contentPane.setLayoutManager(new FreeformLayout());
contentPane.setOpaque(true);
contentPane.setBackgroundColor(ColorConstants.gray);

f.add(contentPane);

return f;
}


private BeanBox getCastedModel() {
return (BeanBox) getModel();
}

/* (non-Javadoc)
* @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren( )
*/
protected List getModelChildren() {
return getCastedModel().getChildren(); // return a list of shapes
}

/*
* (non-Javadoc)
* @see org.eclipse.gef.GraphicalEditPart#getContentPane()
*/
public IFigure getContentPane(){
return contentPane;
}

/* (non-Javadoc)
* @see
java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEvent)
*/
public void propertyChange(PropertyChangeEvent evt) {
String prop = evt.getPropertyName();
if (BeanBox.SIZE_PROP.equals(prop) || BeanBox.LOCATION_PROP.equals(prop)) {
refreshVisuals();
}
// these properties are fired when Shapes are added into or removed from
// the ShapeDiagram instance and must cause a call of refreshChildren()
// to update the diagram's contents.
if (BeanBox.CHILD_ADDED_PROP.equals(prop)
|| BeanBox.CHILD_REMOVED_PROP.equals(prop)) {
refreshChildren();
}
}

protected void refreshVisuals() {
// notify parent container of changed position & location
// if this line is removed, the XYLayoutManager used by the parent
container
// (the Figure of the ShapesDiagramEditPart), will not know the bounds
of this figure
// and will not draw it correctly.
Rectangle bounds = new Rectangle(getCastedModel().getLocation(),
getCastedModel().getSize());

Rectangle childbounds = new Rectangle(10, 10, bounds.width - 20,
bounds.height - 20);
XYLayout layout = (XYLayout) getFigure().getLayoutManager();
layout.setConstraint(contentPane, childbounds);

((GraphicalEditPart) getParent()).setLayoutConstraint(this,
getFigure(), bounds);
}

/**
* EditPolicy for the Figure used by this edit part.
* Children of XYLayoutEditPolicy can be used in Figures with XYLayout.
*/
public class ShapesXYLayoutEditPolicy extends XYLayoutEditPolicy {

/**
* Create a new instance of this edit policy.
* @param layout a non-null XYLayout instance. This should be the
layout of the editpart's
* figure where this instance is installed.
* @throws IllegalArgumentException if layout is null
* @see BeanBoxEditPart#createEditPolicies()
*/
ShapesXYLayoutEditPolicy(XYLayout layout) {
if (layout == null) {
throw new IllegalArgumentException();
}
setXyLayout(layout);
}

/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateAddCommand(org.eclipse.gef.EditPart,
java.lang.Object)
*/
protected Command createAddCommand(EditPart child, Object constraint) {
// not used in this example
return null;
}


/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateChangeConstraintCommand(org.eclipse.gef.requests.ChangeBo undsRequest,
org.eclipse.gef.EditPart, java.lang.Object)
*/
protected Command createChangeConstraintCommand(ChangeBoundsRequest request,
EditPart child, Object constraint) {
if (child instanceof ShapeEditPart && constraint instanceof Rectangle) {
// return a command that can move and/or resize a Shape
return new ShapeSetConstraintCommand(
(Shape) child.getModel(), request, (Rectangle) constraint);
}
return super.createChangeConstraintCommand(request, child, constraint);
}

/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateChangeConstraintCommand(org.eclipse.gef.EditPart,
java.lang.Object)
*/
protected Command createChangeConstraintCommand(EditPart child,
Object constraint) {
// not used in this example
return null;
}

/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateComma nd(org.eclipse.gef.requests.CreateRequest)
*/
protected Command getCreateCommand(CreateRequest request) {
Object childClass = request.getNewObjectType();
if (childClass == Shape.class) {
// return a command that can add a Shape to a BeanBox
return new ShapeCreateCommand(BeanBoxEditPart.this.getCastedModel(),
request);
}
return null;
}

/* (non-Javadoc)
* @see
org.eclipse.gef.editpolicies.LayoutEditPolicy#getDeleteDepen dantCommand(org.eclipse.gef.Request)
*/
protected Command getDeleteDependantCommand(Request request) {
// not used in this example
return null;
}

protected List createSelectionHandles() {
List list = new ArrayList();
addHandles((GraphicalEditPart)this.getHost(), list);
return list;
}

public boolean understandsRequest(Request request) {
if(REQ_MOVE.equals(request.getType()))
return false;
else
return super.understandsRequest(request);
}

public void showSourceFeedback(Request request) {
super.showSourceFeedback(request);
}

public void eraseSourceFeedback(Request request) {
super.eraseSourceFeedback(request);
}

public void addHandles(GraphicalEditPart part, List handles) {
handles.add(createHandle(part, PositionConstants.SOUTH));
handles.add(createHandle(part, PositionConstants.EAST));
handles.add(createHandle(part, PositionConstants.SOUTH_EAST));
}

Handle createHandle(GraphicalEditPart part, int direction) {
ResizeHandle handle = new ResizeHandle(part, direction);
handle.setDragTracker(new ResizeTracker(part, direction));
return handle;
}

}

}
Re: Create a special figure [message #167577 is a reply to message #167546] Wed, 09 February 2005 19:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

This prevents resizing but not moving. The handles which are added have
move dragtrackers. Open a new feature request in bugzilla. You should be
able to fix this problem with some code. Maybe get the handles and replace
their dragtrackers with NULL or something.

"Arnaud" <no@mail.please> escreveu na mensagem
news:cudgg3$5ek$1@www.eclipse.org...
> Thanks, but it doesn't work and I don't understand why (it keeps showing
> me all the handles ).
>
> I tried creating a subclass of ResizableEditPolicy and creating handles
> only in the given directions, but it keeps showing me all the handles too.
>
> I finally tried to prevent figure to be moved, but then again it fails
> ( I added :
> understandsRequest(Request request) {
> if(REQ_MOVE.equals(request.getType()))
> return false;
> in the layoueditpolicie)
>
> The rules I put don't seem to be respected.
> What do I miss ?
>
> Please, have a look at my code below.
>
> TIA
>
> --
> Arnaud
>
> my editpart model is :
> DiagramEditPart containing one or more BeanBoxEditPart itself containing
> one or more ShapeEditPart.
>
> ------------------------------------------------------------ ---------------
> DiagramEditPart : where I tried your solution
> ------------------------------------------------------------ ---------------
> class DiagramEditPart extends AbstractGraphicalEditPart
> implements PropertyChangeListener {
>
> /**
> * Upon activation, attach to the model element as a property change
> listener.
> */
> public void activate() {
> if (!isActive()) {
> super.activate();
> ((ModelElement) getModel()).addPropertyChangeListener(this);
> }
> }
>
> /**
> * Upon deactivation, detach from the model element as a property change
> listener.
> */
> public void deactivate() {
> if (isActive()) {
> super.deactivate();
> ((ModelElement) getModel()).removePropertyChangeListener(this);
> }
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicie s()
> */
> protected void createEditPolicies() {
> // disallows the removal of this edit part from its parent
> installEditPolicy(EditPolicy.COMPONENT_ROLE, new
> RootComponentEditPolicy());
> // handles constraint changes (e.g. moving and/or resizing) of model
> elements
> // and creation of new model elements
> XYLayout layout = (XYLayout) getContentPane().getLayoutManager();
> installEditPolicy(EditPolicy.LAYOUT_ROLE, new
> BeanBoxXYLayoutEditPolicy(layout));
> // disable selection feedback for this edit part
> installEditPolicy(EditPolicy.SELECTION_FEEDBACK_ROLE, null);
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFi gure()
> */
> protected IFigure createFigure() {
> FreeformLayer f = new FreeformLayer();
> f.setLayoutManager(new FreeformLayout());
> f.setOpaque(true);
> f.setBackgroundColor(ColorConstants.red);
> return f;
> }
>
>
>
> private ShapesDiagram getCastedModel() {
> return (ShapesDiagram) getModel();
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren( )
> */
> protected List getModelChildren() {
> return getCastedModel().getChildren(); // return a list of shapes
> }
>
> /* (non-Javadoc)
> * @see
> java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEvent)
> */
> public void propertyChange(PropertyChangeEvent evt) {
> String prop = evt.getPropertyName();
> // these properties are fired when Shapes are added into or removed from
> // the ShapeDiagram instance and must cause a call of refreshChildren()
> // to update the diagram's contents.
> if (ShapesDiagram.CHILD_ADDED_PROP.equals(prop)
> || ShapesDiagram.CHILD_REMOVED_PROP.equals(prop)) {
> refreshChildren();
> }
> }
>
> /**
> * EditPolicy for the Figure used by this edit part.
> * Children of XYLayoutEditPolicy can be used in Figures with XYLayout.
> * @author Elias Volanakis
> */
> private class BeanBoxXYLayoutEditPolicy extends XYLayoutEditPolicy {
>
> /**
> * Create a new instance of this edit policy.
> * @param layout a non-null XYLayout instance. This should be the layout
> of the editpart's
> * figure where this instance is installed.
> * @throws IllegalArgumentException if layout is null
> * @see DiagramEditPart#createEditPolicies()
> */
> BeanBoxXYLayoutEditPolicy(XYLayout layout) {
> if (layout == null) {
> throw new IllegalArgumentException();
> }
> setXyLayout(layout);
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateAddCommand(org.eclipse.gef.EditPart,
> java.lang.Object)
> */
> protected Command createAddCommand(EditPart child, Object constraint) {
> // not used in this example
> return null;
> }
>
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateChangeConstraintCommand(org.eclipse.gef.requests.ChangeBo undsRequest,
> org.eclipse.gef.EditPart, java.lang.Object)
> */
> protected Command createChangeConstraintCommand(ChangeBoundsRequest
> request,
> EditPart child, Object constraint) {
> /*if (child instanceof BeanBoxEditPart && constraint instanceof Rectangle)
> {
> // return a command that can move and/or resize a Shape
> return new BeanBoxSetConstraintCommand(
> (BeanBox) child.getModel(), request, (Rectangle) constraint);
> }
> return super.createChangeConstraintCommand(request, child, constraint);*/
> return null;
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateChangeConstraintCommand(org.eclipse.gef.EditPart,
> java.lang.Object)
> */
> protected Command createChangeConstraintCommand(EditPart child,
> Object constraint) {
> // not used in this example
> return null;
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateComma nd(org.eclipse.gef.requests.CreateRequest)
> */
> protected Command getCreateCommand(CreateRequest request) {
> Object childClass = request.getNewObjectType();
> if (childClass == BeanBox.class) {
> // return a command that can add a Shape to a ShapesDiagram
> return new BeanBoxCreateCommand(DiagramEditPart.this.getCastedModel(),
> request);
> }
> return null;
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.LayoutEditPolicy#getDeleteDepen dantCommand(org.eclipse.gef.Request)
> */
> protected Command getDeleteDependantCommand(Request request) {
> // not used in this example
> return null;
> }
>
> /*
> * (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.LayoutEditPolicy#createChildEdi tPolicy(org.eclipse.gef.EditPart)
> */
> protected EditPolicy createChildEditPolicy(EditPart child) {
> ResizableEditPolicy policy = new ResizableEditPolicy();
> policy.setResizeDirections(PositionConstants.SOUTH_EAST);
> return policy;
> }
>
> }
>
> }
>
>
> ------------------------------------------------------------ ----------------
> BeanBoxEditPart : where I tried to create handles on south and east side
> ------------------------------------------------------------ ----------------
> class BeanBoxEditPart extends AbstractGraphicalEditPart
> implements PropertyChangeListener {
>
> private IFigure contentPane;
>
> /**
> * Upon activation, attach to the model element as a property change
> listener.
> */
> public void activate() {
> if (!isActive()) {
> super.activate();
> ((ModelElement) getModel()).addPropertyChangeListener(this);
> }
> }
>
> /**
> * Upon deactivation, detach from the model element as a property change
> listener.
> */
> public void deactivate() {
> if (isActive()) {
> super.deactivate();
> ((ModelElement) getModel()).removePropertyChangeListener(this);
> }
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicie s()
> */
> protected void createEditPolicies() {
> // allow removal of the associated model element
> //installEditPolicy(EditPolicy.COMPONENT_ROLE, new
> ShapeComponentEditPolicy());
> // handles constraint changes (e.g. moving and/or resizing) of model
> elements
> // and creation of new model elements
> XYLayout layout = (XYLayout) getContentPane().getLayoutManager();
> installEditPolicy(EditPolicy.LAYOUT_ROLE, new
> ShapesXYLayoutEditPolicy(layout));
> }
>
> /*(non-Javadoc)
> * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFi gure()
> */
> protected IFigure createFigure() {
> IFigure f = new RectangleFigure();
> XYLayout layout = new XYLayout();
> f.setLayoutManager(layout);
> f.setOpaque(true);
> f.setBackgroundColor(ColorConstants.lightBlue);
>
> contentPane = new RectangleFigure();
> contentPane.setLayoutManager(new FreeformLayout());
> contentPane.setOpaque(true);
> contentPane.setBackgroundColor(ColorConstants.gray);
>
> f.add(contentPane);
>
> return f;
> }
>
>
> private BeanBox getCastedModel() {
> return (BeanBox) getModel();
> }
>
> /* (non-Javadoc)
> * @see org.eclipse.gef.editparts.AbstractEditPart#getModelChildren( )
> */
> protected List getModelChildren() {
> return getCastedModel().getChildren(); // return a list of shapes
> }
>
> /*
> * (non-Javadoc)
> * @see org.eclipse.gef.GraphicalEditPart#getContentPane()
> */
> public IFigure getContentPane(){
> return contentPane;
> }
>
> /* (non-Javadoc)
> * @see
> java.beans.PropertyChangeListener#propertyChange(java.beans. PropertyChangeEvent)
> */
> public void propertyChange(PropertyChangeEvent evt) {
> String prop = evt.getPropertyName();
> if (BeanBox.SIZE_PROP.equals(prop) || BeanBox.LOCATION_PROP.equals(prop))
> {
> refreshVisuals();
> }
> // these properties are fired when Shapes are added into or removed from
> // the ShapeDiagram instance and must cause a call of refreshChildren()
> // to update the diagram's contents.
> if (BeanBox.CHILD_ADDED_PROP.equals(prop)
> || BeanBox.CHILD_REMOVED_PROP.equals(prop)) {
> refreshChildren();
> }
> }
>
> protected void refreshVisuals() {
> // notify parent container of changed position & location
> // if this line is removed, the XYLayoutManager used by the parent
> container
> // (the Figure of the ShapesDiagramEditPart), will not know the bounds of
> this figure
> // and will not draw it correctly.
> Rectangle bounds = new Rectangle(getCastedModel().getLocation(),
> getCastedModel().getSize());
>
> Rectangle childbounds = new Rectangle(10, 10, bounds.width - 20,
> bounds.height - 20);
> XYLayout layout = (XYLayout) getFigure().getLayoutManager();
> layout.setConstraint(contentPane, childbounds);
>
> ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(),
> bounds);
> }
>
> /**
> * EditPolicy for the Figure used by this edit part.
> * Children of XYLayoutEditPolicy can be used in Figures with XYLayout.
> */
> public class ShapesXYLayoutEditPolicy extends XYLayoutEditPolicy {
>
> /**
> * Create a new instance of this edit policy.
> * @param layout a non-null XYLayout instance. This should be the layout
> of the editpart's
> * figure where this instance is installed.
> * @throws IllegalArgumentException if layout is null
> * @see BeanBoxEditPart#createEditPolicies()
> */
> ShapesXYLayoutEditPolicy(XYLayout layout) {
> if (layout == null) {
> throw new IllegalArgumentException();
> }
> setXyLayout(layout);
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateAddCommand(org.eclipse.gef.EditPart,
> java.lang.Object)
> */
> protected Command createAddCommand(EditPart child, Object constraint) {
> // not used in this example
> return null;
> }
>
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateChangeConstraintCommand(org.eclipse.gef.requests.ChangeBo undsRequest,
> org.eclipse.gef.EditPart, java.lang.Object)
> */
> protected Command createChangeConstraintCommand(ChangeBoundsRequest
> request,
> EditPart child, Object constraint) {
> if (child instanceof ShapeEditPart && constraint instanceof Rectangle) {
> // return a command that can move and/or resize a Shape
> return new ShapeSetConstraintCommand(
> (Shape) child.getModel(), request, (Rectangle) constraint);
> }
> return super.createChangeConstraintCommand(request, child, constraint);
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.ConstrainedLayoutEditPolicy#cre ateChangeConstraintCommand(org.eclipse.gef.EditPart,
> java.lang.Object)
> */
> protected Command createChangeConstraintCommand(EditPart child,
> Object constraint) {
> // not used in this example
> return null;
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateComma nd(org.eclipse.gef.requests.CreateRequest)
> */
> protected Command getCreateCommand(CreateRequest request) {
> Object childClass = request.getNewObjectType();
> if (childClass == Shape.class) {
> // return a command that can add a Shape to a BeanBox
> return new ShapeCreateCommand(BeanBoxEditPart.this.getCastedModel(),
> request);
> }
> return null;
> }
>
> /* (non-Javadoc)
> * @see
> org.eclipse.gef.editpolicies.LayoutEditPolicy#getDeleteDepen dantCommand(org.eclipse.gef.Request)
> */
> protected Command getDeleteDependantCommand(Request request) {
> // not used in this example
> return null;
> }
>
> protected List createSelectionHandles() {
> List list = new ArrayList();
> addHandles((GraphicalEditPart)this.getHost(), list);
> return list;
> }
>
> public boolean understandsRequest(Request request) {
> if(REQ_MOVE.equals(request.getType()))
> return false;
> else
> return super.understandsRequest(request);
> }
>
> public void showSourceFeedback(Request request) {
> super.showSourceFeedback(request);
> }
>
> public void eraseSourceFeedback(Request request) {
> super.eraseSourceFeedback(request);
> }
>
> public void addHandles(GraphicalEditPart part, List handles) {
> handles.add(createHandle(part, PositionConstants.SOUTH));
> handles.add(createHandle(part, PositionConstants.EAST));
> handles.add(createHandle(part, PositionConstants.SOUTH_EAST));
> }
>
> Handle createHandle(GraphicalEditPart part, int direction) {
> ResizeHandle handle = new ResizeHandle(part, direction);
> handle.setDragTracker(new ResizeTracker(part, direction));
> return handle;
> }
>
> }
>
> }
Re: Create a special figure [message #167606 is a reply to message #167577] Wed, 09 February 2005 21:27 Go to previous message
Eclipse UserFriend
Originally posted by: no.mail.please

OK, I found a really simple solution.
I changed the createChangeConstraintCommand in DiagramEditPart, so it
doesn't allow to resize in the NORTH/WEST directions or to move the child :

protected Command createChangeConstraintCommand(ChangeBoundsRequest request,
EditPart child, Object constraint) {
if (child instanceof BeanBoxEditPart && constraint instanceof Rectangle) {
// return a command that can move and/or resize a Shape
Object type = request.getType();
if(RequestConstants.REQ_MOVE.equals(type)
|| RequestConstants.REQ_MOVE_CHILDREN.equals(type)) {
return null;
} else {
int handle = request.getResizeDirection();
if ((handle == PositionConstants.WEST) || (handle ==
PositionConstants.NORTH) || (handle == PositionConstants.NORTH_WEST) ||
(handle == PositionConstants.NORTH_EAST) || (handle ==
PositionConstants.SOUTH_WEST)){
return null;
}
return new BeanBoxSetConstraintCommand((BeanBox) child.getModel(),
request, (Rectangle) constraint);
}

}
return null;
}
Previous Topic:What is the Best place to dispose Images
Next Topic:Moving figures requires two steps??
Goto Forum:
  


Current Time: Sat Apr 27 03:44:27 GMT 2024

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

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

Back to the top