Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Problem when programatically deleting diagram file
Problem when programatically deleting diagram file [message #537121] Tue, 01 June 2010 11:47
Niels Brouwers is currently offline Niels BrouwersFriend
Messages: 80
Registered: July 2009
Member
Hi all,

I would like to request for help to solve one annoying problem. Let me begin by first describing what I am trying to achieve.

We customized the UML 2.0 class diagram and UML 2.0 activity diagram to suite domain specific needs. The customized class diagram contains for example a stereotyped UML component. This component contains one or many UML Packages, each containing one stereotyped activity. The activity provides a behavior specification for one of the operations that is owned by one of the interfaces provided by the stereotyped component. Each activity is edited using the customized activity diagram.

Currently, I am creating a wizard to remove behavior specifications (activities) from the model (including the package which contains the activity). Furthermore, the wizard allows the user to specify whether the customized activity diagram should be deleted as well (as the diagram will contain nodes not corresponding to any model element). The wizard is shown by a pop-up action defined on the EditPart of the component. So the user can right-click on the component, invoke the action and the wizard pops-up.

Now, the annoying problem is this: when the user selects the diagram to be deleted along with the activity element, clicking the finish button on the wizard results in the correct behavior (i.e. activity, references to the activity and the diagram get deleted), but has the annoying side-affect that the customized class diagram from which the wizard was started closes! This requires the user to re-open the diagram, which obviously is very inconvenient.

Does anyone have an idea why the customized class diagram gets closed? Please see the code enclosed below.

Thank you in advance for your effort.

Kind regards,
Niels Brouwers.

performFinish
	public boolean performFinish() {

		org.eclipse.uml2.uml.Package pack = null;
		
		// resolve package to be removed from the model
		String packageName = "la_" + selectLogicalActionBehaviorPage.getLogicalActionBehaviorName();
		pack = resolvePackage(myComponent, packageName);
		if (pack == null) {
			// Package could not be resolved
			return false;
		}
		
		ResourceSet resourceSet = pack.eResource().getResourceSet();

		// remove logical action diagram if required
		if (removalOptionsPage.removeLogicalActionDiagram()) {
			deleteLogicalActionDiagrams(pack, resourceSet);
		}
		
		// remove the package from the model
		deleteElement(pack);
		
		// save all the editors as changes to the uml model seem to be made after the editor is saved.
		PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().saveAllEditors(false);

		// Apparently all went OK, so return true.
		return true;
	}


deleteLogicalActionDiagrams
	private void deleteLogicalActionDiagrams(org.eclipse.uml2.uml.Package pack,	ResourceSet resourceSet) {
		if (myProject != null) {
			for (final IFile diagramFile : findAllLogicalActionDiagrams(myProject)) {
				if (getRootModelElement(diagramFile.getFullPath().toString(), resourceSet) == pack) {
					// pack is the root element of the diagram, so delete the diagram file
					WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
						protected void execute(IProgressMonitor monitor)
								throws CoreException, InvocationTargetException,
								InterruptedException {
							diagramFile.delete(false, monitor);
						}
					};
					try {
						getContainer().run(false, false, operation);
					} catch (InvocationTargetException e) {
						e.printStackTrace();
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}


Note: this problem has also been posted in the UML2Tools section of this forum. Because I was not getting a response there, I'd like to try to get one here, because I assume this is not an UML2Tools specific problem but maybe GMF generic.

Thank you in advance!

Kind regards,
Niels Brouwers.


Kind regards,
Niels Brouwers.
Previous Topic:Light weight modeling framework
Next Topic:nested elements in the palette
Goto Forum:
  


Current Time: Sat May 11 21:32:18 GMT 2024

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

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

Back to the top