Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Trouble controling width of TextFlow figure
Trouble controling width of TextFlow figure [message #235484] Tue, 12 June 2007 15:16 Go to next message
Ian Leslie is currently offline Ian LeslieFriend
Messages: 137
Registered: July 2009
Senior Member
I have an RCP application that uses GEF for its editor. I have a
situation where I need to display an error message in the editor and I am
having trouble creating the figure to display it. My first version used a
Label - which worked OK. The look of the text all on one line was not
good since the message could be quite long (it includes a file name). I
want the message's text to wrap so I used a FlowPage with a TextFlow
inside like this:

public class ErrorMessageFigure2 extends Figure {

public ErrorMessageFigure2 (String message, IStatus status) {
// Setup the error message figure
ToolbarLayout layout = new ToolbarLayout ();
setLayoutManager (layout);
setBorder (new CompoundBorder (new MarginBorder (20),
new LineBorder (ColorConstants.menuForeground, 1)));
setBackgroundColor (ColorConstants.menuBackground);
setOpaque (true);

// Add the components
FlowPage flowPage = new FlowPage ();
add (flowPage);

TextFlow messageFlow = new TextFlow (message);
flowPage.add (messageFlow);
}
}

But this displayed just the same. The text did not wrap but instead just
kept going as long as needed to the right.

I am adding it to the viewer using an edit part that looks like this:

public final class ErrorMessageEditPart extends AbstractGraphicalEditPart {

public ErrorMessageEditPart (String message, IStatus status) {
myMessage = message;
myStatus = status;
}


@Override
protected IFigure createFigure () {

CompartmentFigure messageCanvas = new CompartmentFigure ();
messageCanvas.setBackgroundColor (ColorConstants.button);
messageCanvas.setOpaque (true);

ErrorMessageFigure2 messageFigure = new ErrorMessageFigure2
(myMessage, myStatus);

messageCanvas.add (messageFigure);

return messageCanvas;
}


@Override
protected void createEditPolicies () {
// This is not actually editable - no policies
}


private String myMessage;

private IStatus myStatus;
}

With code like this in my editor's initializeGraphicalViewer method:
if (input.isOK ()) {
// Set the contents of the viewer
viewer.setContents (getModel ());

// Listen for dropped parts
viewer.addDropTargetListener
(createPaletteTransferDropTargetListener ());
viewer.addDropTargetListener
(createCardTransferDropTargetListener ());
} else {
// The editor input is not a valid deck file
IStatus error = input.getStatus ();

viewer.setContents (new ErrorMessageEditPart (error.getMessage
(), error));
}

I have tried setting a setMaximumSize on the figure in the edit part's
create figure method as well as on all the figures in the
ErrorMessageFigure2 (messageCanvas, messageFigure, flowPage and
messageFlow). But the result is always the same - the message does not
wrap but extends as long as needed to the right.

How do I constrain the TextFlow so it wraps its contents? What is the
right level to control that and what is the correct method?

Any help or advice would be appreciated.

Ian
Re: Trouble controling width of TextFlow figure [message #235889 is a reply to message #235484] Mon, 18 June 2007 15:12 Go to previous messageGo to next message
Ian Leslie is currently offline Ian LeslieFriend
Messages: 137
Registered: July 2009
Senior Member
Ian Leslie wrote:

> I have an RCP application that uses GEF for its editor. I have a
> situation where I need to display an error message in the editor and I am
> having trouble creating the figure to display it. My first version used a
> Label - which worked OK. The look of the text all on one line was not
> good since the message could be quite long (it includes a file name). I
> want the message's text to wrap so I used a FlowPage with a TextFlow
> inside like this:

I still do not have a solution to the problem above and now I see the same
problem in my normal digram (this problem is about the inability to get
TextFlow to flow the text and not about showing an error message in the
editor).

In my editor I need to show information about my objects. Each figure
shows a count and a name of my model's objects plus some additional
information. I want my figure to look like this:

+----------------------------------+
| +-------+ +--------------+ |
| | count | | name | |
| +-------+ +--------------+ |
| +-------+ +-------+ |
| | info1 | | info2 | |
| +-------+ +-------+ |
| +-----------------+ |
| | info3 | |
| +-----------------+ |
| +-------------------+ |
| | Rather long text | |
| | that needs to | |
| | wrap. | |
| | | |
| | And may contain | |
| | hard line ends | |
| | too | |
| +-------------------+ |
+----------------------------------+

Most of the information uses a Label (count, name, info1, info2 and info3)
while the paragraph text uses a TextFlow inside a FlowPage. The figures
on the right (name, infoN and the FlowPage) are contained inside a
CompartmentFigure (just like the UML example). What I want is the
FlowPage to be the same width as the other labels in the compartment and
wrap the text as appropriate.

What I get is this:
+-----------------------------------------------------+
| +-------+ +--------------+ |
| | count | | name | |
| +-------+ +--------------+ |
| +-------+ +-------+ |
| | info1 | | info2 | |
| +-------+ +-------+ |
| +-----------------+ |
| | info3 | |
| +-----------------+ |
| +--------------------------------------+ |
| | Rather long text that needs to wrap. | |
| | | |
| | And may contain hard line ends too | |
| +--------------------------------------+ |
+-----------------------------------------------------+

where the width of the figure is the longest line in the paragraph (which
can be quite long).

How can I accomplish what I want (I am more than happy to use a different
structure of figures)?

Any advice or help would be appreciated.

Ian
Re: Trouble controling width of TextFlow figure [message #235896 is a reply to message #235889] Mon, 18 June 2007 16:13 Go to previous message
Ian Leslie is currently offline Ian LeslieFriend
Messages: 137
Registered: July 2009
Senior Member
Ian Leslie wrote:

> Most of the information uses a Label (count, name, info1, info2 and info3)
> while the paragraph text uses a TextFlow inside a FlowPage. The figures
> on the right (name, infoN and the FlowPage) are contained inside a
> CompartmentFigure (just like the UML example). What I want is the
> FlowPage to be the same width as the other labels in the compartment and
> wrap the text as appropriate.

Interesting bit of info: if I call infoCompartment.setMaximumSize (new
Dimension (50, 100)); on the compartment that contains the sub-figures on
the right it has not effect (as I reported in my earlier post) but if I
comment out adding the FlowPage (and its children) suddenly the setMaximum
is respected and all my labels get shrunk.

Is there a known bug that a FlowPage will not respect a parent's (or even
its own) maximum size?

Ian
Previous Topic:[Announce] Directed Graph Example (Digraph1)
Next Topic:Border offset in a Rectangle
Goto Forum:
  


Current Time: Fri Aug 12 21:11:32 GMT 2022

Powered by FUDForum. Page generated in 0.02216 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top