1 package acl2s.plugin.wizards;
2
3 import java.io.ByteArrayInputStream;
4 import java.io.IOException;
5 import java.io.InputStream;
6
7 import org.eclipse.core.resources.IContainer;
8 import org.eclipse.core.resources.IFile;
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.core.runtime.IPath;
11 import org.eclipse.core.runtime.Path;
12 import org.eclipse.jface.dialogs.MessageDialog;
13 import org.eclipse.jface.viewers.ISelection;
14 import org.eclipse.jface.viewers.IStructuredSelection;
15 import org.eclipse.jface.wizard.Wizard;
16 import org.eclipse.ui.INewWizard;
17 import org.eclipse.ui.IWorkbench;
18 import org.eclipse.ui.IWorkbenchPage;
19 import org.eclipse.ui.PartInitException;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.ide.IDE;
22 import org.eclipse.ui.part.FileEditorInput;
23
24 import acl2s.plugin.Acl2sPlugin;
25
26 public class NewLisp extends Wizard implements INewWizard {
27 private NewLispPage page;
28 private ISelection selection;
29
30
31 public NewLisp() {
32 setWindowTitle("New ACL2s/Lisp file");
33 }
34
35 public void addPages() {
36 page = new NewLispPage(selection);
37 addPage(page);
38 }
39
40 @Override
41 public boolean performFinish() {
42 IContainer container = page.getContainerResource();
43 try {
44 IPath relPath = new Path(page.getFileName());
45 final IFile file = container.getFile(relPath);
46 try {
|
Event do_not_call: |
"java.lang.String.getBytes()" implicitly uses the environment's default character set, which might lead to unexpected behavior. Consider using getBytes(String charsetName). |
47 InputStream stream = new ByteArrayInputStream(page.getInitDump().getBytes());
48 file.create(stream, true, null);
49 stream.close();
50 } catch (IOException e) {
51 }
52 if (page.createA2s()) {
53 Acl2sPlugin.createSessionFileFor(new FileEditorInput(file));
54 }
55 getShell().getDisplay().asyncExec(new Runnable() {
56 public void run() {
57 IWorkbenchPage page =
58 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
59 try {
60 IDE.openEditor(page, file, true);
61 } catch (PartInitException e) {
62 }
63 }
64 });
65
66 } catch (CoreException e) {
67 MessageDialog.openError(getShell(), "Error", e.getMessage());
68 return false;
69 }
70 return true;
71 }
72
73 public void init(IWorkbench workbench, IStructuredSelection selection) {
74 this.selection = selection;
75 }
76
77 }