|
Lines 15-35
Link Here
|
| 15 |
|
15 |
|
| 16 |
import static org.eclipse.papyrus.diagram.common.Activator.log; |
16 |
import static org.eclipse.papyrus.diagram.common.Activator.log; |
| 17 |
|
17 |
|
| 18 |
import java.io.IOException; |
|
|
| 19 |
|
| 20 |
import org.eclipse.core.resources.IFile; |
18 |
import org.eclipse.core.resources.IFile; |
| 21 |
import org.eclipse.core.resources.ResourcesPlugin; |
19 |
import org.eclipse.core.resources.ResourcesPlugin; |
| 22 |
import org.eclipse.core.runtime.IPath; |
20 |
import org.eclipse.core.runtime.IPath; |
| 23 |
import org.eclipse.core.runtime.NullProgressMonitor; |
21 |
import org.eclipse.emf.ecore.EObject; |
| 24 |
import org.eclipse.core.runtime.Path; |
|
|
| 25 |
import org.eclipse.emf.ecore.resource.Resource; |
22 |
import org.eclipse.emf.ecore.resource.Resource; |
| 26 |
import org.eclipse.emf.transaction.RecordingCommand; |
|
|
| 27 |
import org.eclipse.jface.viewers.IStructuredSelection; |
23 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 28 |
import org.eclipse.papyrus.core.extension.commands.ICreationCommand; |
|
|
| 29 |
import org.eclipse.papyrus.core.utils.DiResourceSet; |
24 |
import org.eclipse.papyrus.core.utils.DiResourceSet; |
| 30 |
import org.eclipse.papyrus.core.utils.EditorUtils; |
25 |
import org.eclipse.papyrus.wizards.Activator; |
| 31 |
import org.eclipse.papyrus.wizards.NewModelFilePage; |
26 |
import org.eclipse.papyrus.wizards.NewModelFilePage; |
| 32 |
import org.eclipse.papyrus.wizards.SelectDiagramKindPage; |
27 |
import org.eclipse.papyrus.wizards.SelectDiagramKindPage; |
|
|
28 |
import org.eclipse.papyrus.wizards.SelectTemplateWizardPage; |
| 33 |
import org.eclipse.ui.IWorkbench; |
29 |
import org.eclipse.ui.IWorkbench; |
| 34 |
import org.eclipse.ui.IWorkbenchPage; |
30 |
import org.eclipse.ui.IWorkbenchPage; |
| 35 |
import org.eclipse.ui.PartInitException; |
31 |
import org.eclipse.ui.PartInitException; |
|
Lines 51-58
Link Here
|
| 51 |
/** The diagram kind page. */ |
47 |
/** The diagram kind page. */ |
| 52 |
private SelectDiagramKindPage myDiagramKindPage; |
48 |
private SelectDiagramKindPage myDiagramKindPage; |
| 53 |
|
49 |
|
|
|
50 |
/** Select a template to initialize the model with */ |
| 51 |
private SelectTemplateWizardPage selectTemplateWizardPage; |
| 52 |
|
| 54 |
/** The initial project name. */ |
53 |
/** The initial project name. */ |
| 55 |
private String initialProjectName; |
54 |
private String initialProjectName; |
|
|
55 |
|
| 56 |
|
| 56 |
|
57 |
|
| 57 |
/** |
58 |
/** |
| 58 |
* @see org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard#init(org.eclipse.ui.IWorkbench, |
59 |
* @see org.eclipse.ui.wizards.newresource.BasicNewProjectResourceWizard#init(org.eclipse.ui.IWorkbench, |
|
Lines 64-69
Link Here
|
| 64 |
public void init(IWorkbench workbench, IStructuredSelection selection) { |
65 |
public void init(IWorkbench workbench, IStructuredSelection selection) { |
| 65 |
super.init(workbench, selection); |
66 |
super.init(workbench, selection); |
| 66 |
setWindowTitle("New Papyrus Project"); |
67 |
setWindowTitle("New Papyrus Project"); |
|
|
68 |
selectTemplateWizardPage = getSelectTemplateWizardPage(); |
| 69 |
} |
| 70 |
|
| 71 |
protected SelectTemplateWizardPage getSelectTemplateWizardPage() { |
| 72 |
return new SelectTemplateWizardPage(Activator.PLUGIN_ID, null, null) { |
| 73 |
/** |
| 74 |
* This method is invoked for creation of a model |
| 75 |
*/ |
| 76 |
protected void initializeEmptyModel(Resource resource, String rootElementName) { |
| 77 |
Model model = UMLFactory.eINSTANCE.createModel(); |
| 78 |
model.setName(rootElementName); |
| 79 |
resource.getContents().add(model); |
| 80 |
} |
| 81 |
}; |
| 67 |
} |
82 |
} |
| 68 |
|
83 |
|
| 69 |
/** |
84 |
/** |
|
Lines 78-83
Link Here
|
| 78 |
myNewProjectPage.setTitle("Papyrus Project"); |
93 |
myNewProjectPage.setTitle("Papyrus Project"); |
| 79 |
myNewProjectPage.setDescription("Create a New Papyrus Project"); |
94 |
myNewProjectPage.setDescription("Create a New Papyrus Project"); |
| 80 |
} |
95 |
} |
|
|
96 |
|
| 97 |
addPage(selectTemplateWizardPage); |
| 81 |
|
98 |
|
| 82 |
myDiagramKindPage = new SelectDiagramKindPage("Select kind of diagram") { |
99 |
myDiagramKindPage = new SelectDiagramKindPage("Select kind of diagram") { |
| 83 |
|
100 |
|
|
Lines 108-198
Link Here
|
| 108 |
if(!created) { |
125 |
if(!created) { |
| 109 |
return false; |
126 |
return false; |
| 110 |
} |
127 |
} |
| 111 |
// if the user wants to create a diagram |
|
|
| 112 |
if(myDiagramKindPage.getCreationCommand() != null) { |
| 113 |
return createPapyrusModel(); |
| 114 |
} |
| 115 |
return true; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* Creates the papyrus model. |
| 120 |
* |
| 121 |
* @return true, if successful |
| 122 |
*/ |
| 123 |
private boolean createPapyrusModel() { |
| 124 |
final DiResourceSet diResourceSet = new DiResourceSet(); |
128 |
final DiResourceSet diResourceSet = new DiResourceSet(); |
| 125 |
try { |
129 |
// create a new file, result != null if successful |
| 126 |
// create a new file, result != null if successful |
130 |
final IFile newFile = createFile(); |
| 127 |
final IFile newFile = createFile(); |
131 |
selectTemplateWizardPage.initializeModelResource(diResourceSet, newFile, getModelContentType(), getModelFileExtension()); |
| 128 |
|
132 |
if(newFile == null) { |
| 129 |
RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) { |
133 |
return false; |
| 130 |
|
134 |
} |
| 131 |
@Override |
|
|
| 132 |
protected void doExecute() { |
| 133 |
// Create Model Resource, Notation Resource, DI Resource |
| 134 |
diResourceSet.createModelResources(newFile, getModelContentType(), getModelFileExtension()); |
| 135 |
Resource modelResource = diResourceSet.getModelResource(); |
| 136 |
if(modelResource != null) { |
| 137 |
IPath path = new Path(newFile.getName()); |
| 138 |
initializeModelResource(modelResource, path.removeFileExtension().toString()); |
| 139 |
} |
| 140 |
} |
| 141 |
}; |
| 142 |
diResourceSet.getTransactionalEditingDomain().getCommandStack().execute(command); |
| 143 |
|
| 144 |
IWorkbenchPage page = getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| 145 |
if((newFile != null) && (page != null)) { |
| 146 |
|
| 147 |
String diagramName = myDiagramKindPage.getDiagramName(); |
| 148 |
ICreationCommand creationCommand = myDiagramKindPage.getCreationCommand(); |
| 149 |
|
135 |
|
| 150 |
if(creationCommand == null) { |
136 |
EObject root = null; |
| 151 |
// Create an empty editor (no diagrams opened) |
137 |
myDiagramKindPage.createDiagram(diResourceSet, root); |
| 152 |
// Geting an IPageMngr is enough to initialize the |
|
|
| 153 |
// SashSystem. |
| 154 |
EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain()); |
| 155 |
} else { |
| 156 |
creationCommand.createDiagram(diResourceSet, null, diagramName); |
| 157 |
} |
| 158 |
try { |
| 159 |
diResourceSet.save(new NullProgressMonitor()); |
| 160 |
} catch (IOException e) { |
| 161 |
log.error(e); |
| 162 |
return false; |
| 163 |
} |
| 164 |
|
138 |
|
| 165 |
try { |
139 |
IWorkbenchPage page = getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
| 166 |
IDE.openEditor(page, newFile, true); |
140 |
if(page != null) { |
| 167 |
} catch (PartInitException e) { |
141 |
try { |
| 168 |
log.error(e); |
142 |
IDE.openEditor(page, newFile, true); |
| 169 |
return false; |
143 |
} catch (PartInitException e) { |
| 170 |
} |
144 |
log.error(e); |
|
|
145 |
return false; |
| 171 |
} |
146 |
} |
| 172 |
} catch (Exception e) { |
|
|
| 173 |
log.error(e); |
| 174 |
return false; |
| 175 |
} |
147 |
} |
|
|
148 |
|
| 176 |
return true; |
149 |
return true; |
| 177 |
} |
|
|
| 178 |
|
150 |
|
| 179 |
/** |
151 |
|
| 180 |
* Initialize model resource. |
|
|
| 181 |
* |
| 182 |
* @param resource |
| 183 |
* the domain model resource |
| 184 |
* @param rootElementName |
| 185 |
* the root element name |
| 186 |
*/ |
| 187 |
private void initializeModelResource(Resource resource, String rootElementName) { |
| 188 |
// // fjcano #293135 :: support model templates |
| 189 |
// if(!isInitializeFromTemplate()) { |
| 190 |
Model model = UMLFactory.eINSTANCE.createModel(); |
| 191 |
model.setName(rootElementName); |
| 192 |
resource.getContents().add(model); |
| 193 |
// } else { |
| 194 |
// super.initializeModelResource(resource, rootElementName); |
| 195 |
// } |
| 196 |
} |
152 |
} |
| 197 |
|
153 |
|
| 198 |
/** |
154 |
/** |