KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.genimen.djeneric.tools.specifier.editor;
2
3 import java.awt.BorderLayout JavaDoc;
4 import java.awt.Component JavaDoc;
5 import java.awt.Dimension JavaDoc;
6 import java.awt.Font JavaDoc;
7 import java.awt.event.ActionEvent JavaDoc;
8 import java.awt.event.FocusEvent JavaDoc;
9 import java.awt.event.FocusListener JavaDoc;
10 import java.util.HashMap JavaDoc;
11
12 import javax.swing.BorderFactory JavaDoc;
13 import javax.swing.JButton JavaDoc;
14 import javax.swing.JComponent JavaDoc;
15 import javax.swing.JLabel JavaDoc;
16 import javax.swing.JPanel JavaDoc;
17 import javax.swing.JScrollPane JavaDoc;
18 import javax.swing.JTabbedPane JavaDoc;
19 import javax.swing.border.Border JavaDoc;
20 import javax.swing.event.ChangeEvent JavaDoc;
21 import javax.swing.event.ChangeListener JavaDoc;
22
23 import com.genimen.djeneric.language.Messages;
24 import com.genimen.djeneric.repository.DjDomain;
25 import com.genimen.djeneric.repository.DjList;
26 import com.genimen.djeneric.repository.DjObject;
27 import com.genimen.djeneric.repository.exceptions.DjenericException;
28 import com.genimen.djeneric.structure.EditorDefinition;
29 import com.genimen.djeneric.structure.ExtentUsage;
30 import com.genimen.djeneric.structure.PropertyUsage;
31 import com.genimen.djeneric.structure.RelationUsage;
32 import com.genimen.djeneric.structure.ScriptDefinition;
33 import com.genimen.djeneric.tools.specifier.Specifier;
34 import com.genimen.djeneric.tools.specifier.base.AbstractEditorPanel;
35 import com.genimen.djeneric.tools.specifier.components.DjBindable;
36 import com.genimen.djeneric.tools.specifier.components.DjHtmlArea;
37 import com.genimen.djeneric.tools.specifier.components.DjTextArea;
38 import com.genimen.djeneric.tools.specifier.interfaces.ObjectViewer;
39 import com.genimen.djeneric.ui.Util;
40
41 public class EditorPanel extends AbstractEditorPanel implements ChangeListener JavaDoc, FocusListener JavaDoc
42 {
43   private static final long serialVersionUID = 1L;
44   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
45   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
46   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
47   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
48   JButton JavaDoc _butOk = new JButton JavaDoc();
49   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
50   JButton JavaDoc _butApply = new JButton JavaDoc();
51   JButton JavaDoc _butCancel = new JButton JavaDoc();
52   JButton JavaDoc _butUp = new JButton JavaDoc();
53   JButton JavaDoc _butDown = new JButton JavaDoc();
54   JButton JavaDoc _butBottom = new JButton JavaDoc();
55   JButton JavaDoc _butFirst = new JButton JavaDoc();
56   JButton JavaDoc _butDelete = new JButton JavaDoc();
57   JButton JavaDoc _butCreate = new JButton JavaDoc();
58   JLabel JavaDoc _lblExtent = new JLabel JavaDoc();
59   JPanel JavaDoc _content = new JPanel JavaDoc();
60   Border JavaDoc border1;
61   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
62   JButton JavaDoc _butRequery = new JButton JavaDoc();
63   HashMap JavaDoc _tabcontrols = new HashMap JavaDoc();
64
65   ObjectViewer _viewerWithFocus = null;
66   ObjectViewer _masterView = null;
67   EditorDefinition _editorDefinition;
68   ExtentUsage _editorStructure;
69
70   public void construct(EditorDefinition editorDefinition, DjList objects) throws Exception JavaDoc
71   {
72     setStatusMessageNow(Messages.getString("global.Loading"), true);
73
74     _editorDefinition = editorDefinition;
75
76     if (editorDefinition != null) _editorStructure = editorDefinition.getUsages();
77     else throw new DjenericException(Messages.getString("EditorPanel.NoEditor"));
78
79     boolean editorForNewObject = objects.size() == 0;
80
81     if (editorForNewObject)
82     {
83       DjObject obj = getSession().createObject(_editorStructure.getExtent());
84       objects.add(obj);
85     }
86
87     DjList lst = new DjList();
88     for (int i = 0; i < objects.size(); i++)
89     {
90       DjObject org = objects.getDjenericObjectAt(i);
91       DjObject copy = getSession().getObject(org.getExtent(), org.getObjectId());
92       lst.add(copy);
93     }
94     setMasterObjects(lst);
95
96     jbInit();
97
98     setStatusMessage(Specifier.OK_MSG, true);
99
100     buildEditor(_editorStructure, getMasterObjects());
101     if (editorForNewObject) setDefaultValues();
102
103     if (!shouldCommitAndCloseSession()) _butApply.setVisible(false);
104
105     ScriptDefinition script = editorDefinition.getScriptDefinition();
106
107     if (script != null && script.getCode() != null && script.getCode().trim().length() != 0)
108     {
109       setScript(script);
110
111       if (editorForNewObject)
112       {
113         DjObject obj = lst.getDjenericObjectAt(0);
114         beforeObjectCreated(_editorDefinition.getUsages(), obj);
115         afterRowInserted(_editorDefinition.getUsages());
116       }
117     }
118   }
119
120   protected void jbInit() throws Exception JavaDoc
121   {
122     border1 = BorderFactory.createEmptyBorder(0, 5, 0, 0);
123     this.setLayout(borderLayout1);
124     jPanel1.setLayout(borderLayout2);
125     _butOk.setText(Messages.getString("global.Ok"));
126     _butOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
127     {
128       public void actionPerformed(ActionEvent JavaDoc e)
129       {
130         _butOk_actionPerformed(e);
131       }
132     });
133     _butApply.setPreferredSize(new Dimension JavaDoc(24, 24));
134     _butApply.setIcon(Specifier.getImageIcon("save.gif"));
135
136     _butApply.setRequestFocusEnabled(true);
137     _butApply.setToolTipText(Messages.getString("global.ApplyAll"));
138     _butApply.addActionListener(new java.awt.event.ActionListener JavaDoc()
139     {
140       public void actionPerformed(ActionEvent JavaDoc e)
141       {
142         _butApply_actionPerformed(e);
143       }
144     });
145     _butCancel.setRequestFocusEnabled(true);
146     _butCancel.setText(Messages.getString("global.Cancel"));
147     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
148     {
149       public void actionPerformed(ActionEvent JavaDoc e)
150       {
151         _butCancel_actionPerformed(e);
152       }
153     });
154     _content.setLayout(borderLayout3);
155     _butRequery.addActionListener(new java.awt.event.ActionListener JavaDoc()
156     {
157       public void actionPerformed(ActionEvent JavaDoc e)
158       {
159         _butRequery_actionPerformed(e);
160       }
161     });
162     _butRequery.setRequestFocusEnabled(true);
163     _butRequery.setToolTipText(Messages.getString("EditorPanel.ReloadObject"));
164     _butRequery.setIcon(Specifier.getImageIcon("reload.gif"));
165     _butRequery.setPreferredSize(new Dimension JavaDoc(24, 24));
166     _butUp.setPreferredSize(new Dimension JavaDoc(24, 24));
167     _butUp.setIcon(Specifier.getImageIcon("up.gif"));
168     _butUp.setToolTipText(Messages.getString("global.PreviousInList"));
169     _butUp.setRequestFocusEnabled(true);
170     _butUp.addActionListener(new java.awt.event.ActionListener JavaDoc()
171     {
172       public void actionPerformed(ActionEvent JavaDoc e)
173       {
174         _butUp_actionPerformed(e);
175       }
176     });
177     _butDown.addActionListener(new java.awt.event.ActionListener JavaDoc()
178     {
179       public void actionPerformed(ActionEvent JavaDoc e)
180       {
181         _butDown_actionPerformed(e);
182       }
183     });
184     _butDown.setRequestFocusEnabled(true);
185     _butDown.setToolTipText(Messages.getString("global.NextInList"));
186     _butDown.setIcon(Specifier.getImageIcon("down.gif"));
187     _butDown.setPreferredSize(new Dimension JavaDoc(24, 24));
188     _butBottom.setPreferredSize(new Dimension JavaDoc(24, 24));
189     _butBottom.setIcon(Specifier.getImageIcon("bottom.gif"));
190     _butBottom.setToolTipText(Messages.getString("global.LastInList"));
191     _butBottom.setRequestFocusEnabled(true);
192     _butBottom.addActionListener(new java.awt.event.ActionListener JavaDoc()
193     {
194       public void actionPerformed(ActionEvent JavaDoc e)
195       {
196         _butBottom_actionPerformed(e);
197       }
198     });
199     _butFirst.setPreferredSize(new Dimension JavaDoc(24, 24));
200     _butFirst.setIcon(Specifier.getImageIcon("top.gif"));
201     _butFirst.setToolTipText(Messages.getString("global.FirstInList"));
202     _butFirst.setRequestFocusEnabled(true);
203     _butFirst.addActionListener(new java.awt.event.ActionListener JavaDoc()
204     {
205       public void actionPerformed(ActionEvent JavaDoc e)
206       {
207         _butFirst_actionPerformed(e);
208       }
209     });
210     _butDelete.addActionListener(new java.awt.event.ActionListener JavaDoc()
211     {
212       public void actionPerformed(ActionEvent JavaDoc e)
213       {
214         _butDelete_actionPerformed(e);
215       }
216     });
217     _butDelete.setRequestFocusEnabled(true);
218     _butDelete.setToolTipText(Messages.getString("global.DeleteCtrl"));
219     _butDelete.setIcon(Specifier.getImageIcon("delete.gif"));
220     _butDelete.setPreferredSize(new Dimension JavaDoc(24, 24));
221     _butCreate.addActionListener(new java.awt.event.ActionListener JavaDoc()
222     {
223       public void actionPerformed(ActionEvent JavaDoc e)
224       {
225         _butCreate_actionPerformed(e);
226       }
227     });
228     _butCreate.setRequestFocusEnabled(true);
229     _butCreate.setToolTipText(Messages.getString("global.CreateCtrl"));
230     _butCreate.setIcon(Specifier.getImageIcon("new.gif"));
231     _butCreate.setPreferredSize(new Dimension JavaDoc(24, 24));
232     this.add(jPanel1, BorderLayout.SOUTH);
233     jPanel1.add(jPanel2, BorderLayout.EAST);
234     jPanel2.add(_butCancel, null);
235     jPanel2.add(_butOk, null);
236     jPanel1.add(jPanel3, BorderLayout.WEST);
237     jPanel3.add(_butApply, null);
238     jPanel3.add(_butRequery, null);
239     jPanel3.add(_butUp, null);
240     jPanel3.add(_butDown, null);
241     jPanel3.add(_butFirst, null);
242     jPanel3.add(_butBottom, null);
243     jPanel3.add(_butCreate, null);
244     jPanel3.add(_butDelete, null);
245     jPanel1.add(_lblExtent, BorderLayout.CENTER);
246     this.add(_content, BorderLayout.CENTER);
247     Util.sizeButtons(jPanel2);
248   }
249
250   public void initializeUsage(ExtentUsage usageDef) throws DjenericException
251   {
252     if (usageDef != null)
253     {
254       _masterView.setDeleteable(usageDef.isDeleteAllowed());
255       _masterView.setInserteable(usageDef.isInsertAllowed());
256       _masterView.setEditable(usageDef.isEditAllowed());
257     }
258
259     if (!getSession().canCreate()) _masterView.setInserteableRecursive(false);
260     if (!getSession().canDelete()) _masterView.setDeleteableRecursive(false);
261     if (!getSession().canModify()) _masterView.setEditableRecursive(false);
262
263     if (!getSession().canCreate() && !getSession().canDelete() && !getSession().canModify())
264     {
265       _butApply.setEnabled(false);
266       _butOk.setEnabled(false);
267     }
268
269     _masterView.synchronize();
270     _masterView.synchronizeUsage();
271   }
272
273   void _butApply_actionPerformed(ActionEvent JavaDoc e)
274   {
275     try
276     {
277       apply();
278     }
279     catch (Exception JavaDoc x)
280     {
281       setStatusMessage(x);
282     }
283   }
284
285   public void requestFocus()
286   {
287     if (_masterView != null)
288     {
289       _masterView.requestFocus();
290     }
291   }
292
293   public void setSelectedIndexOfMaster(int index) throws DjenericException
294   {
295     _masterView.setSelectedIndex(index);
296   }
297
298   public void _butCancel_actionPerformed(ActionEvent JavaDoc e)
299   {
300     if (canClose()) close();
301   }
302
303   void _butOk_actionPerformed(ActionEvent JavaDoc e)
304   {
305     try
306     {
307       apply();
308       close();
309     }
310     catch (Exception JavaDoc x)
311     {
312       setStatusMessage(x);
313     }
314   }
315
316   protected void createMemoTabs(JTabbedPane JavaDoc tabs, ObjectViewer viewer, ExtentUsage editorStructure) throws Exception JavaDoc
317   {
318     for (int i = 0; i < editorStructure.getPropertyUsageCount(); i++)
319     {
320       PropertyUsage pu = editorStructure.getPropertyUsage(i);
321
322       if (DjDomain.isMemoComponent(pu.getComponentType()) && pu.isDisplayed())
323       {
324         if (pu.getComponentType() == DjDomain.COMP_MEMO) addDefaultMemo(tabs, viewer, pu);
325         else if (pu.getComponentType() == DjDomain.COMP_HTML_MEMO) addHtmlMemo(tabs, viewer, pu);
326         else if (pu.isCustomComponent()) try
327         {
328           addCustomMemo(tabs, viewer, pu);
329         }
330         catch (ClassNotFoundException JavaDoc cnf)
331         {
332           setStatusMessage(cnf);
333           // recover:
334
addDefaultMemo(tabs, viewer, pu);
335         }
336         else throw new DjenericException("Unknown component type: " + pu.getComponentType());
337       }
338     }
339   }
340
341   private void addCustomMemo(JTabbedPane JavaDoc tabs, ObjectViewer viewer, PropertyUsage pu) throws ClassNotFoundException JavaDoc,
342       InstantiationException JavaDoc, IllegalAccessException JavaDoc, DjenericException
343   {
344     String JavaDoc className = pu.getCustomEditorClass();
345     Class JavaDoc clz = Thread.currentThread().getContextClassLoader().loadClass(className);
346     Object JavaDoc o = clz.newInstance();
347
348     if (!(o instanceof DjBindable)) throw new DjenericException(Messages.getString("global.Implement", o.getClass()
349         .getName(), DjBindable.class.getName()));
350     DjBindable bind = (DjBindable) o;
351     bind.setPropertyName(pu.getPropertyName());
352     bind.setViewer(viewer);
353     viewer.bindEditor(getSession(), bind, pu.getPropertyName());
354
355     if (pu.getDescription() != null && pu.getDescription().trim().length() > 0)
356     {
357       bind.setToolTipText(pu.getDescription());
358     }
359
360     if (pu.getSeq() < 0) tabs.add((JComponent JavaDoc) bind, pu.getPrompt(), 0);
361     else tabs.add((JComponent JavaDoc) bind, pu.getPrompt());
362   }
363
364   private void addHtmlMemo(JTabbedPane JavaDoc tabs, ObjectViewer viewer, PropertyUsage pu) throws DjenericException
365   {
366     DjHtmlArea ta = new DjHtmlArea(viewer, pu.getPropertyName());
367     if (pu.getDescription() != null && pu.getDescription().trim().length() > 0)
368     {
369       ta.setToolTipText(pu.getDescription());
370     }
371
372     if (pu.getSeq() < 0) tabs.add(ta, pu.getPrompt(), 0);
373     else tabs.add(ta, pu.getPrompt());
374
375     viewer.bindEditor(getSession(), ta, pu.getPropertyName());
376   }
377
378   private void addDefaultMemo(JTabbedPane JavaDoc tabs, ObjectViewer viewer, PropertyUsage pu) throws DjenericException
379   {
380     DjTextArea ta = new DjTextArea(viewer, pu.getPropertyName());
381     if (pu.getDescription() != null && pu.getDescription().trim().length() > 0)
382     {
383       ta.setToolTipText(pu.getDescription());
384     }
385     ta.setLineWrap(false);
386     ta.setWrapStyleWord(false);
387     ta.setFont(new Font JavaDoc("Monospaced", 0, 11));
388     ta.setTabSize(2);
389     JScrollPane JavaDoc scr = new JScrollPane JavaDoc();
390     scr.getViewport().add(ta, null);
391     scr.setAutoscrolls(true);
392
393     if (pu.getSeq() < 0) tabs.add(scr, pu.getPrompt(), 0);
394     else tabs.add(scr, pu.getPrompt());
395
396     viewer.bindEditor(getSession(), ta, pu.getPropertyName());
397   }
398
399   protected ObjectViewer createDetailViewer(RelationUsage viaRel) throws Exception JavaDoc
400   {
401     ExtentUsage editorStructure = viaRel.getDetail();
402
403     ObjectViewer view = null;
404
405     if (editorStructure.isMultiRow())
406     {
407       view = new DjenericObjectTable(getSession(), editorStructure, getContextManager());
408       setSizeOfView(view, editorStructure);
409     }
410     else
411     {
412       view = new DjenericObjectForm(getSession(), editorStructure, getContextManager());
413     }
414
415     registerViewer(view);
416
417     return view;
418   }
419
420   public JTabbedPane JavaDoc getTabbedPane(String JavaDoc extentUsageId)
421   {
422     return (JTabbedPane JavaDoc) _tabcontrols.get(extentUsageId);
423   }
424
425   protected void recurseEditorTree(ObjectViewer masterViewer, ExtentUsage editorStructure, JPanel JavaDoc inPanel)
426       throws Exception JavaDoc
427   {
428     if ((editorStructure.getDetailRelationCount() > 0) || hasMemos(editorStructure))
429     {
430       JTabbedPane JavaDoc tabs = new JTabbedPane JavaDoc();
431
432       _tabcontrols.put(editorStructure.getId(), tabs);
433
434       tabs.addChangeListener(this);
435       tabs.addFocusListener(this);
436
437       inPanel.add(tabs, BorderLayout.CENTER);
438
439       for (int i = 0; i < editorStructure.getDetailRelationCount(); i++)
440       {
441         RelationUsage via = editorStructure.getDetailRelation(i);
442         ObjectViewer detailView = createDetailViewer(via);
443
444         masterViewer.addDetailViewer(detailView, via);
445
446         // Determine placement of the view. If it has detail place it north
447
// else use all available space (center)
448
String JavaDoc placement;
449
450         ExtentUsage detailEditor = via.getDetail();
451
452         if (via.getDetail().getDetailRelationCount() > 0 || hasMemos(detailEditor))
453         {
454           placement = BorderLayout.NORTH;
455         }
456         else
457         {
458           placement = BorderLayout.CENTER;
459         }
460         JPanel JavaDoc branch = new JPanel JavaDoc(new BorderLayout JavaDoc());
461         branch.add((Component JavaDoc) detailView, placement);
462         tabs.add(branch, via.getDetail().getTitle());
463         recurseEditorTree(detailView, via.getDetail(), branch);
464       }
465       createMemoTabs(tabs, masterViewer, editorStructure);
466     }
467   }
468
469   protected void buildEditor(ExtentUsage editorStructure, DjList dataForMasterModel) throws Exception JavaDoc
470   {
471     if (editorStructure == null)
472     {
473       throw new Exception JavaDoc(Messages.getString("EditorPanel.SorryNoEditor"));
474     }
475     if (editorStructure.isMultiRow())
476     {
477       _masterView = new DjenericObjectTable(getSession(), editorStructure, getContextManager());
478       setSizeOfView(_masterView, editorStructure);
479     }
480     else
481     {
482       _masterView = new DjenericObjectForm(getSession(), editorStructure, getContextManager());
483     }
484
485     registerViewer(_masterView);
486     _masterView.requestFocus();
487
488     String JavaDoc position;
489     if ((editorStructure.getDetailRelationCount() > 0) || hasMemos(editorStructure)) position = BorderLayout.NORTH;
490     else position = BorderLayout.CENTER;
491
492     _content.add((Component JavaDoc) _masterView, position);
493
494     recurseEditorTree(_masterView, editorStructure, _content);
495
496     dataForMasterModel.sort(editorStructure.getPropertySortIndices());
497     _masterView.setViewerFor(dataForMasterModel, null);
498     focusReceived(_masterView, null);
499   }
500
501   void _butRequery_actionPerformed(ActionEvent JavaDoc e)
502   {
503     try
504     {
505       getSession().resetValidValueLists();
506       if (_viewerWithFocus != null) _viewerWithFocus.reload();
507
508     }
509     catch (Exception JavaDoc x)
510     {
511       setStatusMessage(x.getMessage(), false);
512     }
513
514   }
515
516   void _butUp_actionPerformed(ActionEvent JavaDoc e)
517   {
518     try
519     {
520       if (_viewerWithFocus != null) _viewerWithFocus.prev();
521     }
522     catch (Exception JavaDoc x)
523     {
524       setStatusMessage(x.getMessage(), false);
525     }
526   }
527
528   void _butDown_actionPerformed(ActionEvent JavaDoc e)
529   {
530     try
531     {
532       if (_viewerWithFocus != null) _viewerWithFocus.next();
533     }
534     catch (Exception JavaDoc x)
535     {
536       setStatusMessage(x.getMessage(), false);
537     }
538   }
539
540   void _butBottom_actionPerformed(ActionEvent JavaDoc e)
541   {
542     try
543     {
544       if (_viewerWithFocus != null) _viewerWithFocus.bottom();
545     }
546     catch (Exception JavaDoc x)
547     {
548       setStatusMessage(x.getMessage(), false);
549     }
550   }
551
552   void _butFirst_actionPerformed(ActionEvent JavaDoc e)
553   {
554     try
555     {
556       if (_viewerWithFocus != null) _viewerWithFocus.top();
557     }
558     catch (Exception JavaDoc x)
559     {
560       setStatusMessage(x.getMessage(), false);
561     }
562   }
563
564   void _butDelete_actionPerformed(ActionEvent JavaDoc e)
565   {
566     try
567     {
568       if (_viewerWithFocus != null) _viewerWithFocus.markForDelete();
569     }
570     catch (Exception JavaDoc x)
571     {
572       setStatusMessage(x);
573     }
574   }
575
576   void _butCreate_actionPerformed(ActionEvent JavaDoc e)
577   {
578     try
579     {
580       if (_viewerWithFocus != null) _viewerWithFocus.createNew();
581     }
582     catch (Exception JavaDoc x)
583     {
584       setStatusMessage(x.getMessage(), false);
585     }
586
587   }
588
589   public void hideDefaultOkCCancelButtons(boolean hide)
590   {
591     _butOk.setVisible(!hide);
592     _butCancel.setVisible(!hide);
593   }
594
595   public void apply() throws DjenericException
596   {
597     // make sure all data is applied from the view to the underlying model:
598
for (int i = 0; i < getViewerCount(); i++)
599     {
600       ObjectViewer vw = getViewer(i);
601       // only validate masters since details will be validated by masters
602
if (!vw.isDetail())
603       {
604         vw.validateModel(true);
605       }
606     }
607
608     fireEditorEvent("validate");
609
610     if (shouldCommitAndCloseSession()) getSession().commit();
611     getSpecifierPanelContainer().editorApplied(this);
612
613     try
614     {
615       for (int i = 0; i < getViewerCount(); i++)
616       {
617         ObjectViewer vw = getViewer(i);
618         vw.updateAllModels(getSession());
619       }
620
621       if (getAssociatedTreeNode() != null) getAssociatedTreeNode().reload();
622     }
623     catch (Exception JavaDoc x)
624     {
625       // if this fails, do not let the apply fail!
626
}
627   }
628
629   public void focusReceived(ObjectViewer viewer, Component JavaDoc component)
630   {
631     _viewerWithFocus = viewer;
632     _lblExtent.setText(viewer.getExtentUsage().getTitle());
633
634     _butDelete.setEnabled(viewer.isDeleteable());
635     _butCreate.setEnabled(viewer.isInserteable());
636   }
637
638   public void stateChanged(ChangeEvent JavaDoc e)
639   {
640     updateSelectedViewer(e.getSource());
641   }
642
643   protected void updateSelectedViewer(Object JavaDoc src)
644   {
645     if (src instanceof JTabbedPane JavaDoc)
646     {
647       JTabbedPane JavaDoc tp = (JTabbedPane JavaDoc) src;
648       ObjectViewer vw = findObjectViewerChild(tp.getSelectedComponent());
649       if (vw != null)
650       {
651         focusReceived(vw, null);
652         tp.requestFocus();
653       }
654     }
655   }
656
657   public void registerEvent(String JavaDoc eventName, String JavaDoc eventTitle, String JavaDoc eventOption)
658   {
659     hideDefaultOkCCancelButtons(true);
660     registerAdditionalEvent(eventName, eventTitle, eventOption);
661   }
662
663   public void registerAdditionalEvent(String JavaDoc eventName, String JavaDoc eventTitle, String JavaDoc eventOption)
664   {
665     JButton JavaDoc newButton = new JButton JavaDoc();
666
667     newButton.setText(eventTitle);
668     newButton.setActionCommand(eventName + "," + eventOption);
669     newButton.addActionListener(new java.awt.event.ActionListener JavaDoc()
670     {
671       public void actionPerformed(ActionEvent JavaDoc e)
672       {
673         fireEditorEventAndHandleOption(e);
674       }
675     });
676     if (_butOk.isVisible())
677     {
678       jPanel2.add(newButton, null, 0);
679     }
680     else
681     {
682       jPanel2.add(newButton, null);
683     }
684     Util.sizeButtons(jPanel2);
685   }
686
687   public void focusGained(FocusEvent JavaDoc e)
688   {
689     updateSelectedViewer(e.getSource());
690   }
691
692   public void focusLost(FocusEvent JavaDoc e)
693   {
694   }
695
696   public String JavaDoc getTitle()
697   {
698     if (getMasterObjects().size() != 1)
699     {
700       return _editorStructure.getTitle();
701     }
702     String JavaDoc descr = getMasterObjects().getDjenericObjectAt(0).getDescriptor();
703     if (descr == null || descr.trim().length() == 0)
704     {
705       if (getMasterObjects().getDjenericObjectAt(0).isNew())
706       {
707         descr = _editorStructure.getExtent().getTitle() + "*";
708       }
709       else
710       {
711         descr = _editorStructure.getExtent().getTitle();
712       }
713     }
714     return descr;
715   }
716
717   protected boolean hasMemos(ExtentUsage editorStructure)
718   {
719     for (int i = 0; i < editorStructure.getPropertyUsageCount(); i++)
720     {
721       PropertyUsage pu = editorStructure.getPropertyUsage(i);
722       if (DjDomain.isMemoComponent(pu.getComponentType()))
723       {
724         return true;
725       }
726     }
727     return false;
728   }
729
730   protected void setSizeOfView(ObjectViewer viewer, ExtentUsage editorStructure)
731   {
732     int rows = editorStructure.getRowsDisplayed();
733     if (rows == 0)
734     {
735       rows = 4;
736     }
737
738     rows++;
739
740     JComponent JavaDoc vc = (JComponent JavaDoc) viewer;
741     if (rows > 0)
742     {
743       vc.setPreferredSize(new Dimension JavaDoc((int) vc.getPreferredSize().getWidth(), rows * 16 + 4));
744     }
745   }
746
747   protected void releaseEditors()
748   {
749     for (int i = 0; i < getViewerCount(); i++)
750     {
751       ObjectViewer vw = getViewer(i);
752       vw.unbindEditors();
753     }
754   }
755
756   protected void setDefaultValues() throws Exception JavaDoc
757   {
758     _masterView.getModel().setDefaults();
759     _masterView.synchronize();
760   }
761
762   protected void cleanup() throws DjenericException
763   {
764     releaseEditors();
765     if (shouldCommitAndCloseSession())
766     {
767       getSession().close();
768     }
769   }
770
771   public ObjectViewer getMasterView()
772   {
773     return _masterView;
774   }
775 }
Popular Tags