2 * $Id: ListElementWizardPage.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 org.eclipse.swt.SWT;
8 import org.eclipse.swt.events.SelectionEvent;
9 import org.eclipse.swt.events.SelectionListener;
10 import org.eclipse.swt.layout.GridData;
11 import org.eclipse.swt.layout.GridLayout;
12 import org.eclipse.swt.widgets.Combo;
13 import org.eclipse.swt.widgets.Composite;
14 import org.eclipse.swt.widgets.Label;
19 public class ListElementWizardPage extends EditElementWizardPage {
21 final static String[] LIST_TYPES = { "ul", "ol", "dl" };
25 public ListElementWizardPage() {
26 super("ListElementWizardPage");
28 setDescription("Editing list element.");
31 protected void createChildControl(Composite parent) {
32 parent.setLayout(new GridLayout(2, false));
33 Label labe = new Label(parent, SWT.NONE);
34 labe.setText("List &Type:");
36 types = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
38 for (int i = 0; i < LIST_TYPES.length; i++) {
39 String type = LIST_TYPES[i];
41 if (getElementName().equals(type)) {
46 types.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
47 types.addSelectionListener(new SelectionListener() {
48 public void widgetSelected(SelectionEvent e) {
49 setElementName(types.getText());
53 public void widgetDefaultSelected(SelectionEvent e) {
58 public String getPreviewText() {
59 String content = ((EditElementWizard) getWizard()).getSelection()
62 String elemName = getElementName();
63 switch (getEditType()) {
65 content = chooseContent(content).trim();
69 String[] lines = content.split("\n+");
70 StringBuffer result = new StringBuffer();
71 for (int i = 0; i < lines.length; i++) {
73 if (elemName.equals("dl")) {
74 itemElemName = (i % 2 == 0) ? "dt" : "dd";
78 result.append("<" + itemElemName + ">" + lines[i].trim() + "</"
79 + itemElemName + ">\n");
81 content = result.toString();
85 return "<" + elemName + ">\n" + content + "</" + elemName + ">\n";