2 * $Id: EditElementWizard.java,v 1.3 2006-10-21 23:18:43 pombredanne 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
23 public class EditElementWizard extends Wizard {
25 static Object[] elementEditPages = new Object[] {
26 // "a", AElementWizardPage.class,
27 // "img", ImgElementWizardPage.class,
28 "dl", ListElementWizardPage.class, "ul",
29 ListElementWizardPage.class, "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
42 public EditElementWizard(ITextEditor editor, String targetElemName) {
44 this.targetElemName = targetElemName;
46 setWindowTitle("Edit HTML Element");
47 setDefaultPageImageDescriptor(PHPUiImages
48 .getDescriptor("wizban/editelem_wiz.gif"));
50 setForcePreviousAndNextButtons(true);
53 public void addPages() {
54 if (targetElemName == null) {
55 rootPage = new NewElementWizardPage();
57 IDocument doc = getDocument();
58 rootPage = createElementEditPage(targetElemName);
59 rootPage.setEditType(EditElementWizardPage.MODIFY);
64 public boolean performFinish() {
65 IWizardPage page = rootPage;
66 for (IWizardPage p; (p = page.getNextPage()) != null;) {
69 if (page instanceof EditElementWizardPage) {
70 ((EditElementWizardPage) page).performFinish();
75 public IDocument getDocument() {
76 return htEditor.getDocumentProvider().getDocument(
77 htEditor.getEditorInput());
80 public ITextSelection getSelection() {
81 return (ITextSelection) htEditor.getSelectionProvider().getSelection();
84 public void setSelection(ITextSelection sel) {
85 htEditor.getSelectionProvider().setSelection(sel);
88 public IFile getCurrentEditFile() {
89 IEditorInput input = htEditor.getEditorInput();
90 return (input instanceof IFileEditorInput) ? ((IFileEditorInput) input)
95 * If not edit target returns UnknownElementWizardPage.
97 public EditElementWizardPage createElementEditPage(String elementName) {
98 EditElementWizardPage page = null;
100 for (int i = 0; i < elementEditPages.length; i += 2) {
101 if (((String) elementEditPages[i])
102 .equalsIgnoreCase(elementName)) {
103 Class klass = (Class) elementEditPages[i + 1];
104 page = (EditElementWizardPage) klass.newInstance();
107 } catch (InstantiationException e) {
108 PHPeclipsePlugin.log(e);
109 } catch (IllegalAccessException e) {
110 PHPeclipsePlugin.log(e);
113 page = new UnknownElementWizardPage();
115 page.setElementName(elementName);
116 page.setWizard(this);