Skip to main content
summaryrefslogtreecommitdiffstats
blob: c5f3d52858e7244e8ef4a7a142c5bf182983e562 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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());
	}
	
}

Back to the top