Skip to main content



      Home
Home » Modeling » GMF (Graphical Modeling Framework) » Change color EditPolicy
Change color EditPolicy [message #137094] Mon, 18 June 2007 11:53 Go to next message
Eclipse UserFriend
Hi All,

I'm trying to change the colors of nodes programmatically. I've followed
this description but haven't gotten it to work:

http://www.sagewire.org/gmf-modeling-eclipse/changing-connec tion-color-programtically-352798.aspx

I've put in some flags and the code is being executed but the color isn't
changing.

I'm calling the EditPolicy with an OpenRole (double click), does it matter
how the EditPolicy is called or am I missing something really obvious?


Thanks,

Gaff



public class ColorEditPolicy extends OpenEditPolicy {



@Override
protected Command getOpenCommand(Request request) {
EditPart targetEditPart = getTargetEditPart(request);
if (targetEditPart instanceof IGraphicalEditPart == false)
return null;

IGraphicalEditPart editPart = (IGraphicalEditPart) targetEditPart;
EObject modelElement = editPart.resolveSemanticElement();


System.out.println("Flag1");


Command ret = null;



ChangePropertyValueRequest req = new ChangePropertyValueRequest(
StringStatics.BLANK, Properties.ID_LINECOLOR,
FigureUtilities.colorToInteger(DiagramColorConstants.red));
System.out.println("Flag2");
final Command cmd = editPart.getCommand(req);

System.out.println("Flag3");
AbstractEMFOperation operation = new
AbstractEMFOperation(((IGraphicalEditPart) editPart).getEditingDomain(),
StringStatics.BLANK, null) {
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable
info)throws ExecutionException {
cmd.execute();
return Status.OK_STATUS;
}
};

System.out.println("Flag4");
try {
operation.execute(new NullProgressMonitor(), null);
} catch (ExecutionException e) {
// nothing to do here
}


return ret;

}
Re: Change color EditPolicy [message #137226 is a reply to message #137094] Mon, 18 June 2007 21:06 Go to previous message
Eclipse UserFriend
Originally posted by: khai.n.situvista.com

Not sure what you're trying to do with the code below but this code works:

public class ColorEditPolicy extends OpenEditPolicy {
protected Command getOpenCommand(Request request) {
if (getHost() instanceof IGraphicalEditPart) {
ChangePropertyValueRequest req = new
ChangePropertyValueRequest(StringStatics.BLANK,
Properties.ID_LINECOLOR,
FigureUtilities.colorToInteger(DiagramColorConstants.red));
return getHost().getCommand(req);}
return null;
}
}

-- Khai --

Gaff wrote:
> Hi All,
>
> I'm trying to change the colors of nodes programmatically. I've followed
> this description but haven't gotten it to work:
>
> http://www.sagewire.org/gmf-modeling-eclipse/changing-connec tion-color-programtically-352798.aspx
>
>
> I've put in some flags and the code is being executed but the color
> isn't changing.
>
> I'm calling the EditPolicy with an OpenRole (double click), does it
> matter how the EditPolicy is called or am I missing something really
> obvious?
>
>
> Thanks,
>
> Gaff
>
>
>
> public class ColorEditPolicy extends OpenEditPolicy {
>
>
>
> @Override
> protected Command getOpenCommand(Request request) {
> EditPart targetEditPart = getTargetEditPart(request); if
> (targetEditPart instanceof IGraphicalEditPart == false)
> return null;
>
> IGraphicalEditPart editPart = (IGraphicalEditPart) targetEditPart;
> EObject modelElement = editPart.resolveSemanticElement();
>
>
> System.out.println("Flag1");
>
>
> Command ret = null;
>
>
> ChangePropertyValueRequest req = new ChangePropertyValueRequest(
> StringStatics.BLANK, Properties.ID_LINECOLOR,
> FigureUtilities.colorToInteger(DiagramColorConstants.red));
> System.out.println("Flag2");
> final Command cmd = editPart.getCommand(req);
>
> System.out.println("Flag3");
> AbstractEMFOperation operation = new
> AbstractEMFOperation(((IGraphicalEditPart) editPart).getEditingDomain(),
> StringStatics.BLANK, null) {
> protected IStatus doExecute(IProgressMonitor monitor,
> IAdaptable info)throws ExecutionException {
> cmd.execute();
> return Status.OK_STATUS;
> }
> };
>
> System.out.println("Flag4");
> try {
> operation.execute(new NullProgressMonitor(), null);
> } catch (ExecutionException e) {
> // nothing to do here
> }
>
>
> return ret;
>
> }
>
Previous Topic:Custom position for label
Next Topic:Removing default Note connection functionality
Goto Forum:
  


Current Time: Wed May 07 21:30:49 EDT 2025

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

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

Back to the top