Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » text.setForeground(...) don't work as expected
text.setForeground(...) don't work as expected [message #912836] Fri, 14 September 2012 09:16 Go to next message
Junior Lekane Nimpa is currently offline Junior Lekane Nimpa
Messages: 23
Registered: September 2012
Junior Member
Hello all,

i am facing a strange problem, that i can't explain.
I try to implement my first editor for the Ecore-Meta model with Graphiti.
Actually i am able to add rectangle for EClasses. But i have a problem with the name.
I use Text as graphicsalgorithm.
I set explicitly text.setForeground(...(BLACK)), but the name is red.
I change the foreground color to green, it is still red
No matter what color(different from red) i used, the name is still red.
I can not explain this and i also don't know, what is wrong.
If someone can give some tips, i will really appreciate.

Many thanks in advance
Junior
Re: text.setForeground(...) don't work as expected [message #912879 is a reply to message #912836] Fri, 14 September 2012 10:26 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1595
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Junior,

hm, that sounds a bit like you have an update feature in place that returns
true on updateNeeded for that shape. The red color is used by Graphiti to
indicate that.

Michael
Re: text.setForeground(...) don't work as expected [message #912898 is a reply to message #912879] Fri, 14 September 2012 11:20 Go to previous messageGo to next message
Junior Lekane Nimpa is currently offline Junior Lekane Nimpa
Messages: 23
Registered: September 2012
Junior Member
Thanks Michael for your reply.

Actually I try to find, where the problem erase.
I had noted the following.

If I set the shape of the text's name active, the updateNeeded()-method for Eclass is called, when i move the mouse over the name of the class. Since I check in this method that the passed pictogram element must be a containershape, one if-statement is skipped and the method return true. This could be one explanation for the red color.

But when I set the shape of the text's name to inactive, the above method is also called and it returns false. That means for me that the data of the eClass is the same in both model and pictogram element. But why the red color?
Re: text.setForeground(...) don't work as expected [message #915410 is a reply to message #912898] Mon, 17 September 2012 08:13 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1595
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hm, not sure. Could you share some coding of your example?

Michael
Re: text.setForeground(...) don't work as expected [message #915468 is a reply to message #915410] Mon, 17 September 2012 10:49 Go to previous messageGo to next message
Junior Lekane Nimpa is currently offline Junior Lekane Nimpa
Messages: 23
Registered: September 2012
Junior Member
Hello Michael,
you can see in the following my implementation of the updateNeeded() method.
//retrieve the name from pictogram model
		String pictogramName = null;
		PictogramElement pictoElement = context.getPictogramElement();
		if(pictoElement instanceof ContainerShape){
			ContainerShape cs = (ContainerShape)pictoElement;
			for(Shape shape : cs.getChildren()){
				Object businessObject = getBusinessObjectForPictogramElement(shape);
				if(businessObject instanceof EClass){
					if(shape.getGraphicsAlgorithm() instanceof Text){
						Text text = (Text)shape.getGraphicsAlgorithm();
						pictogramName = text.getValue();
					}
				}
			}
		}


		if(pictoElement instanceof Shape){ // added part!!!
			Object bo = getBusinessObjectForPictogramElement(pictoElement);
			if(bo instanceof EClass){
				EClass eClass = (EClass)bo;
				pictogramName = eClass.getName();
			}
		}

		// retrieve the name from the business model
		String businessName = null;
		Object bo = getBusinessObjectForPictogramElement(pictoElement);
		if(bo instanceof EClass){
			EClass eClass = (EClass)bo;
			businessName = eClass.getName();
		}
		
		//update needed, if names are different
		boolean updateNeeded = 
				((pictogramName == null && businessName != null) || 
						pictogramName != null && !pictogramName.equals(businessName));
		if(updateNeeded){
			return Reason.createTrueReason("Name is out of date");
		}else{
			return Reason.createFalseReason();
		}



I found the problem. In the above code i added one more if-statement( @see added part!!! in the code). This solved the problem. But this is quite surprising, because it seems that the update()-method is called with different arguments. In one call the current context returs a containerShape as pictogram element and in another a shape.
Since the shape is also linked to the EClass, one question comes to my mind.
Does it mean that for example the update()-method for one business object is called on all pictogram elements that are linked to this business object?

Thanks in advance
Junior
Re: text.setForeground(...) don't work as expected [message #916571 is a reply to message #915468] Wed, 19 September 2012 07:23 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1595
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Junior,

for which shapes the update feature is called depends on the coding in
getUpdateFeature in your feature provider. Maybe you return that feature
also for the other shape because you simply check for the link to the domain
object?

Michael
Re: text.setForeground(...) don't work as expected [message #1005926 is a reply to message #916571] Tue, 29 January 2013 10:28 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya Mirajkar
Messages: 30
Registered: August 2012
Member
Hi Michael,

Your statement below says "update feature returns true on updateNeeded for a shape and red color is used by Graphiti to indicate that."

As per my understanding text will turn red if updateNeeded() method returns true.

In my case I have an update feature defined.I have a rectangle corresponding to domain object.When the value is changed ,values are properly updated but text changes to red and the rectangle foreground color also is changed to red if I have updateNeeded set to true.

Is it that rectangle foreground color also changes to red due to this update?

I want the values to change on update and the color of text and border of rectangle i.e foreground color to remain same as it was previously applied.

Re: text.setForeground(...) don't work as expected [message #1006391 is a reply to message #1005926] Thu, 31 January 2013 08:36 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1595
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Saniya,

the default behavior of the update needed is simply to draw a red dotted
line (see attached screenshot of tutorial class) and to provide a tooltip
idication the cause returned on updateNeeded.

The must be some other functionality changing the foreground color in your
case.

Michael
Re: text.setForeground(...) don't work as expected [message #1006637 is a reply to message #1006391] Fri, 01 February 2013 09:51 Go to previous messageGo to next message
Saniya Mirajkar is currently offline Saniya Mirajkar
Messages: 30
Registered: August 2012
Member
I have an rectangle whoes foreground color is set to Blue in Add Functionality.

As you said the update needed method changes foreground color of rectangle to dotted red which is correct as per framework.

I want to retain the previously applied Blue color for the foreground and not the dotted red applied by updateNeeded method.

Is there some way to do this?
Re: text.setForeground(...) don't work as expected [message #1006686 is a reply to message #1006637] Fri, 01 February 2013 12:37 Go to previous message
Michael Wenz is currently offline Michael Wenz
Messages: 1595
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Saniya,

I'm afraid changing that behavior is currently not possible. Please open an
enhancement bugzilla for this.

Another option you have is to enable auto updating for your diagram. The
editor will immediatly reflect the changes without drawing the red border.
Have a look into the isAutoUpdate... methods in the tool behavior provider.

Michael
Previous Topic:Add actions/actionsets to the context-menu?
Next Topic:Problem with rendering of elements
Goto Forum:
  


Current Time: Sun Sep 21 00:15:49 GMT 2014

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

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