1 17 package org.eclipse.emf.ecore.sdo.action; 18 19 20 import org.eclipse.jface.action.IAction; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.ui.IActionDelegate; 24 import org.eclipse.ui.actions.ActionDelegate; 25 26 import org.eclipse.emf.common.command.AbstractCommand; 27 import org.eclipse.emf.ecore.sdo.EChangeSummary; 28 import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain; 29 import org.eclipse.emf.edit.domain.EditingDomain; 30 31 32 35 public class ApplyChangeAction 36 extends ActionDelegate 37 implements IActionDelegate 38 { 39 protected EChangeSummary changeSummary; 40 41 public ApplyChangeAction() 42 { 43 } 44 45 public void run(IAction action) 46 { 47 EditingDomain editingDomain = AdapterFactoryEditingDomain.getEditingDomainFor(changeSummary); 48 if (editingDomain != null) 49 { 50 editingDomain.getCommandStack().execute( 51 new 52 AbstractCommand() 53 { 54 protected boolean prepare() { return true; } 55 public boolean canUndo() { return false; } 56 public void execute() { changeSummary.apply(); } 57 public void redo() {} 58 }); 59 } 60 } 61 62 public void selectionChanged(IAction action, ISelection selection) 63 { 64 if (selection instanceof IStructuredSelection) 65 { 66 Object object = ((IStructuredSelection)selection).getFirstElement(); 67 if (object instanceof EChangeSummary) 68 { 69 changeSummary = (EChangeSummary)object; 70 if (!changeSummary.isLogging()) 71 { 72 action.setEnabled(true); 73 return; 74 } 75 } 76 } 77 changeSummary = null; 78 action.setEnabled(false); 79 } 80 81 } 82 | Popular Tags |