[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[gmf-dev] Model - Diagram Programmatic Modifications
|
Hi all,
I have created a simple model and editors to represent software components
as simple boxes. What I would like to do is programmatically change the
model and be able to view the results in the open diagram. So for example,
through a menu item the user could select to add a new sub-component in the
selected component. Such a change should be immediately visible in the (now
dirty) diagram.
My current course of action is roughly the following:
- get the active diagram editor.
- retrieve the editingdomain from the editor
- get the root component/box
- create a Command to add or remove a new component/box
- use the editingDomain to execute the command
However this does not work for me. No changes happen in the diagram. I am
relatively new to GMF and would greatly appreciate any help or ideas at all.
I am attaching a simplified version of my code here:
//Get the active editor and current selection
IWorkbenchWindow workbenchWindow = workbench.getActiveWorkbenchWindow();
IEditorPart ep = workbenchWindow.getActivePage().getActiveEditor();
ISelection s = workbenchWindow.getActivePage().getSelection();
final IEditorPart activeE = ep;
final ISelection activeS = s;
WorkspaceModifyOperation operation =
new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor progressMonitor) {
try {
// Get the editingDomain
EditingDomain ed = null;
//ComponentType is my model for the components
ComponentType root = null;
if (activeE instanceof MyModelEditor){
ed = ((MyModelEditor)activeE).getEditingDomain();
}
ResourceSet resourceSet = ed.getResourceSet();
for (Iterator<Resource> it = resourceSet.getResources().iterator();
it.hasNext(); ){
Resource current = it.next();
if (current instanceof MyModelResourceImpl){
root =
((ComponentType)((MyModelResourceImpl)current).getContents().get(0)).getComponent();
}
}
RemoveCommand cmd = new RemoveCommand(ed, root,
MyModelPackage.eINSTANCE.getComponentType_Component(), root.getComponent());
ed.getCommandStack().execute(cmd);
}
catch (Exception exception) {
...
}
finally {
progressMonitor.done();
}
}
};
--
View this message in context: http://www.nabble.com/Model---Diagram-Programmatic-Modifications-tp16732547p16732547.html
Sent from the Eclipse GMF - Dev mailing list archive at Nabble.com.