[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?
|
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