Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » EditParts: Create additional children edit parts
EditParts: Create additional children edit parts [message #503624] Tue, 15 December 2009 01:29 Go to next message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
Hi,

I have two different diagram editors:

1. An editor to create Function Block Types. Function Block Types have
input events, output events, input variables, and output variables among
other things.

2. An editor to create a Function Block Network. Networks contain
Function Blocks. Function Blocks have an attribute Type that points to a
Function Block Type. In addition, input/output events and variables can
be connected with each other. However, since these are stored in the
Function Block Type, Function Blocks themselves do not contain events
and variables and there cannot be connected to each other.

I would like my Function Blocks to create new events and variables
whenever their Type has been changed, so that their events and variables
correspond to those of the Function Block Type.

For this, I changed the method handleNotificationEvent() in FBEditPart
(The edit part of the Function Blocks). There I have access to the
notifier Function Block that has been changed, the feature that has been
changed, and the Function Block Type that is the new type of the
Function Block.

I thought I should create as well new edit parts for the events and
variables as new figures and assign the figures to the edit parts.
For this I create an EditPart Factory and use it's method
createEditPart(EditPart context, Object model). The context is the
FBEditPart of course and the model is the event/variable, but after
having a look at the method I noticed that the model has to be a View.
However, I cannot get the model from an element. I tried to use the
EditPart itself and used this.getModel to get the model of the Function
Block, but from there I cannot get to the model of the Function Block
Type or its events and variables.

Does anyone have an idea how to solve this?

Thanks,
Matthias
Re: EditParts: Create additional children edit parts [message #503625 is a reply to message #503624] Tue, 15 December 2009 01:34 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
I thought it might be good to add my code:

protected void handleNotificationEvent(Notification notification) {
super.handleNotificationEvent(notification);
Object feature = notification.getFeature();
if ((feature != null) && (feature instanceof EReferenceImpl)) {
EReferenceImpl ref = (EReferenceImpl)feature;
Object notifier = notification.getNotifier();
if ((ref.getName().equals("Type")) && (notifier instanceof FBImpl)) {
FBImpl fb = (FBImpl)notifier;
FBType type = fb.getType();
if (type != null) {
EList<InputEvent> inputEvents = type.getInputEvents();
EList<OutputEvent> outputEvents = type.getOutputEvents();
EList<InputVar> inputVars = type.getInputVars();
EList<OutputVar> outputVars = type.getOutputVars();

CakefeedEditPartFactory fac = new CakefeedEditPartFactory();
for (InputEvent inEv : inputEvents) {
fac.createEditPart(this, inEv);
}
for (OutputEvent outEv : outputEvents) {
fac.createEditPart(this, outEv);
}
for (InputVar inVar : inputVars) {
fac.createEditPart(this, inVar);
}
for (OutputVar outVar : outputVars) {
fac.createEditPart(this, outVar);
}
}
}
Re: EditParts: Create additional children edit parts - cannot execute CreateviewCommand [message #504069 is a reply to message #503625] Wed, 16 December 2009 20:20 Go to previous message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
Hi,

it's me again. This time I use the Commandstack to try and create new
views and edit parts inside the FBEditPart. Here is the code:

protected void handleNotificationEvent(Notification notification) {
if (notification != null) {
Object feat = notification.getFeature();
if ((feat != null) && (feat instanceof EReferenceImpl)) {
EReferenceImpl ref = (EReferenceImpl)feat;
String name = ref.getName();
if ((name != null) && (name.equals("Type"))) {
Object newValue = notification.getNewValue();
if ((newValue != null) && (newValue instanceof CFBTypeImpl)) {
ShapeCompartmentEditPart eP = null;
List children = this.getChildren();
for (Object c : children) {
if (c instanceof ShapeCompartmentEditPart) {
eP = (ShapeCompartmentEditPart)c;
}
}
CFBTypeImpl type = (CFBTypeImpl)newValue;
EList<InputEvent> inputEvents = type.getInputEvents();
EList<OutputEvent> outputEvents = type.getOutputEvents();
EList<InputVar> inputVars = type.getInputVars();
EList<OutputVar> outputVars = type.getOutputVars();
EList[] lists = new EList[4];
lists[0] = inputEvents;
lists[1] = outputEvents;
lists[2] = inputVars;
lists[3] = outputVars;
for (int i = 0; i < 4; i++) {
EList<EObject> list = lists[i];
for (EObject o : list) {
CreateViewRequest req = new CreateViewRequest(o, new
PreferencesHint("prefHint:" + o.toString()));
Command com = eP.getCommand(req);
eP.getDiagramEditDomain()
.getDiagramCommandStack().execute(com);
}
}
}
}
}
}
}

Everything works until the last line. When the command is executed, it
decides that it cannot execute, because no service is provided.

Can you help me with this? There must be some way to create additional
edit parts.

Thanks in advance,
Matthias
Previous Topic:Standard command IDs for GMF
Next Topic:Problem with "clickable" Figures
Goto Forum:
  


Current Time: Fri Apr 16 18:34:19 GMT 2021

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

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

Back to the top