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/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 (-18 / +13 lines)
Lines 22-32 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
	
25
26
	public CreateUMLModelWizard() {
26
	public CreateUMLModelWizard() {
27
		super();
27
		super();
28
	}
28
	}
29
	
29
30
	public CreateUMLModelWizard(URI domainModelURI) {
30
	public CreateUMLModelWizard(URI domainModelURI) {
31
		super(domainModelURI);
31
		super(domainModelURI);
32
	}
32
	}
Lines 37-69 Link Here
37
	 */
37
	 */
38
	// @unused
38
	// @unused
39
	public static final String ID_UMLWIZARD = "org.eclipse.papyrus.wizards.createumlmodel";
39
	public static final String ID_UMLWIZARD = "org.eclipse.papyrus.wizards.createumlmodel";
40
	 /**
40
41
	      * The config element which declares this wizard.
41
	/**
42
	     */
42
	 * The config element which declares this wizard.
43
     private IConfigurationElement configElement;
43
	 */
44
	private IConfigurationElement configElement;
45
44
46
45
	
46
47
47
	@Override
48
	@Override
48
	protected String getModelContentType() {
49
	protected String getModelContentType() {
49
		return UMLPackage.eCONTENT_TYPE;
50
		return UMLPackage.eCONTENT_TYPE;
50
	}
51
	}
51
	
52
52
	@Override
53
	@Override
53
	protected String getModelFileExtension() {
54
	protected String getModelFileExtension() {
54
		return "uml";
55
		return "uml";
55
	}
56
	}
56
57
57
	@Override
58
	protected void initializeEmptyModel(Resource resource, String rootElementName, String templatePath) {
58
	protected void initializeModelResource(Resource resource, String rootElementName) {
59
		Model model = UMLFactory.eINSTANCE.createModel();
59
		// fjcano #293135 :: support model templates
60
		model.setName(rootElementName);
60
		if(!isInitializeFromTemplate()) {
61
		resource.getContents().add(model);
61
			Model model = UMLFactory.eINSTANCE.createModel();
62
			model.setName(rootElementName);
63
			resource.getContents().add(model);
64
		} else {
65
			super.initializeModelResource(resource, rootElementName);
66
		}
67
	}
62
	}
68
63
69
}
64
}
(-)src/org/eclipse/papyrus/wizards/CreateModelWizard.java (-39 / +28 lines)
Lines 155-161 Link Here
155
		try {
155
		try {
156
			// create a new file, result != null if successful
156
			// create a new file, result != null if successful
157
			final IFile newFile = newModelFilePage.createNewFile();
157
			final IFile newFile = newModelFilePage.createNewFile();
158
			NewModelFilePage.fileCount++;
159
158
160
			RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) {
159
			RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) {
161
160
Lines 197-208 Link Here
197
					// SashSystem.
196
					// SashSystem.
198
					EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain());
197
					EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain());
199
				} else {
198
				} else {
200
					// Create requested diagram.
199
					EObject root = domainModelURI != null ? selectRootElementPage.getModelElement() : null;
201
					if(domainModelURI != null) {
200
					creationCommand.createDiagram(diResourceSet, root, diagramName);
202
						creationCommand.createDiagram(diResourceSet, selectRootElementPage.getModelElement(), diagramName);
203
					} else {
204
						creationCommand.createDiagram(diResourceSet, null, diagramName);
205
					}
206
				}
201
				}
207
				try {
202
				try {
208
					diResourceSet.save(new NullProgressMonitor());
203
					diResourceSet.save(new NullProgressMonitor());
Lines 231-277 Link Here
231
	protected abstract String getModelFileExtension();
226
	protected abstract String getModelFileExtension();
232
227
233
	// fjcano #293135 :: support model templates
228
	// fjcano #293135 :: support model templates
234
	protected void initializeModelResource(Resource resource, String rootElementName) {
229
	private void initializeModelResource(Resource resource, String rootElementName) {
235
		if(isInitializeFromTemplate()) {
230
		String templatePath = selectTemplateWizardPage.getTemplatePath();
236
			Resource templateResource = loadTemplateResource();
231
		boolean initializeFromTemplate = templatePath != null;
237
			List<EObject> eObjectsToAdd = new ArrayList<EObject>();
232
		if(initializeFromTemplate) {
238
			for(EObject eObject : templateResource.getContents()) {
233
			initializeFromTemplate(resource, rootElementName, templatePath);
239
				eObjectsToAdd.add(EcoreUtil.copy(eObject));
240
			}
241
			for(EObject eObject : eObjectsToAdd) {
242
				resource.getContents().add(eObject);
243
			}
244
		} else {
234
		} else {
245
			// nothing
235
			initializeEmptyModel(resource, rootElementName);
246
			return;
247
		}
236
		}
248
	}
237
	}
249
238
	
250
	// fjcano #293135 :: support model templates
239
	protected void initializeFromTemplate(Resource resource, String rootElementName,String templatePath) {
251
	protected boolean isInitializeFromTemplate() {
240
		Resource templateResource = loadTemplateResource(templatePath);
252
		return getTemplatePath() != null;
241
		List<EObject> eObjectsToAdd = new ArrayList<EObject>();
242
		for(EObject eObject : templateResource.getContents()) {
243
			eObjectsToAdd.add(EcoreUtil.copy(eObject));
244
		}
245
		for(EObject eObject : eObjectsToAdd) {
246
			resource.getContents().add(eObject);
247
		}
253
	}
248
	}
254
249
	protected void initializeEmptyModel(Resource resource, String rootElementName) {
255
	// fjcano #293135 :: support model templates
256
	protected String getTemplatePath() {
257
		String templatePath = selectTemplateWizardPage.getTemplatePath();
258
		return templatePath;
259
	}
250
	}
260
251
261
	// fjcano #293135 :: support model templates
252
	private Resource loadTemplateResource(String templatePath) {
262
	protected Resource loadTemplateResource() {
263
		String templatePluginID = selectTemplateWizardPage.getTemplatePluginId();
253
		String templatePluginID = selectTemplateWizardPage.getTemplatePluginId();
264
		String templatePath = getTemplatePath();
265
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
254
		java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath);
266
		if(templatePath != null) {
255
		String fullUri = templateURL.getPath();
267
			String fullUri = templateURL.getPath();
256
		URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true);
268
			URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true);
257
		ResourceSet resourceSet = new ResourceSetImpl();
269
			ResourceSet resourceSet = new ResourceSetImpl();
258
		Resource resource = resourceSet.getResource(uri, true);
270
			Resource resource = resourceSet.getResource(uri, true);
259
		if(resource.isLoaded()) {
271
			if(resource.isLoaded()) {
260
			return resource;
272
				return resource;
273
			}
274
		}
261
		}
275
		return null;
262
		return null;
276
	}
263
	}
264
265
277
}
266
}
(-)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