KickJava   Java API By Example, From Geeks To Geeks.

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


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
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * 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, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

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