Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Using Textarea instead of WrappingLabel
Using Textarea instead of WrappingLabel [message #792127] Mon, 06 February 2012 16:45 Go to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Hello,

i have a special Use-Case in a GMF Editor.

For now i use DiagramLabels to be shown in canvas nodes. The problem is that i need multi-line text areas in the node, because the text can be much longer sometimes.

I append a picture to see how its done at the moment.

Is it possible to use a multi-line text area instead of a label in an editpart ?
How can i do this ?



  • Attachment: Testnode.png
    (Size: 0.97KB, Downloaded 198 times)
Re: Using Textarea instead of WrappingLabel [message #792266 is a reply to message #792127] Mon, 06 February 2012 20:22 Go to previous messageGo to next message
Michael Golubev is currently offline Michael GolubevFriend
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:
index.php/fa/7041/0/

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 #792387 is a reply to message #792266] Tue, 07 February 2012 00:05 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Thanks for your help.

The problem is that this is not really what i want.
I can do no manual line breaks in it. And its really hard to do this with spacing.

Can't i simply use a text field or text area in that node ?

Are there any GMF related classes ? Can i use the native java methods ?

Greetings

[Updated on: Tue, 07 February 2012 00:30]

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 Go to previous messageGo to next message
Michael Golubev is currently offline Michael GolubevFriend
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 #792402 is a reply to message #792397] Tue, 07 February 2012 00:31 Go to previous messageGo to next message
Snakebyte Missing name is currently offline Snakebyte Missing nameFriend
Messages: 130
Registered: November 2011
Senior Member
Ok i edited my previous post.
But i maked it.

When editing a multi line property the link breaks are displayed correctly.
Indeed the inplace label is singlelined. Sad

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 ?

[Updated on: Tue, 07 February 2012 00:37]

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 Go to previous messageGo to next message
Michael Golubev is currently offline Michael GolubevFriend
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,
Re: Using Textarea instead of WrappingLabel [message #792634 is a reply to message #792459] Tue, 07 February 2012 08:08 Go to previous message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 637
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

in BonitaStudio, we are using label that goes to new line itself but... we have done it a long time ago and I don't remember how we did it. We are also resizing the container figure when needed to contain all the text.
You can take a look to the sourcecode: http://www.bonitasoft.org/websvn/listing.php?repname=Bonita+Open+Solution&path=%2Fbonita-studio%2Ftags%2Fbonita-studio-5.6.1%2F#path_bonita-studio_tags_bonita-studio-5.6.1_

I think that you can start to take a look to CustomScriptTaskLabel2EditPart for instance.

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Previous Topic:Grouping Nodes and defining property for the group
Next Topic:Issue with ViewService.createEdge()
Goto Forum:
  


Current Time: Thu Mar 28 08:34:07 GMT 2024

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

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

Back to the top