2 * $Id: EditElementWizard.java,v 1.2 2005-07-08 21:30:33 axelcl Exp $
3 * Copyright Narushima Hironori. All rights reserved.
5 package net.sourceforge.phpeclipse.wizards.html;
7 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
8 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
10 import org.eclipse.core.resources.IFile;
11 import org.eclipse.jface.text.IDocument;
12 import org.eclipse.jface.text.ITextSelection;
13 import org.eclipse.jface.wizard.IWizardPage;
14 import org.eclipse.jface.wizard.Wizard;
15 import org.eclipse.ui.IEditorInput;
16 import org.eclipse.ui.IFileEditorInput;
17 import org.eclipse.ui.texteditor.ITextEditor;
20 * EditElementWizard. TODO: privides extension point element editor. pluggable element edit page.
22 public class EditElementWizard extends Wizard {
24 static Object[] elementEditPages = new Object[] {
25 // "a", AElementWizardPage.class,
26 // "img", ImgElementWizardPage.class,
27 "dl", ListElementWizardPage.class,
28 "ul", ListElementWizardPage.class,
29 "ol", ListElementWizardPage.class,
30 "table", TableElementWizardPage.class };
32 String targetElemName;
36 EditElementWizardPage rootPage;
39 * Second argument specify element name, If specify null, call new element edit wizard page.
41 public EditElementWizard(ITextEditor editor, String targetElemName) {
43 this.targetElemName = targetElemName;
45 setWindowTitle("Edit HTML Element");
46 setDefaultPageImageDescriptor(PHPUiImages.getDescriptor("wizban/editelem_wiz.gif"));
48 setForcePreviousAndNextButtons(true);
51 public void addPages() {
52 if (targetElemName == null) {
53 rootPage = new NewElementWizardPage();
55 IDocument doc = getDocument();
56 rootPage = createElementEditPage(targetElemName);
57 rootPage.setEditType(EditElementWizardPage.MODIFY);
62 public boolean performFinish() {
63 IWizardPage page = rootPage;
64 for (IWizardPage p; (p = page.getNextPage()) != null;) {
67 if (page instanceof EditElementWizardPage) {
68 ((EditElementWizardPage) page).performFinish();
73 public IDocument getDocument() {
74 return htEditor.getDocumentProvider().getDocument(htEditor.getEditorInput());
77 public ITextSelection getSelection() {
78 return (ITextSelection) htEditor.getSelectionProvider().getSelection();
81 public void setSelection(ITextSelection sel) {
82 htEditor.getSelectionProvider().setSelection(sel);
85 public IFile getCurrentEditFile() {
86 IEditorInput input = htEditor.getEditorInput();
87 return (input instanceof IFileEditorInput) ? ((IFileEditorInput) input).getFile() : null;
91 * If not edit target returns UnknownElementWizardPage.
93 public EditElementWizardPage createElementEditPage(String elementName) {
94 EditElementWizardPage page = null;
96 for (int i = 0; i < elementEditPages.length; i += 2) {
97 if (((String) elementEditPages[i]).equalsIgnoreCase(elementName)) {
98 Class klass = (Class) elementEditPages[i + 1];
99 page = (EditElementWizardPage) klass.newInstance();
102 } catch (InstantiationException e) {
103 PHPeclipsePlugin.log(e);
104 } catch (IllegalAccessException e) {
105 PHPeclipsePlugin.log(e);
108 page = new UnknownElementWizardPage();
110 page.setElementName(elementName);
111 page.setWizard(this);