Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: ce57de1775661ccc91e662accce313ebfc793181 (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
/*****************************************************************************
 * Copyright (c) 2010 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.domaincontextcodegen;

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

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;

/**
 * <pre>
 *
 * Automated generation of ElementTypes (in the domain model), an ElementType generated for
 * each element of the domain model.
 *
 * </pre>
 */
public class GenerateElementTypeModelAction implements IObjectActionDelegate {

	protected DomainContext selectedContext = null;

	public GenerateElementTypeModelAction() {
	}

	public void run(IAction action) {

		ElementTypes elementTypeList = DomaincontextcodegenFactory.eINSTANCE.createElementTypes();
		selectedContext.setElementTypes(elementTypeList);

		if (selectedContext.getSpecializationOf() == null) {
			if (selectedContext.getMetamodel() != null) {
				Iterator<EClassifier> iterClass = selectedContext.getMetamodel().getEClassifiers().iterator();
				ArrayList<MetaClassType> result = new ArrayList<MetaClassType>();
				while (iterClass.hasNext()) {
					EClassifier eClassifier = iterClass.next();
					if (eClassifier instanceof EClass) {
						MetaClassType elemenType = DomaincontextcodegenFactory.eINSTANCE.createMetaClassType();
						// elemenType.setHelper(selectedContext.getDefaultHelperPath());
						elemenType.setMetaClass((EClass) eClassifier);
						elemenType.setIcon("platform:/plugin/org.eclipse.uml2.uml.edit/icons/full/obj16/" + eClassifier.getName() + ".gif");

						// Convert name to upper case with '_' separator between name parts e.g. NamedElement -> NAMED_ELEMENT
						// String formattedName = CodeGenUtil.format(eClassifier.getName(), '_', null, false, true).toUpperCase();
						// elemenType.setName(not_formattedName);

						// No formatting
						String not_formattedName = eClassifier.getName();
						elemenType.setName(not_formattedName);

						result.add(elemenType);
					}
				}
				System.err.println(result.get(0).getMetaClass().getName());
				Collections.sort(result, new ElementTypeComparator());
				System.err.println(result.get(0).getMetaClass().getName());
				elementTypeList.getTypes().addAll(result);

			}
		}
		// to Do in the case of specialization with a profile

	}

	public void selectionChanged(IAction action, ISelection selection) {
		if (selection instanceof IStructuredSelection) {
			if (((IStructuredSelection) selection).getFirstElement() instanceof DomainContext) {
				selectedContext = (DomainContext) ((IStructuredSelection) selection).getFirstElement();
			}
		}

	}

	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		// TODO Auto-generated method stub

	}

}

Back to the top