| /** |
| * Copyright (c)2020 CEA LIST, Committer Name, and others. |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * CEA LIST - Initial API and implementation |
| * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr |
| * |
| */ |
| package org.eclipse.papyrus.pdp4eng.designer.ui; |
| |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.papyrus.infra.widgets.editors.TreeSelectorDialog; |
| import org.eclipse.papyrus.pdp4eng.designer.controller.api.ModelTransfoFactory; |
| import org.eclipse.papyrus.requirements.sysml14.common.PapyrusAbstractHandler; |
| import org.eclipse.papyrus.uml.tools.providers.UMLContentProvider; |
| import org.eclipse.papyrus.uml.tools.providers.UMLLabelProvider; |
| import org.eclipse.swt.widgets.Display; |
| import org.eclipse.uml2.uml.Activity; |
| import org.eclipse.uml2.uml.Element; |
| import org.eclipse.uml2.uml.NamedElement; |
| import org.eclipse.uml2.uml.Package; |
| import org.eclipse.uml2.uml.UMLPackage; |
| /** |
| * execute the creation of process model form Req DFD |
| * |
| */ |
| public class CreateProcessFromReqHandler extends PapyrusAbstractHandler { |
| public Object execute(ExecutionEvent event) throws ExecutionException { |
| super.execute(event); |
| Element selectedElement = getSelection(); |
| ModelTransfoFactory factory= new ModelTransfoFactory(); |
| if (selectedElement != null) { |
| TreeSelectorDialog dialog = new TreeSelectorDialog(Display.getDefault().getActiveShell()); |
| dialog.setContentProvider(new UMLContentProvider(selectedElement.getNearestPackage(), UMLPackage.eINSTANCE.getPackage_PackagedElement())); |
| dialog.setLabelProvider(new UMLLabelProvider()); |
| dialog.setMessage("Choose Requirement DFD" ); |
| dialog.setTitle("Choose DFD "+((NamedElement)selectedElement).getName()); |
| dialog.create(); |
| dialog.setDescription("Choose Satisfy Link for "+((NamedElement)selectedElement).getQualifiedName()); |
| if(dialog.open() == org.eclipse.jface.window.Window.OK) { |
| Object[] result = dialog.getResult(); |
| if (result.length>0) { |
| Activity ReqDFDSource=(Activity)result[0]; |
| transactionalEditingDomain.getCommandStack().execute(factory.getCreateProcessModelFromReq(transactionalEditingDomain, (Package) selectedElement, ReqDFDSource)); |
| } |
| } |
| } |
| return null; |
| |
| } |
| |
| /** |
| * |
| * @see org.eclipse.core.commands.AbstractHandler#isEnabled() |
| * |
| * @return true if the handler is possible |
| */ |
| @Override |
| public boolean isEnabled() { |
| Element selectedElement = getSelection(); |
| if (selectedElement instanceof org.eclipse.uml2.uml.Package) { |
| return true; |
| } else { |
| return false; |
| } |
| } |
| } |