| /***************************************************************************** |
| * Copyright (c) 2019 CEA LIST. |
| * |
| * |
| * 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: |
| * Xavier Le Pallec (for CEA LIST) xlepallec@lilo.org - Bug 558456 |
| * |
| *****************************************************************************/ |
| |
| package org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.handlers; |
| |
| import org.eclipse.core.commands.AbstractHandler; |
| import org.eclipse.core.commands.ExecutionEvent; |
| import org.eclipse.core.commands.ExecutionException; |
| import org.eclipse.gmf.runtime.notation.View; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.jface.viewers.IStructuredSelection; |
| import org.eclipse.papyrus.uml.architecture.UMLDiagramTypes; |
| import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.PackagePackageableElementCompartmentEditPart; |
| import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.PackagePackageableElementCompartmentEditPartCN; |
| import org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.swt.SwtFactory; |
| //import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.ClassEditPart; |
| import org.eclipse.papyrus.uml.diagram.common.editparts.ClassEditPart; |
| import org.eclipse.ui.handlers.HandlerUtil; |
| |
| public class ClassEditionHandler extends AbstractHandler { |
| |
| @Override |
| public Object execute(ExecutionEvent event) throws ExecutionException { |
| ISelection selection = HandlerUtil.getCurrentSelection(event); |
| if (!selection.isEmpty() && selection instanceof IStructuredSelection) { |
| ClassEditPart selectedUmlClass = getPossibleSelectedUmlClass(IStructuredSelection.class.cast(selection)); |
| if (selectedUmlClass != null) { |
| SwtFactory.getInstance().createUmlClassHTMLEditionDialog(selectedUmlClass); |
| } |
| } |
| return null; |
| } |
| |
| protected ClassEditPart getPossibleSelectedUmlClass(IStructuredSelection structuredSelection) { |
| if (structuredSelection.size() == 1) { |
| Object firstSelectedElement = structuredSelection.getFirstElement(); |
| if (firstSelectedElement instanceof ClassEditPart) { |
| ClassEditPart classEditPart = ClassEditPart.class.cast(firstSelectedElement); |
| if (classEditPart.getParent().getModel() instanceof View) { |
| View parentEditPart = View.class.cast(classEditPart.getParent().getModel()); |
| if (parentEditPart.getType().equals(UMLDiagramTypes.CLASS_DIAGRAM) || |
| parentEditPart.getType().equals(PackagePackageableElementCompartmentEditPart.VISUAL_ID) || |
| parentEditPart.getType().equals(PackagePackageableElementCompartmentEditPartCN.VISUAL_ID)) { |
| return classEditPart; |
| } |
| } |
| } |
| } |
| return null; |
| } |
| |
| } |