/******************************************************************************* | |
* 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 org.eclipse.jface.viewers.IStructuredSelection; | |
import org.eclipse.ui.ISharedImages; | |
import org.eclipse.ui.IWorkbenchPart; | |
import org.eclipse.ui.PlatformUI; | |
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 LocalDeleteAction extends ViatraTreeEditorSelectionAction { | |
public static final String ID = "ViatraTreeEditor.Actions.LocalDeleteAction"; | |
//protected | |
public LocalDeleteAction(IWorkbenchPart part) { | |
super(part); | |
setId(ID); | |
setText("Delete"); | |
setToolTipText("Delete the 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)); | |
} | |
public void run() { | |
ViatraTreeEditor iVTE = (ViatraTreeEditor)iPart; | |
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() { | |
if (getSelectedObjects().size() == 1 && getSelectedObjects().getFirstElement() instanceof IModelElement) | |
setEnabled(true); | |
else | |
setEnabled(false); | |
} | |
} |