1 17 package org.eclipse.emf.ecore.action; 18 19 20 import org.eclipse.core.resources.IFile; 21 import org.eclipse.jface.action.IAction; 22 import org.eclipse.jface.dialogs.MessageDialog; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.ui.IActionDelegate; 26 import org.eclipse.ui.IWorkbenchPage; 27 import org.eclipse.ui.IWorkbenchWindow; 28 import org.eclipse.ui.PartInitException; 29 import org.eclipse.ui.PlatformUI; 30 import org.eclipse.ui.actions.ActionDelegate; 31 import org.eclipse.ui.part.FileEditorInput; 32 33 import org.eclipse.emf.ecore.resource.Resource; 34 35 38 public class OpenEditorAction extends ActionDelegate 39 implements IActionDelegate 40 { 41 protected IFile file; 42 43 public OpenEditorAction() 44 { 45 } 46 47 public void run(IAction action) 48 { 49 IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 50 IWorkbenchPage page = workbenchWindow.getActivePage(); 51 52 try 55 { 56 page.openEditor 57 (new FileEditorInput(file), 58 action.getId().indexOf("XML") == -1 ? 59 "org.eclipse.emf.ecore.presentation.ReflectiveEditorID" : 60 "org.eclipse.emf.ecore.presentation.XMLReflectiveEditorID"); 61 } 62 catch (PartInitException exception) 63 { 64 MessageDialog.openError(workbenchWindow.getShell(), "Open Editor", exception.getMessage()); 65 } 66 } 67 68 public void selectionChanged(IAction action, ISelection selection) 69 { 70 if (selection instanceof IStructuredSelection) 71 { 72 Object object = ((IStructuredSelection)selection).getFirstElement(); 73 if (object instanceof IFile) 74 { 75 file = (IFile)object; 76 77 action.setEnabled 78 (action.getId().indexOf("XML") != -1 || 79 Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().containsKey 80 (file.getFullPath().getFileExtension())); 81 return; 82 } 83 } 84 file = null; 85 action.setEnabled(false); 86 } 87 } 88 | Popular Tags |