Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d70e02e01d1e124a9d69ffd253af36c2778de6d5 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*****************************************************************************
 * Copyright (c) 2013 CEA LIST.
 *
 *
 * 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:
 *  Patrick Tessier (CEA LIST) patrick.tessier@cea.fr - Initial API and implementation
 *
 *****************************************************************************/
package org.eclipse.papyrus.adl4eclipsetool.assistant;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.papyrus.adltool.command.SimplePluginsArchitectureSnapshotCommand;
import org.eclipse.papyrus.adltool.designer.ArchitectureSnapshotDesigner;
import org.eclipse.papyrus.adltool.designer.wizard.BundleSelectionPage;
import org.eclipse.papyrus.editor.PapyrusMultiDiagramEditor;
import org.eclipse.papyrus.infra.core.resource.ModelSet;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForSelection;
import org.eclipse.ui.IImportWizard;
import org.eclipse.ui.ISelectionService;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Package;

/**
 * this class is used to do the retro engineering from workspaceplugin. It adds only in the platform dependencies.
 *
 */
public class SimplePluginImport extends Wizard implements IImportWizard {

	protected BundleSelectionPage bundleSelectionPage;
	protected TransactionalEditingDomain transactionalEditingDomain = null;
	protected PapyrusMultiDiagramEditor papyrusEditor;
	protected ModelSet modelSet;

	/**
	 *
	 * Constructor.
	 *
	 */
	public SimplePluginImport() {
		super();
		setNeedsProgressMonitor(true);
	}

	@Override
	public void addPages() {
		// look for all plugins from the workspace
		ArrayList<Object> bundleList = new ArrayList<Object>();
		bundleList.addAll(ArchitectureSnapshotDesigner.getWorkspaceBundle());
		bundleSelectionPage = new BundleSelectionPage(bundleList);
		addPage(bundleSelectionPage);
	}

	/**
	 *
	 * @return the list of selected bundle from the page
	 */
	public ArrayList<Object> getSelectedBundle() {
		return bundleSelectionPage.getResult();
	}

	@Override
	public boolean performFinish() {

		// one bundle must be selected
		if (getSelectedBundle().size() > 0) {
			// get the domain in order to launche the command
			TransactionalEditingDomain dom = modelSet.getTransactionalEditingDomain();
			ArrayList<Element> selection = getSelectionSet();

			if ((selection.size() == 1) && (selection.get(0) instanceof Package)) {
				// launch the simple retro engineering
				SimplePluginsArchitectureSnapshotCommand comd = new SimplePluginsArchitectureSnapshotCommand(dom, (Package) selection.get(0), getSelectedBundle());
				dom.getCommandStack().execute(comd);
			}
			return true;
		}
		return false;
	}

	public void init(IWorkbench workbench, IStructuredSelection selection) {

		// get the service registry of papyrus from the selection
		ServicesRegistry registry = null;
		try {
			registry = ServiceUtilsForSelection.getInstance().getServiceRegistry(selection);
		} catch (ServiceException e1) {
			e1.printStackTrace();
		}
		try {
			modelSet = registry.getService(ModelSet.class);
		} catch (ServiceException e) {
			e.printStackTrace();
		}

	}

	/**
	 * getSelected element in the diagram or in the model explorer
	 *
	 * @return Element or null
	 */
	protected ArrayList<Element> getSelectionSet() {
		ArrayList<Element> selectedSet = new ArrayList<Element>();
		ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService();
		ISelection selection = selectionService.getSelection();


		if (selection instanceof IStructuredSelection) {
			@SuppressWarnings("rawtypes")
			Iterator selectedobjectIteractor = ((IStructuredSelection) selection).iterator();
			while (selectedobjectIteractor.hasNext()) {
				Object currentSelection = selectedobjectIteractor.next();

				EObject selectedEObject = EMFHelper.getEObject(currentSelection);
				if (selectedEObject instanceof org.eclipse.uml2.uml.Element) {
					selectedSet.add((Element) selectedEObject);
				}
			}
		}

		return selectedSet;
	}

}

Back to the top