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 63889 Details for
Bug 181187
Need a method to add extension models to gmfgen model
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
"Add extension model..." context action with common-styled wizard added
org.eclipse.gmf.codegen.ui.txt (text/plain), 25.60 KB, created by
Anna Karjakina
on 2007-04-16 06:48:01 EDT
(
hide
)
Description:
"Add extension model..." context action with common-styled wizard added
Filename:
MIME Type:
Creator:
Anna Karjakina
Created:
2007-04-16 06:48:01 EDT
Size:
25.60 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.gmf.codegen.ui >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.codegen.ui/plugin.properties,v >retrieving revision 1.16 >diff -u -r1.16 plugin.properties >--- plugin.properties 5 Apr 2007 20:57:00 -0000 1.16 >+++ plugin.properties 16 Apr 2007 10:46:04 -0000 >@@ -23,3 +23,5 @@ > migrate.model.action=Migrate to GMF 2.0 > > dashboard.gende=Generate diagram editor >+ >+addextensionmodel.action=Add extension model... >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.codegen.ui/plugin.xml,v >retrieving revision 1.18 >diff -u -r1.18 plugin.xml >--- plugin.xml 5 Apr 2007 20:57:00 -0000 1.18 >+++ plugin.xml 16 Apr 2007 10:46:04 -0000 >@@ -29,6 +29,19 @@ > id="gmf.codegen.ui.executeTemplatesAction"> > </action> > </objectContribution> >+ <objectContribution >+ adaptable="true" >+ id="gmf.codegen.ui.addExtensionModel" >+ nameFilter="*.gmfgen" >+ objectClass="org.eclipse.core.resources.IFile"> >+ <action >+ label="%addextensionmodel.action" >+ class="org.eclipse.gmf.internal.codegen.popup.actions.AddExtensionModelAction" >+ menubarPath="additions" >+ enablesFor="1" >+ id="gmf.codegen.ui.addExtensionModelAction"> >+ </action> >+ </objectContribution> > <objectContribution > adaptable="true" > id="gmf.codegen.ui.migrate.model.gmfgen" >Index: src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java,v >retrieving revision 1.4 >diff -u -r1.4 Messages.java >--- src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java 18 Jan 2007 18:49:11 -0000 1.4 >+++ src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java 16 Apr 2007 10:46:05 -0000 >@@ -16,6 +16,36 @@ > > private static final String BUNDLE_NAME = "org.eclipse.gmf.internal.codegen.popup.actions.messages"; //$NON-NLS-1$ > >+ public static String AddExtensionModelWizard_0; >+ >+ public static String AddExtensionModelWizard_1; >+ >+ public static String AddExtensionModelWizard_10; >+ >+ public static String AddExtensionModelWizard_11; >+ >+ public static String AddExtensionModelWizard_12; >+ >+ public static String AddExtensionModelWizard_14; >+ >+ public static String AddExtensionModelWizard_15; >+ >+ public static String AddExtensionModelWizard_16; >+ >+ public static String AddExtensionModelWizard_2; >+ >+ public static String AddExtensionModelWizard_3; >+ >+ public static String AddExtensionModelWizard_4; >+ >+ public static String AddExtensionModelWizard_5; >+ >+ public static String AddExtensionModelWizard_6; >+ >+ public static String AddExtensionModelWizard_8; >+ >+ public static String AddExtensionModelWizard_9; >+ > public static String DiagnosticsDialog_Copy_menuItem; > > public static String DiagnosticsDialog_exceptStackTrace_toolTip; >Index: src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties >=================================================================== >RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties,v >retrieving revision 1.4 >diff -u -r1.4 messages.properties >--- src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties 18 Jan 2007 18:49:11 -0000 1.4 >+++ src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties 16 Apr 2007 10:46:05 -0000 >@@ -8,3 +8,18 @@ > DiagnosticsDialog_Copy_menuItem=Copy > DiagnosticsDialog_gotoProblem_menuItem=Go to problem > >+AddExtensionModelWizard_0=Add Your Extension EMF Metamodel To GMF Genmodel >+AddExtensionModelWizard_1=Ecore Model >+AddExtensionModelWizard_2=Ecore Import >+AddExtensionModelWizard_3=Specify one or more '.ecore' or '.emof' URIs and try to load them >+AddExtensionModelWizard_4=Ecore Instance >+AddExtensionModelWizard_5=Ecore Model >+AddExtensionModelWizard_6=Select a model object to create >+AddExtensionModelWizard_8=Open Editor >+AddExtensionModelWizard_9=Select Extension EMF Ecore Model >+AddExtensionModelWizard_10=Select Extension EMF Ecore Model >+AddExtensionModelWizard_11=Problem Loading Metamodel >+AddExtensionModelWizard_12=Problems during processing custom metamodel >+AddExtensionModelWizard_14=Model Object >+AddExtensionModelWizard_15=XML Encoding >+AddExtensionModelWizard_16=UTF-8 ASCII UTF-16 UTF-16BE UTF-16LE ISO-8859-1 >Index: src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelWizard.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelWizard.java >diff -N src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelWizard.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelWizard.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,540 @@ >+/* >+ * Copyright (c) 2007 Borland Software Corporation and others. >+ * 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: >+ * Borland Software Corporation - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.codegen.popup.actions; >+ >+import java.io.File; >+import java.io.IOException; >+import java.util.ArrayList; >+import java.util.Collection; >+import java.util.Collections; >+import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; >+import java.util.Map; >+import java.util.StringTokenizer; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IFile; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.core.resources.ResourcesPlugin; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.Path; >+import org.eclipse.emf.common.ui.dialogs.WorkspaceResourceDialog; >+import org.eclipse.emf.common.util.BasicMonitor; >+import org.eclipse.emf.common.util.Diagnostic; >+import org.eclipse.emf.common.util.Monitor; >+import org.eclipse.emf.common.util.URI; >+import org.eclipse.emf.converter.ModelConverter; >+import org.eclipse.emf.converter.ui.contribution.base.ModelConverterURIPage; >+import org.eclipse.emf.converter.util.ConverterUtil; >+import org.eclipse.emf.ecore.EClass; >+import org.eclipse.emf.ecore.EObject; >+import org.eclipse.emf.ecore.plugin.EcorePlugin; >+import org.eclipse.emf.ecore.resource.Resource; >+import org.eclipse.emf.ecore.resource.ResourceSet; >+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; >+import org.eclipse.emf.ecore.xmi.XMLResource; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.viewers.ViewerFilter; >+import org.eclipse.jface.wizard.Wizard; >+import org.eclipse.jface.wizard.WizardPage; >+import org.eclipse.swt.SWT; >+import org.eclipse.swt.events.ModifyEvent; >+import org.eclipse.swt.events.ModifyListener; >+import org.eclipse.swt.layout.GridData; >+import org.eclipse.swt.layout.GridLayout; >+import org.eclipse.swt.widgets.Combo; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.FileDialog; >+import org.eclipse.swt.widgets.Label; >+import org.eclipse.ui.IEditorDescriptor; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPage; >+import org.eclipse.ui.IWorkbenchPart; >+import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PartInitException; >+import org.eclipse.ui.actions.WorkspaceModifyOperation; >+import org.eclipse.ui.part.FileEditorInput; >+import org.eclipse.ui.part.ISetSelectionTarget; >+ >+public class AddExtensionModelWizard extends Wizard { >+ >+ private EcoreModelWizardInitialObjectCreationPage myInitialObjectCreationPage; >+ >+ private ModelImporterDetailPage myCustomMetamodelSelectionPage; >+ >+ private IFile myFile; >+ >+ private IWorkbench myWorkbench; >+ >+ public AddExtensionModelWizard() { >+ super(); >+ } >+ >+ public void init(IWorkbench workbench, IStructuredSelection selection) { >+ myWorkbench = workbench; >+ myFile = (IFile) selection.getFirstElement(); >+ setWindowTitle(Messages.AddExtensionModelWizard_0); >+ } >+ >+ protected IFile getGmfgenFile() { >+ return myFile; >+ } >+ >+ protected IWorkbench getWorkbench() { >+ return myWorkbench; >+ } >+ >+ public void addPages() { >+ super.addPages(); >+ >+ myCustomMetamodelSelectionPage = new ModelImporterDetailPage(null, Messages.AddExtensionModelWizard_1); >+ myCustomMetamodelSelectionPage.setTitle(Messages.AddExtensionModelWizard_2); >+ myCustomMetamodelSelectionPage.setDescription(Messages.AddExtensionModelWizard_3); //"Select Your Extension EMF Metamodel" >+ addPage(myCustomMetamodelSelectionPage); >+ >+ myInitialObjectCreationPage = new EcoreModelWizardInitialObjectCreationPage(Messages.AddExtensionModelWizard_4); >+ myInitialObjectCreationPage.setTitle(Messages.AddExtensionModelWizard_5); >+ myInitialObjectCreationPage.setDescription(Messages.AddExtensionModelWizard_6); //"Select a Model Object To Create" >+ addPage(myInitialObjectCreationPage); >+ >+ } >+ >+ public boolean performFinish() { >+ try { >+ // Do the work within an operation. >+ // >+ WorkspaceModifyOperation operation = new WorkspaceModifyOperation() { >+ >+ @Override >+ protected void execute(IProgressMonitor progressMonitor) { >+ try { >+ String userEcoreUri = myCustomMetamodelSelectionPage.getUserEcoreUriString(); >+ if (userEcoreUri != null && userEcoreUri.trim().length() > 0) { >+ List<EClass> nonAbstractClasses = readAllNonAbstractClasses(userEcoreUri); >+ int selectedClass = myInitialObjectCreationPage.getInitialObjectNumber(nonAbstractClasses); >+ if (selectedClass >= 0 && selectedClass < nonAbstractClasses.size()) { >+ EClass selected = nonAbstractClasses.get(selectedClass); >+ if (selected != null) { >+ EObject instantiated = selected.getEPackage().getEFactoryInstance().create(selected); >+ String gmfgenUri = URI.createPlatformResourceURI(getGmfgenFile().getFullPath().toString(), true).toString(); >+ Resource[] resources = getLoadedResources(new String[] { gmfgenUri, userEcoreUri }); >+ >+ resources[0].getContents().add(instantiated); >+ >+ // Save the contents of the resource to the file system. >+ // >+ Map<Object, Object> options = new HashMap<Object, Object>(); >+ options.put(XMLResource.OPTION_ENCODING, myInitialObjectCreationPage.getEncoding()); >+ resources[0].save(options); >+ resources[0].unload(); >+ resources[1].unload(); >+ } >+ } >+ } >+ } catch (Exception e) { >+ EcorePlugin.INSTANCE.getPluginLogger().log(e); >+ } finally { >+ progressMonitor.done(); >+ } >+ } >+ }; >+ >+ getContainer().run(false, false, operation); >+ >+ // Select the new file resource in the current view. >+ // >+ IWorkbenchWindow workbenchWindow = getWorkbench().getActiveWorkbenchWindow(); >+ IWorkbenchPage page = workbenchWindow.getActivePage(); >+ final IWorkbenchPart activePart = page.getActivePart(); >+ if (activePart instanceof ISetSelectionTarget) { >+ final ISelection targetSelection = new StructuredSelection(myFile); >+ getShell().getDisplay().asyncExec(new Runnable() { >+ >+ public void run() { >+ ((ISetSelectionTarget) activePart).selectReveal(targetSelection); >+ } >+ }); >+ } >+ >+ // Open an editor on the new file. >+ // >+ try { >+ IEditorDescriptor defaultEditor = getWorkbench().getEditorRegistry().getDefaultEditor(myFile.getFullPath().toString()); >+ page.openEditor(new FileEditorInput(myFile), defaultEditor == null ? "org.eclipse.gmf.codegen.gmfgen.presentation.GMFGenEditorID" : defaultEditor.getId()); //$NON-NLS-1$ >+ } catch (PartInitException exception) { >+ MessageDialog.openError(workbenchWindow.getShell(), Messages.AddExtensionModelWizard_8, exception.getMessage()); >+ return false; >+ } >+ return true; >+ } catch (Exception e) { >+ EcorePlugin.INSTANCE.getPluginLogger().log(e); >+ return false; >+ } >+ } >+ >+ /** >+ * This is the page which allows to browse workspace in order to locate custom metamodel. >+ */ >+ public class ModelImporterDetailPage extends ModelConverterURIPage { >+ >+ private String myUriString; >+ >+ private Resource[] myResources; >+ >+ public ModelImporterDetailPage(ModelConverter modelConverter, String pageName) { >+ super(modelConverter, pageName); >+ } >+ >+ protected boolean browseFileSystem() { >+ FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN | SWT.SINGLE); >+ fileDialog.setFilterExtensions(getFilterExtensions()); >+ URI modelURI = getModelLocationURI(getUserEcoreUriString()); >+ if (modelURI != null) { >+ fileDialog.setFileName(modelURI.toFileString()); >+ } >+ if (fileDialog.open() != null && fileDialog.getFileNames().length > 0) { >+ String filePath = fileDialog.getFilterPath() + File.separator + fileDialog.getFileNames()[0]; >+ String uriText = URI.createFileURI(filePath).toString(); >+ setURIText(uriText); >+ uriTextModified(uriText); >+ return true; >+ } >+ return false; >+ } >+ >+ public URI getModelLocationURI(String uriString) { >+ if (isPageComplete()) { >+ return URI.createURI(uriString); >+ } >+ return null; >+ } >+ >+ protected boolean browseWorkspace() { >+ IFile[] selected = WorkspaceResourceDialog.openFileSelection(getShell(), Messages.AddExtensionModelWizard_9, Messages.AddExtensionModelWizard_10, false, getInitialWorkspaceSelection(), >+ getViewerFiltersList()); >+ if (selected.length == 1 && selected[0] != null) { >+ String uriText = URI.createPlatformResourceURI(selected[0].getFullPath().toString(), true).toString(); >+ setURIText(uriText); >+ uriTextModified(uriText); >+ return true; >+ } >+ return false; >+ } >+ >+ protected void uriTextModified(String text) { >+ super.uriTextModified(text); >+ refreshModel(); >+ } >+ >+ protected void refreshModel() { >+ WorkspaceModifyOperation initializeOperation = new WorkspaceModifyOperation() { >+ >+ protected void execute(IProgressMonitor progressMonitor) throws CoreException { >+ Diagnostic errorDiagnostic = null; >+ setErrorMessage(null); >+ setMessage(null); >+ >+ Monitor monitor = BasicMonitor.toMonitor(progressMonitor); >+ try { >+ String uriString = uriText.getText(); >+ Resource[] resources = getLoadedResources(new String[] { uriString }); >+ setResources(resources); >+ if (validatePage()) { >+ List<EClass> nonAbstractClassNames = readAllNonAbstractClasses(uriString); >+ myInitialObjectCreationPage.refresh(nonAbstractClassNames); >+ } >+ } catch (IOException e) { >+ EcorePlugin.INSTANCE.getPluginLogger().log(e); >+ errorDiagnostic = ConverterUtil.createErrorDiagnostic(e, true); >+ } catch (RuntimeException e) { >+ EcorePlugin.INSTANCE.getPluginLogger().log(e); >+ errorDiagnostic = ConverterUtil.createErrorDiagnostic(e, true); >+ } finally { >+ monitor.done(); >+ setResources(null); >+ } >+ >+ if (errorDiagnostic != null) { >+ handleDiagnostic(errorDiagnostic, errorDiagnostic.getMessage(), Messages.AddExtensionModelWizard_11, Messages.AddExtensionModelWizard_12); >+ } >+ } >+ >+ }; >+ >+ myUriString = uriText.getText(); >+ >+ try { >+ getContainer().run(false, false, initializeOperation); >+ } catch (Exception e) { >+ EcorePlugin.INSTANCE.getPluginLogger().log(e); >+ } >+ >+ if (validatePage()) { >+ setPageComplete(true); >+ } else { >+ setPageComplete(false); >+ uriText.selectAll(); >+ uriText.setFocus(); >+ } >+ } >+ >+ private void setResources(Resource[] resources) { >+ myResources = resources; >+ >+ } >+ >+ public String getUserEcoreUriString() { >+ return myUriString; >+ } >+ >+ public boolean validatePage() { >+ return myResources != null && myResources.length > 0; >+ } >+ >+ private Object[] convertResourcesToWorkspaceResources(Resource[] resources) { >+ IResource[] result = new IResource[resources.length]; >+ for (int i=0; i<resources.length; i++) { >+ result[i] = ResourcesPlugin.getWorkspace().getRoot().findMember(new Path(resources[i].getURI().toString()));; >+ } >+ return result; >+ } >+ >+ private Object[] getInitialWorkspaceSelection() { >+ if (validatePage()) { >+ return convertResourcesToWorkspaceResources(myResources); >+ } >+ return new Object[0]; >+ } >+ >+ private List<ViewerFilter> getViewerFiltersList() { >+ ViewerFilter filter = new ViewerFilter() { >+ >+ public boolean select(Viewer viewer, Object parentElement, Object element) { >+ if (element instanceof IContainer) { >+ return true; >+ } >+ if (element instanceof IFile) { >+ IFile iFile = (IFile) element; >+ String[] exts = getFilterExtensions(); >+ boolean goodExt = false; >+ for (int i = 0; i < exts.length; i++) { >+ if (iFile.getFileExtension().equals(exts[i])) { >+ goodExt = true; >+ } >+ } >+ return goodExt; >+ } >+ return false; >+ } >+ }; >+ return Collections.singletonList(filter); >+ } >+ >+ private String[] getFilterExtensions() { >+ return new String[] { "ecore" }; //$NON-NLS-1$ >+ } >+ } >+ >+ /** >+ * This is the page where the type of object to create is selected. >+ */ >+ public class EcoreModelWizardInitialObjectCreationPage extends WizardPage { >+ >+ protected Combo initialObjectField; >+ >+ protected List<String> encodings; >+ >+ protected Combo encodingField; >+ >+ /** >+ * Pass in the selection. >+ */ >+ public EcoreModelWizardInitialObjectCreationPage(String pageId) { >+ super(pageId); >+ } >+ >+ public void refresh(List<EClass> initialObjectNames) { >+ initialObjectField.setItems(new String[0]); >+ for (EClass objectName : initialObjectNames) { >+ initialObjectField.add(getLabel(objectName)); >+ } >+ if (initialObjectField.getItemCount() > 0) { >+ initialObjectField.select(0); >+ } >+ } >+ >+ public void createControl(Composite parent) { >+ Composite composite = new Composite(parent, SWT.NONE); >+ { >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 1; >+ layout.verticalSpacing = 12; >+ composite.setLayout(layout); >+ >+ GridData data = new GridData(); >+ data.verticalAlignment = GridData.FILL; >+ data.grabExcessVerticalSpace = true; >+ data.horizontalAlignment = GridData.FILL; >+ composite.setLayoutData(data); >+ } >+ >+ Label containerLabel = new Label(composite, SWT.LEFT); >+ { >+ containerLabel.setText(Messages.AddExtensionModelWizard_14); >+ >+ GridData data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ containerLabel.setLayoutData(data); >+ } >+ >+ initialObjectField = new Combo(composite, SWT.BORDER); >+ { >+ GridData data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ data.grabExcessHorizontalSpace = true; >+ initialObjectField.setLayoutData(data); >+ } >+ >+ initialObjectField.addModifyListener(validator); >+ >+ Label encodingLabel = new Label(composite, SWT.LEFT); >+ { >+ encodingLabel.setText(Messages.AddExtensionModelWizard_15); >+ >+ GridData data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ encodingLabel.setLayoutData(data); >+ } >+ encodingField = new Combo(composite, SWT.BORDER); >+ { >+ GridData data = new GridData(); >+ data.horizontalAlignment = GridData.FILL; >+ data.grabExcessHorizontalSpace = true; >+ encodingField.setLayoutData(data); >+ } >+ >+ for (String encoding : getEncodings()) { >+ encodingField.add(encoding); >+ } >+ >+ encodingField.select(0); >+ encodingField.addModifyListener(validator); >+ >+ setPageComplete(validatePage()); >+ setControl(composite); >+ } >+ >+ protected ModifyListener validator = new ModifyListener() { >+ >+ public void modifyText(ModifyEvent e) { >+ setPageComplete(validatePage()); >+ } >+ }; >+ >+ protected boolean validatePage() { >+ return initialObjectField.getText() != null && initialObjectField.getText().trim().length() > 0 && getEncodings().contains(encodingField.getText()); >+ } >+ >+ public void setVisible(boolean visible) { >+ super.setVisible(visible); >+ if (visible) { >+ if (initialObjectField.getItemCount() == 1) { >+ initialObjectField.clearSelection(); >+ encodingField.setFocus(); >+ } else { >+ encodingField.clearSelection(); >+ initialObjectField.setFocus(); >+ } >+ } >+ } >+ >+ public String getInitialObjectName(List<EClass> allClasses) { >+ String label = initialObjectField.getText(); >+ >+ for (EClass next : allClasses) { >+ if (getLabel(next).equals(label)) { >+ return label; >+ } >+ } >+ return null; >+ } >+ >+ public int getInitialObjectNumber(List<EClass> allClasses) { >+ String label = initialObjectField.getText(); >+ for (int i = 0; i < allClasses.size(); i++) { >+ EClass next = allClasses.get(i); >+ if (getLabel(next).equals(label)) { >+ return i; >+ } >+ } >+ return 0; >+ } >+ >+ public String getEncoding() { >+ return encodingField.getText(); >+ } >+ >+ /** >+ * Returns the label for the specified type name. >+ */ >+ protected String getLabel(EClass type) { >+ return type.getName(); >+ } >+ >+ protected Collection<String> getEncodings() { >+ if (encodings == null) { >+ encodings = new ArrayList<String>(); >+ for (StringTokenizer stringTokenizer = new StringTokenizer(Messages.AddExtensionModelWizard_16); stringTokenizer.hasMoreTokens();) { >+ encodings.add(stringTokenizer.nextToken()); >+ } >+ } >+ return encodings; >+ } >+ } >+ >+ public static Resource[] getLoadedResources(String[] textURIs) throws IOException { >+ Resource[] result = new Resource[textURIs.length]; >+ ResourceSet resourceSet = new ResourceSetImpl(); >+ for (int i = 0; i < result.length; i++) { >+ URI nextURI = URI.createURI(textURIs[i]); >+ Resource resource = resourceSet.createResource(nextURI); >+ resource.load(resourceSet.getLoadOptions()); >+ result[i] = resource; >+ } >+ return result; >+ } >+ >+ public static List<EClass> readAllNonAbstractClasses(String textURI) throws IOException { >+ List<EClass> nonAbstractClasses = new ArrayList<EClass>(); >+ Resource resource = getLoadedResources(new String[] { textURI })[0]; >+ if (resource != null && resource.isLoaded()) { >+ Iterator<EObject> contents = resource.getAllContents(); >+ while (contents.hasNext()) { >+ EObject next = contents.next(); >+ if (next instanceof EClass) { >+ EClass clazz = (EClass) next; >+ if (!clazz.isAbstract()) { >+ nonAbstractClasses.add(clazz); >+ } >+ } >+ } >+ resource.unload(); >+ } >+ return nonAbstractClasses; >+ } >+ >+} >Index: src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelAction.java >=================================================================== >RCS file: src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelAction.java >diff -N src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelAction.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelAction.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,57 @@ >+/* >+ * Copyright (c) 2007 Borland Software Corporation and others. >+ * 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: >+ * Borland Software Corporation - initial API and implementation >+ */ >+package org.eclipse.gmf.internal.codegen.popup.actions; >+ >+import org.eclipse.core.resources.IFile; >+import org.eclipse.jface.action.IAction; >+import org.eclipse.jface.viewers.ISelection; >+import org.eclipse.jface.viewers.IStructuredSelection; >+import org.eclipse.jface.viewers.StructuredSelection; >+import org.eclipse.jface.wizard.WizardDialog; >+import org.eclipse.swt.widgets.Shell; >+import org.eclipse.ui.IObjectActionDelegate; >+import org.eclipse.ui.IWorkbench; >+import org.eclipse.ui.IWorkbenchPart; >+ >+public class AddExtensionModelAction implements IObjectActionDelegate { >+ >+ private IFile myFile; >+ >+ private IWorkbenchPart myPart; >+ >+ public void setActivePart(IAction action, IWorkbenchPart targetPart) { >+ myPart = targetPart; >+ } >+ >+ public void selectionChanged(IAction action, ISelection selection) { >+ myFile = (IFile) ((IStructuredSelection) selection).getFirstElement(); >+ } >+ >+ public void run(IAction action) { >+ // Create the wizard >+ AddExtensionModelWizard wizard = new AddExtensionModelWizard(); >+ wizard.init(getWorkbench(), new StructuredSelection(myFile)); >+ >+ // Create the wizard dialog >+ WizardDialog dialog = new WizardDialog(getShell(), wizard); >+ // Open the wizard dialog >+ dialog.open(); >+ } >+ >+ private Shell getShell() { >+ return myPart.getSite().getShell(); >+ } >+ >+ private IWorkbench getWorkbench() { >+ return myPart.getSite().getWorkbenchWindow().getWorkbench(); >+ } >+ >+}
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:
tikhomirov.artem
:
review-
Actions:
View
|
Diff
Attachments on
bug 181187
:
63889
|
64114
|
64119