diff options
author | Sopot Cela | 2012-11-30 00:09:23 +0000 |
---|---|---|
committer | Sopot Cela | 2012-11-30 00:09:23 +0000 |
commit | 3fc36ee77792a10f042083039cb36548de008a97 (patch) | |
tree | 4c26e3a390ecad5ab80d57a371185485ad6c3ce2 | |
parent | f96e09970dcf684ebcfa047ab4673aa0be8dfe98 (diff) | |
download | org.eclipse.e4.tools-3fc36ee77792a10f042083039cb36548de008a97.tar.gz org.eclipse.e4.tools-3fc36ee77792a10f042083039cb36548de008a97.tar.xz org.eclipse.e4.tools-3fc36ee77792a10f042083039cb36548de008a97.zip |
Bug 395371 - Wizard to convert part of the application model to a
fragment
6 files changed, 144 insertions, 3 deletions
diff --git a/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF index 7874eea1..2f80d065 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.tools.emf.ui/META-INF/MANIFEST.MF @@ -30,7 +30,8 @@ Require-Bundle: org.eclipse.core.databinding;bundle-version="1.3.0", org.eclipse.e4.core.di.extensions;bundle-version="0.9.0", org.eclipse.jface.text;bundle-version="3.7.0", org.eclipse.e4.ui.widgets;bundle-version="0.11.0", - org.eclipse.equinox.preferences;bundle-version="3.4.0" + org.eclipse.equinox.preferences;bundle-version="3.4.0", + org.eclipse.e4.tools;bundle-version="0.12.0" Bundle-ActivationPolicy: lazy Import-Package: javax.annotation;version="1.0.0", javax.inject;version="1.0.0", diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java index 206ca120..84192405 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.java @@ -620,4 +620,6 @@ public class Messages { public String Special_UnknownElement; public String Special_UnknownElement_Detail; public String VWindowSharedElementsEditor_Area; + public String ModelEditor_ExtractFragment; + public String ModelEditor_ExtractFragment_NoParentId; }
\ No newline at end of file diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties index 9bb590a1..9fb51c7e 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/Messages.properties @@ -620,4 +620,6 @@ ObjectViewer_Script=Execute Script CommandWizard_ShellTitle=Command/Handler wizard Special_UnknownElement=(unknown model element) Special_UnknownElement_Detail= Use an extension point! -VWindowSharedElementsEditor_Area=Area
\ No newline at end of file +VWindowSharedElementsEditor_Area=Area +ModelEditor_ExtractFragment=Extract into a fragment +ModelEditor_ExtractFragment_NoParentId=Can not extract because parent container has no id. \nAdd an id and try again.
\ No newline at end of file diff --git a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java index 0c222e9b..be8be027 100644 --- a/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java +++ b/bundles/org.eclipse.e4.tools.emf.ui/src/org/eclipse/e4/tools/emf/ui/internal/common/ModelEditor.java @@ -12,6 +12,7 @@ package org.eclipse.e4.tools.emf.ui.internal.common; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import javax.annotation.PostConstruct; @@ -41,6 +42,7 @@ import org.eclipse.e4.core.di.annotations.Execute; import org.eclipse.e4.core.di.annotations.Optional; import org.eclipse.e4.core.di.extensions.Preference; import org.eclipse.e4.core.services.contributions.IContributionFactory; +import org.eclipse.e4.internal.tools.wizards.model.ExtractContributionModelWizard; import org.eclipse.e4.tools.emf.ui.common.EStackLayout; import org.eclipse.e4.tools.emf.ui.common.IContributionClassCreator; import org.eclipse.e4.tools.emf.ui.common.IEditorDescriptor; @@ -133,6 +135,7 @@ import org.eclipse.e4.tools.services.IResourcePool; import org.eclipse.e4.tools.services.Translation; import org.eclipse.e4.ui.di.Focus; import org.eclipse.e4.ui.di.Persist; +import org.eclipse.e4.ui.model.application.MApplication; import org.eclipse.e4.ui.model.application.MApplicationElement; import org.eclipse.e4.ui.model.application.commands.impl.CommandsPackageImpl; import org.eclipse.e4.ui.model.application.impl.ApplicationPackageImpl; @@ -170,6 +173,7 @@ import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.databinding.viewers.ObservableListTreeContentProvider; import org.eclipse.jface.databinding.viewers.TreeStructureAdvisor; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.resource.StringConverter; @@ -191,6 +195,7 @@ import org.eclipse.jface.viewers.StructuredSelection; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerDropAdapter; +import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; @@ -596,7 +601,6 @@ public class ModelEditor { List<Action> actions; if (s.getFirstElement() instanceof VirtualEntry<?>) { actions = virtualEditors.get(((VirtualEntry<?>) s.getFirstElement()).getId()).getActions(s.getFirstElement()); - if (actions.size() > 0) { MenuManager addMenu = new MenuManager(messages.ModelEditor_AddChild); for (Action a : actions) { @@ -605,6 +609,38 @@ public class ModelEditor { } manager.add(addMenu); } + + // build the extract action + if ((!((VirtualEntry<?>) s.getFirstElement()).getList().isEmpty()) && (!isModelFragment())) + manager.add(new Action(messages.ModelEditor_ExtractFragment, ImageDescriptor.createFromImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_ModelFragments))) { + public void run() { + VirtualEntry<?> ve = (VirtualEntry<?>) s.getFirstElement(); + EObject container = (EObject) ve.getOriginalParent(); + String containerId = ((MApplicationElement) container).getElementId(); + if (containerId == null || containerId.isEmpty()) { + MessageDialog.openError(viewer.getControl().getShell(), null, messages.ModelEditor_ExtractFragment_NoParentId); + return; + } + ArrayList<MApplicationElement> maes = new ArrayList<MApplicationElement>(); + IObservableList list = ve.getList(); + Iterator iterator = list.iterator(); + while (iterator.hasNext()) { + maes.add((MApplicationElement) iterator.next()); + } + ExtractContributionModelWizard extractContributionModelWizard = new ExtractContributionModelWizard(maes); + extractContributionModelWizard.setup(project); + WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), extractContributionModelWizard); + if (wizardDialog.open() == WizardDialog.OK) { + for (MApplicationElement mae : maes) { + Command cmd = DeleteCommand.create(ModelEditor.this.modelProvider.getEditingDomain(), mae); + if (cmd.canExecute()) { + ModelEditor.this.modelProvider.getEditingDomain().getCommandStack().execute(cmd); + } + } + } + }; + }); + } else { final EObject o = (EObject) s.getFirstElement(); AbstractComponentEditor editor = getEditor(o.eClass()); @@ -709,6 +745,30 @@ public class ModelEditor { } } + if ((s.getFirstElement() instanceof MApplicationElement) && (!isModelFragment()) && (!(s.getFirstElement() instanceof MApplication))) + manager.add(new Action(messages.ModelEditor_ExtractFragment, ImageDescriptor.createFromImage(resourcePool.getImageUnchecked(ResourceProvider.IMG_ModelFragments))) { + public void run() { + MApplicationElement oe = (MApplicationElement) s.getFirstElement(); + EObject container = ((EObject) oe).eContainer(); + String containerId = ((MApplicationElement) container).getElementId(); + if (containerId == null || containerId.isEmpty()) { + MessageDialog.openError(viewer.getControl().getShell(), null, messages.ModelEditor_ExtractFragment_NoParentId); + return; + } + ExtractContributionModelWizard extractContributionModelWizard = new ExtractContributionModelWizard(oe); + extractContributionModelWizard.setup(project); + WizardDialog wizardDialog = new WizardDialog(viewer.getControl().getShell(), extractContributionModelWizard); + if (wizardDialog.open() == WizardDialog.OK) { + Command cmd = DeleteCommand.create(ModelEditor.this.modelProvider.getEditingDomain(), oe); + if (cmd.canExecute()) { + ModelEditor.this.modelProvider.getEditingDomain().getCommandStack().execute(cmd); + } + } + + }; + + }); + } }); viewer.getControl().setMenu(mgr.createContextMenu(viewer.getControl())); diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java index 72f84636..da32d9f2 100644 --- a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java +++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/BaseApplicationModelWizard.java @@ -157,6 +157,7 @@ public abstract class BaseApplicationModelWizard extends Wizard implements INewW return true; } catch (Exception exception) { + exception.printStackTrace(); MessageDialog.openError(getShell(), "Error", exception.getMessage()); return false; } diff --git a/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/ExtractContributionModelWizard.java b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/ExtractContributionModelWizard.java new file mode 100644 index 00000000..c5f3d528 --- /dev/null +++ b/bundles/org.eclipse.e4.tools/src/org/eclipse/e4/internal/tools/wizards/model/ExtractContributionModelWizard.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2010 BestSolution.at 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: + * Sopot Cela <sopotcela@gmail.com> - initial API and implementation + ******************************************************************************/ +package org.eclipse.e4.internal.tools.wizards.model; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.e4.ui.model.application.MApplicationElement; +import org.eclipse.e4.ui.model.fragment.MFragmentFactory; +import org.eclipse.e4.ui.model.fragment.MModelFragments; +import org.eclipse.e4.ui.model.fragment.MStringModelFragment; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.PlatformUI; + + +public class ExtractContributionModelWizard extends BaseApplicationModelWizard { + + private List<MApplicationElement> oes= new ArrayList<MApplicationElement>(); + + public ExtractContributionModelWizard(MApplicationElement oe){ + super(); + oes.add(oe); + } + + public ExtractContributionModelWizard(List<MApplicationElement> oes){ + this.oes.addAll(oes); + } + + public ExtractContributionModelWizard(){ + super(); + } + + @Override + public String getDefaultFileName() { + return "fragment.e4xmi"; + } + + protected EObject createInitialModel() { + MModelFragments createModelFragments = MFragmentFactory.INSTANCE.createModelFragments(); + MStringModelFragment createStringModelFragment = MFragmentFactory.INSTANCE.createStringModelFragment(); + for (MApplicationElement moe : oes) { + + MApplicationElement e = (MApplicationElement) EcoreUtil.copy((EObject) moe); + String featurename = ((EObject) moe).eContainmentFeature().getName(); + createStringModelFragment.setParentElementId(((MApplicationElement) ((EObject) moe).eContainer()).getElementId()); + createStringModelFragment.getElements().add(e); + createStringModelFragment.setFeaturename(featurename); + } + createModelFragments.getFragments().add(createStringModelFragment); + return (EObject)createModelFragments; + } + + public void setup(IProject project){ + this.init(PlatformUI.getWorkbench(),new StructuredSelection(project)); + } + @Override + protected NewModelFilePage createWizardPage(ISelection selection) { + return new NewModelFilePage(selection,getDefaultFileName()); + } + +}
\ No newline at end of file |