/******************************************************************************* | |
* Copyright (c) 2016 Fundación Tecnalia Research & Innovation. | |
* | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v2.0 | |
* which accompanies this distribution, and is available at | |
* https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html | |
* | |
* SPDX-License-Identifier: EPL-2.0 | |
* | |
* Contributors: | |
* Huascar Espinoza - initial API and implementation | |
* Alejandra Ruíz - initial API and implementation | |
* Idoya Del Río - initial API and implementation | |
* Mari Carmen Palacios - initial API and implementation | |
* Angel López - initial API and implementation | |
*******************************************************************************/ | |
package org.eclipse.opencert.sam.arg.arg.diagram.edit.commands; | |
import java.util.Collections; | |
import java.util.Iterator; | |
import java.util.List; | |
import org.eclipse.core.commands.ExecutionException; | |
import org.eclipse.core.runtime.IAdaptable; | |
import org.eclipse.core.runtime.IProgressMonitor; | |
import org.eclipse.emf.ecore.EAnnotation; | |
import org.eclipse.emf.ecore.EcoreFactory; | |
import org.eclipse.emf.transaction.TransactionalEditingDomain; | |
import org.eclipse.gmf.runtime.common.core.command.CommandResult; | |
import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest; | |
import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand; | |
import org.eclipse.gmf.runtime.notation.View; | |
import org.eclipse.opencert.sam.arg.arg.diagram.edit.parts.CaseEditPart; | |
/** | |
* @generated | |
*/ | |
public class ArgCreateShortcutDecorationsCommand extends | |
AbstractTransactionalCommand { | |
/** | |
* @generated | |
*/ | |
private List myDescriptors; | |
/** | |
* @generated | |
*/ | |
public ArgCreateShortcutDecorationsCommand( | |
TransactionalEditingDomain editingDomain, View parentView, | |
List viewDescriptors) { | |
super(editingDomain, "Create Shortcuts", getWorkspaceFiles(parentView)); //$NON-NLS-1$ | |
myDescriptors = viewDescriptors; | |
} | |
/** | |
* @generated | |
*/ | |
public ArgCreateShortcutDecorationsCommand( | |
TransactionalEditingDomain editingDomain, View parentView, | |
CreateViewRequest.ViewDescriptor viewDescriptor) { | |
this(editingDomain, parentView, Collections | |
.singletonList(viewDescriptor)); | |
} | |
/** | |
* @generated | |
*/ | |
protected CommandResult doExecuteWithResult(IProgressMonitor monitor, | |
IAdaptable info) throws ExecutionException { | |
for (Iterator it = myDescriptors.iterator(); it.hasNext();) { | |
CreateViewRequest.ViewDescriptor nextDescriptor = (CreateViewRequest.ViewDescriptor) it | |
.next(); | |
View view = (View) nextDescriptor.getAdapter(View.class); | |
if (view != null && view.getEAnnotation("Shortcut") == null) { //$NON-NLS-1$ | |
EAnnotation shortcutAnnotation = EcoreFactory.eINSTANCE | |
.createEAnnotation(); | |
shortcutAnnotation.setSource("Shortcut"); //$NON-NLS-1$ | |
shortcutAnnotation.getDetails().put( | |
"modelID", CaseEditPart.MODEL_ID); //$NON-NLS-1$ | |
view.getEAnnotations().add(shortcutAnnotation); | |
} | |
} | |
return CommandResult.newOKCommandResult(); | |
} | |
} |