1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| public class UntitledTextFileWizard extends Wizard implements INewWizard {
private IWorkbenchWindow fWindow;
public UntitledTextFileWizard() {
}
/*
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
*/
public void dispose() {
fWindow= null;
}
private IFileStore queryFileStore() {
IPath stateLocation= EditorsPlugin.getDefault().getStateLocation();
IPath path= stateLocation.append("/_" + new Object().hashCode()); //$NON-NLS-1$
return EFS.getLocalFileSystem().getStore(path);
}
private String getEditorId(IFileStore fileStore) {
IWorkbench workbench= fWindow.getWorkbench();
IEditorRegistry editorRegistry= workbench.getEditorRegistry();
IEditorDescriptor descriptor= editorRegistry.getDefaultEditor(fileStore.getName());
if (descriptor != null)
return descriptor.getId();
return EditorsUI.DEFAULT_TEXT_EDITOR_ID;
}
private IEditorInput createEditorInput(IFileStore fileStore) {
return new NonExistingFileEditorInput(fileStore, TextEditorMessages.NewTextEditorAction_namePrefix);
}
/*
* @see org.eclipse.jface.wizard.Wizard#performFinish()
*/
public boolean performFinish() {
IFileStore fileStore= queryFileStore();
IEditorInput input= createEditorInput(fileStore);
String editorId= getEditorId(fileStore);
IWorkbenchPage page= fWindow.getActivePage();
try {
page.openEditor(input, editorId);
} catch (PartInitException e) {
EditorsPlugin.log(e);
return false;
}
return true;
}
/*
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
fWindow= workbench.getActiveWorkbenchWindow();
}
} |
Partager