001package org.nasdanika.vinci.design;
002
003import java.util.Collection;
004import java.util.Map;
005
006import org.eclipse.emf.common.util.EList;
007import org.eclipse.emf.ecore.EObject;
008import org.eclipse.jface.action.Action;
009import org.eclipse.sirius.tools.api.ui.IExternalJavaAction;
010import org.eclipse.sirius.viewpoint.DRepresentationElement;
011import org.nasdanika.vinci.app.ActionBase;
012import org.nasdanika.vinci.presentation.GenerateTemplatedApplicationAction;
013
014
015public class GenerateApplicationExternalJavaAction implements IExternalJavaAction {
016
017        @Override
018        public boolean canExecute(Collection<? extends EObject> selection) {
019                if (selection.size() == 1) {
020                        EObject selected = selection.iterator().next();
021                        if (selected instanceof DRepresentationElement) {
022                                EList<EObject> semanticElements = ((DRepresentationElement) selected).getSemanticElements();
023                                if (semanticElements.size() == 1) {
024                                        EObject se = semanticElements.iterator().next();
025                                        return se instanceof ActionBase && se.eContainer() == null;
026                                }
027                        }
028                }
029                return false;
030        }
031
032        @Override
033        public void execute(Collection<? extends EObject> selection, Map<String, Object> context) {
034                ActionBase action = (ActionBase) ((DRepresentationElement) selection.iterator().next()).getSemanticElements().iterator().next();
035                Action generateApplicationAction = new GenerateTemplatedApplicationAction("Generate application", action, null);
036                generateApplicationAction.run();
037        }
038
039}