blob: 390221639906a8b830eee09ebad273122d989479 (
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
|
/*****************************************************************************
* Copyright (c) 2011 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:
* Saadia DHOUIB (CEA LIST) - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.robotml.generators.intempora.rtmaps.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.transaction.TransactionalEditingDomain;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.papyrus.infra.core.services.ServiceException;
import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
import org.eclipse.papyrus.robotml.generators.intempora.rtmaps.ui.Activator;
import org.eclipse.ui.handlers.HandlerUtil;
// TODO: Auto-generated Javadoc
/**
* The Class AcceleoGenerateRTMapsCommandHandler.
*/
public class AcceleoGenerateRTMapsCommandHandler extends AbstractHandler {
/** The rtmaps folder. */
private final String rtmapsFolder = "/rtmaps-generated-files";
// /**
// * @see org.eclipse.papyrus.modelexplorer.handler.AbstractCommandHandler#getCommand()
// *
// * @return
// */
//
// @Override
// protected Command getCommand() {
// List<EObject> selectedObjects = getSelectedElements();
// EObject selectedElement = getSelectedElement();
// List<?> selection = getSelection();
// TransactionalEditingDomain editingDomain = getEditingDomain();
// if ((selectedObjects != null) && (selectedObjects.size()>0)){
// EObject selectedObject = selectedObjects.get(0);
// URI targetFolderURI = selectedObject.eResource().getURI();
// int lastindex = targetFolderURI.toPlatformString(false).lastIndexOf("/");
// String targetPath = targetFolderURI.toPlatformString(false).substring(0, lastindex);
// return new org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper(new GenerateRTMapsCodeCommand("Generate RTMaps code command", editingDomain, selectedObject, targetPath + rtmapsFolder));
// }
//
//
//return null;
//
//
// }
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection = HandlerUtil.getCurrentSelection(event);
if(selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection)selection;
EObject selectedElement = EMFHelper.getEObject(structuredSelection.getFirstElement());
if(selectedElement == null) {
return null;
}
URI resourceURI = selectedElement.eResource().getURI();
int lastSegment = resourceURI.segmentCount() - 1;
URI targetFolderURI = resourceURI.trimSegments(lastSegment).appendSegment(rtmapsFolder);
try {
TransactionalEditingDomain editingDomain = ServiceUtilsForEObject.getInstance().getTransactionalEditingDomain(selectedElement);
ICommand generationCommand = new GenerateRTMapsCodeCommand("Generate RTMaps code command", editingDomain, selectedElement, targetFolderURI.toPlatformString(true));
if(generationCommand.canExecute()) {
generationCommand.execute(new NullProgressMonitor(), null);
}
} catch (ServiceException ex) {
Activator.log.error(ex);
}
}
return null;
}
}
|