package es.iiia.sgi.actions;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import es.iiia.shapeeditor.ShapeEditor;
public class DeleteAction extends Action implements ISelectionListener, IWorkbenchAction {
private IWorkbenchWindow workbenchWindow;
private ShapeEditor editor;
public DeleteAction(IWorkbenchWindow window) {
workbenchWindow = window;
window.getSelectionService().addSelectionListener(this);
}
@Override
public void dispose() {
workbenchWindow.getSelectionService().removeSelectionListener(this);
}
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
if (!selection.isEmpty()) {
setEnabled(true);
} else {
setEnabled(false);
}
}
@Override
public void run() {
ShapeEditor editor = (ShapeEditor) workbenchWindow.getActivePage().getActiveEditor();
editor.deleteSelection();
}
}