Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 313179 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/papyrus/diagram/common/wizards/InitUMLDiagramAction.java (+3 lines)
Lines 14-19 Link Here
14
import org.eclipse.papyrus.wizards.CreateModelWizard;
14
import org.eclipse.papyrus.wizards.CreateModelWizard;
15
import org.eclipse.papyrus.wizards.InitDiagramAction;
15
import org.eclipse.papyrus.wizards.InitDiagramAction;
16
16
17
/**
18
 * @deprecated the class is not used - there is no references to it in Papyrus
19
 */
17
public class InitUMLDiagramAction extends InitDiagramAction {
20
public class InitUMLDiagramAction extends InitDiagramAction {
18
21
19
	@Override
22
	@Override
(-)src/org/eclipse/papyrus/diagram/common/wizards/NewPapyrusProjectWizard.java (-5 / +2 lines)
Lines 50-63 Link Here
50
50
51
	private SelectDiagramKindPage myDiagramKindPage;
51
	private SelectDiagramKindPage myDiagramKindPage;
52
52
53
	private IStructuredSelection selection;
54
55
	private String initialProjectName;
53
	private String initialProjectName;
56
54
57
	public void init(IWorkbench workbench, IStructuredSelection selection) {
55
	public void init(IWorkbench workbench, IStructuredSelection selection) {
58
		super.init(workbench, selection);
56
		super.init(workbench, selection);
59
		setWindowTitle("New Papyrus Project");
57
		setWindowTitle("New Papyrus Project");
60
		this.selection = selection;
61
	}
58
	}
62
59
63
	public void addPages() {
60
	public void addPages() {
Lines 89-100 Link Here
89
		}
86
		}
90
		// if the user wants to create a diagram
87
		// if the user wants to create a diagram
91
		if (myDiagramKindPage.getCreationCommand() != null) {
88
		if (myDiagramKindPage.getCreationCommand() != null) {
92
			return createDiagram();
89
			return createPapyrusModel();
93
		}
90
		}
94
		return true;
91
		return true;
95
	}
92
	}
96
	
93
	
97
	private boolean createDiagram() {
94
	private boolean createPapyrusModel() {
98
		final DiResourceSet diResourceSet = new DiResourceSet();
95
		final DiResourceSet diResourceSet = new DiResourceSet();
99
		try {
96
		try {
100
			// create a new file, result != null if successful
97
			// create a new file, result != null if successful
(-)src/org/eclipse/papyrus/diagram/common/wizards/CreateUMLModelWizard.java (-24 / +15 lines)
Lines 22-35 Link Here
22
import org.eclipse.uml2.uml.UMLPackage;
22
import org.eclipse.uml2.uml.UMLPackage;
23
23
24
public class CreateUMLModelWizard extends CreateModelWizard {
24
public class CreateUMLModelWizard extends CreateModelWizard {
25
	
26
	public CreateUMLModelWizard() {
27
		super();
28
	}
29
	
30
	public CreateUMLModelWizard(URI domainModelURI) {
31
		super(domainModelURI);
32
	}
33
25
34
	/**
26
	/**
35
	 * This ID is the id defined in the extension "org.eclipse.ui.newWizards" of
27
	 * This ID is the id defined in the extension "org.eclipse.ui.newWizards" of
Lines 37-69 Link Here
37
	 */
29
	 */
38
	// @unused
30
	// @unused
39
	public static final String ID_UMLWIZARD = "org.eclipse.papyrus.wizards.createumlmodel";
31
	public static final String ID_UMLWIZARD = "org.eclipse.papyrus.wizards.createumlmodel";
40
	 /**
41
	      * The config element which declares this wizard.
42
	     */
43
     private IConfigurationElement configElement;
44
32
45
	
33
	public CreateUMLModelWizard() {
34
		super();
35
	}
36
37
	public CreateUMLModelWizard(URI domainModelURI) {
38
		super(domainModelURI);
39
	}
46
40
47
	@Override
41
	@Override
48
	protected String getModelContentType() {
42
	protected String getModelContentType() {
49
		return UMLPackage.eCONTENT_TYPE;
43
		return UMLPackage.eCONTENT_TYPE;
50
	}
44
	}
51
	
45
52
	@Override
46
	@Override
53
	protected String getModelFileExtension() {
47
	protected String getModelFileExtension() {
54
		return "uml";
48
		return "uml";
55
	}
49
	}
56
50
57
	@Override
51
	/**
58
	protected void initializeModelResource(Resource resource, String rootElementName) {
52
	 * This method is invoked for creation of a model 
59
		// fjcano #293135 :: support model templates
53
	 */
60
		if(!isInitializeFromTemplate()) {
54
	protected void initializeEmptyModel(Resource resource, String rootElementName) {
61
			Model model = UMLFactory.eINSTANCE.createModel();
55
		Model model = UMLFactory.eINSTANCE.createModel();
62
			model.setName(rootElementName);
56
		model.setName(rootElementName);
63
			resource.getContents().add(model);
57
		resource.getContents().add(model);
64
		} else {
65
			super.initializeModelResource(resource, rootElementName);
66
		}
67
	}
58
	}
68
59
69
}
60
}
(-)src/org/eclipse/papyrus/wizards/CreateModelWizard.java (-53 / +67 lines)
Lines 32-37 Link Here
32
import org.eclipse.papyrus.core.utils.DiResourceSet;
32
import org.eclipse.papyrus.core.utils.DiResourceSet;
33
import org.eclipse.papyrus.core.utils.EditorUtils;
33
import org.eclipse.papyrus.core.utils.EditorUtils;
34
import org.eclipse.papyrus.core.utils.PapyrusTrace;
34
import org.eclipse.papyrus.core.utils.PapyrusTrace;
35
import org.eclipse.papyrus.resource.uml.UmlModel;
35
import org.eclipse.ui.INewWizard;
36
import org.eclipse.ui.INewWizard;
36
import org.eclipse.ui.IWorkbench;
37
import org.eclipse.ui.IWorkbench;
37
import org.eclipse.ui.IWorkbenchPage;
38
import org.eclipse.ui.IWorkbenchPage;
Lines 117-140 Link Here
117
	public void init(IWorkbench workbench, IStructuredSelection selection) {
118
	public void init(IWorkbench workbench, IStructuredSelection selection) {
118
		this.workbench = workbench;
119
		this.workbench = workbench;
119
		this.diResourceSet = new DiResourceSet();
120
		this.diResourceSet = new DiResourceSet();
120
		// set the di file name with the selected domain model
121
		IFile file = getSelectedFile(selection);
121
		if(selection != null && !selection.isEmpty()) {
122
		// builds a new Papyrus Model for an existing domain model
122
			if(selection.getFirstElement() instanceof IFile) {
123
		if(isSupportedDomainModelFile(file)) {
123
				IFile file = (IFile)selection.getFirstElement();
124
			this.domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
124
				String extension = file.getFileExtension();
125
			this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new Papyrus model from an existing semantic model", selection, true);
125
				if(getModelFileExtension().equals(extension)) {
126
			this.newModelFilePage.setFileName(getDiagramFileName(file));
126
					this.domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
127
127
128
					this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new Papyrus model from an existing semantic model", selection, true);
128
			// I don't understand a need to load the model during initialization, 
129
					String diModelFileName = (file.getLocation().removeFileExtension().lastSegment());
129
			// I rather expect it to be loaded when wizard is finished and executed or
130
					diModelFileName += ".di";
130
			// when the page that needs the model is initialized 
131
					this.newModelFilePage.setFileName(diModelFileName);
131
			Resource resource = diResourceSet.loadModelResource(file);
132
132
133
					Resource resource = diResourceSet.loadModelResource(file);
133
			EObject diagramRoot = resource.getContents().get(0);
134
					EObject diagramRoot = resource.getContents().get(0);
134
			this.selectRootElementPage = new SelectRootElementPage("Select the root element", diagramRoot);
135
					this.selectRootElementPage = new SelectRootElementPage("Select the root element", diagramRoot);
136
				}
137
			}
138
		}
135
		}
139
		if(domainModelURI == null) {
136
		if(domainModelURI == null) {
140
			this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new empty Papyrus model", selection, false);
137
			this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new empty Papyrus model", selection, false);
Lines 143-150 Link Here
143
		// fjcano #293135 :: support model templates
140
		// fjcano #293135 :: support model templates
144
		selectTemplateWizardPage = new SelectTemplateWizardPage(Activator.PLUGIN_ID, null, null);
141
		selectTemplateWizardPage = new SelectTemplateWizardPage(Activator.PLUGIN_ID, null, null);
145
	}
142
	}
143
	
144
	/**
145
	 * Suggests a name of diagram file for the domain model file 
146
	 */
147
	protected String getDiagramFileName(IFile domainModel) {
148
		String diModelFileName = (domainModel.getLocation().removeFileExtension().lastSegment());
149
		diModelFileName += ".di";
150
		return diModelFileName;
151
	}
146
152
147
	/**
153
	/**
154
	 * Returns the first file from the given selection 
155
	 */
156
	private IFile getSelectedFile(IStructuredSelection selection) {
157
		if(selection != null && !selection.isEmpty() && selection.getFirstElement() instanceof IFile) {
158
			return (IFile)selection.getFirstElement();
159
		}
160
		return null;
161
	}
162
163
	/**
164
	 * Returns true is the file can be served as a model model for the diagram
165
	 */
166
	protected boolean isSupportedDomainModelFile(IFile file) {
167
		return file != null && getModelFileExtension().equals(file.getFileExtension());
168
	}
169
170
171
	/**
148
	 * This method will be invoked, when the "Finish" button is pressed.
172
	 * This method will be invoked, when the "Finish" button is pressed.
149
	 * 
173
	 * 
150
	 * @return <code>true</code> if everything runs without problems, <code>false</code> if an exception must be caught.
174
	 * @return <code>true</code> if everything runs without problems, <code>false</code> if an exception must be caught.
Lines 155-161 Link Here
155
		try {
179
		try {
156
			// create a new file, result != null if successful
180
			// create a new file, result != null if successful
157
			final IFile newFile = newModelFilePage.createNewFile();
181
			final IFile newFile = newModelFilePage.createNewFile();
158
			NewModelFilePage.fileCount++;
159
182
160
			RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) {
183
			RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) {
161
184
Lines 197-208 Link Here
197
					// SashSystem.
220
					// SashSystem.
198
					EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain());
221
					EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain());
199
				} else {
222
				} else {
200
					// Create requested diagram.
223
					EObject root = domainModelURI != null ? selectRootElementPage.getModelElement() : null;
201
					if(domainModelURI != null) {
224
					creationCommand.createDiagram(diResourceSet, root, diagramName);
202
						creationCommand.createDiagram(diResourceSet, selectRootElementPage.getModelElement(), diagramName);
203
					} else {
204
						creationCommand.createDiagram(diResourceSet, null, diagramName);
205
					}
206
				}
225
				}
207
				try {
226
				try {
208
					diResourceSet.save(new NullProgressMonitor());
227
					diResourceSet.save(new NullProgressMonitor());
Lines 231-277 Link Here
231
	protected abstract String getModelFileExtension();
250
	protected abstract String getModelFileExtension();
232
251
233
	// fjcano #293135 :: support model templates
252
	// fjcano #293135 :: support model templates
234
	protected void initializeModelResource(Resource resource, String rootElementName) {
253
	private void initializeModelResource(Resource resource, String rootElementName) {
235
		if(isInitializeFromTemplate()) {
254
		String templatePath = selectTemplateWizardPage.getTemplatePath();
236
			Resource templateResource = loadTemplateResource();
255
		boolean initializeFromTemplate = templatePath != null;
237
			List<EObject> eObjectsToAdd = new ArrayList<EObject>();
256
		if(initializeFromTemplate) {
238
			for(EObject eObject : templateResource.getContents()) {
257
			initializeFromTemplate(resource, rootElementName, templatePath);
239
				eObjectsToAdd.add(EcoreUtil.copy(eObject));
240
			}
241
			for(EObject eObject : eObjectsToAdd) {
242
				resource.getContents().add(eObject);
243
			}
244
		} else {
258
		} else {
245
			// nothing
259
			initializeEmptyModel(resource, rootElementName);
246
			return;
247
		}
260
		}
248
	}
261
	}
249
262
250
	// fjcano #293135 :: support model templates
263
	protected void initializeFromTemplate(Resource resource, String rootElementName, String templatePath) {
251
	protected boolean isInitializeFromTemplate() {
264
		Resource templateResource = loadTemplateResource(templatePath);
252
		return getTemplatePath() != null;
265
		List<EObject> eObjectsToAdd = new ArrayList<EObject>();
266
		for(EObject eObject : templateResource.getContents()) {
267
			eObjectsToAdd.add(EcoreUtil.copy(eObject));
268
		}
269
		for(EObject eObject : eObjectsToAdd) {
270
			resource.getContents().add(eObject);
271
		}
253
	}
272
	}
254
273
255
	// fjcano #293135 :: support model templates
274
	protected void initializeEmptyModel(Resource resource, String rootElementName) {
256
	protected String getTemplatePath() {
257
		String templatePath = selectTemplateWizardPage.getTemplatePath();
258
		return templatePath;
259
	}
275
	}
260
276
261
	// fjcano #293135 :: support model templates
277
	private Resource loadTemplateResource(String templatePath) {
262
	protected Resource loadTemplateResource() {
263
		String templatePluginID = selectTemplateWizardPage.getTemplatePluginId();
278
		String templatePluginID = selectTemplateWizardPage.getTemplatePluginId();
264
		String templatePath = getTemplatePath();
265
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
279
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
266
		if(templatePath != null) {
280
		String fullUri = templateURL.getPath();
267
			String fullUri = templateURL.getPath();
281
		URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true);
268
			URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true);
282
		ResourceSet resourceSet = new ResourceSetImpl();
269
			ResourceSet resourceSet = new ResourceSetImpl();
283
		Resource resource = resourceSet.getResource(uri, true);
270
			Resource resource = resourceSet.getResource(uri, true);
284
		if(resource.isLoaded()) {
271
			if(resource.isLoaded()) {
285
			return resource;
272
				return resource;
273
			}
274
		}
286
		}
275
		return null;
287
		return null;
276
	}
288
	}
289
290
277
}
291
}
(-)src/org/eclipse/papyrus/wizards/NewModelFilePage.java (-1 / +9 lines)
Lines 10-15 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.papyrus.wizards;
11
package org.eclipse.papyrus.wizards;
12
12
13
import org.eclipse.core.resources.IFile;
13
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.jface.viewers.IStructuredSelection;
14
import org.eclipse.swt.widgets.Composite;
15
import org.eclipse.swt.widgets.Composite;
15
import org.eclipse.ui.IWorkbench;
16
import org.eclipse.ui.IWorkbench;
Lines 23-29 Link Here
23
public class NewModelFilePage extends WizardNewFileCreationPage {
24
public class NewModelFilePage extends WizardNewFileCreationPage {
24
25
25
	/** index for several file creation */
26
	/** index for several file creation */
26
	protected static int fileCount = 1;
27
	private static int fileCount = 1;
27
28
28
	protected boolean createFromSemanticModel;
29
	protected boolean createFromSemanticModel;
29
30
Lines 89-94 Link Here
89
		// return false;
90
		// return false;
90
		return true;
91
		return true;
91
	}
92
	}
93
	
94
	@Override
95
	public IFile createNewFile() {
96
		IFile created = super.createNewFile();
97
		fileCount++;
98
		return created;
99
	}
92
100
93
	/**
101
	/**
94
	 * {@inheritDoc}
102
	 * {@inheritDoc}

Return to bug 313179