Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9257c5e75239aae53aae6a28da3ce05e4f62392f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*****************************************************************************
 * Copyright (c) 2010 CEA LIST.
 *
 *    
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *  Tatiana Fesenko (CEA LIST) - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.uml.diagram.wizards.category;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.IPath;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.RecordingCommand;
import org.eclipse.papyrus.resource.IModel;
import org.eclipse.papyrus.resource.ModelSet;
import org.eclipse.papyrus.resource.notation.NotationModel;
import org.eclipse.papyrus.resource.sasheditor.DiModel;
import org.eclipse.papyrus.resource.uml.UmlModel;
import org.eclipse.papyrus.uml.diagram.wizards.CreateModelWizard.DiResourceSetExt;

/**
 * The command to initialize Papyrus diagram for a given domain model.
 */
public class PapyrusModelFromExistingDomainModelCommand extends RecordingCommand {

	/** The my di resource set. */
	private final ModelSet myDiResourceSet;

	/** The my file name without extension. */
	private final IPath myFileNameWithoutExtension;

	/** The my root. */
	private final EObject myRoot;

	/**
	 * Instantiates a new papyrus model from existing domain model command.
	 *
	 * @param diResourceSet the di resource set
	 * @param newFile the new file
	 * @param root the root
	 */
	public PapyrusModelFromExistingDomainModelCommand(ModelSet diResourceSet, IFile newFile, EObject root) {
		super(diResourceSet.getTransactionalEditingDomain());
		myDiResourceSet = diResourceSet;
		myFileNameWithoutExtension = newFile.getFullPath().removeFileExtension();
		// Bug 339504 - [Wizard] NPE when init diagram from an existing model
		((DiResourceSetExt)diResourceSet).setFilenameWithoutExtension(myFileNameWithoutExtension);
		myRoot = root;
	}

	/* (non-Javadoc)
	 * @see org.eclipse.emf.transaction.RecordingCommand#doExecute()
	 */
	@Override
	protected void doExecute() {
		IModel model = myDiResourceSet.getModel(DiModel.MODEL_ID);
		model.createModel(myFileNameWithoutExtension);
		model = myDiResourceSet.getModel(NotationModel.MODEL_ID);
		model.createModel(myFileNameWithoutExtension);
		// START OF WORKAROUND for #315083 
		IModel umlModel = new UmlModel() {

			public void createModel(IPath fullPath) {
				try {
					resourceURI = myRoot.eResource().getURI();
					// as resource already exists, use rs.getResource() not rs.createResource() here
					resource = getResourceSet().getResource(resourceURI, true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			};
		};
		myDiResourceSet.registerModel(umlModel);
		umlModel.createModel(null);

		//					// call snippets to allow them to do their stuff
		//					snippets.performStart(this);
		// END OF WORKAROUND for #315083 
	}

}

Back to the top