Home » Archived » Visual Editor (VE) » Adding a component programmatically
|
Re: Adding a component programmatically - figured - one more question [message #104612 is a reply to message #104463] |
Wed, 31 August 2005 23:50 |
Dylan Bruzenak Messages: 48 Registered: July 2009 |
Member |
|
|
Ok, I figured this out. A combination of re-reading all the code generation
posts I could find on this board and putting breakpoints higher up the food
chain. My code is appended to the end of this message for anyone else trying
to accomplish the same thing.
I have two more questions.
1. Using a combination of EMFClassCreationFactory and the AnnotationCreationFactory
decorator causes a popup to appear asking for the control name. I want to
specify the name and not bother the user with the popup. I see a constructor
that takes a list of keys, but I have no idea what to populate that with ;)
2. Is there an easy way to specify the component width and height for a
newly added component ? My current technique involved finding the existing
line of code and manually editing it using the AST. God help me.
I greatly appreciate any response.
My current code follows:
<code>
BeanSubclassComposition bean = (BeanSubclassComposition) editDomain.getDiagramData();
IJavaObjectInstance rootInstance = bean.getThisPart();
EditPart part = primaryViewer.getRootEditPart().getContents();
part = (EditPart)part.getChildren().get(0); /* get the jpanel */
CreateRequest request = new CreateRequest();
IJavaInstance fieldInstance = BeanUtilities.createJavaObject("javax.swing.JTextField",
rootInstance.eResource().getResourceSet(), "");
/* AnnotationCreationFactory wraps another CreationFactory and
lets the user set the fieldname of the added object with a
popup. The EMFClassCreationFactory takes a namespace URI
and creates object instances based on it.
*/
AnnotationCreationFactory factory = new AnnotationCreationFactory(new
EMFClassCreationFactory(getNSUri(fieldInstance)));
factory.setEditDomain(editDomain);
request.setFactory(factory);
/* The coordinates below are adjusted for the position of the component that
the object is dropped on. If you've moved the panel within the editor the
x,y coordinates here need to be adjusted accordingly. Default is 10,10 I
believe, so the following would actually appear at point 0,0 inside of the
panel. Using the position of the mouse pointer or somesuch is highly recommended
here, as the offset is in no way guaranteed.
*/
request.setLocation(new org.eclipse.draw2d.geometry.Point(10,10));
Command command = part.getCommand(request);
editDomain.getCommandStack().execute(command);
/** This returns a namespace uri for the given field instance. This is the
uri that ve uses to create the eClass object in the factory
*/
private String getNSUri(IJavaInstance fieldInstance) {
return ((EPackageImpl)fieldInstance.eClass().eContainer()).getNsURI ()
+ "#" + fieldInstance.eClass().getName();
}
</code>
Sorry for the hacked out code, my newsgroup client crushes my attempts and
good editing.
Dylan Bruzenak
|
|
|
Re: Adding a component programmatically - figured - one more question [message #104679 is a reply to message #104612] |
Thu, 01 September 2005 14:10 |
Dylan Bruzenak Messages: 48 Registered: July 2009 |
Member |
|
|
Ok, number 2 was easy. Set size on the CreationRequest. I don't know how
I missed that - everything seems so much simpler in the morning. Still stumped
on #1. Once I get all this figured out I may do a write up for the eclipse
wiki, if anyone else is interested. I don't know if that page has any traffic.
Sorry for the noise.
Dylan
> Ok, I figured this out. A combination of re-reading all the code
> generation posts I could find on this board and putting breakpoints
> higher up the food chain. My code is appended to the end of this
> message for anyone else trying to accomplish the same thing.
>
> I have two more questions.
>
> 1. Using a combination of EMFClassCreationFactory and the
> AnnotationCreationFactory decorator causes a popup to appear asking
> for the control name. I want to specify the name and not bother the
> user with the popup. I see a constructor that takes a list of keys,
> but I have no idea what to populate that with ;)
>
> 2. Is there an easy way to specify the component width and height for
> a newly added component ? My current technique involved finding the
> existing line of code and manually editing it using the AST. God help
> me.
>
> I greatly appreciate any response.
>
> My current code follows:
>
> <code>
> BeanSubclassComposition bean = (BeanSubclassComposition)
> editDomain.getDiagramData();
> IJavaObjectInstance rootInstance = bean.getThisPart();
> EditPart part =
> primaryViewer.getRootEditPart().getContents();
> part = (EditPart)part.getChildren().get(0); /* get the
> jpanel */
> CreateRequest request = new CreateRequest();
>
> IJavaInstance fieldInstance =
> BeanUtilities.createJavaObject("javax.swing.JTextField",
> rootInstance.eResource().getResourceSet(), "");
> /* AnnotationCreationFactory wraps another
> CreationFactory and
> lets the user set the fieldname of the added object with a
> popup. The EMFClassCreationFactory takes a namespace
> URI
> and creates object instances based on it.
> */
> AnnotationCreationFactory factory = new
> AnnotationCreationFactory(new
> EMFClassCreationFactory(getNSUri(fieldInstance)));
> factory.setEditDomain(editDomain);
>
> request.setFactory(factory);
>
> /* The coordinates below are adjusted for the position of the
> component that
> the object is dropped on. If you've moved the panel within the editor
> the
> x,y coordinates here need to be adjusted accordingly. Default is
> 10,10 I
> believe, so the following would actually appear at point 0,0 inside of
> the
> panel. Using the position of the mouse pointer or somesuch is highly
> recommended
> here, as the offset is in no way guaranteed.
> */
> request.setLocation(new
> org.eclipse.draw2d.geometry.Point(10,10));
> Command command = part.getCommand(request);
>
> editDomain.getCommandStack().execute(command);
>
> /** This returns a namespace uri for the given field instance. This
> is the
> uri that ve uses to create the eClass object in the factory
> */
> private String getNSUri(IJavaInstance fieldInstance) {
> return
> ((EPackageImpl)fieldInstance.eClass().eContainer()).getNsURI ()
> + "#" + fieldInstance.eClass().getName();
> }
> </code>
> Sorry for the hacked out code, my newsgroup client crushes my attempts
> and good editing.
>
> Dylan Bruzenak
>
|
|
| | | | | | | |
Re: Adding a component programmatically - figured - one more question [message #105817 is a reply to message #105763] |
Thu, 08 September 2005 14:23 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Hi,
There is one important complication to Joe's description. In the VE you
would never do subclasscomposition.add(something) or
javainstance.eSet(feature, value) to the subclasscomposition or to any
javainstance that is in the model. This is because changing it and not
using the command stack and commands will cause bad things to occur.
That is why everytime we change things we do it through commands.
John Cage wrote:
> Hi Joe,
>
> Thank You for your explanation of the problem, it is very clear to
> understand.
>
>
> Best Regards,
>
> John Cage
>
--
Thanks,
Rich Kulp
|
|
| | | |
Re: Adding a component programmatically - figured - one more question [message #610470 is a reply to message #104463] |
Wed, 31 August 2005 23:50 |
Dylan Bruzenak Messages: 48 Registered: July 2009 |
Member |
|
|
Ok, I figured this out. A combination of re-reading all the code generation
posts I could find on this board and putting breakpoints higher up the food
chain. My code is appended to the end of this message for anyone else trying
to accomplish the same thing.
I have two more questions.
1. Using a combination of EMFClassCreationFactory and the AnnotationCreationFactory
decorator causes a popup to appear asking for the control name. I want to
specify the name and not bother the user with the popup. I see a constructor
that takes a list of keys, but I have no idea what to populate that with ;)
2. Is there an easy way to specify the component width and height for a
newly added component ? My current technique involved finding the existing
line of code and manually editing it using the AST. God help me.
I greatly appreciate any response.
My current code follows:
<code>
BeanSubclassComposition bean = (BeanSubclassComposition) editDomain.getDiagramData();
IJavaObjectInstance rootInstance = bean.getThisPart();
EditPart part = primaryViewer.getRootEditPart().getContents();
part = (EditPart)part.getChildren().get(0); /* get the jpanel */
CreateRequest request = new CreateRequest();
IJavaInstance fieldInstance = BeanUtilities.createJavaObject("javax.swing.JTextField",
rootInstance.eResource().getResourceSet(), "");
/* AnnotationCreationFactory wraps another CreationFactory and
lets the user set the fieldname of the added object with a
popup. The EMFClassCreationFactory takes a namespace URI
and creates object instances based on it.
*/
AnnotationCreationFactory factory = new AnnotationCreationFactory(new
EMFClassCreationFactory(getNSUri(fieldInstance)));
factory.setEditDomain(editDomain);
request.setFactory(factory);
/* The coordinates below are adjusted for the position of the component that
the object is dropped on. If you've moved the panel within the editor the
x,y coordinates here need to be adjusted accordingly. Default is 10,10 I
believe, so the following would actually appear at point 0,0 inside of the
panel. Using the position of the mouse pointer or somesuch is highly recommended
here, as the offset is in no way guaranteed.
*/
request.setLocation(new org.eclipse.draw2d.geometry.Point(10,10));
Command command = part.getCommand(request);
editDomain.getCommandStack().execute(command);
/** This returns a namespace uri for the given field instance. This is the
uri that ve uses to create the eClass object in the factory
*/
private String getNSUri(IJavaInstance fieldInstance) {
return ((EPackageImpl)fieldInstance.eClass().eContainer()).getNsURI ()
+ "#" + fieldInstance.eClass().getName();
}
</code>
Sorry for the hacked out code, my newsgroup client crushes my attempts and
good editing.
Dylan Bruzenak
|
|
|
Re: Adding a component programmatically - figured - one more question [message #610478 is a reply to message #104612] |
Thu, 01 September 2005 14:10 |
Dylan Bruzenak Messages: 48 Registered: July 2009 |
Member |
|
|
Ok, number 2 was easy. Set size on the CreationRequest. I don't know how
I missed that - everything seems so much simpler in the morning. Still stumped
on #1. Once I get all this figured out I may do a write up for the eclipse
wiki, if anyone else is interested. I don't know if that page has any traffic.
Sorry for the noise.
Dylan
> Ok, I figured this out. A combination of re-reading all the code
> generation posts I could find on this board and putting breakpoints
> higher up the food chain. My code is appended to the end of this
> message for anyone else trying to accomplish the same thing.
>
> I have two more questions.
>
> 1. Using a combination of EMFClassCreationFactory and the
> AnnotationCreationFactory decorator causes a popup to appear asking
> for the control name. I want to specify the name and not bother the
> user with the popup. I see a constructor that takes a list of keys,
> but I have no idea what to populate that with ;)
>
> 2. Is there an easy way to specify the component width and height for
> a newly added component ? My current technique involved finding the
> existing line of code and manually editing it using the AST. God help
> me.
>
> I greatly appreciate any response.
>
> My current code follows:
>
> <code>
> BeanSubclassComposition bean = (BeanSubclassComposition)
> editDomain.getDiagramData();
> IJavaObjectInstance rootInstance = bean.getThisPart();
> EditPart part =
> primaryViewer.getRootEditPart().getContents();
> part = (EditPart)part.getChildren().get(0); /* get the
> jpanel */
> CreateRequest request = new CreateRequest();
>
> IJavaInstance fieldInstance =
> BeanUtilities.createJavaObject("javax.swing.JTextField",
> rootInstance.eResource().getResourceSet(), "");
> /* AnnotationCreationFactory wraps another
> CreationFactory and
> lets the user set the fieldname of the added object with a
> popup. The EMFClassCreationFactory takes a namespace
> URI
> and creates object instances based on it.
> */
> AnnotationCreationFactory factory = new
> AnnotationCreationFactory(new
> EMFClassCreationFactory(getNSUri(fieldInstance)));
> factory.setEditDomain(editDomain);
>
> request.setFactory(factory);
>
> /* The coordinates below are adjusted for the position of the
> component that
> the object is dropped on. If you've moved the panel within the editor
> the
> x,y coordinates here need to be adjusted accordingly. Default is
> 10,10 I
> believe, so the following would actually appear at point 0,0 inside of
> the
> panel. Using the position of the mouse pointer or somesuch is highly
> recommended
> here, as the offset is in no way guaranteed.
> */
> request.setLocation(new
> org.eclipse.draw2d.geometry.Point(10,10));
> Command command = part.getCommand(request);
>
> editDomain.getCommandStack().execute(command);
>
> /** This returns a namespace uri for the given field instance. This
> is the
> uri that ve uses to create the eClass object in the factory
> */
> private String getNSUri(IJavaInstance fieldInstance) {
> return
> ((EPackageImpl)fieldInstance.eClass().eContainer()).getNsURI ()
> + "#" + fieldInstance.eClass().getName();
> }
> </code>
> Sorry for the hacked out code, my newsgroup client crushes my attempts
> and good editing.
>
> Dylan Bruzenak
>
|
|
| | | | | | | |
Re: Adding a component programmatically - figured - one more question [message #610709 is a reply to message #105763] |
Thu, 08 September 2005 14:23 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
Hi,
There is one important complication to Joe's description. In the VE you
would never do subclasscomposition.add(something) or
javainstance.eSet(feature, value) to the subclasscomposition or to any
javainstance that is in the model. This is because changing it and not
using the command stack and commands will cause bad things to occur.
That is why everytime we change things we do it through commands.
John Cage wrote:
> Hi Joe,
>
> Thank You for your explanation of the problem, it is very clear to
> understand.
>
>
> Best Regards,
>
> John Cage
>
--
Thanks,
Rich Kulp
|
|
| | | |
Goto Forum:
Current Time: Thu Apr 25 14:02:25 GMT 2024
Powered by FUDForum. Page generated in 0.04686 seconds
|