Bug was introduced when working on the RSE paths. I have fixed it and this fixes...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / wizards / html / UnknownElementWizardPage.java
index d6ad3a5..817451d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: UnknownElementWizardPage.java,v 1.1 2004-10-05 20:51:57 jsurfer Exp $
+ * $Id: UnknownElementWizardPage.java,v 1.2 2006-10-21 23:18:43 pombredanne Exp $
  * Copyright Narushima Hironori. All rights reserved.
  */
 package net.sourceforge.phpeclipse.wizards.html;
@@ -32,25 +32,22 @@ import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
 
-
 /**
  * 
- *
+ * 
  */
 public class UnknownElementWizardPage extends EditElementWizardPage {
 
        // key of TableCell for attribute editor.
-       final static String
-               NAME = "ColumnProperty-name",
-               VALUE = "ColumnProperty-value";
-       
+       final static String NAME = "ColumnProperty-name",
+                       VALUE = "ColumnProperty-value";
+
        Button emptyElementCheck, addButton, removeButton, upButton, downButton;
-       
+
        TableViewer unknownElementAttrs;
-       ArrayList
-               attrs = new ArrayList(),
-               listeners = new ArrayList();
-       
+
+       ArrayList attrs = new ArrayList(), listeners = new ArrayList();
+
        SelectionListener elemTypeChangeListener = new SelectionListener() {
                public void widgetSelected(SelectionEvent e) {
                        refreshPreview();
@@ -59,8 +56,8 @@ public class UnknownElementWizardPage extends EditElementWizardPage {
                public void widgetDefaultSelected(SelectionEvent e) {
                }
        };
-       
-       public UnknownElementWizardPage(){
+
+       public UnknownElementWizardPage() {
                super("UnknownElementEditPage");
                setTitle("Unknown");
                setDescription("Editor for any HTML element.");
@@ -68,10 +65,11 @@ public class UnknownElementWizardPage extends EditElementWizardPage {
 
        static IInputValidator attrValidator = new IInputValidator() {
                public String isValid(String newText) {
-                       if( newText.length() == 0){
+                       if (newText.length() == 0) {
                                return "Need to specify name";
                        }
-                       if( newText.indexOf(' ') != -1 || newText.indexOf('\n') != -1 || newText.indexOf('\t') != -1 ){
+                       if (newText.indexOf(' ') != -1 || newText.indexOf('\n') != -1
+                                       || newText.indexOf('\t') != -1) {
                                return "Not contain blank";
                        }
                        return null;
@@ -80,76 +78,80 @@ public class UnknownElementWizardPage extends EditElementWizardPage {
 
        protected void createChildControl(Composite parent) {
                // empty eleemnt
-               parent.setLayout( new GridLayout(2, false) );
-               
-               //// attribute editor
+               parent.setLayout(new GridLayout(2, false));
+
+               // // attribute editor
                Label labe = new Label(parent, SWT.NONE);
                labe.setText("Element &Attribute:");
                GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
                labe.setLayoutData(gd);
                new Label(parent, SWT.NONE);
-               
+
                // attribute display table setting
-               unknownElementAttrs = new TableViewer(parent, SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
+               unknownElementAttrs = new TableViewer(parent, SWT.BORDER | SWT.SINGLE
+                               | SWT.FULL_SELECTION);
                gd = new GridData(GridData.FILL_BOTH);
                gd.horizontalSpan = 1;
                gd.verticalSpan = 4;
                unknownElementAttrs.getControl().setLayoutData(gd);
-               
+
                final Table table = unknownElementAttrs.getTable();
                new TableColumn(table, SWT.LEFT).setText("Name");
                new TableColumn(table, SWT.LEFT).setText("Value");
-               
+
                table.setLinesVisible(true);
                table.setHeaderVisible(true);
                // modifier setting
-               unknownElementAttrs.setColumnProperties(new String[]{ NAME, VALUE });
+               unknownElementAttrs.setColumnProperties(new String[] { NAME, VALUE });
                unknownElementAttrs.setContentProvider(new ArrayContentProvider());
-               
-               unknownElementAttrs.setCellEditors( new CellEditor[]{
-                       new TextCellEditor(table),
-                       new TextCellEditor(table)
-               });
+
+               unknownElementAttrs.setCellEditors(new CellEditor[] {
+                               new TextCellEditor(table), new TextCellEditor(table) });
                unknownElementAttrs.setCellModifier(new ICellModifier() {
                        public boolean canModify(Object element, String property) {
                                return true;
                        }
 
                        public Object getValue(Object element, String property) {
-                               return ((String[])element)[property.equals(NAME) ? 0 : 1];
+                               return ((String[]) element)[property.equals(NAME) ? 0 : 1];
                        }
 
                        public void modify(Object element, String property, Object value) {
                                if (element instanceof Item) {
-                                       ((String[])((Item) element).getData())[property.equals(NAME) ? 0 : 1] = HTMLUtilities.unescape( (String)value );
+                                       ((String[]) ((Item) element).getData())[property
+                                                       .equals(NAME) ? 0 : 1] = HTMLUtilities
+                                                       .unescape((String) value);
                                        refreshPreview();
                                }
                        }
                });
-               
-               unknownElementAttrs.setLabelProvider( new ITableLabelProvider() {
+
+               unknownElementAttrs.setLabelProvider(new ITableLabelProvider() {
                        public Image getColumnImage(Object element, int columnIndex) {
                                return null;
                        }
 
                        public String getColumnText(Object element, int columnIndex) {
-                               return ((String[])element)[columnIndex];
+                               return ((String[]) element)[columnIndex];
                        }
 
-                       public void addListener(ILabelProviderListener listener) {}
+                       public void addListener(ILabelProviderListener listener) {
+                       }
 
-                       public void removeListener(ILabelProviderListener listener) {}
+                       public void removeListener(ILabelProviderListener listener) {
+                       }
 
-                       public void dispose() {}
+                       public void dispose() {
+                       }
 
                        public boolean isLabelProperty(Object element, String property) {
                                return property.equals(NAME) || property.equals(VALUE);
                        }
                });
-               
+
                resetAttributes();
                unknownElementAttrs.setInput(attrs);
-               
+
                TableColumn[] columns = table.getColumns();
                for (int i = 0; i < columns.length; i++) {
                        columns[i].pack();
@@ -158,66 +160,72 @@ public class UnknownElementWizardPage extends EditElementWizardPage {
                // buttonss
                upButton = createButton(parent, "&Up");
                upButton.addSelectionListener(new SelectionListener() {
-                       
+
                        public void widgetSelected(SelectionEvent e) {
                                int index = getSelectionIndex();
-                               if( index > 0){
-                                       attrs.add(index-1, attrs.remove(index));
+                               if (index > 0) {
+                                       attrs.add(index - 1, attrs.remove(index));
                                        refreshPreview();
                                }
                        }
-                       public void widgetDefaultSelected(SelectionEvent e) {}
+
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                       }
                });
-               
+
                downButton = createButton(parent, "&Down");
                downButton.addSelectionListener(new SelectionListener() {
                        public void widgetSelected(SelectionEvent e) {
                                int index = getSelectionIndex();
-                               if( index < attrs.size()-1 ){
-                                       attrs.add(index+1, attrs.remove(index));
+                               if (index < attrs.size() - 1) {
+                                       attrs.add(index + 1, attrs.remove(index));
                                        refreshPreview();
                                }
                        }
-                       public void widgetDefaultSelected(SelectionEvent e) {}
+
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                       }
                });
-               
+
                addButton = createButton(parent, "&Add");
                addButton.addSelectionListener(new SelectionListener() {
                        public void widgetSelected(SelectionEvent e) {
                                int insertIndex = getSelectionIndex();
                                String[] newData = inputValue();
-                               if(newData != null){
+                               if (newData != null) {
                                        attrs.add(newData);
                                        refreshPreview();
                                }
                        }
 
-                       String[] inputValue(){
+                       String[] inputValue() {
                                SomeItemInputDialog dialog = new SomeItemInputDialog(
-                                       getShell(),
-                                       "Input new attribute",
-                                       new String[]{"Attribute name", "Attribute value"},
-                                       new IInputValidator[] {attrValidator, null});
-                               
-                               
-                               if( dialog.open() ==  Window.OK){
+                                               getShell(), "Input new attribute", new String[] {
+                                                               "Attribute name", "Attribute value" },
+                                               new IInputValidator[] { attrValidator, null });
+
+                               if (dialog.open() == Window.OK) {
                                        return dialog.getValues();
                                }
                                return null;
                        }
-                       public void widgetDefaultSelected(SelectionEvent e) {}
+
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                       }
                });
-               
+
                removeButton = createButton(parent, "&Remove");
                removeButton.addSelectionListener(new SelectionListener() {
                        public void widgetSelected(SelectionEvent e) {
                                int index = getSelectionIndex();
-                                if( index != -1){
+                               if (index != -1) {
                                        attrs.remove(index);
                                        refreshPreview();
-                                }
+                               }
+                       }
+
+                       public void widgetDefaultSelected(SelectionEvent e) {
                        }
-                       public void widgetDefaultSelected(SelectionEvent e) {}
                });
 
                emptyElementCheck = new Button(parent, SWT.CHECK);
@@ -226,89 +234,89 @@ public class UnknownElementWizardPage extends EditElementWizardPage {
                emptyElementCheck.setText("&Empty Element");
                emptyElementCheck.addSelectionListener(elemTypeChangeListener);
                emptyElementCheck.setSelection(isEmptyAsText());
-               
+
                new Label(parent, SWT.NONE);
        }
-       
-       static Button createButton(Composite parent, String text){
+
+       static Button createButton(Composite parent, String text) {
                Button button = new Button(parent, SWT.PUSH);
-               GridData gd = new GridData(
-                       GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_END);
+               GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING
+                               | GridData.HORIZONTAL_ALIGN_END);
                gd.widthHint = 60;
-               button.setLayoutData( gd);
+               button.setLayoutData(gd);
                button.setText(text);
                return button;
        }
-       
-       public String getPreviewText(){
+
+       public String getPreviewText() {
                String elemName = getElementName();
-               if(elemName == null){
+               if (elemName == null) {
                        return null;
                }
-               
+
                // sets values
-               
+
                boolean empty = false;
-               if( emptyElementCheck == null ){
+               if (emptyElementCheck == null) {
                        // ui uninitialized
                        empty = isEmptyAsText();
-               }else{
+               } else {
                        // ui initialized
                        empty = emptyElementCheck.getSelection();
                }
-               
+
                String content = getSelectionText();
-               if( !empty && getEditType() == MODIFY){
-                       content = chooseContent( content );
+               if (!empty && getEditType() == MODIFY) {
+                       content = chooseContent(content);
                }
-               
+
                String previewText = "<" + elemName + attrsCode();
-               if(empty){
-                       previewText +=  " />";
-               }else{
+               if (empty) {
+                       previewText += " />";
+               } else {
                        previewText += ">" + content + "</" + elemName + ">";
                }
                return previewText;
        }
-       
-       boolean isEmptyAsText(){
+
+       boolean isEmptyAsText() {
                String selText = getSelectionText();
-               if(getEditType() == MODIFY){
+               if (getEditType() == MODIFY) {
                        int len = selText.length();
-                       return selText.substring(len-2, len).equals("/>");
+                       return selText.substring(len - 2, len).equals("/>");
                }
                return false;
        }
-       
-       void resetAttributes(){
+
+       void resetAttributes() {
                attrs.clear();
-               
+
                Element elem = getParsedSelectionText();
-               if( elem != null){
+               if (elem != null) {
                        NamedNodeMap as = elem.getAttributes();
                        for (int i = 0; i < as.getLength(); i++) {
                                Node n = as.item(i);
-                               attrs.add( new String[]{ n.getNodeName(), n.getNodeValue()});
+                               attrs.add(new String[] { n.getNodeName(), n.getNodeValue() });
                        }
                }
        }
-       
-       String attrsCode(){
+
+       String attrsCode() {
                StringBuffer buff = new StringBuffer();
                Object[] as = attrs.toArray();
                for (int i = 0; i < as.length; i++) {
-                       String[] a = (String[])as[i];
+                       String[] a = (String[]) as[i];
                        buff.append(" " + a[0] + "=\"" + HTMLUtilities.escape(a[1]) + "\"");
                }
                return buff.toString();
        }
 
-       int getSelectionIndex(){
+       int getSelectionIndex() {
                Object sel = unknownElementAttrs.getSelection();
-               if( sel instanceof IStructuredSelection){
-                       Object item = ((IStructuredSelection)sel).getFirstElement();
+               if (sel instanceof IStructuredSelection) {
+                       Object item = ((IStructuredSelection) sel).getFirstElement();
                        return attrs.indexOf(item);
-               }else{
+               } else {
                        return -1;
                }
        }