1 17 package org.eclipse.emf.importer.ui; 18 19 import org.eclipse.core.resources.IFile; 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.jface.viewers.StructuredSelection; 24 import org.eclipse.jface.wizard.WizardDialog; 25 import org.eclipse.swt.widgets.Shell; 26 import org.eclipse.ui.IEditorActionDelegate; 27 import org.eclipse.ui.IEditorInput; 28 import org.eclipse.ui.IEditorPart; 29 import org.eclipse.ui.IFileEditorInput; 30 import org.eclipse.ui.IWorkbench; 31 import org.eclipse.ui.PlatformUI; 32 import org.eclipse.ui.actions.ActionDelegate; 33 34 35 41 public class GenModelReloadActionDelegate extends ActionDelegate implements IEditorActionDelegate 42 { 43 protected boolean fixedFile = false; 44 protected IFile file; 45 46 public GenModelReloadActionDelegate() 47 { 48 super(); 49 } 50 51 public GenModelReloadActionDelegate(IEditorPart editorPart) 52 { 53 this(); 54 } 55 56 public void dispose() 57 { 58 file = null; 59 super.dispose(); 60 } 61 62 public void selectionChanged(IAction action, ISelection selection) 63 { 64 if (fixedFile) return; 65 66 if (selection instanceof IStructuredSelection) 67 { 68 Object object = ((IStructuredSelection)selection).getFirstElement(); 69 if (object instanceof IFile) 70 { 71 file = (IFile)object; 72 action.setEnabled(true); 73 return; 74 } 75 } 76 file = null; 77 action.setEnabled(false); 78 } 79 80 83 public void setActiveEditor(IAction action, IEditorPart targetEditor) 84 { 85 if (targetEditor != null) 86 { 87 IEditorInput input = targetEditor.getEditorInput(); 88 if (input instanceof IFileEditorInput) 89 { 90 file = ((IFileEditorInput)input).getFile(); 91 fixedFile = true; 92 action.setEnabled(true); 93 return; 94 } 95 } 96 file = null; 97 action.setEnabled(false); 98 } 99 100 public void run(IAction action) 101 { 102 run(PlatformUI.getWorkbench(), PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), file); 103 } 104 105 protected void run(IWorkbench workbench, Shell shell, IFile file) 106 { 107 EMFModelWizard wizard = new EMFModelWizard(file); 108 wizard.init(workbench, new StructuredSelection(file)); 109 110 WizardDialog wizardDialog = new WizardDialog(shell, wizard); 111 wizardDialog.create(); 112 wizardDialog.getShell().setSize(540, 580); 113 wizardDialog.open(); 114 } 115 } 116 | Popular Tags |