Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ve-dev] Surrounding Components with a JPanel in VE


Hi Ali,

So what I need to know is,

>a) how can I get the selected components in VE (step 2)? Trough
>org.eclipse.gef.ui.actions.SelectionAction.getSelectedObjects() ?


This will be an edit part.  Cast to ((EditPart)((StructuredSelection)selection.getfirstSelectedItem()).getModel() to get an IJavaInstance

b) how can I read the absolute positions of some Objects which are in a
layout manager (assuming that the current positioning will be the final,
regarding resizing .. etc.) (step 3.1.1) ? Something like
MyButton1.getAbsolutePosition()


To do this you need to call getBounds() on the target VM.  First get the proxy to the live Component

IBeanProxy componentProxy = BeanProxyUtilities.getBeanProxy(IJavaInstance myBean);

Then call getBounds() on the target VM which gives you an object that is a proxy to the rectangle

IRectangleBeanProxy boundsProxy = BeanAwtUtilities.invoke_getBounds(componentProxy);

IRecangleProxy has methods to get the x,y width and height

A great place to debug would be in NullLayoutSwitcher.  This class is called when you have a Container with a bunch of Components and you change the layout to null.  What the VE does is try to preserve the absolute position, so for example if you go from GridBagLayout to null the child components remain at their same location and size.  NullLayoutSwitcher does all of this for you.

>c) how could I modifiy the source (and update the Graphical Editor) to
>add a generic JPanel and then to modify it's position (step 3.1.2), and
>add the old trivial components in it?

To add a JPanel you have to add a ComponentConstraint object to the object you want to add the panel to and then add the panel to this.  The way the VE does this when you drop from the palette is that a GEF request is created that has all the smarts to ask for this to occur and then the EditPart creates a command for it.  Debug into something like NullLayoutPolicyHelper (if the parent is in null layout - there are others like FlowLayoutPolicyHelper, GridBagLayoutPolicyHelper, etc...).  What these will do is have methods like

public Command getCreateChildCommand(Object childComponent, Object parent, Object constraint, Object position){}

These will basically build up a command that creates the correct objects.  The command is then executed with code like

EditDomain.getEditDomain(editPart).getCommandStack().execute(command);

which then manipulates the model.

From your list of things you also have open

(3.1) Change the layout of the surrounding container (e.g. JPanel or
JFrame) to null layout if it isn't already so:


This step is actually tricky because it isn't just done by setting the layout property to null.  The reason is because if it was in Border before or GridBagLayout (or anything that has LayoutManager2) then the constraint objects need removing, and also the bounds needs setting for any existeing children.  the layout switcher does this so debug into NullLayoutSwitcher.  In the property sheet where layout can be changed debug into LayoutManagerPropertyDescriptor.setValue(IPropertySource source, Object setValue) and use the property sheet switching to see what occurs

(3.1.3) adopt the new JPanel in such way that it only contains the
selected components and place it so that the selected components have
still the same absolute positions


Easier than what you're doing which is basically to yank the old guys, put a new parent, and re-add the old children might be to morph the parent.  This can be done by changing the EMF class.

What I think I would like to do is take your scenario and work to get some simple code examples in the VE repository.  It's a great test case of how the model is put together and we keep trying to think of how to create a good tutorial on the model that is real world and also useful.  I'll talk to the other VE developers and once we agree what to throw together and check in some sample code we'll ping you back on the newsgroup - in the meaintime try some of the debugging I suggested and see if that throws light.

Best regards,

Joe Winchester

Back to the top