Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » DiagramEditPart HEELP
DiagramEditPart HEELP [message #152768] Mon, 01 October 2007 15:52
Eclipse UserFriend
Originally posted by: surayya.daimi.au.dk

I want to layout the loaded elements from left to right and not how they are
now from top to down

I suppose that i need to do some magic in the class that extends
DiagramEditPart ?
This class looks like that

public class MacroEditPart extends DiagramEditPart {


public final static String MODEL_ID = "Execution"; //$NON-NLS-1$

private boolean shouldUpdatePageBreakLocation = false;




public static final int VISUAL_ID = 79;




public MacroEditPart(View view) {

super(view);

}

protected void createDefaultEditPolicies() {

super.createDefaultEditPolicies();

installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,

new MacroItemSemanticEditPolicy());

installEditPolicy(EditPolicyRoles.CANONICAL_ROLE,

new MacroCanonicalEditPolicy());

//removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpo licies.EditPolicyRoles.POPUPBAR_ROLE);

}

}




I suppose i need to create a method

protected @Override IFigure createFigure() {}

and to also add createDefaultEditPolicies() with a policy for
FlowLayoutPolicy()

as this policy is abstract i need to extend the policy



as some in the forum sugessted FlowLayout implementatioin could be done by
overiding methods in DiagramEditPart

I did so and ended up with following class

public class MacroEditPart extends DiagramEditPart {

private boolean shouldUpdatePageBreakLocation = false;



public final static String MODEL_ID = "Execution"; //$NON-NLS-1$






public static final int VISUAL_ID = 79;


public MacroEditPart(View view) {

super(view);

}


protected @Override void createDefaultEditPolicies() {

super.createDefaultEditPolicies();

installEditPolicy( EditPolicyRoles.CREATION_ROLE, new CreationEditPolicy());

installEditPolicy(EditPolicy.CONTAINER_ROLE, new ContainerEditPolicy());

installEditPolicy( EditPolicy.COMPONENT_ROLE, new
RootComponentEditPolicy());

installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy() );
//FLOW LAYOUT POLICY IMPL

installEditPolicy( EditPolicyRoles.DRAG_DROP_ROLE, new
DiagramDragDropEditPolicy());

installEditPolicy( EditPolicy.GRAPHICAL_NODE_ROLE, new
ContainerNodeEditPolicy());

installEditPolicy(EditPolicyRoles.SNAP_FEEDBACK_ROLE, new
SnapFeedbackPolicy());

installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE, new
DiagramPopupBarEditPolicy());

installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE, new
MacroItemSemanticEditPolicy()); //OLD PLOICIES of MacroEditPart

installEditPolicy(EditPolicyRoles.CANONICAL_ROLE, new
MacroCanonicalEditPolicy()); //OLD PLOICIES of MacroEditPart

}


protected LayoutEditPolicy createLayoutEditPolicy() {


FlowLayoutEditPolicy lep = new FlowLayoutEditPolicy() {

protected Command createAddCommand(EditPart child, EditPart after) { return
null; }protected Command createMoveChildCommand(EditPart child,EditPart
after) {

return null;}

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

return lep;

}



private class PageBreaksLayoutListener extends LayoutListener.Stub {


public void postLayout(IFigure container) {

super.postLayout(container);

updatePageBreaksLocation();

}



}


protected @Override IFigure createFigure() {


// Override the containsPoint and findFigureAt methods

// to treat this layer (Primary Layer) as if it were opaque.


// This is for the grid layer so that it can be seen beneath the

// figures.

IFigure f = new BorderItemsAwareFreeFormLayer() {

/* (non-Javadoc)

* @see org.eclipse.draw2d.Layer#containsPoint(int, int)

*/

public boolean containsPoint(int x, int y) {

return getBounds().contains(x, y);

}


/* (non-Javadoc)

* @see org.eclipse.draw2d.Layer#findFigureAt(int, int,
org.eclipse.draw2d.TreeSearch)

*/

public IFigure findFigureAt(int x, int y, TreeSearch search) {

if (!isEnabled())

return null;

if (!containsPoint(x, y))

return null;

if (search.prune(this))

return null;

IFigure child = findDescendantAtExcluding(x, y, search);

if (child != null)

return child;

if (search.accept(this))

return this;

return null;

}


/* (non-Javadoc)

* @see org.eclipse.draw2d.Figure#validate()

*/

public void validate() {

super.validate();

if (shouldUpdatePageBreakLocation){

shouldUpdatePageBreakLocation = false;

updatePageBreaksLocation();

}

}

};

f.setLayoutManager(new FlowLayout(true)); ///Here
i set the flow layout and horisontal true

f.addLayoutListener(LayoutAnimator.getDefault());

f.addLayoutListener(new PageBreaksLayoutListener());

return f;

}


}

The problem is that i can not see anything in my diagram when loaded a
diagram

What am i doing wrong

OR How to change the layout to be horizontal

any help is appreciated



Suaryya
Previous Topic:Writing to model
Next Topic:Create element and view when another element is created
Goto Forum:
  


Current Time: Thu Jul 18 04:42:54 GMT 2024

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

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

Back to the top