Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 169501 Details for
Bug 313179
[Usability] Refactor CreateModelWizard
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Initial refactoring
313179 (text/plain), 12.71 KB, created by
Tatiana Fesenko
on 2010-05-21 10:10:55 EDT
(
hide
)
Description:
Initial refactoring
Filename:
MIME Type:
Creator:
Tatiana Fesenko
Created:
2010-05-21 10:10:55 EDT
Size:
12.71 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.papyrus.diagram.common >Index: src/org/eclipse/papyrus/diagram/common/wizards/InitUMLDiagramAction.java >=================================================================== >--- src/org/eclipse/papyrus/diagram/common/wizards/InitUMLDiagramAction.java (revision 1683) >+++ src/org/eclipse/papyrus/diagram/common/wizards/InitUMLDiagramAction.java (working copy) >@@ -14,6 +14,9 @@ > import org.eclipse.papyrus.wizards.CreateModelWizard; > import org.eclipse.papyrus.wizards.InitDiagramAction; > >+/** >+ * @deprecated the class is not used - there is no references to it in Papyrus >+ */ > public class InitUMLDiagramAction extends InitDiagramAction { > > @Override >Index: src/org/eclipse/papyrus/diagram/common/wizards/NewPapyrusProjectWizard.java >=================================================================== >--- src/org/eclipse/papyrus/diagram/common/wizards/NewPapyrusProjectWizard.java (revision 1683) >+++ src/org/eclipse/papyrus/diagram/common/wizards/NewPapyrusProjectWizard.java (working copy) >@@ -50,14 +50,11 @@ > > private SelectDiagramKindPage myDiagramKindPage; > >- private IStructuredSelection selection; >- > private String initialProjectName; > > public void init(IWorkbench workbench, IStructuredSelection selection) { > super.init(workbench, selection); > setWindowTitle("New Papyrus Project"); >- this.selection = selection; > } > > public void addPages() { >@@ -89,12 +86,12 @@ > } > // if the user wants to create a diagram > if (myDiagramKindPage.getCreationCommand() != null) { >- return createDiagram(); >+ return createPapyrusModel(); > } > return true; > } > >- private boolean createDiagram() { >+ private boolean createPapyrusModel() { > final DiResourceSet diResourceSet = new DiResourceSet(); > try { > // create a new file, result != null if successful >Index: src/org/eclipse/papyrus/diagram/common/wizards/CreateUMLModelWizard.java >=================================================================== >--- src/org/eclipse/papyrus/diagram/common/wizards/CreateUMLModelWizard.java (revision 1683) >+++ src/org/eclipse/papyrus/diagram/common/wizards/CreateUMLModelWizard.java (working copy) >@@ -22,14 +22,6 @@ > import org.eclipse.uml2.uml.UMLPackage; > > public class CreateUMLModelWizard extends CreateModelWizard { >- >- public CreateUMLModelWizard() { >- super(); >- } >- >- public CreateUMLModelWizard(URI domainModelURI) { >- super(domainModelURI); >- } > > /** > * This ID is the id defined in the extension "org.eclipse.ui.newWizards" of >@@ -37,33 +29,32 @@ > */ > // @unused > public static final String ID_UMLWIZARD = "org.eclipse.papyrus.wizards.createumlmodel"; >- /** >- * The config element which declares this wizard. >- */ >- private IConfigurationElement configElement; > >- >+ public CreateUMLModelWizard() { >+ super(); >+ } >+ >+ public CreateUMLModelWizard(URI domainModelURI) { >+ super(domainModelURI); >+ } > > @Override > protected String getModelContentType() { > return UMLPackage.eCONTENT_TYPE; > } >- >+ > @Override > protected String getModelFileExtension() { > return "uml"; > } > >- @Override >- protected void initializeModelResource(Resource resource, String rootElementName) { >- // fjcano #293135 :: support model templates >- if(!isInitializeFromTemplate()) { >- Model model = UMLFactory.eINSTANCE.createModel(); >- model.setName(rootElementName); >- resource.getContents().add(model); >- } else { >- super.initializeModelResource(resource, rootElementName); >- } >+ /** >+ * This method is invoked for creation of a model >+ */ >+ protected void initializeEmptyModel(Resource resource, String rootElementName) { >+ Model model = UMLFactory.eINSTANCE.createModel(); >+ model.setName(rootElementName); >+ resource.getContents().add(model); > } > > } >#P org.eclipse.papyrus.wizards >Index: src/org/eclipse/papyrus/wizards/CreateModelWizard.java >=================================================================== >--- src/org/eclipse/papyrus/wizards/CreateModelWizard.java (revision 1683) >+++ src/org/eclipse/papyrus/wizards/CreateModelWizard.java (working copy) >@@ -32,6 +32,7 @@ > import org.eclipse.papyrus.core.utils.DiResourceSet; > import org.eclipse.papyrus.core.utils.EditorUtils; > import org.eclipse.papyrus.core.utils.PapyrusTrace; >+import org.eclipse.papyrus.resource.uml.UmlModel; > import org.eclipse.ui.INewWizard; > import org.eclipse.ui.IWorkbench; > import org.eclipse.ui.IWorkbenchPage; >@@ -117,24 +118,20 @@ > public void init(IWorkbench workbench, IStructuredSelection selection) { > this.workbench = workbench; > this.diResourceSet = new DiResourceSet(); >- // set the di file name with the selected domain model >- if(selection != null && !selection.isEmpty()) { >- if(selection.getFirstElement() instanceof IFile) { >- IFile file = (IFile)selection.getFirstElement(); >- String extension = file.getFileExtension(); >- if(getModelFileExtension().equals(extension)) { >- this.domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true); >+ IFile file = getSelectedFile(selection); >+ // builds a new Papyrus Model for an existing domain model >+ if(isSupportedDomainModelFile(file)) { >+ this.domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true); >+ this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new Papyrus model from an existing semantic model", selection, true); >+ this.newModelFilePage.setFileName(getDiagramFileName(file)); > >- this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new Papyrus model from an existing semantic model", selection, true); >- String diModelFileName = (file.getLocation().removeFileExtension().lastSegment()); >- diModelFileName += ".di"; >- this.newModelFilePage.setFileName(diModelFileName); >+ // I don't understand a need to load the model during initialization, >+ // I rather expect it to be loaded when wizard is finished and executed or >+ // when the page that needs the model is initialized >+ Resource resource = diResourceSet.loadModelResource(file); > >- Resource resource = diResourceSet.loadModelResource(file); >- EObject diagramRoot = resource.getContents().get(0); >- this.selectRootElementPage = new SelectRootElementPage("Select the root element", diagramRoot); >- } >- } >+ EObject diagramRoot = resource.getContents().get(0); >+ this.selectRootElementPage = new SelectRootElementPage("Select the root element", diagramRoot); > } > if(domainModelURI == null) { > this.newModelFilePage = new NewModelFilePage("Create a new Papyrus model", "Create a new empty Papyrus model", selection, false); >@@ -143,8 +140,35 @@ > // fjcano #293135 :: support model templates > selectTemplateWizardPage = new SelectTemplateWizardPage(Activator.PLUGIN_ID, null, null); > } >+ >+ /** >+ * Suggests a name of diagram file for the domain model file >+ */ >+ protected String getDiagramFileName(IFile domainModel) { >+ String diModelFileName = (domainModel.getLocation().removeFileExtension().lastSegment()); >+ diModelFileName += ".di"; >+ return diModelFileName; >+ } > > /** >+ * Returns the first file from the given selection >+ */ >+ private IFile getSelectedFile(IStructuredSelection selection) { >+ if(selection != null && !selection.isEmpty() && selection.getFirstElement() instanceof IFile) { >+ return (IFile)selection.getFirstElement(); >+ } >+ return null; >+ } >+ >+ /** >+ * Returns true is the file can be served as a model model for the diagram >+ */ >+ protected boolean isSupportedDomainModelFile(IFile file) { >+ return file != null && getModelFileExtension().equals(file.getFileExtension()); >+ } >+ >+ >+ /** > * This method will be invoked, when the "Finish" button is pressed. > * > * @return <code>true</code> if everything runs without problems, <code>false</code> if an exception must be caught. >@@ -155,7 +179,6 @@ > try { > // create a new file, result != null if successful > final IFile newFile = newModelFilePage.createNewFile(); >- NewModelFilePage.fileCount++; > > RecordingCommand command = new RecordingCommand(diResourceSet.getTransactionalEditingDomain()) { > >@@ -197,12 +220,8 @@ > // SashSystem. > EditorUtils.getTransactionalIPageMngr(diResourceSet.getDiResource(), diResourceSet.getTransactionalEditingDomain()); > } else { >- // Create requested diagram. >- if(domainModelURI != null) { >- creationCommand.createDiagram(diResourceSet, selectRootElementPage.getModelElement(), diagramName); >- } else { >- creationCommand.createDiagram(diResourceSet, null, diagramName); >- } >+ EObject root = domainModelURI != null ? selectRootElementPage.getModelElement() : null; >+ creationCommand.createDiagram(diResourceSet, root, diagramName); > } > try { > diResourceSet.save(new NullProgressMonitor()); >@@ -231,47 +250,42 @@ > protected abstract String getModelFileExtension(); > > // fjcano #293135 :: support model templates >- protected void initializeModelResource(Resource resource, String rootElementName) { >- if(isInitializeFromTemplate()) { >- Resource templateResource = loadTemplateResource(); >- List<EObject> eObjectsToAdd = new ArrayList<EObject>(); >- for(EObject eObject : templateResource.getContents()) { >- eObjectsToAdd.add(EcoreUtil.copy(eObject)); >- } >- for(EObject eObject : eObjectsToAdd) { >- resource.getContents().add(eObject); >- } >+ private void initializeModelResource(Resource resource, String rootElementName) { >+ String templatePath = selectTemplateWizardPage.getTemplatePath(); >+ boolean initializeFromTemplate = templatePath != null; >+ if(initializeFromTemplate) { >+ initializeFromTemplate(resource, rootElementName, templatePath); > } else { >- // nothing >- return; >+ initializeEmptyModel(resource, rootElementName); > } > } > >- // fjcano #293135 :: support model templates >- protected boolean isInitializeFromTemplate() { >- return getTemplatePath() != null; >+ protected void initializeFromTemplate(Resource resource, String rootElementName, String templatePath) { >+ Resource templateResource = loadTemplateResource(templatePath); >+ List<EObject> eObjectsToAdd = new ArrayList<EObject>(); >+ for(EObject eObject : templateResource.getContents()) { >+ eObjectsToAdd.add(EcoreUtil.copy(eObject)); >+ } >+ for(EObject eObject : eObjectsToAdd) { >+ resource.getContents().add(eObject); >+ } > } > >- // fjcano #293135 :: support model templates >- protected String getTemplatePath() { >- String templatePath = selectTemplateWizardPage.getTemplatePath(); >- return templatePath; >+ protected void initializeEmptyModel(Resource resource, String rootElementName) { > } > >- // fjcano #293135 :: support model templates >- protected Resource loadTemplateResource() { >+ private Resource loadTemplateResource(String templatePath) { > String templatePluginID = selectTemplateWizardPage.getTemplatePluginId(); >- String templatePath = getTemplatePath(); > java.net.URL templateURL = Platform.getBundle(templatePluginID).getResource(templatePath); >- if(templatePath != null) { >- String fullUri = templateURL.getPath(); >- URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true); >- ResourceSet resourceSet = new ResourceSetImpl(); >- Resource resource = resourceSet.getResource(uri, true); >- if(resource.isLoaded()) { >- return resource; >- } >+ String fullUri = templateURL.getPath(); >+ URI uri = URI.createPlatformPluginURI(templatePluginID + fullUri, true); >+ ResourceSet resourceSet = new ResourceSetImpl(); >+ Resource resource = resourceSet.getResource(uri, true); >+ if(resource.isLoaded()) { >+ return resource; > } > return null; > } >+ >+ > } >Index: src/org/eclipse/papyrus/wizards/NewModelFilePage.java >=================================================================== >--- src/org/eclipse/papyrus/wizards/NewModelFilePage.java (revision 1683) >+++ src/org/eclipse/papyrus/wizards/NewModelFilePage.java (working copy) >@@ -10,6 +10,7 @@ > *******************************************************************************/ > package org.eclipse.papyrus.wizards; > >+import org.eclipse.core.resources.IFile; > import org.eclipse.jface.viewers.IStructuredSelection; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.ui.IWorkbench; >@@ -23,7 +24,7 @@ > public class NewModelFilePage extends WizardNewFileCreationPage { > > /** index for several file creation */ >- protected static int fileCount = 1; >+ private static int fileCount = 1; > > protected boolean createFromSemanticModel; > >@@ -89,6 +90,13 @@ > // return false; > return true; > } >+ >+ @Override >+ public IFile createNewFile() { >+ IFile created = super.createNewFile(); >+ fileCount++; >+ return created; >+ } > > /** > * {@inheritDoc}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
sebastien.gerard
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 313179
:
168758
| 169501 |
169796
|
169962
|
169963
|
170771