Home » Modeling » GMF (Graphical Modeling Framework) » How does code generation and custom code co-exist in a normal project?
| |
Re: How does code generation and custom code co-exist in a normal project? [message #212593 is a reply to message #212586] |
Wed, 03 December 2008 03:54 |
RefuX Zanzeebarr Messages: 51 Registered: July 2009 |
Member |
|
|
OK, that is interesting. I didn't know you could do that :)
My problem:
/**
* @generated
*/
public class MyEditPart extends ShapedNodeEditPart {
public class MyFigure extends RectangleFigure {
/**
* @generated
*/
private void createContents() {
class ScalePolyClass extends Shape {
..... lots o code
}
ScalePolyClass sp = new ScalePolyClass ();
this.add(sp);
..... lots o code
WrappingLabel label1 = new WrappingLabel();
label1.setText("LABEL");
sp.add(label1);
....... lots o code
}
}
}
What I want to do is add a line, right after label1 is defined, with:
label1.setAlignment(PositionConstants.CENTER);
So yes, I can use your tick to rename the method, but then it is going
just nasty going to dig the WrappingLabel out of the Figure by calling
getChildren and finding the WrappingLabel.
It seems to me if I have the expectation of repeatedly generating my
codebase as I add features, it is going to be a LOT of work to preserve
the @generated sections so code generation will still work. Thus
performing relatively simple things like centering a label, suddenly
become quite onerous.
The good news is (I hope!), there are lots of people using GMF, who must
be already dealing with these issues, which gets back to me asking the
group (and you Ed :) "How does code generation and custom code co-exist
in a normal (GMF) project?"
Oh, and any ideas on my problem stated above would be much appreciated! :)
Ed Merks wrote:
> If you have a method foo(), you can rename it fooGen (still with
> @generated on it) and define a new method foo() (without @generated on
> it) that calls fooGen(). In this way, you can ensure that fooGen()
> will still be generated but your changes in foo() that specialize it
> will not be lost. Not sure if that works for what you're trying to do...
>
>
> RefuX wrote:
>> I was looking into centering my text in a label and I was able to
>> figure out that in the generated code I can change the code in my
>> 'createContents' method to set the alignment on the WrappingLabel to
>> center.
>>
>> However I'm still in the early days of tweaking my gmfgraph etc.. and
>> as soon as I regenerate I will lose my custom code in the
>> 'createContents' method. I don't want to do a @generated not, since
>> there is still plenty of tweaking to do, and I do want the
>> 'createContents' method to continue to be generated :)
>>
>> So what do people typically do in this situation?
>>
>> My expectation was that code generation would continue throughout the
>> life-cycle of a GMF project. Maybe later on I decide to add some more
>> diagram elements or change the ones I currently have. I'd sure like to
>> continue to generate GMF code. But how can I continue to use GMF if
>> all my custom code gets removed? Sure I could "@generated not" on all
>> the sections I want to keep, but once I stop generated code being
>> placed in places like my createContents method, then what value is GMF
>> providing me now?
>>
>> Anyways, I'm sure people have an approach that they have come up with
>> that works well. I'd sure like to know what it is! :)
>>
>> p.s. If anyone can tell me how to define the center alignment on a
>> label in the gmpgraph, that would be great
|
|
| |
Re: How does code generation and custom code co-exist in a normal project? [message #212625 is a reply to message #212593] |
Wed, 03 December 2008 12:04 |
Ed Merks Messages: 33142 Registered: July 2009 |
Senior Member |
|
|
So in this case the answer is that you don't need to modify the code
because GMF lets you configure it in the model. :-P
RefuX wrote:
> OK, that is interesting. I didn't know you could do that :)
>
> My problem:
>
> /**
> * @generated
> */
> public class MyEditPart extends ShapedNodeEditPart {
> public class MyFigure extends RectangleFigure {
>
> /**
> * @generated
> */
> private void createContents() {
>
> class ScalePolyClass extends Shape {
> ..... lots o code
> }
>
> ScalePolyClass sp = new ScalePolyClass ();
> this.add(sp);
>
> ..... lots o code
>
> WrappingLabel label1 = new WrappingLabel();
> label1.setText("LABEL");
>
> sp.add(label1);
>
> ....... lots o code
> }
> }
> }
>
> What I want to do is add a line, right after label1 is defined, with:
> label1.setAlignment(PositionConstants.CENTER);
>
> So yes, I can use your tick to rename the method, but then it is going
> just nasty going to dig the WrappingLabel out of the Figure by calling
> getChildren and finding the WrappingLabel.
>
> It seems to me if I have the expectation of repeatedly generating my
> codebase as I add features, it is going to be a LOT of work to
> preserve the @generated sections so code generation will still work.
> Thus performing relatively simple things like centering a label,
> suddenly become quite onerous.
>
> The good news is (I hope!), there are lots of people using GMF, who
> must be already dealing with these issues, which gets back to me
> asking the group (and you Ed :) "How does code generation and custom
> code co-exist in a normal (GMF) project?"
>
> Oh, and any ideas on my problem stated above would be much
> appreciated! :)
>
> Ed Merks wrote:
>> If you have a method foo(), you can rename it fooGen (still with
>> @generated on it) and define a new method foo() (without @generated
>> on it) that calls fooGen(). In this way, you can ensure that
>> fooGen() will still be generated but your changes in foo() that
>> specialize it will not be lost. Not sure if that works for what
>> you're trying to do...
>>
>>
>> RefuX wrote:
>>> I was looking into centering my text in a label and I was able to
>>> figure out that in the generated code I can change the code in my
>>> 'createContents' method to set the alignment on the WrappingLabel to
>>> center.
>>>
>>> However I'm still in the early days of tweaking my gmfgraph etc..
>>> and as soon as I regenerate I will lose my custom code in the
>>> 'createContents' method. I don't want to do a @generated not, since
>>> there is still plenty of tweaking to do, and I do want the
>>> 'createContents' method to continue to be generated :)
>>>
>>> So what do people typically do in this situation?
>>>
>>> My expectation was that code generation would continue throughout
>>> the life-cycle of a GMF project. Maybe later on I decide to add some
>>> more diagram elements or change the ones I currently have. I'd sure
>>> like to continue to generate GMF code. But how can I continue to use
>>> GMF if all my custom code gets removed? Sure I could "@generated
>>> not" on all the sections I want to keep, but once I stop generated
>>> code being placed in places like my createContents method, then what
>>> value is GMF providing me now?
>>>
>>> Anyways, I'm sure people have an approach that they have come up
>>> with that works well. I'd sure like to know what it is! :)
>>>
>>> p.s. If anyone can tell me how to define the center alignment on a
>>> label in the gmpgraph, that would be great
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: How does code generation and custom code co-exist in a normal project? [message #212704 is a reply to message #212617] |
Thu, 04 December 2008 03:57 |
RefuX Zanzeebarr Messages: 51 Registered: July 2009 |
Member |
|
|
Nope, doesn't work for me :(
I took:
<descriptors
name="NamedNodeRectangle">
<actualFigure
xsi:type="gmfgraph:Rectangle">
<layout
xsi:type="gmfgraph:FlowLayout"
vertical="true"
matchMinorSize="true"
forceSingleLine="true"
majorAlignment="CENTER"
minorAlignment="CENTER"
majorSpacing="0"
minorSpacing="0"/>
<children
xsi:type="gmfgraph:Label"
text="TEST"/>
</actualFigure>
<accessors
accessor="Name"
figure="//@figures.0/@descriptors.4/@actualFigure/@children.0 "/>
</descriptors>
Pasted it into my gmfgraph I'm using.
The label is on the left side :(
I generated code is:
public class ReallySimpleFigure extends RectangleFigure {
private WrappingLabel fFigureLabel;
public ReallySimpleFigure() {
ToolbarLayout layoutThis = new ToolbarLayout();
layoutThis.setStretchMinorAxis(true);
layoutThis.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
layoutThis.setSpacing(0);
layoutThis.setVertical(true);
this.setLayoutManager(layoutThis);
createContents();
}
private void createContents() {
fFigureLabel = new WrappingLabel();
fFigureLabel.setText("TEST");
this.add(fFigureLabel);
}
private boolean myUseLocalCoordinates = false;
protected boolean useLocalCoordinates() {
return myUseLocalCoordinates;
}
protected void setUseLocalCoordinates(boolean useLocalCoordinates) {
myUseLocalCoordinates = useLocalCoordinates;
}
public WrappingLabel getFigureLabel() {
return fFigureLabel;
}
}
From looking at GMF Q&A page:
gmf -> d2d BorderLayout -> org.eclipse.draw2d.BorderLayout XYLayout ->
org.eclipse.draw2d.XYLayout StackLayout ->
org.eclipse.draw2d.StackLayout FlowLayout, isForceSingleLine == true ->
org.eclipse.draw2d.ToolbarLayout FlowLayout, isForceSingleLine == false
-> org.eclipse.draw2d.FlowLayout GridLayout -> (missed now, vote for scr
#133281)
So since ForceSingleLine is ture, I deduce that ToolbarLayout is the
correct one (which is the item in the generated code).
When I fire up the debugger, I see that the ToolbarLayout, first checks
to see if the orientation is vertical or horizontal. If it's vertical
(which is what i want) it then defines the widthHint as the parent width
(i.e. the rectangle it is in). (ToolbarLayout:279)
When it's time to calc the prefSizes (ToolbarLayout:301), it uses the
width hint, which is the width of the parent width .
So the layout is working out the horizontal adjustment to move the label
over, it's math is the clientArea.with - width, both of which are the
width of the parent, so the adjustment is zero :( :(
So the only way (using this ToolbarLayout) I can get the label centered
is by aligning the text in the label by adding:
fFigureLabel.setAlignment(PositionConstants.CENTER);
Again I get the feeling I must be lost somewhere here, since people must
be centering labels just fine! (without editing code!)
Any help, magic tweaks much appreciated!
Alex Shatalin wrote:
> Hello RefuX,
>
>> p.s. If anyone can tell me how to define the center alignment on a
>> label in the gmpgraph, that would be great
> You are right that this kind of modification should be done directly in
> .gmfgraph model. See
> org.eclipse.gmf.graphdef/models/basic.gmfgraph#NamedNode as an example
> of a node figure with centered label (FlowLayout with
> majorAlignment="CENTER", minorAlignment="CENTER" was used there).
>
> -----------------
> Alex Shatalin
>
>
|
|
| |
Re: How does code generation and custom code co-exist in a normal project? [message #212922 is a reply to message #212578] |
Mon, 08 December 2008 03:11 |
Jevon Messages: 164 Registered: July 2009 |
Senior Member |
|
|
For the EMF model code, I follow the "@generated NOT" technique.
For the GMF editors, I use dynamic templates to implement my custom code.
I also have additional custom code in a separate plugin which uses the
GMF extension points (e.g.
org.eclipse.gmf.runtime.diagram.ui.editpartProviders,
org.eclipse.ui.popupMenus) to add functionality.
In both cases, I test all of my custom code changes through test cases
to make sure they continue to work throughout the development lifecycle.
Jevon
RefuX wrote:
> I was looking into centering my text in a label and I was able to figure
> out that in the generated code I can change the code in my
> 'createContents' method to set the alignment on the WrappingLabel to
> center.
>
> However I'm still in the early days of tweaking my gmfgraph etc.. and as
> soon as I regenerate I will lose my custom code in the 'createContents'
> method. I don't want to do a @generated not, since there is still plenty
> of tweaking to do, and I do want the 'createContents' method to continue
> to be generated :)
>
> So what do people typically do in this situation?
>
> My expectation was that code generation would continue throughout the
> life-cycle of a GMF project. Maybe later on I decide to add some more
> diagram elements or change the ones I currently have. I'd sure like to
> continue to generate GMF code. But how can I continue to use GMF if all
> my custom code gets removed? Sure I could "@generated not" on all the
> sections I want to keep, but once I stop generated code being placed in
> places like my createContents method, then what value is GMF providing
> me now?
>
> Anyways, I'm sure people have an approach that they have come up with
> that works well. I'd sure like to know what it is! :)
>
> p.s. If anyone can tell me how to define the center alignment on a label
> in the gmpgraph, that would be great
|
|
|
Goto Forum:
Current Time: Sat Apr 27 00:59:10 GMT 2024
Powered by FUDForum. Page generated in 0.03901 seconds
|