Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » 2 different content panes
2 different content panes [message #167813] Fri, 11 February 2005 09:34 Go to next message
Eclipse UserFriend
Originally posted by: seb01016.fh-hagenber.at

Hello!

I know that there were some discussions about multiple content panes in
this forum, but I am not able to solve my problem. Maybe somebody could
exactly tell what I have to to.

Situation: I have three different edit parts: FormEditPart,
CommandEditPart and ItemEditPart. Form is the container. FormFigure has a
large Panel that contains a smaller one, exactly speaking it contains a
scrollpanel. Now I want to add commands at the button of the form, that
means it should be added to the large panel, whereas Items should be added
to the scrollpanel.

So you do I manage this situation? Which method do I need to overwrite??
(addChildVisual???)

thx in advance
Hannes
Re: 2 different content panes [message #167836 is a reply to message #167813] Fri, 11 February 2005 12:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: no.mail.please

I suppose here that :
- your model for FormEditPart is a Form
- your model for CommandEditPart is a Command

So :

1) You should add a LayoutEditPolicy to your FormEditPart, that controls
creation of Commands :
protected void createEditPolicies() {
// 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
CommandXYLayoutEditPolicy(layout));
}


2) And create an inner class :
private class CommandXYLayoutEditPolicy extends XYLayoutEditPolicy {

CommandXYLayoutEditPolicy(XYLayout layout) {
if (layout == null) {
throw new IllegalArgumentException();
}
setXyLayout(layout);
}

protected Command createAddCommand(EditPart child, Object constraint) {
return null;
}

protected Command createChangeConstraintCommand(ChangeBoundsRequest request,
EditPart child, Object constraint) {
return null;
}

protected Command createChangeConstraintCommand(EditPart child,
Object constraint) {
return null;
}

protected Command getCreateCommand(CreateRequest request) {
Object childClass = request.getNewObjectType();
// We have to put all the expected classes here
if (childClass == Command.class) {
// return a command that can add a Command to the Form
return new CommandCreateCommand(FormEditPart.this.getCastedModel(),
request);
}
return null;
}

protected Command getDeleteDependantCommand(Request request) {
return null;
}
}

As you see, the heart of the LayoutEditPolicy is, for your problem,
getCreateCommand() : it allows you to select the parts that can be
dropped here. It returns a valid creation command (which I named here
CommandCreateCommand - not very clever ;))

Note that the getCastedModel() method is just a convenient private
method of FormEditPart that returns the model element.

3) The CommandCreateCommand should look like this :
public class CommandCreateCommand extends Command {

/** The new Command. */
private Command newCommand;

/** Form to add to. */
private final Form parent;
/** A request to create a new Command. */
private final CreateRequest request;
/** True, if newCommand was added to parent. */
private boolean commandAdded;

public CommandCreateCommand(Form parent, CreateRequest req) {
if (parent == null || req == null || !(req.getNewObject() instanceof
Command)) {
throw new IllegalArgumentException();
}
this.parent = parent;
this.request = req;
setLabel("command creation");
}

public boolean canUndo() {
return commandAdded;
}

public void execute() {
newCommand = (Command) request.getNewObject();
// Get desired location and size from the request
newCommand.setSize(request.getSize()); // might be null!
newCommand.setLocation(request.getLocation());
redo();
}

public void redo() {
commandAdded = parent.addChild(newCommand);
}

public void undo() {
parent.removeChild(newCommand);
}

}

4) Whith this, only commands will be allowed to be added to Form. Then
do the same thing with the scrollpane (which should have an editPart too
- don't know what you did, but you didn't mention it) and items.

Hope this helps.

--
Arnaud


------------------------------------------------------------ ------------
Schoenboeck a écrit :
> Hello!
>
> I know that there were some discussions about multiple content panes in
> this forum, but I am not able to solve my problem. Maybe somebody could
> exactly tell what I have to to.
>
> Situation: I have three different edit parts: FormEditPart,
> CommandEditPart and ItemEditPart. Form is the container. FormFigure has
> a large Panel that contains a smaller one, exactly speaking it contains
> a scrollpanel. Now I want to add commands at the button of the form,
> that means it should be added to the large panel, whereas Items should
> be added to the scrollpanel.
>
> So you do I manage this situation? Which method do I need to overwrite??
> (addChildVisual???)
> thx in advance
> Hannes
>
Re: 2 different content panes [message #167844 is a reply to message #167836] Fri, 11 February 2005 12:58 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: seb01016.fh-hagenberg.at

Thanks for your explanation, but it does not solve the problem I have. I
have got a FormEditPart that has an XYLayout policies. Forms are able to
have ItemEditPart and CommandEditPart as child edit parts. This works
fine. I have overwritten the method getContentPane to get the drawing
panel of the form figure. That is exactly the point where I wanted to make
a decision: If the child edit part is a Command i want to have the large
panel, so that commands are placed on that, if it is an ItemEditPart i
want to draw the figure on the scrollpane. I wanted to avoid the way you
described, to add an extra child EditPart that acts as a container for
items, because it would have no other use and that's why I wanted to avoid
this workaround.


Arnaud wrote:

> I suppose here that :
> - your model for FormEditPart is a Form
> - your model for CommandEditPart is a Command

> So :

> 1) You should add a LayoutEditPolicy to your FormEditPart, that controls
> creation of Commands :
> protected void createEditPolicies() {
> // 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
> CommandXYLayoutEditPolicy(layout));
> }


> 2) And create an inner class :
> private class CommandXYLayoutEditPolicy extends XYLayoutEditPolicy {

> CommandXYLayoutEditPolicy(XYLayout layout) {
> if (layout == null) {
> throw new IllegalArgumentException();
> }
> setXyLayout(layout);
> }

> protected Command createAddCommand(EditPart child, Object constraint) {
> return null;
> }

> protected Command createChangeConstraintCommand(ChangeBoundsRequest request,
> EditPart child, Object constraint) {
> return null;
> }

> protected Command createChangeConstraintCommand(EditPart child,
> Object constraint) {
> return null;
> }

> protected Command getCreateCommand(CreateRequest request) {
> Object childClass = request.getNewObjectType();
> // We have to put all the expected classes here
> if (childClass == Command.class) {
> // return a command that can add a Command to the Form
> return new CommandCreateCommand(FormEditPart.this.getCastedModel(),
> request);
> }
> return null;
> }

> protected Command getDeleteDependantCommand(Request request) {
> return null;
> }
> }

> As you see, the heart of the LayoutEditPolicy is, for your problem,
> getCreateCommand() : it allows you to select the parts that can be
> dropped here. It returns a valid creation command (which I named here
> CommandCreateCommand - not very clever ;))

> Note that the getCastedModel() method is just a convenient private
> method of FormEditPart that returns the model element.

> 3) The CommandCreateCommand should look like this :
> public class CommandCreateCommand extends Command {

> /** The new Command. */
> private Command newCommand;

> /** Form to add to. */
> private final Form parent;
> /** A request to create a new Command. */
> private final CreateRequest request;
> /** True, if newCommand was added to parent. */
> private boolean commandAdded;

> public CommandCreateCommand(Form parent, CreateRequest req) {
> if (parent == null || req == null || !(req.getNewObject() instanceof
> Command)) {
> throw new IllegalArgumentException();
> }
> this.parent = parent;
> this.request = req;
> setLabel("command creation");
> }

> public boolean canUndo() {
> return commandAdded;
> }

> public void execute() {
> newCommand = (Command) request.getNewObject();
> // Get desired location and size from the request
> newCommand.setSize(request.getSize()); // might be null!
> newCommand.setLocation(request.getLocation());
> redo();
> }

> public void redo() {
> commandAdded = parent.addChild(newCommand);
> }

> public void undo() {
> parent.removeChild(newCommand);
> }

> }

> 4) Whith this, only commands will be allowed to be added to Form. Then
> do the same thing with the scrollpane (which should have an editPart too
> - don't know what you did, but you didn't mention it) and items.

> Hope this helps.

> --
> Arnaud


> ------------------------------------------------------------ ------------
> Schoenboeck a écrit :
> > Hello!
> >
> > I know that there were some discussions about multiple content panes in
> > this forum, but I am not able to solve my problem. Maybe somebody could
> > exactly tell what I have to to.
> >
> > Situation: I have three different edit parts: FormEditPart,
> > CommandEditPart and ItemEditPart. Form is the container. FormFigure has
> > a large Panel that contains a smaller one, exactly speaking it contains
> > a scrollpanel. Now I want to add commands at the button of the form,
> > that means it should be added to the large panel, whereas Items should
> > be added to the scrollpanel.
> >
> > So you do I manage this situation? Which method do I need to overwrite??
> > (addChildVisual???)
> > thx in advance
> > Hannes
> >
Re: 2 different content panes [message #167872 is a reply to message #167844] Fri, 11 February 2005 17:25 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: no.mail.please

Schoenboeck a écrit :
> Thanks for your explanation, but it does not solve the problem I have. I
> have got a FormEditPart that has an XYLayout policies. Forms are able to
> have ItemEditPart and CommandEditPart as child edit parts. This works
> fine. I have overwritten the method getContentPane to get the drawing
> panel of the form figure. That is exactly the point where I wanted to
> make a decision: If the child edit part is a Command i want to have the
> large panel, so that commands are placed on that, if it is an
> ItemEditPart i want to draw the figure on the scrollpane. I wanted to
> avoid the way you described, to add an extra child EditPart that acts as
> a container for items, because it would have no other use and that's why
> I wanted to avoid this workaround.

Ok, I see what you want to do. I guess something like that (in the
layout editpolicy of the FormEditPart) is what you think to, don't you ?

protected Command getCreateCommand(CreateRequest request) {
Object childClass = request.getNewObjectType();
Point location = request.getLocation();

// Checks if we drop a command in the good location
if (childClass == Command.class && !(isInScrollPaneBounds(location))) {
// return a command that can add a Command at the bottom of the
Form
return new
CommandCreateCommand(FormEditPart.this.getCastedModel(), request);
}

// Checks if we drop an item in the good location
if (childClass == Command.class && isInScrollPaneBounds(location)) {
// return a command that can add an Item to the scrollpane
return new
ItemCreateCommand(FormEditPart.this.getCastedModel(), request);
}

// else
return null;
}

where isInScrollPaneBounds is a method that test the drop location
according to the bounds of scrollpane.

Another way is to change the coordinates the command gets if they are
not correct (not very difficult to implement from thie base code, I let
you try it).

Anyway, the problem is that when you're out of the contentpane, your
figures aren't drawn (but you can still select them I think).

My feeling is that you can't get it work without defining a new editpart
which will accept a specific type of child. But I'm not an expert.
Pratik Shah or Randy Hudson would know it better.

--
Arnaud
Re: 2 different content panes [message #167887 is a reply to message #167813] Fri, 11 February 2005 19:37 Go to previous message
Pratik Shah is currently offline Pratik ShahFriend
Messages: 1077
Registered: July 2009
Senior Member
In its getModelChildren() method, FormEditPart should return all the
commands + a list containing the items. You'll have to create EditParts for
that list (and that EditPart would be the one to create the inner scrollpane
figure) and return it from your EditPartFactory. Keep in mind that when
your FormEditPart gets a notification of change in children items, it would
have to refresh the children of its ListEditPart.

Alternatively, you could organize this slightly differently. Have your
FormEditPart return two lists at its children, one for the commands and one
for the items. Then create two separate EditParts for each. The EDiagram
example demonstrated how to do this. ClassEditPart returns a list of
attributes and a list of operations as its two children. Look at that if
you need more help.


"Schoenboeck" <seb01016@fh-hagenber.at> wrote in message
news:cuhu6d$j1t$1@www.eclipse.org...
> Hello!
>
> I know that there were some discussions about multiple content panes in
> this forum, but I am not able to solve my problem. Maybe somebody could
> exactly tell what I have to to.
>
> Situation: I have three different edit parts: FormEditPart,
> CommandEditPart and ItemEditPart. Form is the container. FormFigure has a
> large Panel that contains a smaller one, exactly speaking it contains a
> scrollpanel. Now I want to add commands at the button of the form, that
> means it should be added to the large panel, whereas Items should be added
> to the scrollpanel.
>
> So you do I manage this situation? Which method do I need to overwrite??
> (addChildVisual???)
>
> thx in advance
> Hannes
>
Previous Topic:EMF enum property editor
Next Topic:Selecting connections
Goto Forum:
  


Current Time: Sat Apr 27 01:30:50 GMT 2024

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

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

Back to the top