Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How to change the color of editPart objects (I need to change the default color of editPart Objects )
How to change the color of editPart objects [message #1731568] Fri, 06 May 2016 21:00 Go to next message
Tito Tito is currently offline Tito TitoFriend
Messages: 4
Registered: May 2016
Junior Member
He there

I'm totally new in GEF and trying to implement some kind of model reduction algorithm on a plugin tool. when executing my command i need to show the ouput by marking the relevant editparts in the editor. The problem is that the color is not fixed. Once i click, edit,
reposition an object , or even navigate other editors , the color is changed back to its default color
(black). Second problem is that the editor is multipage editor, editParts that don't belong to the active page are never colored. could you please help. I just need to color the editParts permenantly but I feel that refreshVisuals() changes the editparts to its default color. Could you please HELP Sad

here is my code i used to mark the edit part objects:


for(EObject element:visitedNodes) // list of target model elements
{
//get editpart
modelEditPart=(EditPart)viewer.getEditPartRegistry().get((EObject) element );

// color the editPart
( (GraphicalEditPart) modelEditPart).getFigure().setForegroundColor(ColorConstants.green);

}



Attached two snapshots,one after executing my command which marks the the related paths with their model elements, and the other snapshot "TheIssue" is what i get when i just click on different page/edior and return to the previous one or just doing any edit on the editor.
Re: How to change the color of editPart objects [message #1731716 is a reply to message #1731568] Mon, 09 May 2016 13:39 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
As you have already observed, refreshVisuals() is called whenever the model changes to update the visuals. Therefore, you have to overwrite it in order to ensure that the desired colors are used, rather then setting the color from outside.
Re: How to change the color of editPart objects [message #1732022 is a reply to message #1731716] Wed, 11 May 2016 22:10 Go to previous messageGo to next message
Tito Tito is currently offline Tito TitoFriend
Messages: 4
Registered: May 2016
Junior Member
Thank you soooo much, i let refreshVisuals() call my "color" static function under some conditions and it works like a charm.

however, i need to do the same when selecting(click) or deselecting
an object because the objects turn to black when simple click or deselect ocuurs. I believe
that refreshVisuals() is not called when objects are selected/deselected; it's only invoked when an edit takes place and i have to edit the an object in order to refresh the screen so that the objects are recolored again .
could you help me how should fix this
Re: How to change the color of editPart objects [message #1732025 is a reply to message #1732022] Thu, 12 May 2016 05:25 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
Selection should not affect the coloring of your part's visuals. Can you post your refreshVisuals() implementation, I have the impression something may be wrong there?
Re: How to change the color of editPart objects [message #1732047 is a reply to message #1732025] Thu, 12 May 2016 08:34 Go to previous messageGo to next message
Tito Tito is currently offline Tito TitoFriend
Messages: 4
Registered: May 2016
Junior Member
This is the refreshVisuals(). i'm implementing my model reduction technique on an existing
open source plugin tool called jUCMNav,. Therefore, non of the code below is mine except
the last two lines where i call my doColor() after checking my command is ON
[HINT: pathnode, startPoint, EndPoint , etc are model element types].

attached two snapshots, "beforeSelection" is when i execute my command is the my target
paths are colored with their objects. "Afterselection" snapshot you can see some objects(with x shape) are reset to black_ this happens when i click on these objects

if i do one simple change/edit on the editor, the objects are colored normally to green.
the issue is that when just click/deselect objects and not doing any editing, the objects are reset to black and never changed until an edit occurs.

-could it be some kind of select/deselect notifier that's called when selecting/deselecting objects? cuz i noticed that a rectangle appears bordering the target object once it is selected (it is shown in "AfterSelection" snapshot)



here is the refreshVisuals() code



public void refreshVisuals() {
PathNodeFigure nodeFigure = getNodeFigure();
PathNode node = getNode();

if (node instanceof StartPoint) {// If it's a startpoint, update it's type
switch (((StartPoint) node).getFailureKind().getValue()) {
case FailureKind.NONE:
((StartPointFigure) nodeFigure).setType(0, ((StartPoint) node).isLocal());
break;
case FailureKind.FAILURE:
((StartPointFigure) nodeFigure).setType(1, ((StartPoint) node).isLocal());
break;
case FailureKind.ABORT:
((StartPointFigure) nodeFigure).setType(2, ((StartPoint) node).isLocal());
break;
default:
break;
}
}

if(node instanceof EndPoint) {
((EndPointFigure)nodeFigure).setType(((EndPoint) node).isLocal());
}

// inform and forks/joins how many branches they must display.
if (node instanceof AndFork) {
((AndForkJoinFigure) nodeFigure).setBranchCount(((PathNode) getModel()).getSucc().size());
} else if (node instanceof AndJoin) {
((AndForkJoinFigure) nodeFigure).setBranchCount(((PathNode) getModel()).getPred().size());
}

boolean scenariosActive = ScenarioUtils.getActiveScenario(node) != null && ScenarioUtils.getTraversalHitCount(node) > 0;
nodeFigure.setTraversed(scenariosActive);

// Set tool tip or hit count.
if (ScenarioUtils.getActiveScenario(node) != null) {
String hits = Integer.toString(ScenarioUtils.getTraversalHitCount(node));
//nodeFigure.setToolTip(new Label(Messages.getString("PathNodeEditPart.Hits") + hits)); //$NON-NLS-1$
Metadata metaHitCount = MetadataHelper.getMetaDataObj(node, METADATA_HITS);
if (metaHitCount != null) {
metaHitCount.setValue(hits);
} else {
MetadataHelper.addMetaData(diagram.getUrndefinition().getUrnspec(), node, METADATA_HITS, hits);
}
UrnMetadata.setToolTip(node, nodeFigure);
} else
UrnMetadata.setToolTip(node, nodeFigure);

// check if path node is used as a border for a pointcut expression
nodeFigure.setIsPointcutBorder(PointcutBorderDetector.detectPointcutBorder(node));

// refresh node connection decorations
// must not continue or will cause infinite loops
if (refreshDecorations())
return;

// position the figure
Dimension dim = nodeFigure.getPreferredSize().getCopy();
Point location = new Point(node.getX() - (dim.width / 2), node.getY() - (dim.height / 2)); // The
// position of the current figure
Rectangle bounds = new Rectangle(location, dim);
figure.setBounds(bounds);

// rotate it if necessary.
// note: you can't have andjoin rotate from previous for andjoin because it would cause infinite loops with connection router.
if (!(node instanceof AndJoin || node instanceof AndFork) && nodeFigure instanceof IRotateable && ((PathNode) getModel()).getPred().size() > 0) {
rotateFromPrevious(nodeFigure);
} else if ((node instanceof AndJoin || node instanceof AndFork || node instanceof FailurePoint || node instanceof Stub) && nodeFigure instanceof IRotateable && ((PathNode) getModel()).getSucc().size() > 0) {
rotateFromNext(nodeFigure);
}

// hide empty points when not in view all elements mode.
if (getModel() instanceof EmptyPoint) {
//((IFigure) getFigure().getChildren().get(0)).setVisible(((UCMConnectionOnBottomRootEditPart) getRoot()).getMode() == 0);
((IFigure) getFigure().getChildren().get(0)).setVisible(GeneralPreferencePage.getUcmEmptyPointVisible());
}
// should we offset it so that it doesn't overlap another element?
if (getModel() instanceof EndPoint) {
((EndPointFigure) nodeFigure).setOffset((((EndPoint) getModel()).getSucc().size() > 0));
}
// notify parent container of changed position & location
// if this line is removed, the XYLayoutManager used by the parent
// container
// (the Figure of the ShapesDiagramEditPart), will not know the bounds
// of this figure
// and will not draw it correctly.
if (getParent() != null)
((GraphicalEditPart) getParent()).setLayoutConstraint(this, figure, bounds);

// if (((UCMConnectionOnBottomRootEditPart)
// getRoot()).isStrategyView()){
//
// nodeFigure.setForegroundColor(
// new Color(Display.getCurrent(),StringConverter.asRGB("75,75,75")));
// } else{

// if (ScenarioUtils.getActiveScenario(getNode())!=null &&
// ScenarioUtils.getTraversalHitCount(getNode())>0) {
// nodeFigure.setColor(PathNodeFigure.RED);
// }
// else {
// nodeFigure.setColor(PathNodeFigure.BLACK);
// }
// nodeFigure.setForegroundColor(
// new Color(Display.getCurrent(),StringConverter.asRGB("0,0,0"))); //$NON-NLS-1$
// }

if(ColorUtils.ReduceON)
ColorUtils.doColor();
}



Re: How to change the color of editPart objects [message #1732234 is a reply to message #1732047] Fri, 13 May 2016 15:31 Go to previous messageGo to next message
Alexander Nyssen is currently offline Alexander NyssenFriend
Messages: 244
Registered: July 2009
Location: Lünen
Senior Member
This does not look problematic. Can it be that some action is triggered from within select?
Re: How to change the color of editPart objects [message #1732330 is a reply to message #1732234] Mon, 16 May 2016 04:03 Go to previous message
Tito Tito is currently offline Tito TitoFriend
Messages: 4
Registered: May 2016
Junior Member
I think so, where do you think i can find the code for "select and deselect" notification/event?
my problem is that i'm totally new in GEF and have to implement my model reduction technique within an existing plugin tool Sad
Previous Topic:Accessibility programming guide for Draw2D
Next Topic:Creating parts
Goto Forum:
  


Current Time: Tue Apr 23 10:19:38 GMT 2024

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

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

Back to the top