01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.tests.macro;
11:
12: import java.io.ByteArrayInputStream;
13: import java.io.InputStream;
14: import java.io.UnsupportedEncodingException;
15:
16: import org.eclipse.core.resources.IFile;
17: import org.eclipse.jface.viewers.ISelection;
18: import org.eclipse.jface.viewers.IStructuredSelection;
19: import org.eclipse.jface.viewers.StructuredSelection;
20: import org.eclipse.jface.wizard.Wizard;
21: import org.eclipse.ui.ISelectionService;
22: import org.eclipse.ui.PlatformUI;
23: import org.eclipse.ui.dialogs.WizardNewFileCreationPage;
24:
25: public class NewMacroWizard extends Wizard {
26: private String contents;
27: private NewMacroPage page;
28:
29: class NewMacroPage extends WizardNewFileCreationPage {
30: public NewMacroPage(IStructuredSelection ssel) {
31: super ("newFile", ssel);
32: setTitle("Macro script name");
33: setDescription("Select the target location and the name of the new script (extension *.emc).");
34: }
35:
36: public InputStream getInitialContents() {
37: InputStream is = null;
38: try {
39: is = new ByteArrayInputStream(contents.getBytes("UTF8"));
40: } catch (UnsupportedEncodingException e) {
41: }
42: return is;
43: }
44: }
45:
46: public NewMacroWizard(String contents) {
47: this .contents = contents;
48: setWindowTitle("Macro Recorder");
49: }
50:
51: public void addPages() {
52: ISelectionService sservice = PlatformUI.getWorkbench()
53: .getActiveWorkbenchWindow().getSelectionService();
54: ISelection selection = sservice.getSelection();
55: IStructuredSelection ssel;
56: if (!(selection instanceof IStructuredSelection))
57: ssel = new StructuredSelection();
58: else
59: ssel = (IStructuredSelection) selection;
60:
61: page = new NewMacroPage(ssel);
62: addPage(page);
63: }
64:
65: public boolean performFinish() {
66: IFile file = page.createNewFile();
67: return file != null;
68: }
69: }
|