Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » UML2 Tools » Problem when programatically deleting diagram file
Problem when programatically deleting diagram file [message #535937] Wed, 26 May 2010 12:30
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();
					}
				}
			}
		}
	}



Kind regards,
Niels Brouwers.

[Updated on: Wed, 26 May 2010 12:30]

Report message to a moderator

Previous Topic:How to change appearance of diagram programatically?
Next Topic:Problem when programatically deleting diagram file
Goto Forum:
  


Current Time: Thu Apr 25 10:58:58 GMT 2024

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

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

Back to the top