1 56 package org.objectstyle.cayenne.modeler.dialog; 57 58 import java.util.ArrayList ; 59 60 import org.objectstyle.cayenne.map.DbEntity; 61 import org.objectstyle.cayenne.map.DbJoin; 62 import org.objectstyle.cayenne.map.DbRelationship; 63 import org.objectstyle.cayenne.modeler.ProjectController; 64 import org.objectstyle.cayenne.modeler.util.CayenneTableModel; 65 66 70 public class DbJoinTableModel extends CayenneTableModel { 71 72 static final int SOURCE = 0; 74 static final int TARGET = 1; 75 76 protected DbRelationship relationship; 77 protected DbEntity source; 78 protected DbEntity target; 79 80 81 private boolean editable; 82 83 public DbJoinTableModel( 84 DbRelationship relationship, 85 ProjectController mediator, 86 Object src) { 87 88 super(mediator, src, new ArrayList (relationship.getJoins())); 89 this.relationship = relationship; 90 this.source = (DbEntity) relationship.getSourceEntity(); 91 this.target = (DbEntity) relationship.getTargetEntity(); 92 } 93 94 public DbJoinTableModel( 95 DbRelationship relationship, 96 ProjectController mediator, 97 Object src, 98 boolean editable) { 99 100 this(relationship, mediator, src); 101 this.editable = editable; 102 } 103 104 public Class getElementsClass() { 105 return DbJoin.class; 106 } 107 108 109 public void commit() { 110 relationship.setJoins(getObjectList()); 111 } 112 113 116 public String getOrderingKey() { 117 return null; 118 } 119 120 public int getColumnCount() { 121 return 2; 122 } 123 124 public String getColumnName(int column) { 125 if (column == SOURCE) 126 return "Source"; 127 else if (column == TARGET) 128 return "Target"; 129 else 130 return ""; 131 } 132 133 public DbJoin getJoin(int row) { 134 return (row >= 0 && row < objectList.size()) 135 ? (DbJoin) objectList.get(row) 136 : null; 137 } 138 139 public Object getValueAt(int row, int column) { 140 DbJoin join = getJoin(row); 141 if (join == null) { 142 return null; 143 } 144 145 if (column == SOURCE) { 146 return join.getSourceName(); 147 } 148 else if (column == TARGET) { 149 return join.getTargetName(); 150 } 151 else { 152 return null; 153 } 154 155 } 156 157 public void setUpdatedValueAt(Object aValue, int row, int column) { 158 DbJoin join = getJoin(row); 159 if (join == null) { 160 return; 161 } 162 163 String value = (String ) aValue; 164 if (column == SOURCE) { 165 if (source == null || source.getAttribute(value) == null) { 166 value = null; 167 } 168 169 join.setSourceName(value); 170 } 171 else if (column == TARGET) { 172 if (target == null || target.getAttribute(value) == null) { 173 value = null; 174 } 175 176 join.setTargetName(value); 177 } 178 179 fireTableRowsUpdated(row, row); 180 } 181 182 public boolean isCellEditable(int row, int col) { 183 if (col == SOURCE) { 184 return relationship.getSourceEntity() != null && editable; 185 } 186 else if (col == TARGET) { 187 return relationship.getTargetEntity() != null && editable; 188 } 189 190 return false; 191 } 192 } 193 | Popular Tags |