Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » changing the color of note figure
changing the color of note figure [message #193324] Wed, 18 June 2008 19:04
Amro Al-Akkad is currently offline Amro Al-AkkadFriend
Messages: 33
Registered: July 2009
Member
hi!

I like to set programmatically the background and foreground color for the
note, when it is dropped into the diagram or attached via the 'Add Note'
Action.

What is the best way to get the NoteFigure and do the coloring?

I've already seen the threads
( http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg00567.html,
http://dev.eclipse.org/newslists/news.eclipse.modeling.gmf/m sg13238.html),
and it helped a me little bit.

Then I thought of two inefficient ways:

1)to override the handleNotification: I've started like this:
@Override
protected void handleNotificationEvent(Notification notification) {

int type = notification.getEventType();

Object newValue = notification.getNewValue();

if(type == Notification.ADD){
if(newValue instanceof NodeImpl){
NodeImpl nodeImpl = (NodeImpl) newValue;

if(nodeImpl.getType().equals("Note")){

//get notefigure and process coloring

}

}
}

super.handleNotificationEvent(notification);
}

I don't know how to get the editpart and its corresponding figure?
What I could do is to iterate the diagramEditPart and search explicitly
for NoteEditParts, and check if its EObject is the newValue object, and
then set the coloring, but this totally inefficient.

2)I've already tried to create another single action, in the manner of
mindmap tutorial part 3, where a new subtopic and the corresponding edge
is created. Unfortunately I've got no success: an execution runtime is
thrown, and when I restart the application the note is in the left upper
corner, but the attachment is missing. here is the code:

public void run(IAction action) {
IElementType NOTE = ElementTypeRegistry
.getInstance()
.getType(
"org.eclipse.gmf.runtime.diagram.ui.presentation.note");

IElementType NOTE_ATTACHMENT = ElementTypeRegistry
.getInstance()
.getType(
" org.eclipse.gmf.runtime.diagram.ui.presentation.noteAttachme nt ");

//note request
CreateViewRequest createNoteRequest = CreateViewRequestFactory
.getCreateShapeRequest(
NOTE,
PreferencesHint.USE_DEFAULTS);



CompoundCommand cc = new CompoundCommand("Create Note and Attachment");

Point p =
selectedComponentEditPart.getFigure().getBounds().getTopRigh t().getCopy();
selectedComponentEditPart.getFigure().translateToAbsolute(p) ;
int edgeCount =
selectedComponentEditPart.getNotationView().getSourceEdges() .size();
// A quick hack to get subtopics to layout to the right, from top to
bottom
int offset = (edgeCount * 50) - 100;
createNoteRequest.setLocation(p.translate(100, offset));

DesignPipelineEditPart mapEditPart = (DesignPipelineEditPart)
selectedComponentEditPart.getParent();
Command createTopicCmd = mapEditPart.getCommand(createNoteRequest);
IAdaptable noteViewAdapter = (IAdaptable) ((List)
createNoteRequest.getNewObject()).get(0);

cc.add(createTopicCmd);

// create the attach link command
CreateConnectionViewAndElementRequest
createConnectionViewAndElementRequest = new
CreateConnectionViewAndElementRequest(NOTE_ATTACHMENT,
((IHintedType) NOTE_ATTACHMENT).getSemanticHint(),
PreferencesHint.USE_DEFAULTS);

IAdaptable componentAdapter = new EObjectAdapter((EObject)
selectedComponentEditPart.getModel());

ICommand createNoteAttachmentCmd = new
DeferredCreateConnectionViewAndElementCommand(createConnecti onViewAndElementRequest,
componentAdapter,
noteViewAdapter, selectedComponentEditPart.getViewer());

cc.add(new ICommandProxy(createNoteAttachmentCmd));

selectedComponentEditPart.getDiagramEditDomain().getDiagramC ommandStack().execute(cc);

// put the new topic in edit mode
final EditPartViewer viewer = selectedComponentEditPart.getViewer();
final EditPart elementPart = (EditPart)
viewer.getEditPartRegistry().get(noteViewAdapter.getAdapter( View.class));
if (elementPart != null) {
Display.getCurrent().asyncExec(new Runnable() {

public void run() {
viewer.setSelection(new StructuredSelection(elementPart));
Request der = new Request(RequestConstants.REQ_DIRECT_EDIT);
elementPart.performRequest(der);
}
});
}
}

I don't know maybe the DeferredCreateConnectionViewAndElementCommand is
not the right command?


Any ideas?

Regards,
Amro
Previous Topic:Resize only smaller
Next Topic:Create Node Manually
Goto Forum:
  


Current Time: Fri Apr 26 05:19:35 GMT 2024

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

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

Back to the top