how to change the name of a generated constraint bean [message #117525] |
Mon, 13 February 2006 11:17  |
Eclipse User |
|
|
|
Originally posted by: markus.wawra.shark-soft.com
Hi again!
I'm adding a new layout to VE. My problem is the following:
I want to let VE create a constraint bean for each object in the getJPanel
method (quite similar to what the GridBagLayout does).
First this constraint object was a common java.awt.Rectangle, which worked
pretty fine.
This code was created:
private JPanel getJPanel() {
if (jPanel == null) {
Rectangle rectangle = new Rectangle();
rectangle.height = 33;
rectangle.x = 101;
rectangle.y = 203;
rectangle.width = 73;
jPanel = new JPanel();
jPanel.setLayout(new MyLayout());
jPanel.add(getJButton(), rectangle);
}
return thirdPanel;
}
The next step was to write a new constraint class, let's call it
MyConstraints.
This ended in this code:
private JPanel getJPanel() {
if (jPanel == null) {
MyConstraints MyConstraints = new MyConstraints();
MyConstraints.setLeftEdge(101);
MyConstraints.setOtherThings;
.
.
.
jPanel = new JPanel();
jPanel.setLayout(new MyLayout());
jPanel.add(getJButton4(), MyConstraints);
}
return jPanel;
}
As you can see the created constraint bean is called MyConstraints,
starting with an upper-case character.
How can I change the (default) name of such constraints?
It would be sufficient to call it myConstraints, starting with a small
letter.
In the first case with the java.awt.Rectangle, the rectangle was created
automatically with a lower-case character. Also the GridBagLayout creates
gridBagConstraints, starting with a small letter.
Regards,
Markus
|
|
|
|
Re: how to change the name of a generated constraint bean [message #117809 is a reply to message #117576] |
Tue, 14 February 2006 08:47   |
Eclipse User |
|
|
|
Originally posted by: markus.wawra.shark-soft.com
No I didn't add an Annotation.
How can I do that?
I searched for anything like that, but the only thing I found was
something in the RootPaneCreationPolicy. If I add that to my PolicyHelper
a dialogbox is opened where I can change the name of the constraint. That
ensures that it is named as I want, but I don't want a dialogbox like
that. It should be created directly.
Here are my methods of the MyLayoutPolicyHelper that create the
constraints (without the part of the RootPaneCreationPolicy). They are
built like the ones of GridBagLayout (and work perfectly if MyConstraints
is a java.awt.Rectangle):
public Command getChangeConstraintCommand(List children, List constraints)
{
RuledCommandBuilder cb = new RuledCommandBuilder(policy.getEditDomain());
Iterator childs = children.iterator();
Iterator consts = constraints.iterator();
while (childs.hasNext()) {
EObject child = (EObject) childs.next();
EObject constraintComponent =
InverseMaintenanceAdapter.getIntermediateReference((EObject)
policy.getContainer(), sfComponents, sfConstraintComponent, child);
Object oconstraint = consts.next();
if (oconstraint != NO_CONSTRAINT_VALUE) {
IJavaObjectInstance constraint = (oconstraint != null ?
convertConstraint(oconstraint) : null);
cb.applyAttributeSetting(constraintComponent, sfConstraintConstraint,
constraint);
} else
cb.cancelAttributeSetting(constraintComponent, sfConstraintConstraint);
}
return cb.getCommand();
}
protected IJavaObjectInstance convertConstraint(Object constraint) {
stConstraint = (MyConstraints) constraint;
MyConstraints defaultConstraint = new MyConstraints();
IJavaObjectInstance javaMyConstraint = (IJavaObjectInstance)
BeanUtilities.createJavaObject("new.layout.MyConstraints", rset,
(String)null);
if (stConstraint.getLeftEdgeAttachment() !=
defaultConstraint.getLeftEdgeAttachment()) {
Object left = BeanUtilities.createJavaObject(primInt, rset,
String.valueOf(stConstraint.getLeftEdge()));
javaMyConstraint.eSet(stleft, left);
}
//set other things in the same way
return javaMyConstraint;
}
|
|
|
|
|
|
|
|
|
|
|
Re: how to change the name of a generated constraint bean [message #612102 is a reply to message #117576] |
Tue, 14 February 2006 08:47  |
Eclipse User |
|
|
|
No I didn't add an Annotation.
How can I do that?
I searched for anything like that, but the only thing I found was
something in the RootPaneCreationPolicy. If I add that to my PolicyHelper
a dialogbox is opened where I can change the name of the constraint. That
ensures that it is named as I want, but I don't want a dialogbox like
that. It should be created directly.
Here are my methods of the MyLayoutPolicyHelper that create the
constraints (without the part of the RootPaneCreationPolicy). They are
built like the ones of GridBagLayout (and work perfectly if MyConstraints
is a java.awt.Rectangle):
public Command getChangeConstraintCommand(List children, List constraints)
{
RuledCommandBuilder cb = new RuledCommandBuilder(policy.getEditDomain());
Iterator childs = children.iterator();
Iterator consts = constraints.iterator();
while (childs.hasNext()) {
EObject child = (EObject) childs.next();
EObject constraintComponent =
InverseMaintenanceAdapter.getIntermediateReference((EObject)
policy.getContainer(), sfComponents, sfConstraintComponent, child);
Object oconstraint = consts.next();
if (oconstraint != NO_CONSTRAINT_VALUE) {
IJavaObjectInstance constraint = (oconstraint != null ?
convertConstraint(oconstraint) : null);
cb.applyAttributeSetting(constraintComponent, sfConstraintConstraint,
constraint);
} else
cb.cancelAttributeSetting(constraintComponent, sfConstraintConstraint);
}
return cb.getCommand();
}
protected IJavaObjectInstance convertConstraint(Object constraint) {
stConstraint = (MyConstraints) constraint;
MyConstraints defaultConstraint = new MyConstraints();
IJavaObjectInstance javaMyConstraint = (IJavaObjectInstance)
BeanUtilities.createJavaObject("new.layout.MyConstraints", rset,
(String)null);
if (stConstraint.getLeftEdgeAttachment() !=
defaultConstraint.getLeftEdgeAttachment()) {
Object left = BeanUtilities.createJavaObject(primInt, rset,
String.valueOf(stConstraint.getLeftEdge()));
javaMyConstraint.eSet(stleft, left);
}
//set other things in the same way
return javaMyConstraint;
}
|
|
|
Re: how to change the name of a generated constraint bean [message #612104 is a reply to message #117809] |
Tue, 14 February 2006 10:40  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
I don't know why. If you can get into debug mode, try debugging into
org.eclipse.ve.internal.java.codegen.java.rules.InstanceVari ableCreationRule.getInstanceVariableName(EObject
obj, IType currentType, IVEModelInstance cm, IBeanDeclModel bdm)
There is a call to CDEUtilities.lowCaseFirstCharacter(name) within that
method. That is where it should of lower-cased it for you.
Maybe you can see why it didn't call this or why it returned it unchanged.
--
Thanks,
Rich Kulp
|
|
|
|
Re: how to change the name of a generated constraint bean [message #612106 is a reply to message #117845] |
Tue, 14 February 2006 11:55  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
If you are at VE 1.2M1 there is a way, but at VE 1.1.0.1 there really
isn't a good way. But to be VE 1.2M1, you will need to step up to
Eclipse 3.2M4, GEF 3.2M4, and EMF 2.2M4 also.
This is how you would do it at VE1.2M1:
IJavaInstance javaInst = BeanUtilities.createJavaObject(...);
AnnotationLinkagePolicy policy = editDomain.getAnnotationLinkagePolicy();
Annotation annotation = AnnotationPolicy.createAnnotation(javaInst);
EStringToStringMapEntryImpl nameEntry = (EStringToStringMapEntryImpl)
EcoreFactory.eINSTANCE.create(EcorePackage.eINSTANCE.getEStr ingToStringMapEntry());
nameEntry.setKey(NameInCompositionPropertyDescriptor.NAME_IN _COMPOSITION_KEY);
nameEntry.setValue(NameInMemberPropertyDescriptor.FORCE_NAME _IN_COMPOSITION_PREFIX+ "nameIwant");
//$NON-NLS-1$
annotation.getKeyedValues().add(nameEntry);
policy.setModelOnAnnotation(javaInst, annotation);
Markus wrote:
> Is there also a way to add an Annotation as you mentioned in the earlier
> posting?
>
> A solution where I can set the default name in the PolicyHelper myself
> would be better than just making a lower-case first character.
> Regards,
> Markus
>
--
Thanks,
Rich Kulp
|
|
|
Re: how to change the name of a generated constraint bean [message #612113 is a reply to message #117855] |
Wed, 15 February 2006 09:34  |
Eclipse User |
|
|
|
Since I'm using VE 1.1.0.1 I had to keep searching for the problem why no
lower-case character was created. And I found it.
The hint to look in
CDEUtilities.lowCaseFirstCharacter(name)
was very good.
The name of a bean class you want to use in the VE must not start with 3
or more upper-case characters!
Thanks for your help,
Markus
|
|
|
Re: how to change the name of a generated constraint bean [message #612117 is a reply to message #117949] |
Wed, 15 February 2006 10:52  |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
I'm confused. Your example didn't have three upper-cases (MyConstraint).
That is only one uppercase.
Markus wrote:
> Since I'm using VE 1.1.0.1 I had to keep searching for the problem why
> no lower-case character was created. And I found it.
> The hint to look in
>
>
> CDEUtilities.lowCaseFirstCharacter(name)
>
>
> was very good.
> The name of a bean class you want to use in the VE must not start with 3
> or more upper-case characters!
>
> Thanks for your help,
>
> Markus
>
--
Thanks,
Rich Kulp
|
|
|
Re: how to change the name of a generated constraint bean [message #612126 is a reply to message #117998] |
Thu, 16 February 2006 07:56  |
Eclipse User |
|
|
|
Sure!
I tried different things. First I had constraints called
TestNullConstraints, which was a simple subclass of java.awt.Rectangle. It
didn't work for other reasons, which I do not search anymore since I don't
need them. It was just a first test.
For the layout I actually need, I had a class called STFramingSpec which
starts with 3 upper-cases. Now it's just called FramingSpec and that works.
In my posting I wrote MyConstraints to keep it simple and easier to read.
Bad mistake obviously, which I will not make once more. I didn't expect
that it's the name that makes the problems, but hoped that I can set the
created name somewhere. I'm very sorry for that!
Regards,
Markus
|
|
|
|
Powered by
FUDForum. Page generated in 0.05464 seconds