KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > modeler > extenteditor > ExtentEditor


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

27 package com.genimen.djeneric.tools.modeler.extenteditor;
28
29 import java.awt.BorderLayout JavaDoc;
30 import java.awt.Color JavaDoc;
31 import java.awt.Dimension JavaDoc;
32 import java.awt.event.ActionEvent JavaDoc;
33 import java.awt.event.FocusEvent JavaDoc;
34 import java.awt.event.KeyEvent JavaDoc;
35 import java.awt.event.MouseAdapter JavaDoc;
36 import java.awt.event.MouseEvent JavaDoc;
37 import java.util.ArrayList JavaDoc;
38 import java.util.Arrays JavaDoc;
39
40 import javax.swing.DefaultComboBoxModel JavaDoc;
41 import javax.swing.JButton JavaDoc;
42 import javax.swing.JCheckBox JavaDoc;
43 import javax.swing.JComboBox JavaDoc;
44 import javax.swing.JComponent JavaDoc;
45 import javax.swing.JLabel JavaDoc;
46 import javax.swing.JOptionPane JavaDoc;
47 import javax.swing.JPanel JavaDoc;
48 import javax.swing.JPopupMenu JavaDoc;
49 import javax.swing.JScrollPane JavaDoc;
50 import javax.swing.JTabbedPane JavaDoc;
51 import javax.swing.JTable JavaDoc;
52 import javax.swing.JTextArea JavaDoc;
53 import javax.swing.JTextField JavaDoc;
54 import javax.swing.JToolTip JavaDoc;
55
56 import com.genimen.djeneric.language.Messages;
57 import com.genimen.djeneric.repository.DjExtent;
58 import com.genimen.djeneric.repository.DjPackage;
59 import com.genimen.djeneric.repository.DjPersistenceManager;
60 import com.genimen.djeneric.repository.DjSession;
61 import com.genimen.djeneric.repository.exceptions.CatalogException;
62 import com.genimen.djeneric.repository.exceptions.DjenericException;
63 import com.genimen.djeneric.tools.modeler.ModelEditor;
64 import com.genimen.djeneric.tools.modeler.diagrammer.ExtentViewer;
65 import com.genimen.djeneric.ui.DjCloseable;
66 import com.genimen.djeneric.ui.DjFocusMeLater;
67 import com.genimen.djeneric.ui.DjMultiLineToolTip;
68 import com.genimen.djeneric.ui.DjPropertyPathCompleter;
69 import com.genimen.djeneric.ui.DjStatusListener;
70 import com.genimen.djeneric.ui.DjTable;
71 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
72 import com.genimen.djeneric.ui.Util;
73 import com.genimen.djeneric.util.DjLogger;
74 import com.genimen.djeneric.util.DjString;
75
76 public class ExtentEditor extends JPanel JavaDoc implements DjStatusListener, DjCloseable
77 {
78   private static final long serialVersionUID = 1L;
79   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
80   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
81   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
82   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
83   JLabel JavaDoc jLabel1 = new JLabel JavaDoc();
84   DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout();
85   JLabel JavaDoc jLabel2 = new JLabel JavaDoc();
86   JLabel JavaDoc jLabel3 = new JLabel JavaDoc();
87   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
88   JPanel JavaDoc jPanel4 = new JPanel JavaDoc();
89   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
90   JTextField JavaDoc _edtName = new JTextField JavaDoc();
91   JTextField JavaDoc _edtAlias = new JTextField JavaDoc();
92   DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout();
93   JTextField JavaDoc _edtObjectType = new JTextField JavaDoc();
94   JPanel JavaDoc jPanel5 = new JPanel JavaDoc();
95   BorderLayout JavaDoc borderLayout4 = new BorderLayout JavaDoc();
96   JScrollPane JavaDoc _scrProperties = new JScrollPane JavaDoc();
97   DjTable _grdProperties = new DjTable();
98   PropertyTableModel _propertyModel;
99   RelationTableModel _relationModel;
100
101   JPanel JavaDoc jPanel8 = new JPanel JavaDoc();
102   JPanel JavaDoc jPanel9 = new JPanel JavaDoc();
103   BorderLayout JavaDoc borderLayout5 = new BorderLayout JavaDoc();
104   JButton JavaDoc _butAccept = new JButton JavaDoc();
105   JButton JavaDoc _butCancel = new JButton JavaDoc();
106   DjExtent _extent;
107   DjExtent _scratchExtent;
108   ModelEditor _editor;
109   JTabbedPane JavaDoc _tabs = new JTabbedPane JavaDoc();
110   JScrollPane JavaDoc _scrRelations = new JScrollPane JavaDoc();
111   DjTable _grdRelations = new DjTable();
112   JScrollPane JavaDoc _scrDescription = new JScrollPane JavaDoc();
113   JTextArea JavaDoc _edtDescription = new JTextArea JavaDoc();
114   JPopupMenu JavaDoc jPopupMenu1 = new JPopupMenu JavaDoc();
115   JPanel JavaDoc jPanel11 = new JPanel JavaDoc();
116   JTextField JavaDoc _edtTitle = new JTextField JavaDoc();
117   JTextField JavaDoc _edtPlural = new JTextField JavaDoc();
118   DjVerticalFlowLayout verticalFlowLayout4 = new DjVerticalFlowLayout();
119   DjVerticalFlowLayout verticalFlowLayout3 = new DjVerticalFlowLayout();
120   JLabel JavaDoc jLabel6 = new JLabel JavaDoc();
121   JPanel JavaDoc jPanel7 = new JPanel JavaDoc();
122   JLabel JavaDoc jLabel5 = new JLabel JavaDoc();
123   JPanel JavaDoc jPanel6 = new JPanel JavaDoc();
124   JLabel JavaDoc jLabel4 = new JLabel JavaDoc();
125   JTextField JavaDoc _edtSingular = new JTextField JavaDoc();
126   JPanel JavaDoc jPanel12 = new JPanel JavaDoc();
127   BorderLayout JavaDoc borderLayout6 = new BorderLayout JavaDoc();
128   JPanel JavaDoc jPanel13 = new JPanel JavaDoc();
129   JPanel JavaDoc jPanel14 = new JPanel JavaDoc();
130   DjVerticalFlowLayout verticalFlowLayout5 = new DjVerticalFlowLayout();
131   DjVerticalFlowLayout verticalFlowLayout6 = new DjVerticalFlowLayout();
132   BorderLayout JavaDoc borderLayout7 = new BorderLayout JavaDoc();
133   ExtentViewer _extentViewer;
134   boolean _modelsModified = false;
135   JLabel JavaDoc jLabel7 = new JLabel JavaDoc();
136   JTextField JavaDoc _edtDescriptorExpression = new JTextField JavaDoc()
137                                                      {
138                                                        private static final long serialVersionUID = 1L;
139
140                                                        public JToolTip JavaDoc createToolTip()
141                                                        {
142                                                          DjMultiLineToolTip tip = new DjMultiLineToolTip();
143                                                          tip.setComponent(this);
144                                                          return tip;
145                                                        }
146                                                      };
147   JLabel JavaDoc jLabel8 = new JLabel JavaDoc();
148   JComboBox JavaDoc _cbbSuper = new JComboBox JavaDoc();
149   DefaultComboBoxModel JavaDoc _superModel;
150   JButton JavaDoc _butUp = new JButton JavaDoc();
151   JButton JavaDoc _butDelete = new JButton JavaDoc();
152   JButton JavaDoc _butDown = new JButton JavaDoc();
153   JButton JavaDoc _butBottom = new JButton JavaDoc();
154   JButton JavaDoc _butFirst = new JButton JavaDoc();
155   JPanel JavaDoc jPanel10 = new JPanel JavaDoc();
156   JButton JavaDoc _butCreate = new JButton JavaDoc();
157   JButton JavaDoc _butApply = new JButton JavaDoc();
158   JLabel JavaDoc jLabel9 = new JLabel JavaDoc();
159   JCheckBox JavaDoc _chkLarge = new JCheckBox JavaDoc();
160   JLabel JavaDoc _lblTransient = new JLabel JavaDoc();
161   JCheckBox JavaDoc _chkTransient = new JCheckBox JavaDoc();
162   JComboBox JavaDoc _cbbPackage = new JComboBox JavaDoc();
163   JLabel JavaDoc _lblPackage = new JLabel JavaDoc();
164   DjPackage _defaultPackage = new DjPackage("Default");
165
166   public ExtentEditor(ModelEditor editor, ExtentViewer extentViewer)
167   {
168     _extent = extentViewer.getExtent();
169     _extentViewer = extentViewer;
170     _scratchExtent = (DjExtent) _extent.clone();
171
172     _editor = editor;
173
174     try
175     {
176       ArrayList JavaDoc extents = new ArrayList JavaDoc();
177       extents.add(Messages.getString("global.none"));
178       extents.addAll(editor.getPersistenceManager().getExtentsAsArrayList());
179       extents.remove(extentViewer.getExtent());
180
181       _superModel = new DefaultComboBoxModel JavaDoc(extents.toArray(new Object JavaDoc[0]));
182       _cbbSuper.setModel(_superModel);
183       if (_scratchExtent.getSuper() == null)
184       {
185         _cbbSuper.setSelectedIndex(0);
186       }
187       else
188       {
189         _cbbSuper.setSelectedItem(_scratchExtent.getSuper());
190       }
191
192       ArrayList JavaDoc packages = new ArrayList JavaDoc();
193       packages.add(_defaultPackage);
194       packages.addAll(Arrays.asList(editor.getPersistenceManager().getPackages()));
195       _cbbPackage.setModel(new DefaultComboBoxModel JavaDoc(packages.toArray()));
196
197       jbInit();
198
199       _superModel = new DefaultComboBoxModel JavaDoc(extents.toArray(new Object JavaDoc[0]));
200
201       _edtName.setText(_scratchExtent.getName());
202       _edtDescriptorExpression.setText(_scratchExtent.getDescriptorExpression());
203       _edtAlias.setText(_scratchExtent.getInternalCode());
204       _edtObjectType.setText(_scratchExtent.getObjectType());
205       _edtDescription.setText(_scratchExtent.getDescription());
206       _edtTitle.setText(_scratchExtent.getTitle());
207       _edtSingular.setText(_scratchExtent.getNameSingular());
208       _edtPlural.setText(_scratchExtent.getNamePlural());
209       _edtDescription.setText(_scratchExtent.getDescription());
210       _chkLarge.setSelected(_scratchExtent.isLarge());
211       _chkTransient.setSelected(_scratchExtent.isTransient());
212
213       DjPackage current = _scratchExtent.getPackage();
214       if (current == null) current = _defaultPackage;
215
216       _cbbPackage.setSelectedItem(current);
217
218       _scrProperties.addMouseListener(new MouseAdapter JavaDoc()
219       {
220         public void mouseClicked(MouseEvent JavaDoc e)
221         {
222           doubleClick(e, _grdProperties);
223         }
224       });
225       _scrRelations.addMouseListener(new MouseAdapter JavaDoc()
226       {
227         public void mouseClicked(MouseEvent JavaDoc e)
228         {
229           doubleClick(e, _grdRelations);
230         }
231       });
232       _butAccept.setEnabled(_editor.isModelLocked());
233       _butApply.setEnabled(_editor.isModelLocked());
234       _butCreate.setEnabled(_editor.isModelLocked());
235       _butDelete.setEnabled(_editor.isModelLocked());
236       tableFirst(_grdProperties);
237       tableFirst(_grdRelations);
238       DjPropertyPathCompleter ppc = new DjPropertyPathCompleter(_scratchExtent, _edtDescriptorExpression);
239       ppc.addStatusListener(this);
240       validateDescriptorExpression();
241     }
242     catch (Exception JavaDoc ex)
243     {
244       JOptionPane.showMessageDialog(this, ex.getMessage());
245       _editor.closeCloseable(this);
246       DjLogger.log(ex);
247     }
248   }
249
250   public void requestFocus()
251   {
252     _edtName.requestFocus();
253   }
254
255   public void notifyNewExtent()
256   {
257     _edtName.setText("");
258     _edtAlias.setText("");
259     _edtPlural.setText("");
260     _edtSingular.setText("");
261     _edtObjectType.setText("");
262     _edtTitle.setText("");
263
264   }
265
266   void jbInit() throws Exception JavaDoc
267   {
268     _propertyModel = new PropertyTableModel(_editor.getPersistenceManager(), _scratchExtent);
269     _propertyModel.setEditable(_editor.isModelLocked());
270     _relationModel = new RelationTableModel(_editor.getPersistenceManager(), _scratchExtent);
271     _propertyModel.setEditable(_editor.isModelLocked());
272
273     this.setLayout(borderLayout1);
274     jPanel1.setLayout(borderLayout2);
275     jLabel1.setText(Messages.getString("global.Alias"));
276     jPanel2.setLayout(verticalFlowLayout1);
277     jLabel2.setText(Messages.getString("global.Name"));
278     jLabel3.setText(Messages.getString("ExtentEditor.ObjectType"));
279     jPanel3.setLayout(borderLayout3);
280     jPanel4.setLayout(verticalFlowLayout2);
281     _edtObjectType.setMinimumSize(new Dimension JavaDoc(126, 21));
282     _edtObjectType.setPreferredSize(new Dimension JavaDoc(190, 21));
283     _edtObjectType.setToolTipText(Messages.getString("ExtentEditor.NameOfClass"));
284     _edtObjectType.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
285     {
286       public void keyReleased(KeyEvent JavaDoc e)
287       {
288         applyPluralAndObjectType(e);
289       }
290     });
291     jPanel5.setLayout(borderLayout4);
292     jPanel8.setLayout(borderLayout5);
293     _butAccept.setText(Messages.getString("ExtentEditor.Accept"));
294     _butAccept.addActionListener(new java.awt.event.ActionListener JavaDoc()
295     {
296       public void actionPerformed(ActionEvent JavaDoc e)
297       {
298         _butAccept_actionPerformed(e);
299       }
300     });
301     _butCancel.setText(Messages.getString("global.Cancel"));
302     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
303     {
304       public void actionPerformed(ActionEvent JavaDoc e)
305       {
306         _butCancel_actionPerformed(e);
307       }
308     });
309     _edtAlias.setPreferredSize(new Dimension JavaDoc(190, 21));
310     _edtAlias.setToolTipText(Messages.getString("ExtentEditor.ShortIDCode"));
311     _edtName.setPreferredSize(new Dimension JavaDoc(190, 21));
312     _edtName.setToolTipText(Messages.getString("ExtentEditor.TheNameOfExtent"));
313     _edtDescriptorExpression.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 12));
314     _edtDescriptorExpression.setPreferredSize(new Dimension JavaDoc(450, 21));
315     _edtDescriptorExpression.setToolTipText(Messages.getString("global.Descriptor"));
316     _edtDescriptorExpression.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
317     {
318       public void keyReleased(KeyEvent JavaDoc e)
319       {
320         _edtDescriptorExpression_keyReleased(e);
321       }
322     });
323     _grdProperties.setModel(_propertyModel);
324     _grdRelations.setModel(_relationModel);
325     _edtDescription.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 12));
326     _edtDescription.setWrapStyleWord(false);
327     _edtTitle.setPreferredSize(new Dimension JavaDoc(190, 21));
328     _edtTitle.setToolTipText(Messages.getString("ExtentEditor.Title1"));
329     _edtPlural.setPreferredSize(new Dimension JavaDoc(190, 21));
330     _edtPlural.setToolTipText(Messages.getString("ExtentEditor.TitleForList"));
331     _edtPlural.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
332     {
333       public void keyReleased(KeyEvent JavaDoc e)
334       {
335         applyPluralAndObjectType(e);
336       }
337     });
338     verticalFlowLayout4.setHorizontalFill(false);
339     jLabel6.setText(Messages.getString("ExtentEditor.Plural"));
340     jPanel7.setLayout(verticalFlowLayout4);
341     jLabel5.setText(Messages.getString("ExtentEditor.Singular"));
342     jPanel6.setLayout(verticalFlowLayout3);
343     jLabel4.setText(Messages.getString("global.Title"));
344     _edtSingular.setPreferredSize(new Dimension JavaDoc(190, 21));
345     _edtSingular.setToolTipText(Messages.getString("ExtentEditor.TitleForSingle"));
346     jPanel12.setLayout(borderLayout6);
347     jPanel13.setLayout(verticalFlowLayout5);
348     jPanel14.setLayout(verticalFlowLayout6);
349     jPanel11.setLayout(borderLayout7);
350     jLabel7.setText(Messages.getString("ExtentEditor.DescriptorExpr"));
351     jLabel8.setText(Messages.getString("global.Super"));
352     _cbbSuper.addActionListener(new java.awt.event.ActionListener JavaDoc()
353     {
354       public void actionPerformed(ActionEvent JavaDoc e)
355       {
356         _cbbSuper_actionPerformed(e);
357       }
358     });
359     _cbbSuper.setPreferredSize(new Dimension JavaDoc(130, 21));
360     _cbbSuper.setToolTipText(Messages.getString("ExtentEditor.ExtentToInherit"));
361     _butUp.setPreferredSize(new Dimension JavaDoc(24, 24));
362     _butUp.setIcon(ModelEditor.getImageIcon("up.gif"));
363     _butUp.setToolTipText(Messages.getString("global.PreviousInList"));
364     //_butUp.setRequestFocusEnabled(true);
365
_butUp.addActionListener(new java.awt.event.ActionListener JavaDoc()
366     {
367       public void actionPerformed(ActionEvent JavaDoc e)
368       {
369         _butUp_actionPerformed(e);
370       }
371     });
372     _butDelete.addActionListener(new java.awt.event.ActionListener JavaDoc()
373     {
374       public void actionPerformed(ActionEvent JavaDoc e)
375       {
376         _butDelete_actionPerformed(e);
377       }
378     });
379     //_butDelete.setRequestFocusEnabled(true);
380
_butDelete.setToolTipText(Messages.getString("global.DeleteCtrl"));
381     _butDelete.setIcon(ModelEditor.getImageIcon("delete.gif"));
382     _butDelete.setPreferredSize(new Dimension JavaDoc(24, 24));
383     _butDown.addActionListener(new java.awt.event.ActionListener JavaDoc()
384     {
385       public void actionPerformed(ActionEvent JavaDoc e)
386       {
387         _butDown_actionPerformed(e);
388       }
389     });
390     //_butDown.setRequestFocusEnabled(true);
391
_butDown.setToolTipText(Messages.getString("global.NextInList"));
392     _butDown.setIcon(ModelEditor.getImageIcon("down.gif"));
393     _butDown.setPreferredSize(new Dimension JavaDoc(24, 24));
394     _butBottom.setPreferredSize(new Dimension JavaDoc(24, 24));
395     _butBottom.setIcon(ModelEditor.getImageIcon("bottom.gif"));
396     _butBottom.setToolTipText(Messages.getString("global.LastInList"));
397     //_butBottom.setRequestFocusEnabled(true);
398
_butBottom.addActionListener(new java.awt.event.ActionListener JavaDoc()
399     {
400       public void actionPerformed(ActionEvent JavaDoc e)
401       {
402         _butBottom_actionPerformed(e);
403       }
404     });
405     _butFirst.setPreferredSize(new Dimension JavaDoc(24, 24));
406     _butFirst.setIcon(ModelEditor.getImageIcon("top.gif"));
407     _butFirst.setToolTipText(Messages.getString("global.FirstInList"));
408     //_butFirst.setRequestFocusEnabled(true);
409
_butFirst.addActionListener(new java.awt.event.ActionListener JavaDoc()
410     {
411       public void actionPerformed(ActionEvent JavaDoc e)
412       {
413         _butFirst_actionPerformed(e);
414       }
415     });
416     _butCreate.setPreferredSize(new Dimension JavaDoc(24, 24));
417     _butCreate.setIcon(ModelEditor.getImageIcon("new.gif"));
418     _butCreate.setToolTipText(Messages.getString("global.CreateCtrl"));
419     //_butCreate.setRequestFocusEnabled(true);
420
_butCreate.addActionListener(new java.awt.event.ActionListener JavaDoc()
421     {
422       public void actionPerformed(ActionEvent JavaDoc e)
423       {
424         _butCreate_actionPerformed(e);
425       }
426     });
427     _butApply.setPreferredSize(new Dimension JavaDoc(24, 24));
428     _butApply.setIcon(ModelEditor.getImageIcon("save.gif"));
429     //_butApply.setRequestFocusEnabled(true);
430
_butApply.setToolTipText(Messages.getString("global.ApplyAll"));
431     _butApply.addActionListener(new java.awt.event.ActionListener JavaDoc()
432     {
433       public void actionPerformed(ActionEvent JavaDoc e)
434       {
435         _butApply_actionPerformed(e);
436       }
437     });
438     _scrDescription.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
439     _scrDescription.setAutoscrolls(true);
440     jLabel9.setToolTipText("");
441     jLabel9.setText(Messages.getString("ExtentEditor.LargeComplex"));
442     _chkLarge.setPreferredSize(new Dimension JavaDoc(190, 21));
443     _chkLarge.setToolTipText(Messages.getString("ExtentEditor.ComplexDescr"));
444     _chkLarge.setText("");
445     _lblTransient.setText(Messages.getString("ExtentEditor.Transient"));
446     _chkTransient.setToolTipText(Messages.getString("ExtentEditor.TransientDescr"));
447     _chkTransient.setText("");
448     _lblPackage.setText(Messages.getString("ExtentEditor.Package"));
449     jPanel2.add(jLabel2, null);
450     jPanel2.add(jLabel8, null);
451     jPanel2.add(jLabel1, null);
452     jPanel2.add(_lblPackage, null);
453     jPanel2.add(jLabel3, null);
454     jPanel2.add(jLabel9, null);
455     jPanel1.add(jPanel3, BorderLayout.CENTER);
456     jPanel3.add(jPanel4, BorderLayout.WEST);
457     jPanel4.add(_edtName, null);
458     jPanel4.add(_cbbSuper, null);
459     jPanel4.add(_edtAlias, null);
460     jPanel4.add(_cbbPackage, null);
461     jPanel4.add(_edtObjectType, null);
462     jPanel4.add(_chkLarge, null);
463     jPanel3.add(jPanel5, BorderLayout.CENTER);
464     jPanel5.add(jPanel11, BorderLayout.WEST);
465     jPanel7.add(_edtTitle, null);
466     jPanel7.add(_edtSingular, null);
467     jPanel7.add(_edtPlural, null);
468     jPanel7.add(_edtDescriptorExpression, null);
469     jPanel7.add(_chkTransient, null);
470     jPanel5.add(jPanel12, BorderLayout.CENTER);
471     jPanel12.add(jPanel13, BorderLayout.WEST);
472     jPanel12.add(jPanel14, BorderLayout.CENTER);
473     jPanel11.add(jPanel6, BorderLayout.WEST);
474     jPanel6.add(jLabel4, null);
475     jPanel6.add(jLabel5, null);
476     jPanel6.add(jLabel6, null);
477     jPanel6.add(jLabel7, null);
478     jPanel6.add(_lblTransient, null);
479     jPanel11.add(jPanel7, BorderLayout.CENTER);
480     this.add(jPanel1, BorderLayout.NORTH);
481     jPanel1.add(jPanel2, BorderLayout.WEST);
482     this.add(jPanel8, BorderLayout.SOUTH);
483     jPanel8.add(jPanel9, BorderLayout.EAST);
484     jPanel9.add(_butCancel, null);
485     jPanel9.add(_butAccept, null);
486     jPanel8.add(jPanel10, BorderLayout.WEST);
487     jPanel10.add(_butApply, null);
488     jPanel10.add(_butUp, null);
489     jPanel10.add(_butDown, null);
490     jPanel10.add(_butFirst, null);
491     jPanel10.add(_butBottom, null);
492     jPanel10.add(_butCreate, null);
493     jPanel10.add(_butDelete, null);
494     this.add(_tabs, BorderLayout.CENTER);
495     _tabs.add(_scrProperties, Messages.getString("ExtentEditor.Properties"));
496     _scrProperties.getViewport().add(_grdProperties, null);
497     _tabs.add(_scrRelations, Messages.getString("ExtentEditor.RelationsWithMaster"));
498     _tabs.add(_scrDescription, Messages.getString("ExtentEditor.ExtentDescription"));
499     _scrRelations.getViewport().add(_grdRelations, null);
500     _scrDescription.getViewport().add(_edtDescription, null);
501
502     _propertyModel.addStatusListener(this);
503     _relationModel.addStatusListener(this);
504     Util.sizeButtons(jPanel9);
505     Util.sizeLabels(jPanel2);
506     Util.sizeLabels(jPanel6);
507   }
508
509   public DjExtent getExtent()
510   {
511     return _extent;
512   }
513
514   public boolean isModified()
515   {
516     return !(stringsAreEqual(_edtDescriptorExpression.getText(), _extent.getDescriptorExpression())
517              && stringsAreEqual(_edtName.getText(), _extent.getName())
518              && stringsAreEqual(_edtAlias.getText(), _extent.getInternalCode())
519              && stringsAreEqual(_edtObjectType.getText(), _extent.getObjectType())
520              && stringsAreEqual(_edtTitle.getText(), _extent.getTitle())
521              && stringsAreEqual(_edtSingular.getText(), _extent.getNameSingular())
522              && stringsAreEqual(_edtPlural.getText(), _extent.getNamePlural())
523              && stringsAreEqual(_edtDescription.getText(), _extent.getDescription())
524              && _chkLarge.isSelected() == _extent.isLarge() && _chkTransient.isSelected() == _extent.isTransient() && !_modelsModified);
525   }
526
527   boolean stringsAreEqual(String JavaDoc str1, String JavaDoc str2)
528   {
529     if (str1 == null) str1 = "";
530     if (str2 == null) str2 = "";
531
532     return str1.equals(str2);
533   }
534
535   void updateSuperExtent()
536   {
537     Object JavaDoc superExtent = _cbbSuper.getSelectedItem();
538     if (!(superExtent instanceof DjExtent)) _scratchExtent.setSuper(null);
539     else _scratchExtent.setSuper((DjExtent) superExtent);
540
541     _propertyModel.fireTableStructureChanged();
542   }
543
544   void apply() throws Exception JavaDoc
545   {
546     defaultFields();
547
548     _propertyModel.autoAdjustMappings();
549     _scratchExtent.setName(_edtName.getText().trim());
550     _scratchExtent.setDescriptorExpression(_edtDescriptorExpression.getText().trim());
551     _scratchExtent.setAlias(_edtAlias.getText().trim());
552     _scratchExtent.setInternalCode(_edtAlias.getText().trim());
553     _scratchExtent.setObjectType(_edtObjectType.getText().trim());
554     _scratchExtent.setTitle(_edtTitle.getText().trim());
555     _scratchExtent.setNameSingular(_edtSingular.getText().trim());
556     _scratchExtent.setNamePlural(_edtPlural.getText().trim());
557     _scratchExtent.setDescription(_edtDescription.getText().trim());
558     _scratchExtent.setLarge(_chkLarge.isSelected());
559     _scratchExtent.setTransient(_chkTransient.isSelected());
560
561     DjPackage pack = (DjPackage) _cbbPackage.getSelectedItem();
562     if (pack == _defaultPackage) pack = null;
563     _scratchExtent.setPackage(pack);
564
565     updateSuperExtent();
566
567     _scratchExtent.validate(_editor.getPersistenceManager(), false);
568
569     DjSession session = null;
570     try
571     {
572       session = _editor.getPersistenceManager().createSession();
573
574       if (!_scratchExtent.getAlias().equals(_extent.getAlias()))
575       {
576         boolean isEmpty = true;
577
578         try
579         {
580           isEmpty = _extent.isEmpty(session);
581         }
582         catch (DjenericException de)
583         {
584           DjLogger.log(de);
585           setStatusMessage(Messages.getString("ExtentEditor.CouldNotDetermineContentsAliasUnchecked"), false);
586         }
587
588         if (!isEmpty)
589         {
590           _edtAlias.setText(_extent.getAlias());
591           throw new Exception JavaDoc(Messages.getString("ExtentEditor.DataFound"));
592         }
593       }
594     }
595     finally
596     {
597       if (session != null) session.close();
598     }
599
600     _scratchExtent.copyInto(_extent);
601     _editor.getPersistenceManager().rebuildDependancies();
602     _extent.sortProperties();
603
604     // ABSOLUTELY NECESSARY:
605
// this fixes any relation detail columns pointing to the old columns
606
_editor.validateModel(false);
607
608     _editor.fixInvalidReferences();
609     _editor.setStatusMessage(Messages.getString("ExtentEditor.ChangesApplied"));
610     _editor.getPersistenceManager().rebuildDependancies();
611     _modelsModified = false;
612   }
613
614   void _butApply_actionPerformed(ActionEvent JavaDoc e)
615   {
616     DjExtent temp = null;
617     try
618     {
619       temp = (DjExtent) _extent.clone();
620       apply();
621     }
622     catch (Exception JavaDoc x)
623     {
624       try
625       {
626         if (temp != null) temp.copyInto(_extent);
627       }
628       catch (Exception JavaDoc x2)
629       {
630         DjLogger.log(x2);
631         // Hmm, pity; could not revert. No serious harm done; validate on save
632
// will catch all.
633
}
634       _editor.setStatusMessage(x);
635     }
636   }
637
638   void _butAccept_actionPerformed(ActionEvent JavaDoc e)
639   {
640     DjExtent temp = null;
641     try
642     {
643       temp = (DjExtent) _extent.clone();
644       apply();
645       _editor.closeCloseable(this);
646     }
647     catch (Exception JavaDoc x)
648     {
649       try
650       {
651         if (temp != null) temp.copyInto(_extent);
652       }
653       catch (Exception JavaDoc x2)
654       {
655         // Hmm, pity; could not revert. No serious harm done; validate on save
656
// will catch all.
657
}
658       _editor.setStatusMessage(x);
659     }
660
661   }
662
663   void _butCancel_actionPerformed(ActionEvent JavaDoc e)
664   {
665     if (canClose()) _editor.closeCloseable(this);
666   }
667
668   public boolean canClose()
669   {
670     if (!isModified()) return true;
671     int result = JOptionPane.showOptionDialog(this, Messages.getString("ExtentEditor.DiscardChanges"), Messages
672         .getString("global.CloseEditor"), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
673                                               new String JavaDoc[]{Messages.getString("global.Discard"),
674                                                   Messages.getString("global.Cancel")}, null);
675     return result == 0;
676   }
677
678   public boolean close()
679   {
680     _editor.closeCloseable(this);
681     return true;
682   }
683
684   public void doubleClick(MouseEvent JavaDoc e, DjTable table)
685   {
686     table.requestFocus();
687     if (e.getClickCount() < 2) return;
688
689     try
690     {
691       table.insertRow();
692     }
693     catch (Exception JavaDoc x)
694     {
695       _editor.setStatusMessage(x);
696     }
697   }
698
699   public void setStatusMessage(String JavaDoc msg, boolean isInformative)
700   {
701     _editor.setStatusMessage(msg, isInformative);
702   }
703
704   public void setStatusMessage(Throwable JavaDoc t)
705   {
706     _editor.setStatusMessage(t);
707   }
708
709   public void notifyModified()
710   {
711     _modelsModified = true;
712   }
713
714   void _cbbSuper_actionPerformed(ActionEvent JavaDoc e)
715   {
716     updateSuperExtent();
717   }
718
719   void _field_focusGained(FocusEvent JavaDoc e)
720   {
721     if (e.getComponent() instanceof JComponent JavaDoc)
722     {
723       JComponent JavaDoc comp = DjFocusMeLater.getNeededComponent((JComponent JavaDoc) e.getComponent());
724       if (comp instanceof JTextField JavaDoc)
725       {
726         JTextField JavaDoc tf = (JTextField JavaDoc) e.getComponent();
727         tf.selectAll();
728       }
729     }
730   }
731
732   void defaultFields()
733   {
734     if (_edtAlias.getText().trim().length() == 0)
735     {
736       StringBuffer JavaDoc alias = new StringBuffer JavaDoc(_edtName.getText());
737       if (alias.length() > DjPersistenceManager.MAX_INTERNAL_CODE_LENGTH)
738       {
739         int i = 0;
740         while (i < alias.length())
741         {
742           if ("aAeEiIoOuU".indexOf(alias.charAt(i)) != -1) alias.deleteCharAt(i);
743           else i++;
744         }
745         if (alias.length() > DjPersistenceManager.MAX_INTERNAL_CODE_LENGTH)
746         {
747           alias = new StringBuffer JavaDoc(alias.substring(0, DjPersistenceManager.MAX_INTERNAL_CODE_LENGTH));
748         }
749         if (alias.length() == 0)
750         {
751           alias = new StringBuffer JavaDoc(_edtName.getText().trim()
752               .substring(0, DjPersistenceManager.MAX_INTERNAL_CODE_LENGTH));
753         }
754       }
755       _edtAlias.setText(alias.toString());
756     }
757
758     String JavaDoc title = DjString.initCapNoLowerCase(_edtName.getText().trim());
759
760     if (_edtObjectType.getText().trim().length() == 0) _edtObjectType.setText(title);
761
762     String JavaDoc suffix = "s";
763     if (title.endsWith(suffix)) suffix = "";
764     if (_edtPlural.getText().trim().length() == 0) _edtPlural.setText(title + suffix);
765     if (_edtSingular.getText().trim().length() == 0) _edtSingular.setText(title);
766     if (_edtTitle.getText().trim().length() == 0) _edtTitle.setText(title);
767     applyPluralAndObjectType(null);
768   }
769
770   private void tableFirst(JTable JavaDoc table)
771   {
772     if (table.getRowCount() <= 0) return;
773
774     table.setRowSelectionInterval(0, 0);
775   }
776
777   private void tableBottom(JTable JavaDoc table)
778   {
779     int row = table.getRowCount() - 1;
780     if (row != -1) table.setRowSelectionInterval(row, row);
781   }
782
783   private void tableUp(JTable JavaDoc table)
784   {
785     int row = table.getSelectedRow();
786     if (row > 0) table.setRowSelectionInterval(row - 1, row - 1);
787   }
788
789   private void tableDown(JTable JavaDoc table)
790   {
791     int row = table.getSelectedRow();
792     if (row < table.getRowCount() - 1) table.setRowSelectionInterval(row + 1, row + 1);
793   }
794
795   void _butDown_actionPerformed(ActionEvent JavaDoc e)
796   {
797     if (_tabs.getSelectedComponent() == _scrProperties) tableDown(_grdProperties);
798     else if (_tabs.getSelectedComponent() == _scrRelations) tableDown(_grdRelations);
799   }
800
801   void _butDelete_actionPerformed(ActionEvent JavaDoc e)
802   {
803     try
804     {
805       if (_tabs.getSelectedComponent() == _scrProperties) _grdProperties.deleteRow();
806       else if (_tabs.getSelectedComponent() == _scrRelations) _grdRelations.deleteRow();
807     }
808     catch (Exception JavaDoc x)
809     {
810       setStatusMessage(x.getMessage(), false);
811     }
812   }
813
814   void _butBottom_actionPerformed(ActionEvent JavaDoc e)
815   {
816     if (_tabs.getSelectedComponent() == _scrProperties) tableBottom(_grdProperties);
817     else if (_tabs.getSelectedComponent() == _scrRelations) tableBottom(_grdRelations);
818   }
819
820   void _butFirst_actionPerformed(ActionEvent JavaDoc e)
821   {
822     if (_tabs.getSelectedComponent() == _scrProperties) tableFirst(_grdProperties);
823     else if (_tabs.getSelectedComponent() == _scrRelations) tableFirst(_grdRelations);
824   }
825
826   void _butCreate_actionPerformed(ActionEvent JavaDoc e)
827   {
828     try
829     {
830       if (_tabs.getSelectedComponent() == _scrProperties) _grdProperties.insertRow();
831       else if (_tabs.getSelectedComponent() == _scrRelations) _grdRelations.insertRow();
832     }
833     catch (Exception JavaDoc x)
834     {
835       setStatusMessage(x.getMessage(), false);
836     }
837   }
838
839   void _butUp_actionPerformed(ActionEvent JavaDoc e)
840   {
841     if (_tabs.getSelectedComponent() == _scrProperties) tableUp(_grdProperties);
842     else if (_tabs.getSelectedComponent() == _scrRelations) tableUp(_grdRelations);
843   }
844
845   void applyPluralAndObjectType(KeyEvent JavaDoc e)
846   {
847     _scratchExtent.setNamePlural(_edtPlural.getText());
848     _scratchExtent.setObjectType(_edtObjectType.getText());
849   }
850
851   void _edtDescriptorExpression_keyReleased(KeyEvent JavaDoc e)
852   {
853     validateDescriptorExpression();
854   }
855
856   protected void validateDescriptorExpression()
857   {
858     try
859     {
860       _scratchExtent.setDescriptorExpression(_edtDescriptorExpression.getText());
861       _scratchExtent.validateDescriptorExpression();
862       _edtDescriptorExpression.setForeground(Color.black);
863     }
864     catch (CatalogException ce)
865     {
866       _edtDescriptorExpression.setForeground(Color.red);
867     }
868   }
869 }
Popular Tags