2 * $Id: TableElementCellModifier.java,v 1.1 2004-10-05 20:51:57 jsurfer Exp $
3 * Copyright Narushima Hironori. All rights reserved.
5 package net.sourceforge.phpeclipse.wizards.html;
7 import javax.xml.parsers.DocumentBuilderFactory;
9 import org.eclipse.jface.util.*;
10 import org.eclipse.jface.viewers.ICellModifier;
11 import org.eclipse.swt.widgets.Item;
17 public class TableElementCellModifier implements ICellModifier {
19 DocumentBuilderFactory builderFactory;
20 IPropertyChangeListener listener;
22 public TableElementCellModifier(IPropertyChangeListener listener) {
23 builderFactory = DocumentBuilderFactory.newInstance();
24 this.listener = listener;
27 public boolean canModify(Object element, String property) {
28 return getValue(element, property) != null;
31 public Object getValue(Object trElem, String property) {
32 if(trElem instanceof Element){
33 Element e = (Element)trElem;
34 if( e.getNodeName().equals("tr") ){
35 int v = TableElementModel.toNumeric(property);
36 Element[] cells = TableElementModel.chooseCellElements(e);
37 if(v >= 0 && v < cells.length){
38 NodeList nodes = cells[v].getChildNodes();
39 if(nodes.getLength() == 1){
40 Node n = nodes.item(0);
41 if(n instanceof Text){
42 return n.getNodeValue();
51 public void modify(Object element, String property, Object value) {
52 if (element instanceof Item) {
53 element = ((Item) element).getData();
55 Element trElem = (Element)element;
56 int index = TableElementModel.toNumeric(property);
57 Element cellElem = TableElementModel.chooseCellElements(trElem)[index];
59 NodeList nodes = cellElem.getChildNodes();
60 for(int i=0; i<nodes.getLength(); i++){
61 cellElem.removeChild( nodes.item(i) );
63 Document doc = cellElem.getOwnerDocument();
65 if( value instanceof String){
66 cellElem.appendChild(doc.createTextNode((String)value));
70 String oldValue = nodes.item(0).getNodeValue();
71 listener.propertyChange(new PropertyChangeEvent(this, property, (String)value, oldValue));