|
Re: Using Textarea instead of WrappingLabel [message #792266 is a reply to message #792127] |
Mon, 06 February 2012 20:22 |
Michael Golubev Messages: 383 Registered: July 2009 |
Senior Member |
|
|
Hello,
I have just modified the standard MindMap sample to show the multiline labels for Threads, see attached screenshot:
In order to do that, I have replaced the default child Label in the gmfgraph model to somewhat tricky construction as below:
<descriptors
name="StickyNoteFigure">
<actualFigure
xsi:type="gmfgraph:Rectangle"
name="StickyNoteFigure">
... omitted
<!-- HERE IS REPLACEMENT FOR DEFAULT LABEL -->
<children
xsi:type="gmfgraph:CustomFigure"
name="StickyNoteNameFigure"
qualifiedClassName="org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel">
<minimumSize
dx="200"
dy="50"/>
<preferredSize
dx="200"
dy="50"/>
<attributes
name="textWrap"
value="true"/>
</children>
<!-- END OF REPLACEMENT - ALL THE REST IS THE SAME -->
... the rest omitted
</descriptors>
The label looks fine, but at least in my sample, I found the problem with inplace editor for it -- the inplace editor is single-lined, and not correctly positioned. Please let me know if you will observe the same issue.
Please don't hesitate to submit Bugzilla for out of the box support for multi-line labels without tricks like the one above.
Regards,
Michael "Borlander" Golubev
at Montages Think Tank, Prague, Czech Republic
Montages AG, Zürich, Switzerland
[Updated on: Mon, 06 February 2012 20:32] Report message to a moderator
|
|
|
|
Re: Using Textarea instead of WrappingLabel [message #792397 is a reply to message #792387] |
Tue, 07 February 2012 00:22 |
Michael Golubev Messages: 383 Registered: July 2009 |
Senior Member |
|
|
Well, if it helps, I may say that the trick above is expected to be translated into the code like below:
(to be generated into the inner class of XXXEditPart.YYYFigure):
fNameLabelFigure = new WrappingLabel(); //you should have it
//add those 3 lines
fNameLabelFigure.setTextWrap(true);
fNameLabelFigure.setMinimumSize(new Dimension(...));
fNameLabelFigure.setPreferredSize(new Dimension(...));
Regards,
Michael
[Updated on: Tue, 07 February 2012 00:22] Report message to a moderator
|
|
|
|
Re: Using Textarea instead of WrappingLabel [message #792459 is a reply to message #792402] |
Tue, 07 February 2012 02:27 |
Michael Golubev Messages: 383 Registered: July 2009 |
Senior Member |
|
|
Hello,
Quote:And the WrappingLabel seems to be a bit dirty when doing automated line breaks.
There is always a small part (just one letter) on the left, not showing correctly.
Is this a bug ?
May be, but if it is, it is for GMF Runtime, let's wait for Aurelien's comment.
You can't use the pure SWT widget here as you need something implements IFigure to to be placed inside the heirarchy of Draw2D figures. If you don't like the default WrappingLabel behavior, you always may try to implement your own using the primitives from org.eclipse.draw2d.text.* package.
But I am pretty sure that either ctrl-enter or shift-enter will insert manual line break there -- you always may experiment with GMF notes available for every diagram.
If you still want to fix the inplace editor, you may look at the code here, in particular to the following:
/**
* @generated
*/
public static CellEditorLocator getTextCellEditorLocator(ITextAwareEditPart source) {
if (source.getFigure() instanceof WrappingLabel) {
return new TextCellEditorLocator((WrappingLabel) source.getFigure());
} else {
return new LabelCellEditorLocator((Label) source.getFigure());
}
}
/**
* @generated
*/
static private class TextCellEditorLocator implements CellEditorLocator {
/**
* @generated
*/
private WrappingLabel wrapLabel;
/**
* @generated
*/
public TextCellEditorLocator(WrappingLabel wrapLabel) {
this.wrapLabel = wrapLabel;
}
/**
* @generated
*/
public WrappingLabel getWrapLabel() {
return wrapLabel;
}
/**
* @generated
*/
public void relocate(CellEditor celleditor) {
Text text = (Text) celleditor.getControl();
Rectangle rect = getWrapLabel().getTextBounds().getCopy();
getWrapLabel().translateToAbsolute(rect);
if (!text.getFont().isDisposed()) {
if (getWrapLabel().isTextWrapOn() && getWrapLabel().getText().length() > 0) {
rect.setSize(new Dimension(text.computeSize(rect.width, SWT.DEFAULT)));
} else {
int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
}
}
if (!rect.equals(new Rectangle(text.getBounds()))) {
text.setBounds(rect.x, rect.y, rect.width, rect.height);
}
}
}
Regards,
|
|
|
|
Powered by
FUDForum. Page generated in 0.02512 seconds