blob: bbd657be2799db12dfb82e3bd41a3a1818470f73 (
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 Atos Origin.
*
*
* 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:
* Atos Origin - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.sysml.diagram.blockdiagram;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
import org.eclipse.papyrus.core.adaptor.gmf.AbstractPapyrusGmfCreateDiagramCommandHandler;
import org.eclipse.papyrus.sysml.diagram.blockdiagram.part.SysmlDiagramEditorPlugin;
import org.eclipse.papyrus.sysml.util.SysmlResource;
import org.eclipse.papyrus.umlutils.PackageUtil;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Package;
import org.eclipse.uml2.uml.Profile;
import org.eclipse.uml2.uml.UMLFactory;
public class BDDCreation extends AbstractPapyrusGmfCreateDiagramCommandHandler {
/**
* Name of the Diagram
*/
protected static final String CSD_DEFAULT_NAME = "BDD"; //$NON-NLS-1$
public static final String MODEL_ID = "BDD"; //$NON-NLS-1$
public BDDCreation() {
}
/**
* {@inheritDoc}
*/
protected String getDefaultDiagramName() {
return openDiagramNameDialog(CSD_DEFAULT_NAME);
}
/**
* {@inheritDoc}
*/
protected String getDiagramNotationID() {
return MODEL_ID;
}
/**
* {@inheritDoc}
*/
protected PreferencesHint getPreferenceHint() {
return SysmlDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT;
}
/**
* {@inheritDoc}
*/
protected EObject createRootElement() {
return UMLFactory.eINSTANCE.createModel();
}
/**
* Overrides to add the SysML profile to the nearest containing package if it is not yet applied {@inheritDoc}
*/
@Override
protected void initializeModel(EObject owner) {
if(owner instanceof Element) {
Element element = (Element)owner;
Package pack = element.getNearestPackage();
if((pack.getAppliedProfile("SysML::Blocks", true) == null) || (pack.getAppliedProfile("SysML::PortAndFlows", true) == null)) {
// Retrieve SysML profile and apply with sub-profiles
Profile sysml = (Profile)PackageUtil.loadPackage(URI.createURI(SysmlResource.SYSML_PROFILE_URI), pack.eResource().getResourceSet());
PackageUtil.applyProfile(pack, sysml, true);
}
}
super.initializeModel(owner);
}
}
|