|
Lines 13-25
Link Here
|
| 13 |
package org.eclipse.papyrus.wizards; |
13 |
package org.eclipse.papyrus.wizards; |
| 14 |
|
14 |
|
| 15 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
| 16 |
import java.util.Collection; |
|
|
| 17 |
import java.util.List; |
16 |
import java.util.List; |
| 18 |
|
17 |
|
| 19 |
import org.eclipse.core.resources.IFile; |
18 |
import org.eclipse.core.resources.IFile; |
| 20 |
import org.eclipse.core.runtime.IConfigurationElement; |
|
|
| 21 |
import org.eclipse.core.runtime.IExtension; |
| 22 |
import org.eclipse.core.runtime.IExtensionRegistry; |
| 23 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
| 24 |
import org.eclipse.core.runtime.Path; |
20 |
import org.eclipse.core.runtime.Path; |
| 25 |
import org.eclipse.core.runtime.Platform; |
21 |
import org.eclipse.core.runtime.Platform; |
|
Lines 30-42
Link Here
|
| 30 |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
26 |
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; |
| 31 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
27 |
import org.eclipse.emf.ecore.util.EcoreUtil; |
| 32 |
import org.eclipse.emf.transaction.RecordingCommand; |
28 |
import org.eclipse.emf.transaction.RecordingCommand; |
| 33 |
import org.eclipse.jface.viewers.ILabelProviderListener; |
|
|
| 34 |
import org.eclipse.jface.viewers.IStructuredContentProvider; |
| 35 |
import org.eclipse.jface.viewers.IStructuredSelection; |
| 36 |
import org.eclipse.jface.viewers.ITableLabelProvider; |
| 37 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 38 |
import org.eclipse.jface.viewers.TableViewer; |
| 39 |
import org.eclipse.jface.viewers.Viewer; |
| 40 |
import org.eclipse.jface.wizard.IWizardPage; |
29 |
import org.eclipse.jface.wizard.IWizardPage; |
| 41 |
import org.eclipse.jface.wizard.WizardPage; |
30 |
import org.eclipse.jface.wizard.WizardPage; |
| 42 |
import org.eclipse.papyrus.core.utils.DiResourceSet; |
31 |
import org.eclipse.papyrus.core.utils.DiResourceSet; |
|
Lines 44-58
Link Here
|
| 44 |
import org.eclipse.papyrus.resource.notation.NotationModel; |
33 |
import org.eclipse.papyrus.resource.notation.NotationModel; |
| 45 |
import org.eclipse.papyrus.resource.sasheditor.DiModel; |
34 |
import org.eclipse.papyrus.resource.sasheditor.DiModel; |
| 46 |
import org.eclipse.papyrus.resource.uml.UmlModel; |
35 |
import org.eclipse.papyrus.resource.uml.UmlModel; |
| 47 |
import org.eclipse.swt.SWT; |
36 |
import org.eclipse.papyrus.wizards.template.SelectModelTemplateComposite; |
| 48 |
import org.eclipse.swt.events.SelectionEvent; |
|
|
| 49 |
import org.eclipse.swt.events.SelectionListener; |
| 50 |
import org.eclipse.swt.graphics.Image; |
| 51 |
import org.eclipse.swt.layout.GridData; |
| 52 |
import org.eclipse.swt.layout.GridLayout; |
| 53 |
import org.eclipse.swt.widgets.Button; |
| 54 |
import org.eclipse.swt.widgets.Composite; |
37 |
import org.eclipse.swt.widgets.Composite; |
| 55 |
import org.eclipse.swt.widgets.Group; |
|
|
| 56 |
|
38 |
|
| 57 |
/** |
39 |
/** |
| 58 |
* A wizard page that allows the selection of template models contributed via an |
40 |
* A wizard page that allows the selection of template models contributed via an |
|
Lines 64-118
Link Here
|
| 64 |
*/ |
46 |
*/ |
| 65 |
public class SelectTemplateWizardPage extends WizardPage { |
47 |
public class SelectTemplateWizardPage extends WizardPage { |
| 66 |
|
48 |
|
| 67 |
private Button newModelButton; |
49 |
/** The select template composite. */ |
| 68 |
|
50 |
private SelectModelTemplateComposite selectTemplateComposite; |
| 69 |
private Button useTemplateButton; |
|
|
| 70 |
|
| 71 |
private TableViewer templateTableViewer; |
| 72 |
|
| 73 |
private String editorId; |
| 74 |
|
51 |
|
|
|
52 |
/** |
| 53 |
* Instantiates a new select template wizard page. |
| 54 |
* |
| 55 |
* @param pageName the page name |
| 56 |
*/ |
| 75 |
protected SelectTemplateWizardPage(String pageName) { |
57 |
protected SelectTemplateWizardPage(String pageName) { |
| 76 |
super(pageName); |
58 |
super(pageName); |
| 77 |
// TODO Auto-generated constructor stub |
|
|
| 78 |
} |
59 |
} |
| 79 |
|
60 |
|
|
|
61 |
/** |
| 62 |
* Instantiates a new select template wizard page. |
| 63 |
* |
| 64 |
* @param editorId the editor id |
| 65 |
* @param nextPage the next page |
| 66 |
* @param templatePage the template page |
| 67 |
*/ |
| 80 |
public SelectTemplateWizardPage(String editorId, WizardPage nextPage, WizardPage templatePage) { |
68 |
public SelectTemplateWizardPage(String editorId, WizardPage nextPage, WizardPage templatePage) { |
| 81 |
super("Select creation approach"); |
69 |
super("Select creation approach"); |
| 82 |
this.setTitle("Select creation approach"); |
70 |
this.setTitle("Select creation approach"); |
| 83 |
this.setDescription("Diagrams can be created from scratch or from a template"); |
71 |
this.setDescription("Diagrams can be created from scratch or from a template"); |
| 84 |
this.editorId = editorId; |
|
|
| 85 |
} |
72 |
} |
| 86 |
|
73 |
|
| 87 |
public String getTemplatePath() { |
|
|
| 88 |
if(this.useTemplateButton.getSelection()) { |
| 89 |
if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) { |
| 90 |
Object first = ((IStructuredSelection)this.templateTableViewer.getSelection()).getFirstElement(); |
| 91 |
if(first instanceof ModelTemplateDescription) { |
| 92 |
return ((ModelTemplateDescription)first).getPath(); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|
| 97 |
return null; |
| 98 |
} |
| 99 |
|
| 100 |
public String getTemplatePluginId() { |
| 101 |
if(this.useTemplateButton.getSelection()) { |
| 102 |
if(this.templateTableViewer.getSelection() instanceof IStructuredSelection) { |
| 103 |
Object first = ((IStructuredSelection)this.templateTableViewer.getSelection()).getFirstElement(); |
| 104 |
if(first instanceof ModelTemplateDescription) { |
| 105 |
return ((ModelTemplateDescription)first).getPluginId(); |
| 106 |
} |
| 107 |
} |
| 108 |
} |
| 109 |
|
74 |
|
| 110 |
return null; |
75 |
/** |
| 111 |
} |
76 |
* @see org.eclipse.jface.dialogs.DialogPage#setVisible(boolean) |
|
|
77 |
* |
| 78 |
* @param visible |
| 79 |
*/ |
| 112 |
@Override |
80 |
@Override |
| 113 |
public void setVisible(boolean visible) { |
81 |
public void setVisible(boolean visible) { |
| 114 |
super.setVisible(visible); |
82 |
super.setVisible(visible); |
| 115 |
templateTableViewer.setInput(getDiagramCategory()); |
83 |
selectTemplateComposite.setInput(getDiagramCategory()); |
| 116 |
} |
84 |
} |
| 117 |
|
85 |
|
| 118 |
/** |
86 |
/** |
|
Lines 128-204
Link Here
|
| 128 |
return ((SelectDiagramCategoryPage)previousPage).getDiagramCategory(); |
96 |
return ((SelectDiagramCategoryPage)previousPage).getDiagramCategory(); |
| 129 |
} |
97 |
} |
| 130 |
|
98 |
|
|
|
99 |
/** |
| 100 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
| 101 |
* |
| 102 |
* @param parent |
| 103 |
*/ |
| 131 |
public void createControl(Composite parent) { |
104 |
public void createControl(Composite parent) { |
| 132 |
Composite root = new Composite(parent, SWT.NONE); |
105 |
selectTemplateComposite = new SelectModelTemplateComposite(parent); |
| 133 |
GridLayout gridLayout = new GridLayout(); |
106 |
setControl(selectTemplateComposite); |
| 134 |
root.setLayout(gridLayout); |
|
|
| 135 |
Group composite = new Group(root, 0); |
| 136 |
composite.setText("Creation approach"); |
| 137 |
|
| 138 |
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); |
| 139 |
gridLayout = new GridLayout(1, false); |
| 140 |
gridLayout.marginWidth = 20; |
| 141 |
gridLayout.marginTop = 10; |
| 142 |
gridLayout.verticalSpacing = 10; |
| 143 |
composite.setLayout(gridLayout); |
| 144 |
createDialogArea(composite); |
| 145 |
|
| 146 |
setControl(root); |
| 147 |
} |
| 148 |
|
| 149 |
private void createDialogArea(Composite composite) { |
| 150 |
createApproachSelectionButtons(composite); |
| 151 |
createTemplatesViewer(composite); |
| 152 |
} |
| 153 |
|
| 154 |
private void createTemplatesViewer(Composite composite) { |
| 155 |
GridData data = new GridData(GridData.FILL_BOTH); |
| 156 |
templateTableViewer = new TableViewer(composite); |
| 157 |
templateTableViewer.getTable().setLayoutData(data); |
| 158 |
|
| 159 |
templateTableViewer.setContentProvider(new ModelTemplatesContentProvider()); |
| 160 |
templateTableViewer.setLabelProvider(new ModelTemplatesLabelProvider()); |
| 161 |
if(templateTableViewer.getTable().getItemCount() > 0) { |
| 162 |
IStructuredSelection ss = new StructuredSelection(templateTableViewer.getElementAt(0)); |
| 163 |
templateTableViewer.setSelection(ss); |
| 164 |
} else { |
| 165 |
useTemplateButton.setEnabled(false); |
| 166 |
} |
| 167 |
templateTableViewer.getControl().setEnabled(false); |
| 168 |
} |
107 |
} |
| 169 |
|
108 |
|
| 170 |
private void createApproachSelectionButtons(Composite composite) { |
|
|
| 171 |
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); |
| 172 |
newModelButton = new Button(composite, SWT.RADIO); |
| 173 |
newModelButton.setText("Create new model"); |
| 174 |
newModelButton.setLayoutData(data); |
| 175 |
newModelButton.setSelection(true); |
| 176 |
|
| 177 |
data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING); |
| 178 |
useTemplateButton = new Button(composite, SWT.RADIO); |
| 179 |
useTemplateButton.setText("Initialize from template"); |
| 180 |
useTemplateButton.setLayoutData(data); |
| 181 |
useTemplateButton.setSelection(false); |
| 182 |
|
| 183 |
useTemplateButton.addSelectionListener(new SelectionListener() { |
| 184 |
|
| 185 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 186 |
// TODO Auto-generated method stub |
| 187 |
|
| 188 |
} |
| 189 |
|
109 |
|
| 190 |
public void widgetSelected(SelectionEvent e) { |
110 |
/** |
| 191 |
if(useTemplateButton.getSelection()) { |
111 |
* Initialize model resource. |
| 192 |
templateTableViewer.getControl().setEnabled(true); |
112 |
* |
| 193 |
} else { |
113 |
* @param diResourceSet the di resource set |
| 194 |
templateTableViewer.getControl().setEnabled(false); |
114 |
* @param newFile the new file |
| 195 |
} |
115 |
* @param root the root |
| 196 |
} |
116 |
* @param modelContentType the model content type |
| 197 |
|
117 |
* @param modelFileExtension the model file extension |
| 198 |
}); |
118 |
*/ |
| 199 |
|
|
|
| 200 |
} |
| 201 |
|
| 202 |
public void initializeModelResource(final DiResourceSet diResourceSet, final IFile newFile, final EObject root, final String modelContentType, final String modelFileExtension) { |
119 |
public void initializeModelResource(final DiResourceSet diResourceSet, final IFile newFile, final EObject root, final String modelContentType, final String modelFileExtension) { |
| 203 |
RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) { |
120 |
RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) { |
| 204 |
|
121 |
|
|
Lines 258-264
Link Here
|
| 258 |
* the root element name |
175 |
* the root element name |
| 259 |
*/ |
176 |
*/ |
| 260 |
protected void initializeModelResource(Resource resource, String rootElementName) { |
177 |
protected void initializeModelResource(Resource resource, String rootElementName) { |
| 261 |
String templatePath = getTemplatePath(); |
178 |
String templatePath = selectTemplateComposite.getTemplatePath(); |
| 262 |
boolean initializeFromTemplate = templatePath != null; |
179 |
boolean initializeFromTemplate = templatePath != null; |
| 263 |
if(initializeFromTemplate) { |
180 |
if(initializeFromTemplate) { |
| 264 |
initializeFromTemplate(resource, rootElementName, templatePath); |
181 |
initializeFromTemplate(resource, rootElementName, templatePath); |
|
Lines 307-313
Link Here
|
| 307 |
* @return the resource |
224 |
* @return the resource |
| 308 |
*/ |
225 |
*/ |
| 309 |
private Resource loadTemplateResource(String templatePath) { |
226 |
private Resource loadTemplateResource(String templatePath) { |
| 310 |
String templatePluginID = getTemplatePluginId(); |
227 |
String templatePluginID = selectTemplateComposite.getTemplatePluginId(); |
| 311 |
java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath); |
228 |
java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath); |
| 312 |
String fullUri = templateURL.getPath(); |
229 |
String fullUri = templateURL.getPath(); |
| 313 |
URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true); |
230 |
URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true); |
|
Lines 319-475
Link Here
|
| 319 |
return null; |
236 |
return null; |
| 320 |
} |
237 |
} |
| 321 |
|
238 |
|
| 322 |
|
|
|
| 323 |
private class ModelTemplatesContentProvider implements IStructuredContentProvider { |
| 324 |
|
| 325 |
private static final String extensionPointId = "org.eclipse.papyrus.wizards.templates"; |
| 326 |
|
| 327 |
private static final String ATTRIBUTE_NAME = "name"; |
| 328 |
|
| 329 |
private static final String ATTRIBUTE_FILE = "file"; |
| 330 |
|
| 331 |
private static final String ATTRIBUTE_LANGUAGE = "language"; |
| 332 |
|
| 333 |
public void dispose() { |
| 334 |
// TODO Auto-generated method stub |
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
private ModelTemplateDescription[] getTemplatesDescription() { |
| 339 |
List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>(); |
| 340 |
|
| 341 |
IExtensionRegistry registry = Platform.getExtensionRegistry(); |
| 342 |
IExtension[] extensions = registry.getExtensionPoint(extensionPointId).getExtensions(); |
| 343 |
|
| 344 |
for(IExtension extension : extensions) { |
| 345 |
templates.addAll(processExtension(extension)); |
| 346 |
} |
| 347 |
|
| 348 |
return templates.toArray(new ModelTemplateDescription[templates.size()]); |
| 349 |
} |
| 350 |
|
| 351 |
private Collection<ModelTemplateDescription> processExtension(IExtension extension) { |
| 352 |
List<ModelTemplateDescription> templates = new ArrayList<ModelTemplateDescription>(); |
| 353 |
for(IConfigurationElement configElement : extension.getConfigurationElements()) { |
| 354 |
ModelTemplateDescription template = new ModelTemplateDescription(configElement.getAttribute(ATTRIBUTE_NAME), extension.getContributor().getName(), configElement.getAttribute(ATTRIBUTE_FILE)); |
| 355 |
template.setLanguage(configElement.getAttribute(ATTRIBUTE_LANGUAGE)); |
| 356 |
templates.add(template); |
| 357 |
} |
| 358 |
return templates; |
| 359 |
} |
| 360 |
|
| 361 |
public Object[] getElements(Object inputElement) { |
| 362 |
if(inputElement instanceof String) { |
| 363 |
List<ModelTemplateDescription> result = new ArrayList<ModelTemplateDescription>(); |
| 364 |
String diagramCategory = (String)inputElement; |
| 365 |
for(ModelTemplateDescription template : getTemplatesDescription()) { |
| 366 |
if(diagramCategory == null || diagramCategory.equals(template.getLanguage())) { |
| 367 |
result.add(template); |
| 368 |
} |
| 369 |
} |
| 370 |
return result.toArray(); |
| 371 |
} |
| 372 |
return new Object[0]; |
| 373 |
} |
| 374 |
|
| 375 |
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { |
| 376 |
if(viewer instanceof TableViewer) { |
| 377 |
((TableViewer)viewer).add(getElements(null)); |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
} |
| 382 |
|
| 383 |
private class ModelTemplateDescription { |
| 384 |
|
| 385 |
private String name; |
| 386 |
|
| 387 |
// private String metamodelURI; |
| 388 |
private String path; |
| 389 |
|
| 390 |
private String pluginId; |
| 391 |
|
| 392 |
private String language; |
| 393 |
|
| 394 |
public ModelTemplateDescription(String name, String pluginId, String path) { |
| 395 |
super(); |
| 396 |
this.name = name; |
| 397 |
// this.e = metamodelURI; |
| 398 |
this.path = path; |
| 399 |
this.pluginId = pluginId; |
| 400 |
} |
| 401 |
|
| 402 |
public void setLanguage(String language) { |
| 403 |
this.language = language; |
| 404 |
} |
| 405 |
|
| 406 |
/** |
| 407 |
* @return the name |
| 408 |
*/ |
| 409 |
public String getName() { |
| 410 |
return name; |
| 411 |
} |
| 412 |
|
| 413 |
// /** |
| 414 |
// * @return the metamodelURI |
| 415 |
// */ |
| 416 |
// public String getMetamodelURI() { |
| 417 |
// return metamodelURI; |
| 418 |
// } |
| 419 |
|
| 420 |
/** |
| 421 |
* @return the path |
| 422 |
*/ |
| 423 |
public String getPath() { |
| 424 |
return path; |
| 425 |
} |
| 426 |
|
| 427 |
public String getFileName() { |
| 428 |
String[] pathParts = path.split("/"); |
| 429 |
return pathParts[pathParts.length - 1]; |
| 430 |
} |
| 431 |
|
| 432 |
public String getPluginId() { |
| 433 |
return pluginId; |
| 434 |
} |
| 435 |
|
| 436 |
public String getLanguage() { |
| 437 |
return language; |
| 438 |
} |
| 439 |
|
| 440 |
} |
| 441 |
|
| 442 |
private class ModelTemplatesLabelProvider implements ITableLabelProvider { |
| 443 |
|
| 444 |
public Image getColumnImage(Object element, int columnIndex) { |
| 445 |
return null; |
| 446 |
} |
| 447 |
|
| 448 |
public String getColumnText(Object element, int columnIndex) { |
| 449 |
if(element instanceof ModelTemplateDescription) { |
| 450 |
ModelTemplateDescription modelTemplate = (ModelTemplateDescription)element; |
| 451 |
return modelTemplate.getName() + " (" + modelTemplate.getFileName() + ")"; |
| 452 |
} |
| 453 |
return null; |
| 454 |
} |
| 455 |
|
| 456 |
public void addListener(ILabelProviderListener listener) { |
| 457 |
|
| 458 |
} |
| 459 |
|
| 460 |
public void dispose() { |
| 461 |
|
| 462 |
} |
| 463 |
|
| 464 |
public boolean isLabelProperty(Object element, String property) { |
| 465 |
|
| 466 |
return false; |
| 467 |
} |
| 468 |
|
| 469 |
public void removeListener(ILabelProviderListener listener) { |
| 470 |
|
| 471 |
} |
| 472 |
|
| 473 |
} |
| 474 |
|
| 475 |
} |
239 |
} |