Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoratikhomirov2007-04-18 09:13:10 -0400
committeratikhomirov2007-04-18 09:13:10 -0400
commit729f850fa113c99dd184de17f9cb3ed639bdd5de (patch)
tree6f3f7d9675583cafe503f6b039b5b52b1e407843
parentcaea342fbe7ea8b73df209a381bd299c05bdcbd8 (diff)
downloadorg.eclipse.gmf-tooling-729f850fa113c99dd184de17f9cb3ed639bdd5de.tar.gz
org.eclipse.gmf-tooling-729f850fa113c99dd184de17f9cb3ed639bdd5de.tar.xz
org.eclipse.gmf-tooling-729f850fa113c99dd184de17f9cb3ed639bdd5de.zip
[181187] akarjakina - Need a method to add extension models to gmfgen model
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/plugin.properties2
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/plugin.xml7
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelAction.java63
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/GMFGenExtensionModelWizard.java186
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java10
-rw-r--r--plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties5
6 files changed, 273 insertions, 0 deletions
diff --git a/plugins/org.eclipse.gmf.codegen.ui/plugin.properties b/plugins/org.eclipse.gmf.codegen.ui/plugin.properties
index 96549b166..60bf0f0fa 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/plugin.properties
+++ b/plugins/org.eclipse.gmf.codegen.ui/plugin.properties
@@ -23,3 +23,5 @@ generatecode.badsrc=Source generator model is not completely ok, would you like
migrate.model.action=Migrate to GMF 2.0
dashboard.gende=Generate diagram editor
+
+addextensionmodel.action=Add extension model...
diff --git a/plugins/org.eclipse.gmf.codegen.ui/plugin.xml b/plugins/org.eclipse.gmf.codegen.ui/plugin.xml
index c0ea24a56..bad961c99 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/plugin.xml
+++ b/plugins/org.eclipse.gmf.codegen.ui/plugin.xml
@@ -28,6 +28,13 @@
enablesFor="1"
id="gmf.codegen.ui.executeTemplatesAction">
</action>
+ <action
+ label="%addextensionmodel.action"
+ class="org.eclipse.gmf.internal.codegen.popup.actions.AddExtensionModelAction"
+ menubarPath="additions"
+ enablesFor="+"
+ id="gmf.codegen.ui.addExtensionModelAction">
+ </action>
</objectContribution>
<objectContribution
adaptable="true"
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelAction.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelAction.java
new file mode 100644
index 000000000..01ae4bf21
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/AddExtensionModelAction.java
@@ -0,0 +1,63 @@
+/*
+ * 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.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+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;
+import org.eclipse.ui.IWorkbenchWizard;
+
+public class AddExtensionModelAction implements IObjectActionDelegate {
+
+ private IStructuredSelection mySelection;
+
+ private IWorkbenchPart myPart;
+
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ myPart = targetPart;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ mySelection = (IStructuredSelection) selection;
+ }
+
+ public void run(IAction action) {
+ // Create the wizard
+ IWorkbenchWizard wizard = createWizard();
+ wizard.init(getWorkbench(), getSelection());
+
+ // Create the wizard dialog
+ WizardDialog dialog = new WizardDialog(getShell(), wizard);
+ // Open the wizard dialog
+ dialog.open();
+ }
+
+ protected IWorkbenchWizard createWizard() {
+ return new GMFGenExtensionModelWizard();
+ }
+
+ private Shell getShell() {
+ return myPart.getSite().getShell();
+ }
+
+ private IWorkbench getWorkbench() {
+ return myPart.getSite().getWorkbenchWindow().getWorkbench();
+ }
+
+ private IStructuredSelection getSelection() {
+ return mySelection;
+ }
+}
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/GMFGenExtensionModelWizard.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/GMFGenExtensionModelWizard.java
new file mode 100644
index 000000000..67c86be5c
--- /dev/null
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/GMFGenExtensionModelWizard.java
@@ -0,0 +1,186 @@
+/*
+ * 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.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EcorePackage;
+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.gmf.internal.bridge.ui.Plugin;
+import org.eclipse.gmf.internal.bridge.wizards.WizardUtil;
+import org.eclipse.gmf.internal.common.ui.ElementSelectorExtension;
+import org.eclipse.gmf.internal.common.ui.ExtensibleModelSelectionPage;
+import org.eclipse.gmf.internal.common.ui.ListElementSelectorExtension;
+import org.eclipse.gmf.internal.common.ui.PredefinedModelExtension;
+import org.eclipse.gmf.internal.common.ui.ResourceLocationProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWizard;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.actions.WorkspaceModifyOperation;
+
+public class GMFGenExtensionModelWizard extends Wizard implements IWorkbenchWizard {
+ private static final String GMFGEN_FILE_EXTENSION = "gmfgen"; //$NON-NLS-1$
+ private static final String ECORE_FILE_EXTENSION = "ecore"; //$NON-NLS-1$
+
+ private IWorkbench myWorkbench;
+ private IStructuredSelection mySelection;
+ private ElementSelectorExtension myRootElementSelectorExtension;
+ private ResourceSet myResourceSet;
+ private ResourceLocationProvider myResourceLocationProvider;
+ private Map<String, Object> myGmfgenResourceSaveOptions;
+
+ public GMFGenExtensionModelWizard() {
+ super();
+ }
+
+ public void init(IWorkbench workbench, IStructuredSelection selection) {
+ myWorkbench = workbench;
+ mySelection = selection;
+ setWindowTitle(Messages.GMFGenExtensionModelWizard_windowTitle);
+ }
+
+ public IWorkbench getWorkbench() {
+ return myWorkbench;
+ }
+
+ public IStructuredSelection getSelection() {
+ return mySelection;
+ }
+
+ protected ResourceSet getResourceSet() {
+ if (myResourceSet == null) {
+ myResourceSet = new ResourceSetImpl();
+ }
+ return myResourceSet;
+ }
+
+ private Map<String, Object> getGmfgenResourceSaveOptions() {
+ if (myGmfgenResourceSaveOptions == null) {
+ myGmfgenResourceSaveOptions = new HashMap<String, Object>();
+ myGmfgenResourceSaveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
+ }
+ return myGmfgenResourceSaveOptions;
+ }
+
+ public ElementSelectorExtension getRootElementSelectorExtension() {
+ return myRootElementSelectorExtension;
+ }
+
+ public ResourceLocationProvider getResourceLocationProvider() {
+ return myResourceLocationProvider;
+ }
+
+ @Override
+ public void addPages() {
+ myResourceLocationProvider = new ResourceLocationProvider(getSelection());
+ ExtensibleModelSelectionPage domainModelSelectionPage = new ExtensibleModelSelectionPage("domain", myResourceLocationProvider, getResourceSet(), ECORE_FILE_EXTENSION); //$NON-NLS-1$
+ domainModelSelectionPage.setTitle(Messages.GMFGenExtensionModelWizard_pageTitle);
+ domainModelSelectionPage.setDescription(Messages.GMFGenExtensionModelWizard_pageDescription);
+ List<URI> uris = myResourceLocationProvider.getSelectedURIs(ECORE_FILE_EXTENSION);
+ domainModelSelectionPage.addExtension("prem", new PredefinedModelExtension(domainModelSelectionPage, uris)); //$NON-NLS-1$
+ myRootElementSelectorExtension = new ListElementSelectorExtension() {
+
+ protected String getModelElementName() {
+ return Messages.GMFGenExtensionModelWizard_classChooserLabel;
+ }
+
+ protected String getModelElementLabel(EObject modelElement) {
+ String name = ((EClass) modelElement).getName();
+ if (name == null || name.trim().length() == 0) {
+ name = Messages.GMFGenExtensionModelWizard_unnamedClassName;
+ }
+ return name;
+ }
+
+ @Override
+ protected boolean isApplicable(EObject element) {
+ EClass clazz = (EClass) element;
+ return !clazz.isAbstract();
+ }
+
+ @Override
+ protected EClass getModelElementClass() {
+ return EcorePackage.eINSTANCE.getEClass();
+ }
+
+ @Override
+ protected void sortModelElements(List<EObject> elements) {
+ // we override this method to turn off sorting of the list and provide natural classes order
+ };
+ };
+ domainModelSelectionPage.addExtension("domainElement", myRootElementSelectorExtension); //$NON-NLS-1$
+ addPage(domainModelSelectionPage);
+ super.addPages();
+ }
+
+ @Override
+ public boolean performFinish() {
+ WorkspaceModifyOperation operation = new WorkspaceModifyOperation() {
+
+ protected void execute(IProgressMonitor progressMonitor) {
+ try {
+ ElementSelectorExtension extension = getRootElementSelectorExtension();
+ EClass rootClass = (EClass) extension.getModelElement();
+ EObject instantiated = rootClass.getEPackage().getEFactoryInstance().create(rootClass);
+ List<URI> gmfgenURIs = getResourceLocationProvider().getSelectedURIs(GMFGEN_FILE_EXTENSION);
+ for (int i=0; i<gmfgenURIs.size(); i++) {
+ URI nextGmfgenURI = gmfgenURIs.get(i);
+ addExtensionMetamodelRootToGmfgen(nextGmfgenURI, instantiated);
+ }
+ } catch (Exception ex) {
+ Plugin.log(ex);
+ } finally {
+ progressMonitor.done();
+ }
+ }
+ };
+
+ try {
+ getContainer().run(false, false, operation);
+ List<IFile> selectedGmfgenFiles = getResourceLocationProvider().getSelectedFiles(GMFGEN_FILE_EXTENSION, false);
+ WizardUtil.selectReveal(getWorkbench(), new StructuredSelection(selectedGmfgenFiles));
+ if (!selectedGmfgenFiles.isEmpty()) {
+ WizardUtil.openInEditor(getWorkbench(), selectedGmfgenFiles.get(0));
+ }
+ } catch (InvocationTargetException ex) {
+ return false;
+ } catch (InterruptedException ex) {
+ return false;
+ } catch (PartInitException ex) {
+ Plugin.log(ex);
+ }
+ return true;
+ }
+
+ protected void addExtensionMetamodelRootToGmfgen(URI nextGmfgenURI, EObject instantiated) throws IOException {
+ Resource gmfgenModel = getResourceSet().createResource(nextGmfgenURI);
+ gmfgenModel.load(getResourceSet().getLoadOptions());
+ gmfgenModel.getContents().add(instantiated);
+ gmfgenModel.save(getGmfgenResourceSaveOptions());
+ gmfgenModel.unload();
+ }
+
+}
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java
index 2c47541f4..4d57d900e 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/Messages.java
@@ -22,6 +22,16 @@ public class Messages extends NLS {
public static String DiagnosticsDialog_gotoProblem_menuItem;
+ public static String GMFGenExtensionModelWizard_classChooserLabel;
+
+ public static String GMFGenExtensionModelWizard_pageDescription;
+
+ public static String GMFGenExtensionModelWizard_pageTitle;
+
+ public static String GMFGenExtensionModelWizard_unnamedClassName;
+
+ public static String GMFGenExtensionModelWizard_windowTitle;
+
public static String migration_confirmModelOverwriteMessage;
public static String migration_confirmModelOverwriteTitle;
diff --git a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties
index 0bb58ce83..5c3fd2cae 100644
--- a/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties
+++ b/plugins/org.eclipse.gmf.codegen.ui/src/org/eclipse/gmf/internal/codegen/popup/actions/messages.properties
@@ -8,3 +8,8 @@ DiagnosticsDialog_exceptStackTrace_toolTip=Exception Stack Trace
DiagnosticsDialog_Copy_menuItem=Copy
DiagnosticsDialog_gotoProblem_menuItem=Go to problem
+GMFGenExtensionModelWizard_windowTitle=Add Your Extension Domain Model To GMFGen
+GMFGenExtensionModelWizard_pageTitle=Select Extension Domain Model
+GMFGenExtensionModelWizard_pageDescription=Load extension model and select root element to create in GMFGen.
+GMFGenExtensionModelWizard_classChooserLabel=Root Class:
+GMFGenExtensionModelWizard_unnamedClassName=<unnamed>

Back to the top