1 19 package org.netbeans.modules.j2ee.websphere6.dd.loaders.ui; 20 21 import java.util.List ; 23 import org.openide.util.NbBundle; 24 import org.netbeans.modules.j2ee.websphere6.dd.beans.*; 25 import org.netbeans.modules.schema2beans.*; 26 import org.netbeans.modules.xml.multiview.*; 27 28 public class PageTableModel extends org.netbeans.modules.j2ee.websphere6.dd.loaders.ui.InnerTableModel { 29 30 private List children; 31 private BaseBean parent; 32 private static final String [] columnNames = { 33 NbBundle.getMessage(PageTableModel.class,"TTL_PageId"), 34 NbBundle.getMessage(PageTableModel.class,"TTL_PageName"), 35 NbBundle.getMessage(PageTableModel.class,"TTL_PageUri") 36 }; 37 38 private static final int [] columnWidths= {200, 160, 180}; 39 40 public PageTableModel(XmlMultiViewDataSynchronizer synchronizer) { 41 super(synchronizer,columnNames,columnWidths); 42 } 43 44 45 46 protected String [] getColumnNames() { 47 return columnNames; 48 } 49 50 protected BaseBean getParent() { 51 return parent; 52 } 53 54 protected List getChildren() { 55 return children; 56 } 57 58 public int getColumnCount() { 59 return getColumnNames().length; 60 } 61 62 public int getRowCount() { 63 if (children != null) { 64 return (children.size()); 65 } else { 66 return (0); 67 } 68 } 69 70 71 public String getColumnName(int column) { 72 return getColumnNames()[column]; 73 } 74 75 public boolean isCellEditable(int row, int column) { 76 return (false); 77 } 78 79 public int getRowWithValue(int column, Object value) { 80 for(int row = 0; row < getRowCount(); row++) { 81 Object obj = getValueAt(row, column); 82 if (obj.equals(value)) { 83 return (row); 84 } 85 } 86 87 return (-1); 88 } 89 90 91 92 public void setData(BaseBean parent,BaseBean[] children) { 93 this.parent = parent; 94 this.children = new java.util.ArrayList (); 95 if (children==null) return; 96 for(int i=0;i<children.length;i++) 97 this.children.add(children[i]); 98 fireTableDataChanged(); 99 } 100 101 102 public void setValueAt(Object value, int row, int column) { 103 PageType page = (PageType)getChildren().get(row); 104 105 if (column == 0) page.setXmiId((String )value); 106 else if(column==1) page.setName((String )value); 107 else page.setUri((String )value); 108 } 109 110 111 public Object getValueAt(int row, int column) { 112 PageType page = (PageType)getChildren().get(row); 113 114 if (column == 0) return page.getXmiId(); 115 else if(column == 1) return page.getName(); 116 else if(column == 2) return page.getUri(); 117 return null; 118 } 119 120 public BaseBean addRow(Object [] values) { 121 PageType page = new PageType(); 123 page.setXmiId((String )values[0]); 124 page.setName((String )values[1]); 125 page.setUri((String )values[2]); 126 ((MarkupLanguagesType)getParent()).addPages(page); 127 getChildren().add(page); 128 fireTableRowsInserted(getRowCount() - 1, getRowCount() - 1); 129 return page; 130 132 } 134 135 public int addRow() { 136 return -1; 137 } 138 139 140 public void editRow(int row, Object [] values) { 141 PageType page = (PageType)getChildren().get(row); 142 page.setXmiId((String )values[0]); 143 page.setName((String )values[1]); 144 page.setUri((String )values[2]); 145 fireTableRowsUpdated(row,row); 146 } 147 148 public void removeRow(int row) { 149 ((MarkupLanguagesType)getParent()).removePages((PageType)getChildren().get(row)); 150 getChildren().remove(row); 151 fireTableRowsDeleted(row, row); 152 153 } 154 } | Popular Tags |