blob: 3cc98b766125a7d5f633924ea002318d98a87587 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro
* 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:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.treeeditor.actions;
import java.util.Iterator;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.viatra2.core.IEntity;
import org.eclipse.viatra2.core.IModelElement;
import org.eclipse.viatra2.core.IRelation;
import org.eclipse.viatra2.treeeditor.ViatraTreeEditor;
import org.eclipse.viatra2.treeeditor.commands.DeleteModelElementCommand;
import org.eclipse.viatra2.treeeditor.commands.ViatraCompoundCommand;
public class ViatraDeleteAction extends ViatraRetargetAction {
public ViatraDeleteAction() {
super(ActionFactory.DELETE.getId(),"Delete model element");
setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
setHoverImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_HOVER));
}
@Override
public void run() {
ViatraCompoundCommand ccmd = new ViatraCompoundCommand();
for (Object o : ((IStructuredSelection)iVTE.getSite().getSelectionProvider().getSelection()).toList())
{
IModelElement me = (IModelElement) o;
DeleteModelElementCommand cmd = new DeleteModelElementCommand();
if (me instanceof IEntity)
cmd.setEntity((IEntity)me);
else
cmd.setRelation((IRelation)me);
ccmd.add(cmd);
}
if (!ccmd.isEmpty())
{
iVTE.getCommandStack().execute(ccmd);
iVTE.updateActions();
}
}
@Override
public void updateSelf(ViatraTreeEditor vte) {
super.updateSelf(vte);
if (vte.getSite().getSelectionProvider().getSelection() instanceof IStructuredSelection) {
boolean res = false;
Iterator it = ((IStructuredSelection)vte.getSite().getSelectionProvider().getSelection()).iterator();
while (it.hasNext()) {
Object o = it.next();
if (o !=null && o instanceof IModelElement && ((IModelElement)o).getFullyQualifiedName()!=null &&
((IModelElement)o).getFullyQualifiedName().length()>0 )
{
res = true;
break;
}
}
setEnabled(res);
}
else
setEnabled(false);
}
}