Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [ve-dev] Help with generating complex constraint objects


Hi,

This section from BoxLayoutPolicyFactory would be the best:

                PTClassInstanceCreation ic = InstantiationFactory.eINSTANCE.createPTClassInstanceCreation() ;
                ic.setType("javax.swing.BoxLayout") ; //$NON-NLS-1$
               
                // set the arguments
                PTInstanceReference ir = InstantiationFactory.eINSTANCE.createPTInstanceReference() ;
                ir.setReference(container) ;        
                PTFieldAccess fa = InstantiationFactory.eINSTANCE.createPTFieldAccess();        
                PTName name = InstantiationFactory.eINSTANCE.createPTName("javax.swing.BoxLayout") ; //$NON-NLS-1$
                if (javaClass.getName().equals("BoxLayoutY_Axis")) { //$NON-NLS-1$
                        fa.setField("Y_AXIS"); //$NON-NLS-1$
                } else {
                        fa.setField("X_AXIS");        // default to X_AXIS //$NON-NLS-1$
                }                
                fa.setReceiver(name) ;
                       
                ic.getArguments().add(ir);
                ic.getArguments().add(fa) ;
               
                JavaAllocation alloc = InstantiationFactory.eINSTANCE.createParseTreeAllocation(ic);        
                JavaHelpers boxLayoutJavaClass = JavaRefFactory.eINSTANCE.reflectType("javax.swing.BoxLayout", rset); //$NON-NLS-1$                
               
                return BeanUtilities.createJavaObject(boxLayoutJavaClass, rset, alloc);

To change it to be to allocation something like new FormLayout("a", "b") would be:

                JavaHelpers formLayoutJavaClass = JavaRefFactory.eINSTANCE.reflectType("x.y.FormLayout", rset); //$NON-NLS-1$
                PTClassInstanceCreation ic = InstantiationFactory.eINSTANCE.createPTClassInstanceCreation() ;
                ic.setType(formLayoutJavaClass.getQualifiedNameForReflection()) ; //$NON-NLS-1$
               
                // set the arguments.
                PTStringLiteral arg1 = InstantiationFactory.eINSTANCE.createPTStringLiteral();
                arg1.setLiteralValue("a");
                PTStringLiteral arg2 = InstantiationFactory.eINSTANCE.createPTStringLiteral();
                arg2.setLiteralValue("b");
                ic.getArguments().add(arg1);
                ic.getArguments().add(arg2) ;
               
                JavaAllocation alloc = InstantiationFactory.eINSTANCE.createParseTreeAllocation(ic);        
                return BeanUtilities.createJavaObject(formLayoutJavaClass, rset, alloc);

Basically what we are doing here is creating the initialization as a tree of expressions needed to execute to produce the final result. The tree here is the new class _expression_, that takes two arguments, which are each a string literal _expression_. The reason we want the tree is so that we don't have to parse it to evaluate it. Field references give us a big problem if not using a parse tree because it is hard to tell if x.y.Z.g is a reference to field g of class x.y.Z or is it an inner class g of class x.y.Z. With the parse tree you can't make that confusion because they are physically different types of nodes in the parse tree.

If your string literals where actually static field references to some common code, such as is done with BoxLayout and the references to javax.swing.BoxLayout.X_AXIS fields, then you would use the field reference type of argument shown in the BoxLayout example.

For your ints in the CellConstraint, if they are literals you would use (for an argument with the value 3):

                PTNumberLiteral arg1 = InstantiationFactory.eINSTANCE.createPTNumberLiteral("3");

Thanks,
Rich


Gerald Rosenberg <gerald@xxxxxxxxxx>
Sent by: ve-dev-bounces@xxxxxxxxxxx

06/01/2006 01:39 AM

Please respond to
Discussions people developing code for the Visual Editor project <ve-dev@xxxxxxxxxxx>

To
ve-dev@xxxxxxxxxxx
cc
Subject
Re: [ve-dev] Help with generating complex constraint objects





Thanks.

(My target platform is Eclipse 3.2 and VE 1.2.  Development platform is Callisto 3.2RC3.)

Next question is how to provide arguments to constructors as generated.  I am able to automatically generate this code on a layoutswitch:

private
JPanel getJPanel() {
if (jPanel == null) {
FormLayout formLayout = new FormLayout();
formLayout.setRowGroups(new int[][] {});
formLayout.setColumnGroups(new int[][] {});
jPanel = new JPanel();
jPanel.setLayout(formLayout);
jPanel.add(getJButton1(), new CellConstraints());
jPanel.add(getJButton2(), new CellConstraints());
}
return jPanel;
}

However, ...

The FormLayout signature as generated needs to be "new FormLayout(String, String)"
The CellConstratins signature as generated needs to be "new CellConstraints(int, int, int, int)"

I am currently following the pattern of GridLayoutSwitcher to specify the form layout manager and create the "setRowGroups/setColumnGroups" initializers.  Not obvious how to also specify constructor arguments.

BoxLayout appears to be able to specify constructor arguments, but I have not succeeded in tracing through the source to see how it is done.

A pointer to the right place in the code to look and/or an explanation of the right methods to use would be appreciated.

Gerald


At 05:46 PM 5/31/2006, you wrote:


Hi,

Sorry, but the current code parsing doesn't understand method calls to anything other than  getControl().getName() for the constraint argument in the add call. It only understands the getName() against a component and field references and literals like String and numbers and new class creation calls.


So if you change to instead of your format to (Note: This is in VE 1.2. I don't know if this works in VE 1.1, we made many changes since then):


jPanel
.add(getJButton1(), new CellConstraint(1,1))

we would be able to parse and understand this, assuming the FormLayout you created would take a "CellConstraint" as a constraint.


You can open an enhancement request against VE to allow method calls there instead.


Rich
_______________________________________________
ve-dev mailing list
ve-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/ve-dev


Back to the top