[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.modeling.gmf] Re: How does code generation and custom code co-exist in a normal project?
|
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