| /******************************************************************************* |
| * Copyright (c) 2014 - Joao Martins and others. |
| * 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: |
| * Joao Martins <joaomartins27396@gmail.com> - initial API and implementation |
| * Maxime Porhel <maxime.porhel@obeo.fr> Obeo - Bug 438074, remarks and correction during review. |
| *******************************************************************************/ |
| |
| package org.eclipse.sirius.diagram.editor.tools.internal.menu.initializer; |
| |
| import java.util.Collection; |
| |
| import org.eclipse.emf.common.command.Command; |
| import org.eclipse.emf.common.command.UnexecutableCommand; |
| import org.eclipse.emf.ecore.EObject; |
| import org.eclipse.emf.edit.domain.EditingDomain; |
| import org.eclipse.jface.viewers.ISelection; |
| import org.eclipse.sirius.editor.tools.api.menu.AbstractEObjectRefactoringAction; |
| import org.eclipse.sirius.viewpoint.description.Viewpoint; |
| import org.eclipse.ui.IEditorPart; |
| |
| /** |
| * Action to launch the Intializer, it is valid only when the selection contains |
| * one Viewpoint. |
| * |
| * |
| * @author Joao Martins. |
| * |
| */ |
| public class InitializerAction extends AbstractEObjectRefactoringAction { |
| |
| /** |
| * Create the action. |
| * |
| * @param editor |
| * the current editor. |
| * @param selection |
| * the current selection. |
| */ |
| public InitializerAction(final IEditorPart editor, final ISelection selection) { |
| super(editor, selection); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| protected Command buildActionCommand(final EditingDomain arg0, final Collection<EObject> selection) { |
| Command result = UnexecutableCommand.INSTANCE; |
| setSelectionValid(false); |
| if (selection.size() == 1 && selection.iterator().next() instanceof Viewpoint) { |
| setSelectionValid(true); |
| result = new InitializerCommand(arg0.getResourceSet(), selection); |
| } |
| |
| return result; |
| } |
| |
| } |