Package es.iiia.sgi.actions

Source Code of es.iiia.sgi.actions.CutAction

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;
import es.iiia.shapeeditor.controllers.ControllerBase;

public class CutAction extends Action implements IWorkbenchAction, ISelectionListener {
  private IWorkbenchWindow workbenchWindow;
  private ShapeEditor editor;
 
  public CutAction(IWorkbenchWindow window) {
    workbenchWindow = window;
    window.getSelectionService().addSelectionListener(this);
  }
 
  @Override
  public void selectionChanged(IWorkbenchPart part, ISelection selection) {
    if (!selection.isEmpty()) {
      setEnabled(true);
    } else {
      setEnabled(false);
    }  
   
  }
 
  @Override
  public void dispose() {
    workbenchWindow.getSelectionService().removeSelectionListener(this);
  }

  @Override
  public void run() {
    ShapeEditor editor = (ShapeEditor) workbenchWindow.getActivePage().getActiveEditor();
    ShapeClipboard.put(editor.getSelectedControllers());
    for (ControllerBase ctr : editor.getSelectedControllers()) {
      editor.getModel().removeChild(ctr.getModel());
    }
    editor.getSelectedControllers().clear();
  }
}
TOP

Related Classes of es.iiia.sgi.actions.CutAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.