2 * $Id: ListElementWizardPage.java,v 1.2 2005-05-06 00:57:33 stefanbjarni 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() );
52 public void widgetDefaultSelected(SelectionEvent e) {}
56 public String getPreviewText() {
57 String content = ((EditElementWizard) getWizard() ).getSelection().getText().trim();
59 String elemName = getElementName();
60 switch (getEditType()) {
62 content = chooseContent(content).trim();
66 String[] lines = content.split("\n+");
67 StringBuffer result = new StringBuffer();
68 for (int i = 0; i < lines.length; i++) {
70 if(elemName.equals("dl")){
71 itemElemName = (i % 2 == 0) ? "dt" : "dd";
75 result.append( "<" + itemElemName + ">" + lines[i].trim() + "</" + itemElemName + ">\n");
77 content = result.toString();
81 return "<" + elemName + ">\n" + content + "</" + elemName + ">\n";