00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00065 package org.mpcl.nui.treetable;
00066
00067 import javax.swing.event.EventListenerList;
00068 import javax.swing.event.TreeModelEvent;
00069 import javax.swing.event.TreeModelListener;
00070 import javax.swing.tree.TreePath;
00071
00072
00084 public abstract class TAbstractTreeTableModel implements ITreeTableModel
00085 {
00086
00088 protected EventListenerList tEventListenerList;
00089
00091 protected Object tRootNode;
00092
00093
00094
00095
00096
00097
00102 public TAbstractTreeTableModel (Object tROOT_NODE)
00103 {
00104 tRootNode = tROOT_NODE;
00105 tEventListenerList = new EventListenerList();
00106 }
00107
00113 public void addTreeModelListener (TreeModelListener tTREE_MODEL_LISTENER)
00114 {
00115 tEventListenerList.add (TreeModelListener.class, tTREE_MODEL_LISTENER);
00116 }
00117
00123 public void removeTreeModelListener (TreeModelListener tTREE_MODEL_LISTENER)
00124 {
00125 tEventListenerList.remove (TreeModelListener.class, tTREE_MODEL_LISTENER);
00126 }
00127
00135 public void setValueAt (Object tVALUE, Object tNODE, int iCOLUMN) {}
00136
00145 public void valueForPathChanged (TreePath tTREE_PATH, Object newValue) {}
00146
00147
00148
00149
00150
00151
00157 protected void fireTreeNodesChanged (TreePath tTREE_PATH)
00158 {
00159
00160 Object[] aListenerTypeListenerPair;
00161 TreeModelEvent tTreeModelEvent = null;
00162
00163
00164
00165
00166
00167
00168 aListenerTypeListenerPair = tEventListenerList.getListenerList();
00169 for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00170 {
00171 if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00172 {
00173 if ( tTreeModelEvent == null )
00174 {
00175 tTreeModelEvent = new TreeModelEvent (this, tTREE_PATH);
00176 }
00177 ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeNodesChanged (tTreeModelEvent);
00178 }
00179 }
00180
00181 }
00182
00201 protected void fireTreeNodesChanged ( Object tSOURCE ,
00202 Object[] atPATH ,
00203 int[] aiCHILD_INDICES ,
00204 Object[] atCHILDREN )
00205 {
00206
00207 Object[] aListenerTypeListenerPair;
00208 TreeModelEvent tTreeModelEvent = null;
00209
00210
00211
00212
00213
00214
00215 aListenerTypeListenerPair = tEventListenerList.getListenerList();
00216 for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00217 {
00218 if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00219 {
00220 if ( tTreeModelEvent == null )
00221 {
00222 tTreeModelEvent = new TreeModelEvent (tSOURCE, atPATH, aiCHILD_INDICES, atCHILDREN);
00223 }
00224 ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeNodesChanged (tTreeModelEvent);
00225 }
00226 }
00227
00228 }
00229
00248 protected void fireTreeNodesInserted ( Object tSOURCE ,
00249 Object[] atPATH ,
00250 int[] aiCHILD_INDICES ,
00251 Object[] atCHILDREN )
00252 {
00253
00254 Object[] aListenerTypeListenerPair;
00255 TreeModelEvent tTreeModelEvent = null;
00256
00257
00258
00259
00260
00261
00262 aListenerTypeListenerPair = tEventListenerList.getListenerList();
00263 for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00264 {
00265 if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00266 {
00267 if ( tTreeModelEvent == null )
00268 {
00269 tTreeModelEvent = new TreeModelEvent (tSOURCE, atPATH, aiCHILD_INDICES, atCHILDREN);
00270 }
00271 ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeNodesInserted (tTreeModelEvent);
00272 }
00273 }
00274
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295 protected void fireTreeNodesRemoved ( Object tSOURCE ,
00296 Object[] atPATH ,
00297 int[] aiCHILD_INDICES ,
00298 Object[] atCHILDREN )
00299 {
00300
00301 Object[] aListenerTypeListenerPair;
00302 TreeModelEvent tTreeModelEvent = null;
00303
00304
00305
00306
00307
00308
00309 aListenerTypeListenerPair = tEventListenerList.getListenerList();
00310 for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00311 {
00312 if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00313 {
00314 if ( tTreeModelEvent == null )
00315 {
00316 tTreeModelEvent = new TreeModelEvent (tSOURCE, atPATH, aiCHILD_INDICES, atCHILDREN);
00317 }
00318 ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeNodesRemoved (tTreeModelEvent);
00319 }
00320 }
00321
00322 }
00323
00329 protected void fireTreeStructureChanged (TreePath tTREE_PATH)
00330 {
00331
00332 Object[] aListenerTypeListenerPair;
00333 TreeModelEvent tTreeModelEvent = null;
00334
00335
00336
00337
00338
00339
00340 aListenerTypeListenerPair = tEventListenerList.getListenerList();
00341 for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00342 {
00343 if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00344 {
00345 if ( tTreeModelEvent == null )
00346 {
00347 tTreeModelEvent = new TreeModelEvent (this, tTREE_PATH);
00348 }
00349 ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeStructureChanged (tTreeModelEvent);
00350 }
00351 }
00352
00353 }
00354
00373 protected void fireTreeStructureChanged ( Object tSOURCE ,
00374 Object[] atPATH ,
00375 int[] aiCHILD_INDICES ,
00376 Object[] atCHILDREN )
00377 {
00378
00379 Object[] aListenerTypeListenerPair;
00380 TreeModelEvent tTreeModelEvent = null;
00381
00382
00383
00384
00385
00386
00387 aListenerTypeListenerPair = tEventListenerList.getListenerList();
00388 for (int I = aListenerTypeListenerPair.length-2; ( I >= 0 ) ;I-=2)
00389 {
00390 if ( aListenerTypeListenerPair [I] == TreeModelListener.class )
00391 {
00392 if ( tTreeModelEvent == null )
00393 {
00394 tTreeModelEvent = new TreeModelEvent (tSOURCE, atPATH, aiCHILD_INDICES, atCHILDREN);
00395 }
00396 ((TreeModelListener) aListenerTypeListenerPair [I + 1]).treeStructureChanged (tTreeModelEvent);
00397 }
00398 }
00399
00400 }
00401
00402
00403
00404
00405
00406
00415 public Class getColumnClass (int iCOLUMN)
00416 {
00417 return Object.class;
00418 }
00419
00428 public int getIndexOfChild (Object tPARENT_NODE, Object tCHILD_NODE)
00429 {
00430 int iChildNodeIndex = -1;
00431
00432 for (int I = 0; ( I < getChildCount (tPARENT_NODE) ) ;++I)
00433 {
00434 if ( getChild (tPARENT_NODE, I).equals (tCHILD_NODE) )
00435 {
00436 iChildNodeIndex = I;
00437 break;
00438 }
00439 }
00440 return iChildNodeIndex;
00441 }
00442
00448 public Object getRoot()
00449 {
00450 return tRootNode;
00451 }
00452
00463 public boolean isCellEditable (Object tNODE, int iCOLUMN)
00464 {
00465 return ( getColumnClass (iCOLUMN) == ITreeTableModel.class );
00466 }
00467
00477 public boolean isLeaf (Object tNODE)
00478 {
00479 return ( getChildCount (tNODE) == 0 );
00480 }
00481
00482 }