1 11 12 package org.eclipse.pde.internal.ui.editor.schema; 13 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.core.resources.ResourcesPlugin; 16 import org.eclipse.core.runtime.IPath; 17 import org.eclipse.core.runtime.NullProgressMonitor; 18 import org.eclipse.jface.action.IAction; 19 import org.eclipse.jface.dialogs.MessageDialog; 20 import org.eclipse.jface.viewers.StructuredSelection; 21 import org.eclipse.pde.internal.ui.PDEUIMessages; 22 import org.eclipse.pde.internal.ui.search.PreviewReferenceAction; 23 import org.eclipse.pde.internal.ui.util.PDEModelUtility; 24 import org.eclipse.swt.widgets.Display; 25 import org.eclipse.ui.IEditorLauncher; 26 27 31 public class SchemaPreviewLauncher implements IEditorLauncher { 32 33 36 public void open(IPath filePath) { 37 PreviewReferenceAction action = new PreviewReferenceAction(); 39 IFile file = 42 ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(filePath); 43 if (file == null) { 45 Display.getDefault().beep(); 48 } else { 49 handleUnsavedOpenSchemaEditor(file); 53 IAction emptyAction = null; 56 action.selectionChanged(emptyAction, new StructuredSelection(file)); 58 action.run(emptyAction); 60 } 61 } 62 63 66 private void handleUnsavedOpenSchemaEditor(IFile file) { 67 SchemaEditor editor = PDEModelUtility.getOpenSchemaEditor(file); 70 if (editor == null) { 72 return; 74 } else if (editor.isDirty() == false) { 75 return; 77 } 78 boolean doSave = 82 MessageDialog.openQuestion( 83 Display.getDefault().getActiveShell(), 84 PDEUIMessages.SchemaPreviewLauncher_msgEditorHasUnsavedChanges, 85 PDEUIMessages.SchemaPreviewLauncher_msgSaveChanges); 86 if (doSave) { 88 editor.doSave(new NullProgressMonitor()); 89 } 90 } 91 92 } 93 | Popular Tags |