KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > specifier > editor > DjenericObjectTable


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, is permitted
5  * provided that the following conditions are met:
6  * - Redistributions of source code must retain the above copyright notice, this list of conditions
7  * and the following disclaimer.
8  * - Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * - All advertising materials mentioning features or use of this software must display the
12  * following acknowledgment: "This product includes Djeneric."
13  * - Products derived from this software may not be called "Djeneric" nor may
14  * "Djeneric" appear in their names without prior written permission of Genimen BV.
15  * - Redistributions of any form whatsoever must retain the following acknowledgment: "This
16  * product includes Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG,
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.specifier.editor;
31
32 import java.awt.Component JavaDoc;
33 import java.awt.event.FocusEvent JavaDoc;
34 import java.awt.event.FocusListener JavaDoc;
35 import java.awt.event.MouseAdapter JavaDoc;
36 import java.awt.event.MouseEvent JavaDoc;
37 import java.math.BigDecimal JavaDoc;
38 import java.util.ArrayList JavaDoc;
39 import java.util.Date JavaDoc;
40
41 import javax.swing.DefaultListSelectionModel JavaDoc;
42 import javax.swing.JOptionPane JavaDoc;
43 import javax.swing.JScrollPane JavaDoc;
44 import javax.swing.ListSelectionModel JavaDoc;
45 import javax.swing.event.ListSelectionEvent JavaDoc;
46 import javax.swing.event.ListSelectionListener JavaDoc;
47 import javax.swing.event.TableModelEvent JavaDoc;
48 import javax.swing.table.TableCellEditor JavaDoc;
49
50 import com.genimen.djeneric.language.Messages;
51 import com.genimen.djeneric.repository.DjAssociation;
52 import com.genimen.djeneric.repository.DjExtent;
53 import com.genimen.djeneric.repository.DjList;
54 import com.genimen.djeneric.repository.DjObject;
55 import com.genimen.djeneric.repository.DjProperty;
56 import com.genimen.djeneric.repository.DjSession;
57 import com.genimen.djeneric.repository.DjValueObject;
58 import com.genimen.djeneric.repository.exceptions.DjenericException;
59 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException;
60 import com.genimen.djeneric.repository.exceptions.PropertyRequiredException;
61 import com.genimen.djeneric.structure.ExtentUsage;
62 import com.genimen.djeneric.structure.PropertyUsage;
63 import com.genimen.djeneric.structure.RelationUsage;
64 import com.genimen.djeneric.tools.specifier.components.DjBindable;
65 import com.genimen.djeneric.tools.specifier.exceptions.ObjectViewerApplyException;
66 import com.genimen.djeneric.tools.specifier.interfaces.ObjectModelListener;
67 import com.genimen.djeneric.tools.specifier.interfaces.ObjectViewer;
68 import com.genimen.djeneric.tools.specifier.interfaces.ObjectViewerListener;
69 import com.genimen.djeneric.ui.DjTable;
70 import com.genimen.djeneric.util.DjLogger;
71
72 /**
73  * Description of the Class
74  *
75  *@author Wido Riezebos
76  *@created November 4, 2001
77  */

78 public class DjenericObjectTable extends JScrollPane JavaDoc
79     implements
80       ObjectViewer,
81       DjValueObject,
82       ListSelectionListener JavaDoc,
83       FocusListener JavaDoc
84 {
85   private static final long serialVersionUID = 1L;
86   DjenericObjectModel _model;
87   private DjenericObjectEditorProxy _proxy;
88   private ExtentUsage _usage;
89   private ListSelectionModel JavaDoc _selectionModel;
90   private ObjectViewer _master = null;
91   private int[] _rememberedSelectedIndex = null;
92   private ArrayList JavaDoc _allListeners = new ArrayList JavaDoc();
93   private DjAssociation _currentAssociation = null;
94   private DjTable _table = new TableHelper();
95   private ArrayList JavaDoc _detailViewers = new ArrayList JavaDoc();
96   private DjSession _session;
97
98   /**
99    * Constructor for the DjenericObjectTable object
100    *
101    *@param session Description of the Parameter
102    *@param usage Description of the Parameter
103    *@exception Exception Description of the Exception
104    */

105   public DjenericObjectTable(DjSession session, ExtentUsage usage, DjenericContextManager contextManager)
106       throws DjenericException
107   {
108     super();
109
110     contextManager.registerViewer(usage.getId(), this);
111
112     _usage = usage;
113     _session = session;
114     _model = new DjenericObjectModel(session, usage, contextManager);
115     _proxy = new DjenericObjectEditorProxy(this);
116     _table.setModel(_model);
117     _table.addFocusListener(this);
118     getViewport().add(_table, null);
119     addMouseListener(new MouseAdapter JavaDoc()
120     {
121       public void mouseClicked(MouseEvent JavaDoc e)
122       {
123         doubleClick(e);
124       }
125     });
126
127     _selectionModel = new DefaultListSelectionModel JavaDoc();
128     _selectionModel.addListSelectionListener(this);
129     _selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
130     _table.setSelectionModel(_selectionModel);
131   }
132
133   public String JavaDoc toString()
134   {
135     return Messages.getString("global.ViewerFor", getExtent().getName());
136   }
137
138   public DjExtent getExtent()
139   {
140     return _model.getExtent();
141   }
142
143   public ExtentUsage getExtentUsage()
144   {
145     return _usage;
146   }
147
148   public DjenericObjectModel getModel()
149   {
150     return _model;
151   }
152
153   public int getSelectedIndex()
154   {
155     if (_model.getRowCount() == 0) return -1;
156
157     if (_model.getRowCount() != 0 && _table.getSelectedRow() == -1) _table.setRowSelectionInterval(0, 0);
158
159     return _table.getSelectedRow();
160   }
161
162   public DjObject getSelectedValue()
163   {
164     int idx = getSelectedIndex();
165     if (idx == -1)
166     {
167       return null;
168     }
169     return _model.get(idx);
170   }
171
172   public String JavaDoc getString(int cellIdx)
173   {
174     Object JavaDoc o = getValue(cellIdx);
175
176     if (o == null)
177     {
178       return "";
179     }
180
181     return o.toString();
182   }
183
184   public Object JavaDoc getValue(int cellIdx)
185   {
186     if (getSelectedIndex() == -1)
187     {
188       return null;
189     }
190
191     Object JavaDoc o = _model.getValueAt(getSelectedIndex(), cellIdx);
192     return o;
193   }
194
195   public void setString(int cellIdx, String JavaDoc value) throws DjenericException
196   {
197     setValue(cellIdx, value);
198   }
199
200   public void setValue(int cellIdx, Object JavaDoc value) throws DjenericException
201   {
202     if (getSelectedIndex() == -1)
203     {
204       throw new DjenericException(Messages.getString("global.NoCreated", getExtent().getNameSingular()));
205     }
206     if (value instanceof String JavaDoc && value.toString().equals(""))
207     {
208       value = null;
209     }
210     _model.setValueAtX(value, getSelectedIndex(), cellIdx);
211
212     DjProperty prop = _usage.getExtent().getProperty(_model.cellIdx2PropertyName(cellIdx));
213     if (prop.isPartOfRestrictedPath()) _proxy.updateAllRestrictedModels(_session);
214   }
215
216   public void setStatusMessage(String JavaDoc msg, boolean isInformative)
217   {
218     _model.setStatusMessage(msg, isInformative);
219   }
220
221   public void setStatusMessage(String JavaDoc msg)
222   {
223     _model.setStatusMessage(msg);
224   }
225
226   public void setStatusMessage(Throwable JavaDoc t)
227   {
228     _model.setStatusMessage(t);
229   }
230
231   public boolean isDetail()
232   {
233     return _master != null;
234   }
235
236   public void setSelectionModel(ListSelectionModel JavaDoc selectionModel)
237   {
238     _table.setSelectionModel(selectionModel);
239   }
240
241   public boolean isInserteable()
242   {
243     return _model.isInsertable();
244   }
245
246   public boolean isEditable()
247   {
248     return _model.isEditable();
249   }
250
251   public boolean isDeleteable()
252   {
253     return _model.isDeleteable();
254   }
255
256   public void setMaster(ObjectViewer master, RelationUsage via)
257   {
258     _master = master;
259   }
260
261   public ObjectViewer getMaster()
262   {
263     return _master;
264   }
265
266   public void addDetailViewer(ObjectViewer detail, RelationUsage via)
267   {
268     _detailViewers.add(new ViewerLink(detail, via));
269     detail.setMaster(this, via);
270   }
271
272   protected void notifyTableChanged()
273   {
274     int idx = getSelectedIndex();
275     _table.tableChanged(new TableModelEvent JavaDoc(_model));
276     if (idx != -1 && idx < getRowCount()) _table.setRowSelectionInterval(idx, idx);
277
278   }
279
280   public void synchronizeProxy()
281   {
282     if (getSelectedIndex() == -1)
283     {
284       _proxy.clear();
285     }
286     else
287     {
288       _proxy.synchronize();
289     }
290   }
291
292   public void synchronize() throws DjenericException
293   {
294     notifyTableChanged();
295     synchronizeDetails();
296   }
297
298   public void synchronizeDetails() throws DjenericException
299   {
300     for (int i = 0; i < _detailViewers.size(); i++)
301     {
302       ViewerLink pl = (ViewerLink) _detailViewers.get(i);
303       if (getSelectedValue() == null)
304       {
305         pl.getViewer().clear();
306       }
307       else
308       {
309         String JavaDoc relationName = pl.getRelationUsage().getRelation().getName();
310         DjExtent detailExtent = pl.getRelationUsage().getDetail().getExtent();
311
312         DjAssociation currentAssociation = getSelectedValue().getDetailAssociationByName(relationName);
313
314         // Avoid sorting too many times: only when first loaded. So:
315
boolean shouldSort = !currentAssociation.isDetailsLoaded();
316         DjList lst = currentAssociation.getObjects();
317
318         if (shouldSort) lst.sort(pl.getViewer().getExtentUsage().getPropertySortIndices());
319         pl.getViewer().setViewerFor(lst, currentAssociation);
320         pl.getViewer().setEnabled(true);
321       }
322     }
323   }
324
325   public void clear() throws DjenericException
326   {
327     _table.setEnabled(false);
328     DjList lst = new DjList();
329     lst.setStoredTypeName(getExtent());
330     _model.setData(lst);
331     for (int i = 0; i < _detailViewers.size(); i++)
332     {
333       ViewerLink pl = (ViewerLink) _detailViewers.get(i);
334       pl.getViewer().clear();
335     }
336     synchronize();
337   }
338
339   public void setEnabled(boolean b)
340   {
341     _table.setEnabled(b);
342   }
343
344   public boolean isEnabled()
345   {
346     return _table.isEnabled();
347   }
348
349   public void setViewerFor(DjList theseObjects, DjAssociation assoc) throws DjenericException
350   {
351     if (_currentAssociation != assoc)
352     {
353       if (_currentAssociation != null) _currentAssociation.removeSynchronizationListener(this);
354       if (assoc != null) assoc.addSynchronizationListener(this);
355       _currentAssociation = assoc;
356     }
357
358     if (getSelectedIndex() != -1)
359     {
360       if (_table.isEditing()) _table.editingStopped(null);
361       _proxy.applyEditorsToProxy();
362     }
363     if (!_table.isEnabled())
364     {
365       _table.setEnabled(true);
366     }
367     _model.setData(theseObjects);
368     notifyTableChanged();
369
370     if (theseObjects.size() == 0)
371     {
372       setSelectedIndex(-1);
373     }
374     else
375     {
376       setSelectedIndex(0);
377     }
378
379     synchronizeDetails();
380
381   }
382
383   public boolean isNew()
384   {
385     DjObject obj = getSelectedValue();
386     if (obj == null)
387     {
388       return true;
389     }
390     return obj.isNew();
391   }
392
393   public boolean isNoObjectsPresent()
394   {
395     return _model.isNoObjectsPresent();
396   }
397
398   public void createNew() throws DjenericException
399   {
400     _table.insertRow();
401   }
402
403   public void markForDelete() throws DjenericException
404   {
405     _table.deleteRow();
406   }
407
408   public void doubleClick(MouseEvent JavaDoc e)
409   {
410     if (!_table.isEnabled())
411     {
412       return;
413     }
414
415     _table.requestFocus();
416     if (e.getClickCount() < 2)
417     {
418       return;
419     }
420
421     try
422     {
423       _table.insertRow();
424     }
425     catch (Exception JavaDoc x)
426     {
427       _model.setStatusMessage(x);
428     }
429
430   }
431
432   public void tellRowPosition()
433   {
434     setStatusMessage(Messages.getString("global.position", getExtent().getNameSingular(), String
435         .valueOf(getSelectedIndex() + 1), String.valueOf(_model.getRowCount())));
436   }
437
438   public void next() throws DjenericException
439   {
440     if (getSelectedIndex() < _model.getRowCount() - 1)
441     {
442       setSelectedIndex(getSelectedIndex() + 1);
443     }
444
445   }
446
447   public void top() throws DjenericException
448   {
449     int idx = 0;
450     if (_model.getRowCount() == 0) idx = -1;
451     if (getSelectedIndex() != -1) setSelectedIndex(idx);
452   }
453
454   public void bottom() throws DjenericException
455   {
456     if (getSelectedIndex() != _model.getRowCount() - 1) setSelectedIndex(_model.getRowCount() - 1);
457   }
458
459   public void prev() throws DjenericException
460   {
461     if (getSelectedIndex() > 0)
462     {
463       setSelectedIndex(getSelectedIndex() - 1);
464     }
465   }
466
467   public int getRowCount()
468   {
469     return _model.getRowCount();
470   }
471
472   public void setSelectedIndex(int idx) throws DjenericException
473   {
474     if (getSelectedIndex() != -1)
475     {
476       _proxy.applyEditorsToProxy();
477     }
478     setSelectedIndexWithoutApply(idx);
479   }
480
481   public void setSelectedIndexWithoutApply(int idx) throws DjenericException
482   {
483     if (idx == -1)
484     {
485       _table.clearSelection();
486     }
487     else
488     {
489       _table.setRowSelectionInterval(idx, idx);
490     }
491     synchronizeProxy();
492     synchronizeDetails();
493   }
494
495   public boolean isRestricted(int propertyUsageIdx) throws DjenericException
496   {
497     if (getSelectedIndex() == -1) return false;
498     return _model.isRestricted(getSelectedIndex(), propertyUsageIdx);
499   }
500
501   public void removeModelListener(ObjectModelListener lsnr)
502   {
503     _model.removeStatusListener(lsnr);
504   }
505
506   public void addModelListener(ObjectModelListener lsnr)
507   {
508     _model.addStatusListener(lsnr);
509   }
510
511   public void removeViewerListener(ObjectViewerListener lsnr)
512   {
513     _allListeners.remove(lsnr);
514   }
515
516   public void addViewerListener(ObjectViewerListener lsnr)
517   {
518     _allListeners.add(lsnr);
519   }
520
521   public boolean isCellUpdateable(int cellIdx)
522   {
523     return _usage.getPropertyUsage(_model.cellIdx2UsageIdx(cellIdx)).isUpdateable();
524   }
525
526   public boolean isCellRequired(int cellIdx)
527   {
528     return _usage.getPropertyUsage(_model.cellIdx2UsageIdx(cellIdx)).isRequired();
529   }
530
531   public PropertyUsage getPropertyUsage(int cellIdx)
532   {
533     return _usage.getPropertyUsage(_model.cellIdx2UsageIdx(cellIdx));
534   }
535
536   public PropertyUsage getPropertyUsageByName(String JavaDoc propertyName) throws ObjectNotDefinedException
537   {
538     return getPropertyUsage(getCellIndex(propertyName));
539   }
540
541   public int getPropertyUsageCount()
542   {
543     return _usage.getPropertyUsageCount();
544   }
545
546   public int getCellIndex(String JavaDoc propertyName) throws ObjectNotDefinedException
547   {
548     return _model.getCellIndex(propertyName);
549   }
550
551   public void rememberSelectedIndex()
552   {
553     _rememberedSelectedIndex = new int[_detailViewers.size() + 1];
554     _rememberedSelectedIndex[0] = getSelectedIndex();
555     for (int v = 0; v < _detailViewers.size(); v++)
556     {
557       ViewerLink pl = (ViewerLink) _detailViewers.get(v);
558       _rememberedSelectedIndex[v + 1] = pl.getViewer().getSelectedIndex();
559     }
560
561   }
562
563   public void returnToRemberedIndex() throws DjenericException
564   {
565     if (_rememberedSelectedIndex == null) return;
566
567     setSelectedIndex(_rememberedSelectedIndex[0]);
568     for (int v = 0; v < _detailViewers.size(); v++)
569     {
570       ViewerLink pl = (ViewerLink) _detailViewers.get(v);
571       pl.getViewer().setSelectedIndex(_rememberedSelectedIndex[v + 1]);
572     }
573   }
574
575   public void validateModel(boolean rememberIndices) throws DjenericException
576   {
577     if (rememberIndices) rememberSelectedIndex();
578
579     try
580     {
581       for (int i = 0; i < _model.getRowCount(); i++)
582       {
583         setSelectedIndex(i);
584         DjObject object = getSelectedValue();
585         _usage.checkRequiredProperties(object);
586         object.validate();
587         for (int v = 0; v < _detailViewers.size(); v++)
588         {
589           ViewerLink pl = (ViewerLink) _detailViewers.get(v);
590           pl.getViewer().validateModel(false);
591         }
592       }
593     }
594     catch (PropertyRequiredException prx)
595     {
596       // this will translate property names into prompts
597
if (prx.getMissingProperties().length > 0)
598       {
599         requestFocus(prx.getMissingProperties()[0]);
600       }
601       throw new ObjectViewerApplyException(this, prx);
602     }
603     if (rememberIndices) returnToRemberedIndex();
604   }
605
606   public void bindEditor(DjSession session, DjBindable comp, String JavaDoc propertyName)
607   {
608     _proxy.bindEditor(session, comp, propertyName);
609   }
610
611   public void unbindEditors()
612   {
613     _proxy.unbindEditors();
614     TableCellEditor JavaDoc ced = _table.getCellEditor();
615     if (ced != null) ced.cancelCellEditing();
616   }
617
618   // ListSelectionListener, row selection change of domains table:
619
public void valueChanged(ListSelectionEvent JavaDoc e)
620   {
621     try
622     {
623       synchronizeProxy();
624       synchronizeDetails();
625     }
626     catch (Exception JavaDoc x)
627     {
628       setStatusMessage(x);
629     }
630   }
631
632   public void requestFocus(String JavaDoc propertyName)
633   {
634     try
635     {
636       int idx = _usage.getPropertyUsageIndex(propertyName);
637       _table.requestFocus();
638       _table.setColumnSelectionInterval(idx, idx);
639     }
640     catch (Exception JavaDoc x)
641     {
642       DjLogger.log(x);
643     }
644   }
645
646   public void requestFocus()
647   {
648     _table.requestFocus();
649   }
650
651   public String JavaDoc getTitle()
652   {
653     return _usage.getTitle();
654   }
655
656   public void updateAllModels(DjSession session) throws DjenericException
657   {
658     _proxy.updateAllLookupModels(session);
659   }
660
661   public void updateDetailLinks() throws DjenericException
662   {
663     DjObject obj = getSelectedValue();
664     if (obj != null) obj.updateDetailObjectLinks();
665   }
666
667   public void focusGained(FocusEvent JavaDoc e)
668   {
669     focusReceived(_table);
670   }
671
672   public void focusLost(FocusEvent JavaDoc e)
673   {
674   }
675
676   public void focusReceived(Component JavaDoc component)
677   {
678     for (int i = 0; i < _allListeners.size(); i++)
679     {
680       ObjectViewerListener lsnr = (ObjectViewerListener) _allListeners.get(i);
681       lsnr.focusReceived(this, component);
682     }
683   }
684
685   public void reload() throws DjenericException
686   {
687     DjObject cp = getSelectedValue();
688     if (cp == null) return;
689
690     if (cp.isModified() && !cp.isNew())
691     {
692       int answ = JOptionPane.showOptionDialog(this, Messages.getString("global.ReloadDiscard", getExtent()
693           .getNameSingular()), Messages.getString("global.Reload"), JOptionPane.DEFAULT_OPTION,
694                                               JOptionPane.QUESTION_MESSAGE, null, new String JavaDoc[]{
695                                                   Messages.getString("global.Reload"),
696                                                   Messages.getString("global.Cancel")}, null);
697       if (answ != 0)
698       {
699         return;
700       }
701     }
702
703     if (!cp.isNew()) cp.reload();
704     synchronize();
705   }
706
707   public void synchNeeded(DjAssociation association, DjList added, DjList removed)
708   {
709     try
710     {
711       synchronize();
712     }
713     catch (Exception JavaDoc x)
714     {
715       setStatusMessage(x);
716     }
717   }
718
719   public void synchronizeUnderlyingAssociation() throws DjenericException
720   {
721     if (_currentAssociation != null) _currentAssociation.synchronizeWithSession();
722   }
723
724   public void synchronizeUsage()
725   {
726     // No need for this with tables
727
}
728
729   public void setDeleteable(boolean b)
730   {
731     _model.setDeleteable(b);
732   }
733
734   public void setEditable(boolean b)
735   {
736     _model.setEditable(b);
737   }
738
739   public void setInserteable(boolean b)
740   {
741     _model.setInsertable(b);
742   }
743
744   public void setInserteableRecursive(boolean b)
745   {
746     setInserteable(b);
747     for (int i = 0; i < _detailViewers.size(); i++)
748     {
749       ViewerLink pl = (ViewerLink) _detailViewers.get(i);
750       pl.getViewer().setInserteableRecursive(b);
751     }
752   }
753
754   public void setDeleteableRecursive(boolean b)
755   {
756     setDeleteable(b);
757     for (int i = 0; i < _detailViewers.size(); i++)
758     {
759       ViewerLink pl = (ViewerLink) _detailViewers.get(i);
760       pl.getViewer().setDeleteableRecursive(b);
761     }
762   }
763
764   public void setEditableRecursive(boolean b)
765   {
766     setEditable(b);
767     for (int i = 0; i < _detailViewers.size(); i++)
768     {
769       ViewerLink pl = (ViewerLink) _detailViewers.get(i);
770       pl.getViewer().setEditableRecursive(b);
771     }
772   }
773   
774   public void checkRequiredProperties() throws PropertyRequiredException
775   {
776     DjObject obj = getSelectedValue();
777     if (obj != null) obj.checkRequiredProperties();
778   }
779
780   public Object JavaDoc get(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
781   {
782     DjObject obj = getSelectedValue();
783     if (obj != null) return obj.get(propertyName);
784
785     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
786   }
787
788   public BigDecimal JavaDoc getBigDecimal(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
789   {
790     DjObject obj = getSelectedValue();
791     if (obj != null) return obj.getBigDecimal(propertyName);
792
793     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
794   }
795
796   public byte[] getBytes(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
797   {
798     DjObject obj = getSelectedValue();
799     if (obj != null) return obj.getBytes(propertyName);
800
801     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
802   }
803
804   public Date JavaDoc getDate(String JavaDoc propertyName) throws ObjectNotDefinedException, DjenericException
805   {
806     DjObject obj = getSelectedValue();
807     if (obj != null) return obj.getDate(propertyName);
808
809     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
810   }
811
812   public DjAssociation getDetailAssociationByName(String JavaDoc assocName) throws ObjectNotDefinedException, DjenericException
813   {
814     DjObject obj = getSelectedValue();
815     if (obj != null) return obj.getDetailAssociationByName(assocName);
816
817     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
818   }
819
820   public DjAssociation[] getDetailAssociations() throws DjenericException
821   {
822     DjObject obj = getSelectedValue();
823     if (obj != null) return obj.getDetailAssociations();
824
825     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
826   }
827
828   public int getInt(String JavaDoc propertyName) throws DjenericException
829   {
830     DjObject obj = getSelectedValue();
831     if (obj != null) return obj.getInt(propertyName);
832
833     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
834   }
835
836   public long getLong(String JavaDoc propertyName) throws DjenericException
837   {
838     DjObject obj = getSelectedValue();
839     if (obj != null) return obj.getLong(propertyName);
840
841     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
842   }
843
844   public long getObjectId() throws DjenericException
845   {
846     DjObject obj = getSelectedValue();
847     if (obj != null) return obj.getObjectId();
848
849     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
850   }
851
852   public String JavaDoc getString(String JavaDoc propertyName) throws DjenericException
853   {
854     DjObject obj = getSelectedValue();
855     if (obj != null) return obj.getString(propertyName);
856
857     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
858   }
859
860   public boolean isEmpty() throws DjenericException
861   {
862     DjObject obj = getSelectedValue();
863     if (obj != null) return obj.isEmpty();
864
865     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
866   }
867
868   public boolean isMarkedForDelete() throws DjenericException
869   {
870     DjObject obj = getSelectedValue();
871     if (obj != null) return obj.isMarkedForDelete();
872
873     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
874   }
875
876   public boolean isModified() throws DjenericException
877   {
878     DjObject obj = getSelectedValue();
879     if (obj != null) return obj.isModified();
880
881     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
882   }
883
884   public boolean isNull(String JavaDoc propertyName) throws DjenericException
885   {
886     DjObject obj = getSelectedValue();
887     if (obj != null) return obj.isNull(propertyName);
888
889     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
890   }
891
892   public boolean isPersisted() throws DjenericException
893   {
894     DjObject obj = getSelectedValue();
895     if (obj != null) return obj.isPersisted();
896
897     throw new DjenericException(Messages.getString("global.NoCurrentToGetFrom"));
898   }
899
900   public void set(String JavaDoc propertyName, Object JavaDoc value) throws DjenericException
901   {
902     DjObject obj = getSelectedValue();
903     if (obj != null) obj.set(propertyName, value);
904     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
905   }
906
907   public void setBigDecimal(String JavaDoc propertyName, BigDecimal JavaDoc value) throws DjenericException
908   {
909     DjObject obj = getSelectedValue();
910     if (obj != null) obj.setBigDecimal(propertyName, value);
911     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
912   }
913
914   public void setBytes(String JavaDoc propertyName, byte[] value) throws DjenericException
915   {
916     DjObject obj = getSelectedValue();
917     if (obj != null) obj.setBytes(propertyName, value);
918     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
919   }
920
921   public void setDate(String JavaDoc propertyName, Date JavaDoc dt) throws DjenericException
922   {
923     DjObject obj = getSelectedValue();
924     if (obj != null) obj.setDate(propertyName, dt);
925     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
926   }
927
928   public void setInt(String JavaDoc propertyName, int value) throws DjenericException
929   {
930     DjObject obj = getSelectedValue();
931     if (obj != null) obj.setInt(propertyName, value);
932     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
933   }
934
935   public void setInt(String JavaDoc propertyName, Integer JavaDoc value) throws DjenericException
936   {
937     DjObject obj = getSelectedValue();
938     if (obj != null) obj.setInt(propertyName, value);
939     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
940   }
941
942   public void setLong(String JavaDoc propertyName, long value) throws DjenericException
943   {
944     DjObject obj = getSelectedValue();
945     if (obj != null) obj.setLong(propertyName, value);
946     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
947   }
948
949   public void setLong(String JavaDoc propertyName, Long JavaDoc value) throws DjenericException
950   {
951     DjObject obj = getSelectedValue();
952     if (obj != null) obj.setLong(propertyName, value);
953     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
954   }
955
956   public void setNull(String JavaDoc propertyName) throws DjenericException
957   {
958     DjObject obj = getSelectedValue();
959     if (obj != null) obj.setNull(propertyName);
960     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
961   }
962
963   public void setString(String JavaDoc propertyName, String JavaDoc value) throws DjenericException
964   {
965     DjObject obj = getSelectedValue();
966     if (obj != null) obj.setString(propertyName, value);
967     else throw new DjenericException(Messages.getString("global.NoCurrentToSet"));
968   }
969
970   public boolean exists()
971   {
972     return getSelectedValue() != null;
973   }
974
975   class TableHelper extends DjTable
976   {
977     private static final long serialVersionUID = 1L;
978
979     public int insertRow() throws DjenericException
980     {
981       int result = super.insertRow();
982       if (result != -1)
983       {
984         if (_master != null) _master.updateDetailLinks();
985
986         for (int i = 0; i < _allListeners.size(); i++)
987         {
988           ObjectViewerListener lsnr = (ObjectViewerListener) _allListeners.get(i);
989           lsnr.afterRowInserted(_usage);
990         }
991         if (_allListeners.size() > 0) synchronize();
992         addColumnSelectionInterval(0, 0);
993       }
994       return result;
995     }
996
997     public Component JavaDoc prepareEditor(TableCellEditor JavaDoc editor, int row, int column)
998     {
999       try
1000      {
1001        if (_model.isRestricted(row, column))
1002        {
1003          setStatusMessage(Messages.getString("DjenericObjectTable.DependantDetails"), false);
1004          return null;
1005        }
1006      }
1007      catch (Exception JavaDoc x)
1008      {
1009        setStatusMessage(x);
1010      }
1011      return super.prepareEditor(editor, row, column);
1012    }
1013
1014    public boolean deleteRow() throws DjenericException
1015    {
1016      boolean result = super.deleteRow();
1017      if (result)
1018      {
1019        if (_model.getRowCount() == 0)
1020        {
1021          synchronizeDetails();
1022        }
1023        for (int i = 0; i < _allListeners.size(); i++)
1024        {
1025          ObjectViewerListener lsnr = (ObjectViewerListener) _allListeners.get(i);
1026          lsnr.afterRowDeleted(_usage);
1027        }
1028        synchronize();
1029      }
1030      return result;
1031    }
1032  };
1033}
Popular Tags