Skip to main content



      Home
Home » Eclipse Projects » GEF » Paintorder of editparts?
Paintorder of editparts? [message #172614] Sun, 20 March 2005 11:23 Go to next message
Eclipse UserFriend
Originally posted by: max.larsson.abz-informatik.de

Hello,

i've a wired problem, which poped up suddenly.
I ahve a root editpart, which loads a jpeg image
as a background and adds a border with 20 pixels.

My problem is now that child editparts with postion
in the jpeg image area aren't shown. But if
they are located in border i can see them.

Anyone an ides what that could be, i would gues
it has to do something with the paint order of
editparts, bit i could find anything about how
to influence it. help neede.


regards


Max
Re: Paintorder of editparts? [message #172689 is a reply to message #172614] Mon, 21 March 2005 10:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.us.ibm.com

> i've a wired problem, which poped up suddenly.
> I ahve a root editpart, which loads a jpeg image
> as a background and adds a border with 20 pixels.
>
> My problem is now that child editparts with postion
> in the jpeg image area aren't shown. But if
> they are located in border i can see them.
>

This sounds pretty strange. Children should not appear on top of borders,
and your image should be behind the children. Are you overriding
paintFigure to paint the background image? It's hard to diagnose the
problem without code or more information. Do you have just one level of
container? (diagram + children)?

> Anyone an ides what that could be, i would gues
> it has to do something with the paint order of
> editparts, bit i could find anything about how
> to influence it. help neede.
>
>
> regards
>
>
> Max
Re: Paintorder of editparts? [message #172850 is a reply to message #172689] Mon, 21 March 2005 15:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: max.larsson.abz-informatik.de

Randy Hudson wrote:
>>i've a wired problem, which poped up suddenly.
>>I ahve a root editpart, which loads a jpeg image
>>as a background and adds a border with 20 pixels.
>>
>>My problem is now that child editparts with postion
>>in the jpeg image area aren't shown. But if
>>they are located in border i can see them.
>>
>
>
> This sounds pretty strange. Children should not appear on top of borders,
> and your image should be behind the children. Are you overriding
> paintFigure to paint the background image? It's hard to diagnose the
> problem without code or more information. Do you have just one level of
> container? (diagram + children)?

I will try to explain as such as possible. First of all i am instanting
my editor in the folloowing way:

But i don't thing that has to do soething with it.

My Model is like this:

public class Edge {
// Helper object for change notification. This will not be persisted.

transient private PropertyChangeSupport propertyChangeSupport;

final private Edges parent;
private int x;
private int y;

Edge( final Edges eParent,final int iX,final int iY ) {
parent = eParent;
x = iX;
y = iY;
}

public Edges getEdges() {
return parent;
}

public int getX() {
return x;
}

public void setX( int iX ) {
final int old = x;
x = iX;
firePropertyChange( "coordinates",old,x );
}

public int getY() {
return y;
}

public void setY( int iY ) {
final int old = y;
y = iY;
firePropertyChange( "coordinates",old,y );
}

// methods for bean bahviour about changes

private PropertyChangeSupport getPropertyChangeSupport() {
if (propertyChangeSupport == null) {
propertyChangeSupport = new PropertyChangeSupport( this );
}
return propertyChangeSupport;
}

public void addPropertyChangeListener( PropertyChangeListener
listener) {
getPropertyChangeSupport().addPropertyChangeListener( listener );
}

public void removePropertyChangeListener( PropertyChangeListener
listener ) {
getPropertyChangeSupport().removePropertyChangeListener(
listener );
}

protected void firePropertyChange( String propertyName,int
oldValue,int newValue ) {
getPropertyChangeSupport().firePropertyChange(
propertyName,oldValue,newValue );
}
}


public class Edges implements List {
final private FacilityDOMObject parent;

final private List list = new ArrayList( 4 );

Edges( final FacilityDOMObject fbParent ) {
parent = fbParent;
add( new Edge( this,10,10 ) );
add( new Edge( this,90,10 ) );
add( new Edge( this,90,90 ) );
add( new Edge( this,10,90 ) );
}

public FacilityDOMObject getFacilityDOMObject() {
return parent;
}

private double calcDistance( final Edge start,final Edge end ) {
return Math.sqrt( Math.pow( start.getX() - end.getX(),2 ) + Math.pow(
start.getY() - end.getY(),2 ) );
}

public boolean add( final Object obj ) {
if( ! ( obj instanceof Edge ) )
throw new IllegalArgumentException( "Edges only contains edge
classes!" );
// search the position within the edges
if( list.size() > 2 ) {
final Edge nw = (Edge)obj;
final Edge[] nearest = new Edge[] { (Edge)list.get( 0
),(Edge)list.get( 1 ) };
final double[] distance = new double[] { calcDistance(
nw,(Edge)list.get( 0 ) ),calcDistance( nw,(Edge)list.get( 1 ) ) };
for( int loop = 2;loop < list.size();loop++ ) {
final Edge edge = (Edge)list.get( loop );
final double dist = calcDistance( nw,edge );
if( distance[0] > distance[1] ) {
if( dist < distance[0] ) {
distance[0] = dist;
nearest[0] = edge;
}
}
else {
if( dist <= distance[1] ) {
distance[1] = dist;
nearest[1] = edge;
}
}
}
final int min = Math.min( list.indexOf( nearest[0] ),list.indexOf(
nearest[1] ) );
if( min == 0 )
list.add( Math.max( list.indexOf( nearest[0] ),list.indexOf(
nearest[1] ) ) + 1,obj );
else
list.add( min + 1,obj );
}
else
list.add( obj );

if( list.contains( obj ) ) {
parent.firePropertyChange( "newedge",null,obj );
return true;
}
return false;
}

public void add( final int index,final Object element ) {
list.add( index,element );
}

public boolean addAll( final int index,final Collection c ) {
return list.addAll( index,c );
}

public boolean addAll( final Collection c ) {
return list.addAll( c );
}

public void clear() {
list.clear();
}

public boolean contains( final Object o ) {
return list.contains( o );
}

public boolean containsAll( final Collection c ) {
return list.containsAll( c );
}

public boolean equals( final Object obj ) {
return list.equals( obj );
}

public Object get( final int index ) {
return list.get( index );
}

public int hashCode() {
return list.hashCode();
}

public int indexOf( final Object o ) {
return list.indexOf( o );
}

public boolean isEmpty() {
return list.isEmpty();
}

public Iterator iterator() {
return list.iterator();
}

public int lastIndexOf( final Object o ) {
return list.lastIndexOf( o );
}

public ListIterator listIterator() {
return list.listIterator();
}

public ListIterator listIterator( final int index ) {
return list.listIterator( index );
}

public Object remove( final int index ) {
return list.remove( index );
}

public boolean remove( final Object obj ) {
if( ! ( obj instanceof Edge ) )
throw new IllegalArgumentException( "Edges only contains edge
classes!" );

if( list.remove( obj ) ) {
parent.firePropertyChange( "rmeoveedge",obj,null );
return true;
}
return false;
}

public boolean removeAll( final Collection c ) {
return list.removeAll( c );
}

public boolean retainAll( final Collection c ) {
return list.retainAll( c );
}

public Object set( final int index,final Object element ) {
return list.set( index,element );
}

public int size() {
return list.size();
}

public List subList( final int fromIndex,final int toIndex ) {
return list.subList( fromIndex,toIndex );
}

public Object[] toArray() {
return list.toArray();
}

public Object[] toArray( final Object[] a ) {
return list.toArray( a );
}

public String toString() {
return "Edges: " + list.toString();
}
}


abstract public class FacilityDOMObject {
// Helper object for change notification. This will not be persisted.
transient private PropertyChangeSupport propertyChangeSupport;

final private Edges edges;

private FacilityDOMGroup parent;
private String name;

private boolean useparents = true;
private File file = null;
private Image image = null;

protected FacilityDOMObject( final String sName ) {
name = sName;
edges = new Edges( this );
}

public void dispose() {
if( parent != null )
parent.remove( this );
if( image != null )
image.dispose();
}

protected void finalize() throws Throwable {
parent = null;
file = null;
image = null;
}

protected void setParent( final FacilityDOMGroup parentGroup ) throws
IllegalArgumentException {
if( parentGroup != null )
parentGroup.acceptFacilityDOMObject( this );
parent = parentGroup;
if( parent == null )
useparents = false; // TODO: maybe throw indication that connection
will be lost?
}

abstract public void acceptVisitor( final FacilitDOMVisitor visitor );

final public void setName( final String sNewName ) throws
IllegalArgumentException {
if( parent != null )
parent.acceptNameForFacilityDOMObject( this,sNewName );
name = sNewName;
}

final public String getName() {
return name;
}

final public void useVisualtionFromParent( final boolean bUseIt ) {
// only use from parent parent is available
useparents = bUseIt && parent != null;
// if parent usage earse local information
if( bUseIt )
setImage( null );
}

final public boolean usesVisualationFromParent() {
return useparents;
}

final public void setImage( final File fImage ) {
final Image old = image;
// dispose old image
if( image != null )
image.dispose();
if( fImage != null ) {
// load new image
final Image iImage = new Image(
Display.getCurrent(),fImage.getAbsolutePath() );
// redirect to use local image
useVisualtionFromParent( false );
file = fImage;
image = iImage;
}
else {
file = null;
image = null;
}
firePropertyChange( "image",old,image );
}

final public Image getImage() {
if( useparents && parent != null )
return parent.getImage();
return image;
}

final public File getImageFile() {
if( useparents && parent != null )
return parent.getImageFile();
return file;
}

public List getEdges() {
return edges;
}

public void addEdge( final int iX,final int iY ) {
edges.add( new Edge( edges,iX,iY ) );
}

public boolean removeEdge( final Edge edge ) {
return edges.remove( edge );
}

public String toString() {
return name;
}

// methods for bean bahviour about changes
private PropertyChangeSupport getPropertyChangeSupport() {
if (propertyChangeSupport == null) {
propertyChangeSupport = new PropertyChangeSupport( this );
}
return propertyChangeSupport;
}

public void addPropertyChangeListener( PropertyChangeListener
listener) {
getPropertyChangeSupport().addPropertyChangeListener( listener );
}

public void removePropertyChangeListener( PropertyChangeListener
listener ) {
getPropertyChangeSupport().removePropertyChangeListener(
listener );
}

protected void firePropertyChange( String propertyName,Object
oldValue,Object newValue) {
getPropertyChangeSupport().firePropertyChange(
propertyName,oldValue,newValue );
}

protected void firePropertyChange( String propertyName,int
oldValue,int newValue ) {
getPropertyChangeSupport().firePropertyChange(
propertyName,oldValue,newValue );
}
}





My EditPartFactory:

public class EditPartFacilityBOSDOMFactory implements EditPartFactory {

public EditPart createEditPart( final EditPart context,final Object
model ) {
if( model instanceof Edge )
return new EdgeEditPart( context,(Edge)model );
else if( model instanceof Edges )
return new EdgesEditPart( context,(Edges)model );
else if( model instanceof FacilityDOMObject )
return new FacilityDOMObjectEditPart( (FacilityDOMObject)model );

throw new RuntimeException( "Unknow model part " ); }
}



My EditParts:

public class EdgeEditPart extends AbstractGraphicalEditPart implements
PropertyChangeListener {

EdgeEditPart( final EditPart parent,final Edge edge ) {
setParent( parent );
setModel( edge );
}

Edge getCastedModel() {
return (Edge)getModel();
}

public void activate() {
super.activate();
getCastedModel().addPropertyChangeListener( this );
}

public void deactivate() {
super.deactivate();
getCastedModel().removePropertyChangeListener( this );
}

protected IFigure createFigure() {
final Figure figure = new Figure();
figure.setLayoutManager( new XYLayout() );
figure.add( new RectangleFigure(),new Rectangle( 0,0,5,5 ) );
return figure;
}

protected void refreshVisuals() {
final Rectangle rect = new Rectangle(
getCastedModel().getX(),getCastedModel().getY(),-1,-1 );
((GraphicalEditPart)getParent()).setLayoutConstraint(
this,getFigure(),rect );
}

public void propertyChange( final PropertyChangeEvent event ) {
refreshVisuals();
}

protected void createEditPolicies() {
// enables the deletion of edge parts
installEditPolicy( EditPolicy.COMPONENT_ROLE,new ComponentEditPolicy() {
protected Command createDeleteCommand( GroupRequest deleteRequest ) {
return new Command() {
public void execute() {
getCastedModel().getEdges().remove( getModel() );
}
};
}
} );
}
}


public class EdgesEditPart extends AbstractGraphicalEditPart {
EdgesEditPart( final EditPart parent,final Edges edge ) {
setParent( parent );
setModel( edge );
}

Edges getCastedModel() {
return (Edges)getModel();
}

protected IFigure createFigure() {
final Polyline figure = new Polyline();
figure.setLayoutManager( new XYLayout() );
final Iterator points = getCastedModel().iterator();
if( points.hasNext() ) {
final Edge first = (Edge)points.next();
figure.addPoint( new Point( first.getX(),first.getY() ) );
while( points.hasNext() ) {
final Edge edge = (Edge)points.next();
figure.addPoint( new Point( edge.getX(),edge.getY() ) );
}
figure.addPoint( new Point( first.getX(),first.getY() ) );
}
return figure;
}

protected List getModelChildren() {
return Collections.unmodifiableList( getCastedModel() );
}

protected void refreshVisuals() {
((GraphicalEditPart)getParent()).setLayoutConstraint(
this,getFigure(),new Rectangle(
20,20,getFigure().getBounds().width,getFigure().getBounds(). height ) );
}

protected void createEditPolicies() {
// remove visual feedback for root part
installEditPolicy( EditPolicy.SELECTION_FEEDBACK_ROLE,null );
}
}

public class FacilityDOMObjectEditPart extends AbstractGraphicalEditPart
implements PropertyChangeListener {
FacilityDOMObjectEditPart( final FacilityDOMObject fbObj ) {
setModel( fbObj );
}

FacilityDOMObject getCastedModel() {
return (FacilityDOMObject)getModel();
}

public void activate() {
super.activate();
getCastedModel().addPropertyChangeListener( this );
}

public void deactivate() {
super.deactivate();
getCastedModel().removePropertyChangeListener( this );
}

protected IFigure createFigure() {
// use draw2d to create figute
final Figure figure = new Figure();
figure.setOpaque( true );
figure.setBackgroundColor( new Color(
Display.getCurrent(),0xC0,0xC0,0xC0 ) );
figure.setLayoutManager( new XYLayout() );
if( getCastedModel().getImage() != null ) {
final Figure imgfig = new ImageFigure(
getCastedModel().getImage() );
imgfig.setOpaque( false );
figure.add( imgfig,new Rectangle( 20,20,-1,-1 ) );
}
figure.add( new Label( getCastedModel().getName() ),new
Rectangle( 10,10,-1,-1 ) );
return figure;
}

protected List getModelChildren() {
final List childs = new ArrayList( 1 );
childs.add( getCastedModel().getEdges() );
return Collections.unmodifiableList( childs );
}

public void propertyChange( final PropertyChangeEvent event ) {
refreshChildren();
}

protected void createEditPolicies() {
// disallow the deletion of the root
installEditPolicy( EditPolicy.COMPONENT_ROLE,new
RootComponentEditPolicy() );
// remove visual feedback for root part
installEditPolicy( EditPolicy.SELECTION_FEEDBACK_ROLE,null );


XYLayoutEditPolicy policy = new XYLayoutEditPolicy() {
protected Command createAddCommand( EditPart child,Object constraint ) {
System.err.println( "get unsuported create add command! "
+child.getModel().getClass() );

return null;
}

protected Command createChangeConstraintCommand( final EditPart
child,final Object constraint ) {
if( child.getModel() instanceof Edge ) {
return new Command() {
public void execute() {
final Rectangle newRect = (Rectangle)constraint;
final Edge edge = (Edge)child.getModel(); edge.setX( newRect.x );
edge.setY( newRect.y );
}
};
}

// unsupported change request
System.err.println( "get unsupported change command! " +
child.getModel().getClass() );
return null;
}

protected Command getCreateCommand( final CreateRequest request ) {
return new Command() {
public void execute() {
getCastedModel().addEdge(
request.getLocation().x,request.getLocation().y );
}
};
}

protected Command getDeleteDependantCommand( Request request ) {
System.err.println( "get unsupported delete command! " +
getTargetEditPart( request ).getModel().getClass() );
return null;
}
};
policy.setXyLayout( (XYLayout)getFigure().getLayoutManager() );
installEditPolicy( EditPolicy.LAYOUT_ROLE,policy );
}
}



I found out if i make soemthing like an ImageEditPart and return Image
as child of FacilityDOMObjectEditPart it works. If you need further
information, don't hestiate to ask.

HTH

regards

Max
Re: Paintorder of editparts? [message #173203 is a reply to message #172850] Wed, 23 March 2005 00:21 Go to previous messageGo to next message
Eclipse UserFriend
Wow. I hope this is not production-level code. You don't actually expect
us to read and make sense of all that you've posted, do you?

I took a quick look and here are a few things that caught my eye:
1) You're setting XYLayout on a Polyline and then adding other figures to
that Polyline. Polyline is not meant to be used this way. Look at its
Javadoc.
2) In your post you said you're using a border, but I didn't see one being
used anywhere. You're just placing children figures at desired locations,
but not actually using a Border.

"Max Larsson" <max.larsson@abz-informatik.de> wrote in message
news:d1ngav$fk6$1@news.eclipse.org...
> Randy Hudson wrote:
> >>i've a wired problem, which poped up suddenly.
> >>I ahve a root editpart, which loads a jpeg image
> >>as a background and adds a border with 20 pixels.
> >>
> >>My problem is now that child editparts with postion
> >>in the jpeg image area aren't shown. But if
> >>they are located in border i can see them.
> >>
> >
> >
> > This sounds pretty strange. Children should not appear on top of
borders,
> > and your image should be behind the children. Are you overriding
> > paintFigure to paint the background image? It's hard to diagnose the
> > problem without code or more information. Do you have just one level of
> > container? (diagram + children)?
>
> I will try to explain as such as possible. First of all i am instanting
> my editor in the folloowing way:
>
> But i don't thing that has to do soething with it.
>
> My Model is like this:
>
> public class Edge {
> // Helper object for change notification. This will not be persisted.
>
> transient private PropertyChangeSupport propertyChangeSupport;
>
> final private Edges parent;
> private int x;
> private int y;
>
> Edge( final Edges eParent,final int iX,final int iY ) {
> parent = eParent;
> x = iX;
> y = iY;
> }
>
> public Edges getEdges() {
> return parent;
> }
>
> public int getX() {
> return x;
> }
>
> public void setX( int iX ) {
> final int old = x;
> x = iX;
> firePropertyChange( "coordinates",old,x );
> }
>
> public int getY() {
> return y;
> }
>
> public void setY( int iY ) {
> final int old = y;
> y = iY;
> firePropertyChange( "coordinates",old,y );
> }
>
> // methods for bean bahviour about changes
>
> private PropertyChangeSupport getPropertyChangeSupport() {
> if (propertyChangeSupport == null) {
> propertyChangeSupport = new PropertyChangeSupport( this );
> }
> return propertyChangeSupport;
> }
>
> public void addPropertyChangeListener( PropertyChangeListener
> listener) {
> getPropertyChangeSupport().addPropertyChangeListener( listener );
> }
>
> public void removePropertyChangeListener( PropertyChangeListener
> listener ) {
> getPropertyChangeSupport().removePropertyChangeListener(
> listener );
> }
>
> protected void firePropertyChange( String propertyName,int
> oldValue,int newValue ) {
> getPropertyChangeSupport().firePropertyChange(
> propertyName,oldValue,newValue );
> }
> }
>
>
> public class Edges implements List {
> final private FacilityDOMObject parent;
>
> final private List list = new ArrayList( 4 );
>
> Edges( final FacilityDOMObject fbParent ) {
> parent = fbParent;
> add( new Edge( this,10,10 ) );
> add( new Edge( this,90,10 ) );
> add( new Edge( this,90,90 ) );
> add( new Edge( this,10,90 ) );
> }
>
> public FacilityDOMObject getFacilityDOMObject() {
> return parent;
> }
>
> private double calcDistance( final Edge start,final Edge end ) {
> return Math.sqrt( Math.pow( start.getX() - end.getX(),2 ) + Math.pow(
> start.getY() - end.getY(),2 ) );
> }
>
> public boolean add( final Object obj ) {
> if( ! ( obj instanceof Edge ) )
> throw new IllegalArgumentException( "Edges only contains edge
> classes!" );
> // search the position within the edges
> if( list.size() > 2 ) {
> final Edge nw = (Edge)obj;
> final Edge[] nearest = new Edge[] { (Edge)list.get( 0
> ),(Edge)list.get( 1 ) };
> final double[] distance = new double[] { calcDistance(
> nw,(Edge)list.get( 0 ) ),calcDistance( nw,(Edge)list.get( 1 ) ) };
> for( int loop = 2;loop < list.size();loop++ ) {
> final Edge edge = (Edge)list.get( loop );
> final double dist = calcDistance( nw,edge );
> if( distance[0] > distance[1] ) {
> if( dist < distance[0] ) {
> distance[0] = dist;
> nearest[0] = edge;
> }
> }
> else {
> if( dist <= distance[1] ) {
> distance[1] = dist;
> nearest[1] = edge;
> }
> }
> }
> final int min = Math.min( list.indexOf( nearest[0] ),list.indexOf(
> nearest[1] ) );
> if( min == 0 )
> list.add( Math.max( list.indexOf( nearest[0] ),list.indexOf(
> nearest[1] ) ) + 1,obj );
> else
> list.add( min + 1,obj );
> }
> else
> list.add( obj );
>
> if( list.contains( obj ) ) {
> parent.firePropertyChange( "newedge",null,obj );
> return true;
> }
> return false;
> }
>
> public void add( final int index,final Object element ) {
> list.add( index,element );
> }
>
> public boolean addAll( final int index,final Collection c ) {
> return list.addAll( index,c );
> }
>
> public boolean addAll( final Collection c ) {
> return list.addAll( c );
> }
>
> public void clear() {
> list.clear();
> }
>
> public boolean contains( final Object o ) {
> return list.contains( o );
> }
>
> public boolean containsAll( final Collection c ) {
> return list.containsAll( c );
> }
>
> public boolean equals( final Object obj ) {
> return list.equals( obj );
> }
>
> public Object get( final int index ) {
> return list.get( index );
> }
>
> public int hashCode() {
> return list.hashCode();
> }
>
> public int indexOf( final Object o ) {
> return list.indexOf( o );
> }
>
> public boolean isEmpty() {
> return list.isEmpty();
> }
>
> public Iterator iterator() {
> return list.iterator();
> }
>
> public int lastIndexOf( final Object o ) {
> return list.lastIndexOf( o );
> }
>
> public ListIterator listIterator() {
> return list.listIterator();
> }
>
> public ListIterator listIterator( final int index ) {
> return list.listIterator( index );
> }
>
> public Object remove( final int index ) {
> return list.remove( index );
> }
>
> public boolean remove( final Object obj ) {
> if( ! ( obj instanceof Edge ) )
> throw new IllegalArgumentException( "Edges only contains edge
> classes!" );
>
> if( list.remove( obj ) ) {
> parent.firePropertyChange( "rmeoveedge",obj,null );
> return true;
> }
> return false;
> }
>
> public boolean removeAll( final Collection c ) {
> return list.removeAll( c );
> }
>
> public boolean retainAll( final Collection c ) {
> return list.retainAll( c );
> }
>
> public Object set( final int index,final Object element ) {
> return list.set( index,element );
> }
>
> public int size() {
> return list.size();
> }
>
> public List subList( final int fromIndex,final int toIndex ) {
> return list.subList( fromIndex,toIndex );
> }
>
> public Object[] toArray() {
> return list.toArray();
> }
>
> public Object[] toArray( final Object[] a ) {
> return list.toArray( a );
> }
>
> public String toString() {
> return "Edges: " + list.toString();
> }
> }
>
>
> abstract public class FacilityDOMObject {
> // Helper object for change notification. This will not be persisted.
> transient private PropertyChangeSupport propertyChangeSupport;
>
> final private Edges edges;
>
> private FacilityDOMGroup parent;
> private String name;
>
> private boolean useparents = true;
> private File file = null;
> private Image image = null;
>
> protected FacilityDOMObject( final String sName ) {
> name = sName;
> edges = new Edges( this );
> }
>
> public void dispose() {
> if( parent != null )
> parent.remove( this );
> if( image != null )
> image.dispose();
> }
>
> protected void finalize() throws Throwable {
> parent = null;
> file = null;
> image = null;
> }
>
> protected void setParent( final FacilityDOMGroup parentGroup ) throws
> IllegalArgumentException {
> if( parentGroup != null )
> parentGroup.acceptFacilityDOMObject( this );
> parent = parentGroup;
> if( parent == null )
> useparents = false; // TODO: maybe throw indication that connection
> will be lost?
> }
>
> abstract public void acceptVisitor( final FacilitDOMVisitor visitor );
>
> final public void setName( final String sNewName ) throws
> IllegalArgumentException {
> if( parent != null )
> parent.acceptNameForFacilityDOMObject( this,sNewName );
> name = sNewName;
> }
>
> final public String getName() {
> return name;
> }
>
> final public void useVisualtionFromParent( final boolean bUseIt ) {
> // only use from parent parent is available
> useparents = bUseIt && parent != null;
> // if parent usage earse local information
> if( bUseIt )
> setImage( null );
> }
>
> final public boolean usesVisualationFromParent() {
> return useparents;
> }
>
> final public void setImage( final File fImage ) {
> final Image old = image;
> // dispose old image
> if( image != null )
> image.dispose();
> if( fImage != null ) {
> // load new image
> final Image iImage = new Image(
> Display.getCurrent(),fImage.getAbsolutePath() );
> // redirect to use local image
> useVisualtionFromParent( false );
> file = fImage;
> image = iImage;
> }
> else {
> file = null;
> image = null;
> }
> firePropertyChange( "image",old,image );
> }
>
> final public Image getImage() {
> if( useparents && parent != null )
> return parent.getImage();
> return image;
> }
>
> final public File getImageFile() {
> if( useparents && parent != null )
> return parent.getImageFile();
> return file;
> }
>
> public List getEdges() {
> return edges;
> }
>
> public void addEdge( final int iX,final int iY ) {
> edges.add( new Edge( edges,iX,iY ) );
> }
>
> public boolean removeEdge( final Edge edge ) {
> return edges.remove( edge );
> }
>
> public String toString() {
> return name;
> }
>
> // methods for bean bahviour about changes
> private PropertyChangeSupport getPropertyChangeSupport() {
> if (propertyChangeSupport == null) {
> propertyChangeSupport = new PropertyChangeSupport( this );
> }
> return propertyChangeSupport;
> }
>
> public void addPropertyChangeListener( PropertyChangeListener
> listener) {
> getPropertyChangeSupport().addPropertyChangeListener( listener );
> }
>
> public void removePropertyChangeListener( PropertyChangeListener
> listener ) {
> getPropertyChangeSupport().removePropertyChangeListener(
> listener );
> }
>
> protected void firePropertyChange( String propertyName,Object
> oldValue,Object newValue) {
> getPropertyChangeSupport().firePropertyChange(
> propertyName,oldValue,newValue );
> }
>
> protected void firePropertyChange( String propertyName,int
> oldValue,int newValue ) {
> getPropertyChangeSupport().firePropertyChange(
> propertyName,oldValue,newValue );
> }
> }
>
>
>
>
>
> My EditPartFactory:
>
> public class EditPartFacilityBOSDOMFactory implements EditPartFactory {
>
> public EditPart createEditPart( final EditPart context,final Object
> model ) {
> if( model instanceof Edge )
> return new EdgeEditPart( context,(Edge)model );
> else if( model instanceof Edges )
> return new EdgesEditPart( context,(Edges)model );
> else if( model instanceof FacilityDOMObject )
> return new FacilityDOMObjectEditPart( (FacilityDOMObject)model );
>
> throw new RuntimeException( "Unknow model part " ); }
> }
>
>
>
> My EditParts:
>
> public class EdgeEditPart extends AbstractGraphicalEditPart implements
> PropertyChangeListener {
>
> EdgeEditPart( final EditPart parent,final Edge edge ) {
> setParent( parent );
> setModel( edge );
> }
>
> Edge getCastedModel() {
> return (Edge)getModel();
> }
>
> public void activate() {
> super.activate();
> getCastedModel().addPropertyChangeListener( this );
> }
>
> public void deactivate() {
> super.deactivate();
> getCastedModel().removePropertyChangeListener( this );
> }
>
> protected IFigure createFigure() {
> final Figure figure = new Figure();
> figure.setLayoutManager( new XYLayout() );
> figure.add( new RectangleFigure(),new Rectangle( 0,0,5,5 ) );
> return figure;
> }
>
> protected void refreshVisuals() {
> final Rectangle rect = new Rectangle(
> getCastedModel().getX(),getCastedModel().getY(),-1,-1 );
> ((GraphicalEditPart)getParent()).setLayoutConstraint(
> this,getFigure(),rect );
> }
>
> public void propertyChange( final PropertyChangeEvent event ) {
> refreshVisuals();
> }
>
> protected void createEditPolicies() {
> // enables the deletion of edge parts
> installEditPolicy( EditPolicy.COMPONENT_ROLE,new ComponentEditPolicy() {
> protected Command createDeleteCommand( GroupRequest deleteRequest ) {
> return new Command() {
> public void execute() {
> getCastedModel().getEdges().remove( getModel() );
> }
> };
> }
> } );
> }
> }
>
>
> public class EdgesEditPart extends AbstractGraphicalEditPart {
> EdgesEditPart( final EditPart parent,final Edges edge ) {
> setParent( parent );
> setModel( edge );
> }
>
> Edges getCastedModel() {
> return (Edges)getModel();
> }
>
> protected IFigure createFigure() {
> final Polyline figure = new Polyline();
> figure.setLayoutManager( new XYLayout() );
> final Iterator points = getCastedModel().iterator();
> if( points.hasNext() ) {
> final Edge first = (Edge)points.next();
> figure.addPoint( new Point( first.getX(),first.getY() ) );
> while( points.hasNext() ) {
> final Edge edge = (Edge)points.next();
> figure.addPoint( new Point( edge.getX(),edge.getY() ) );
> }
> figure.addPoint( new Point( first.getX(),first.getY() ) );
> }
> return figure;
> }
>
> protected List getModelChildren() {
> return Collections.unmodifiableList( getCastedModel() );
> }
>
> protected void refreshVisuals() {
> ((GraphicalEditPart)getParent()).setLayoutConstraint(
> this,getFigure(),new Rectangle(
> 20,20,getFigure().getBounds().width,getFigure().getBounds(). height ) );
> }
>
> protected void createEditPolicies() {
> // remove visual feedback for root part
> installEditPolicy( EditPolicy.SELECTION_FEEDBACK_ROLE,null );
> }
> }
>
> public class FacilityDOMObjectEditPart extends AbstractGraphicalEditPart
> implements PropertyChangeListener {
> FacilityDOMObjectEditPart( final FacilityDOMObject fbObj ) {
> setModel( fbObj );
> }
>
> FacilityDOMObject getCastedModel() {
> return (FacilityDOMObject)getModel();
> }
>
> public void activate() {
> super.activate();
> getCastedModel().addPropertyChangeListener( this );
> }
>
> public void deactivate() {
> super.deactivate();
> getCastedModel().removePropertyChangeListener( this );
> }
>
> protected IFigure createFigure() {
> // use draw2d to create figute
> final Figure figure = new Figure();
> figure.setOpaque( true );
> figure.setBackgroundColor( new Color(
> Display.getCurrent(),0xC0,0xC0,0xC0 ) );
> figure.setLayoutManager( new XYLayout() );
> if( getCastedModel().getImage() != null ) {
> final Figure imgfig = new ImageFigure(
> getCastedModel().getImage() );
> imgfig.setOpaque( false );
> figure.add( imgfig,new Rectangle( 20,20,-1,-1 ) );
> }
> figure.add( new Label( getCastedModel().getName() ),new
> Rectangle( 10,10,-1,-1 ) );
> return figure;
> }
>
> protected List getModelChildren() {
> final List childs = new ArrayList( 1 );
> childs.add( getCastedModel().getEdges() );
> return Collections.unmodifiableList( childs );
> }
>
> public void propertyChange( final PropertyChangeEvent event ) {
> refreshChildren();
> }
>
> protected void createEditPolicies() {
> // disallow the deletion of the root
> installEditPolicy( EditPolicy.COMPONENT_ROLE,new
> RootComponentEditPolicy() );
> // remove visual feedback for root part
> installEditPolicy( EditPolicy.SELECTION_FEEDBACK_ROLE,null );
>
>
> XYLayoutEditPolicy policy = new XYLayoutEditPolicy() {
> protected Command createAddCommand( EditPart child,Object constraint ) {
> System.err.println( "get unsuported create add command! "
> +child.getModel().getClass() );
>
> return null;
> }
>
> protected Command createChangeConstraintCommand( final EditPart
> child,final Object constraint ) {
> if( child.getModel() instanceof Edge ) {
> return new Command() {
> public void execute() {
> final Rectangle newRect = (Rectangle)constraint;
> final Edge edge = (Edge)child.getModel(); edge.setX( newRect.x );
> edge.setY( newRect.y );
> }
> };
> }
>
> // unsupported change request
> System.err.println( "get unsupported change command! " +
> child.getModel().getClass() );
> return null;
> }
>
> protected Command getCreateCommand( final CreateRequest request ) {
> return new Command() {
> public void execute() {
> getCastedModel().addEdge(
> request.getLocation().x,request.getLocation().y );
> }
> };
> }
>
> protected Command getDeleteDependantCommand( Request request ) {
> System.err.println( "get unsupported delete command! " +
> getTargetEditPart( request ).getModel().getClass() );
> return null;
> }
> };
> policy.setXyLayout( (XYLayout)getFigure().getLayoutManager() );
> installEditPolicy( EditPolicy.LAYOUT_ROLE,policy );
> }
> }
>
>
>
> I found out if i make soemthing like an ImageEditPart and return Image
> as child of FacilityDOMObjectEditPart it works. If you need further
> information, don't hestiate to ask.
>
> HTH
>
> regards
>
> Max
Re: Paintorder of editparts? [message #173418 is a reply to message #173203] Thu, 24 March 2005 03:33 Go to previous message
Eclipse UserFriend
Originally posted by: max.larsson.abz-informatik.de

Pratik Shah wrote:
> Wow. I hope this is not production-level code. You don't actually expect
> us to read and make sense of all that you've posted, do you?

Nope, but i came to the conclusion, that that is the minmal part, where
everything is covered.

> I took a quick look and here are a few things that caught my eye:
> 1) You're setting XYLayout on a Polyline and then adding other figures to
> that Polyline. Polyline is not meant to be used this way. Look at its
> Javadoc.

I will check it out.

> 2) In your post you said you're using a border, but I didn't see one being
> used anywhere. You're just placing children figures at desired locations,
> but not actually using a Border.

Well the Edge Model are children figures of the Edges (the s is
impoprtant) model and the Editpart of the edges are using the polyine to
draw a lines between the edgees (# of edge model).

Actual what i want to to is make a polyline shape, wehre each edge can
be moved removed. And what you see was my solution. But any hints on how
to do it right are welcome

regards

Max
Previous Topic:Create multiple objects in the same drag&drop operation in an graphical editor
Next Topic:Changing the dimension
Goto Forum:
  


Current Time: Sun May 11 22:29:51 EDT 2025

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

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

Back to the top