KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > modeler > userperspective > EditorEditorPanel


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.modeler.userperspective;
31
32 import java.awt.BorderLayout JavaDoc;
33 import java.awt.Dimension JavaDoc;
34 import java.awt.FlowLayout JavaDoc;
35 import java.awt.event.ActionEvent JavaDoc;
36 import java.awt.event.KeyEvent JavaDoc;
37 import java.awt.event.MouseEvent JavaDoc;
38 import java.util.ArrayList JavaDoc;
39 import java.util.Collections JavaDoc;
40 import java.util.Iterator JavaDoc;
41
42 import javax.swing.DefaultComboBoxModel JavaDoc;
43 import javax.swing.JButton JavaDoc;
44 import javax.swing.JCheckBox JavaDoc;
45 import javax.swing.JLabel JavaDoc;
46 import javax.swing.JList JavaDoc;
47 import javax.swing.JOptionPane JavaDoc;
48 import javax.swing.JPanel JavaDoc;
49 import javax.swing.JScrollPane JavaDoc;
50 import javax.swing.JTabbedPane JavaDoc;
51 import javax.swing.JTable JavaDoc;
52 import javax.swing.JTextField JavaDoc;
53 import javax.swing.JTree JavaDoc;
54 import javax.swing.event.TreeExpansionEvent JavaDoc;
55 import javax.swing.event.TreeSelectionEvent JavaDoc;
56 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
57 import javax.swing.tree.DefaultTreeModel JavaDoc;
58 import javax.swing.tree.ExpandVetoException JavaDoc;
59 import javax.swing.tree.TreeNode JavaDoc;
60 import javax.swing.tree.TreePath JavaDoc;
61
62 import com.genimen.djeneric.language.Messages;
63 import com.genimen.djeneric.repository.DjExtent;
64 import com.genimen.djeneric.repository.DjRelation;
65 import com.genimen.djeneric.repository.exceptions.DjenericException;
66 import com.genimen.djeneric.structure.EditorDefinition;
67 import com.genimen.djeneric.structure.ExtentUsage;
68 import com.genimen.djeneric.structure.RelationDescriptor;
69 import com.genimen.djeneric.structure.RelationUsage;
70 import com.genimen.djeneric.tools.modeler.ModelEditor;
71 import com.genimen.djeneric.ui.DjCloseable;
72 import com.genimen.djeneric.ui.DjCloseableCloser;
73 import com.genimen.djeneric.ui.DjTable;
74 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
75 import com.genimen.djeneric.ui.Util;
76 import com.genimen.djeneric.util.DjLogger;
77 import com.genimen.djeneric.util.DjStringComparator;
78
79 /**
80  * Description of the Class
81  *
82  * @author Wido Riezebos @created 5 juni 2002
83  */

84 public class EditorEditorPanel extends JPanel JavaDoc implements DjCloseable
85 {
86   private static final long serialVersionUID = 1L;
87   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
88   ExtentUsageNode _root;
89   DefaultTreeModel JavaDoc _treeModel;
90   ExtentNodeRenderer _treeCellRendrer = new ExtentNodeRenderer();
91
92   ViewEditor _viewEditor;
93   ModelEditor _modelEditor;
94   JPanel JavaDoc jPanel5 = new JPanel JavaDoc();
95   JPanel JavaDoc jPanel4 = new JPanel JavaDoc();
96   DjVerticalFlowLayout verticalFlowLayout = new DjVerticalFlowLayout();
97   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
98   JCheckBox JavaDoc _chkEditAllowed = new JCheckBox JavaDoc();
99   JScrollPane JavaDoc jScrollPane5 = new JScrollPane JavaDoc();
100   JScrollPane JavaDoc _scrProperties = new JScrollPane JavaDoc();
101   JScrollPane JavaDoc jScrollPane3 = new JScrollPane JavaDoc();
102   JPanel JavaDoc jPanel11 = new JPanel JavaDoc();
103   JButton JavaDoc _butAdd = new JButton JavaDoc();
104   BorderLayout JavaDoc borderLayout10 = new BorderLayout JavaDoc();
105   JCheckBox JavaDoc _chkInsertAllowed = new JCheckBox JavaDoc();
106   JButton JavaDoc _butDown = new JButton JavaDoc();
107   BorderLayout JavaDoc borderLayout9 = new BorderLayout JavaDoc();
108   BorderLayout JavaDoc borderLayout6 = new BorderLayout JavaDoc();
109   JButton JavaDoc _butDelete = new JButton JavaDoc();
110   JButton JavaDoc _butUp = new JButton JavaDoc();
111   JLabel JavaDoc jLabel6 = new JLabel JavaDoc();
112   JLabel JavaDoc jLabel4 = new JLabel JavaDoc();
113   JTextField JavaDoc _edtNodeTitle = new JTextField JavaDoc();
114   JLabel JavaDoc _lblExtentName = new JLabel JavaDoc();
115   JTree JavaDoc _tree = new JTree JavaDoc();
116   JList JavaDoc _lstExtents = new JList JavaDoc();
117   JPanel JavaDoc jPanel2 = new JPanel JavaDoc();
118   JPanel JavaDoc jPanel6 = new JPanel JavaDoc();
119   BorderLayout JavaDoc borderLayout4 = new BorderLayout JavaDoc();
120   JPanel JavaDoc jPanel7 = new JPanel JavaDoc();
121   JPanel JavaDoc jPanel8 = new JPanel JavaDoc();
122   DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout();
123   DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout();
124   DjVerticalFlowLayout verticalFlowLayout3 = new DjVerticalFlowLayout();
125   DjTable _tabProperties = new DjTable();
126   PropertyUsageTableModel _emptyModel = new PropertyUsageTableModel(null);
127   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
128   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
129   DjVerticalFlowLayout verticalFlowLayout4 = new DjVerticalFlowLayout();
130   JCheckBox JavaDoc _chkMultiRow = new JCheckBox JavaDoc();
131   JPanel JavaDoc jPanel9 = new JPanel JavaDoc();
132   JCheckBox JavaDoc _chkDeleteAllowed = new JCheckBox JavaDoc();
133   JPanel JavaDoc jPanel12 = new JPanel JavaDoc();
134   DjVerticalFlowLayout verticalFlowLayout5 = new DjVerticalFlowLayout();
135   JLabel JavaDoc jLabel1 = new JLabel JavaDoc();
136   JTextField JavaDoc _edtRowsDisplayed = new JTextField JavaDoc();
137   JPanel JavaDoc jPanel13 = new JPanel JavaDoc();
138   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
139   JPanel JavaDoc jPanel14 = new JPanel JavaDoc();
140   JButton JavaDoc _butAddAll = new JButton JavaDoc();
141   JLabel JavaDoc jLabel2 = new JLabel JavaDoc();
142   JTextField JavaDoc _edtNodeId = new JTextField JavaDoc();
143   JTabbedPane JavaDoc _tabs = new JTabbedPane JavaDoc();
144   BorderLayout JavaDoc borderLayout8 = new BorderLayout JavaDoc();
145   JPanel JavaDoc jPanel20 = new JPanel JavaDoc();
146   BorderLayout JavaDoc borderLayout13 = new BorderLayout JavaDoc();
147   JPanel JavaDoc _pnlEditorStructure = new JPanel JavaDoc();
148   ScriptEditorPanel _pnlScript;
149   JPanel JavaDoc jPanel10 = new JPanel JavaDoc();
150   FlowLayout JavaDoc flowLayout1 = new FlowLayout JavaDoc();
151   JButton JavaDoc _butOk = new JButton JavaDoc();
152   JButton JavaDoc _butCancel = new JButton JavaDoc();
153   DjCloseableCloser _closer;
154   EditorDefinition _currentEditorDefinition;
155   EditorDefinition _scratchEditorDefinition;
156   JPanel JavaDoc jPanel15 = new JPanel JavaDoc();
157   JLabel JavaDoc jLabel3 = new JLabel JavaDoc();
158   BorderLayout JavaDoc borderLayout5 = new BorderLayout JavaDoc();
159   JTextField JavaDoc _edtEditorName = new JTextField JavaDoc();
160   JPanel JavaDoc jPanel16 = new JPanel JavaDoc();
161   BorderLayout JavaDoc borderLayout7 = new BorderLayout JavaDoc();
162   JPanel JavaDoc jPanel17 = new JPanel JavaDoc();
163   JPanel JavaDoc jPanel18 = new JPanel JavaDoc();
164   DjVerticalFlowLayout verticalFlowLayout6 = new DjVerticalFlowLayout();
165   DjVerticalFlowLayout verticalFlowLayout7 = new DjVerticalFlowLayout();
166   JLabel JavaDoc jLabel5 = new JLabel JavaDoc();
167   JCheckBox JavaDoc _chkCustomEditor = new JCheckBox JavaDoc();
168   JTextField JavaDoc _edtCustomClassName = new JTextField JavaDoc();
169   JPanel JavaDoc jPanel19 = new JPanel JavaDoc();
170   BorderLayout JavaDoc borderLayout11 = new BorderLayout JavaDoc();
171
172   /**
173    * Constructor for the EditorEditor object
174    */

175   public EditorEditorPanel(DjCloseableCloser closer, ViewEditor viewEditor, EditorDefinition editorDef)
176   {
177     try
178     {
179       _currentEditorDefinition = editorDef;
180
181       EditorDefinition scratch = (EditorDefinition) editorDef.clone();
182       _closer = closer;
183       _modelEditor = viewEditor.getModelEditor();
184       _viewEditor = viewEditor;
185
186       _pnlScript = new ScriptEditorPanel();
187       _pnlScript.setScriptType(ScriptEditorPanel.SCRIPT_TYPE_EMBEDDED);
188       _pnlScript.setPersistenceManager(_modelEditor.getPersistenceManager());
189       _pnlScript.setOkCancelButtonVisible(false);
190
191       jbInit();
192
193       _butAdd.setIcon(ModelEditor.getImageIcon("add.gif"));
194       _butDelete.setIcon(ModelEditor.getImageIcon("remove.gif"));
195       _butUp.setIcon(ModelEditor.getImageIcon("up.gif"));
196       _butDown.setIcon(ModelEditor.getImageIcon("down.gif"));
197       _tree.putClientProperty("JTree.lineStyle", "Angled");
198
199       setSelectedEditor(scratch);
200
201       // Set the script AFTER setting the scratch editor as current; as it is used by the
202
// script editor to validate references to the editor's blocks
203
_pnlScript.setScriptDefinition(scratch.getScriptDefinition());
204     }
205     catch (Exception JavaDoc ex)
206     {
207       JOptionPane.showMessageDialog(this, ex.getMessage());
208       DjLogger.log(ex);
209     }
210   }
211
212   public EditorDefinition getCurrentEditorDefinition()
213   {
214     return _currentEditorDefinition;
215   }
216
217   void jbInit() throws Exception JavaDoc
218   {
219     this.setLayout(borderLayout1);
220     jPanel5.setLayout(verticalFlowLayout2);
221     jPanel4.setLayout(borderLayout10);
222     jPanel1.setLayout(borderLayout9);
223     jScrollPane5.setPreferredSize(new Dimension JavaDoc(300, 131));
224     jScrollPane3.setPreferredSize(new Dimension JavaDoc(320, 100));
225     jPanel11.setLayout(borderLayout6);
226     _butAdd.setPreferredSize(new Dimension JavaDoc(24, 24));
227     _butAdd.setToolTipText(Messages.getString("EditorEditorPanel.CreateDetailBasedOn"));
228     _butAdd.addActionListener(new java.awt.event.ActionListener JavaDoc()
229     {
230       public void actionPerformed(ActionEvent JavaDoc e)
231       {
232         _butAdd_actionPerformed(e);
233       }
234     });
235     _butDown.setPreferredSize(new Dimension JavaDoc(24, 24));
236     _butDown.setToolTipText(Messages.getString("global.MoveDown"));
237     _butDown.addActionListener(new java.awt.event.ActionListener JavaDoc()
238     {
239       public void actionPerformed(ActionEvent JavaDoc e)
240       {
241         _butDown_actionPerformed(e);
242       }
243     });
244     _butDelete.setPreferredSize(new Dimension JavaDoc(24, 24));
245     _butDelete.setToolTipText(Messages.getString("EditorEditorPanel.RemoveDetail"));
246     _butDelete.addActionListener(new java.awt.event.ActionListener JavaDoc()
247     {
248       public void actionPerformed(ActionEvent JavaDoc e)
249       {
250         _butDelete_actionPerformed(e);
251       }
252     });
253     _butUp.setPreferredSize(new Dimension JavaDoc(24, 24));
254     _butUp.setToolTipText(Messages.getString("global.MoveUp"));
255     _butUp.addActionListener(new java.awt.event.ActionListener JavaDoc()
256     {
257       public void actionPerformed(ActionEvent JavaDoc e)
258       {
259         _butUp_actionPerformed(e);
260       }
261     });
262     jLabel6.setText(Messages.getString("global.Extent"));
263     jLabel4.setText(Messages.getString("global.Title"));
264     _tree.setCellRenderer(_treeCellRendrer);
265     _tree.setShowsRootHandles(false);
266     _tree.addTreeWillExpandListener(new javax.swing.event.TreeWillExpandListener JavaDoc()
267     {
268       public void treeWillExpand(TreeExpansionEvent JavaDoc e)
269       {
270       }
271
272       public void treeWillCollapse(TreeExpansionEvent JavaDoc e) throws ExpandVetoException JavaDoc
273       {
274         _tree_treeWillCollapse(e);
275       }
276     });
277     _tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener JavaDoc()
278     {
279       public void valueChanged(TreeSelectionEvent JavaDoc e)
280       {
281         _tree_valueChanged(e);
282       }
283     });
284     _tree.setAutoscrolls(true);
285     _lstExtents.addMouseListener(new java.awt.event.MouseAdapter JavaDoc()
286     {
287       public void mouseClicked(MouseEvent JavaDoc e)
288       {
289         _lstExtents_mouseClicked(e);
290       }
291     });
292     _chkEditAllowed.addActionListener(new java.awt.event.ActionListener JavaDoc()
293     {
294       public void actionPerformed(ActionEvent JavaDoc e)
295       {
296         _chkEditAllowed_actionPerformed(e);
297       }
298     });
299     _chkInsertAllowed.addActionListener(new java.awt.event.ActionListener JavaDoc()
300     {
301       public void actionPerformed(ActionEvent JavaDoc e)
302       {
303         _chkInsertAllowed_actionPerformed(e);
304       }
305     });
306     jPanel2.setLayout(verticalFlowLayout3);
307     jPanel6.setLayout(borderLayout4);
308     jPanel7.setLayout(verticalFlowLayout1);
309     jPanel8.setLayout(verticalFlowLayout);
310     _chkEditAllowed.setText(Messages.getString("global.EditAllowed"));
311     _chkInsertAllowed.setText(Messages.getString("global.Insertallowed"));
312     _tabProperties.setAutoCreateColumnsFromModel(false);
313     _tabProperties.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
314     _scrProperties.addMouseListener(new java.awt.event.MouseAdapter JavaDoc()
315     {
316       public void mouseClicked(MouseEvent JavaDoc e)
317       {
318         _scrProperties_mouseClicked(e);
319       }
320     });
321     _edtNodeTitle.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
322     {
323       public void keyReleased(KeyEvent JavaDoc e)
324       {
325         _edtNodeTitle_keyReleased(e);
326       }
327     });
328     jPanel3.setLayout(borderLayout2);
329     _chkMultiRow.addActionListener(new java.awt.event.ActionListener JavaDoc()
330     {
331       public void actionPerformed(ActionEvent JavaDoc e)
332       {
333         _chkMultiRow_actionPerformed(e);
334       }
335     });
336     _chkMultiRow.setText(Messages.getString("EditorEditorPanel.MultiRow"));
337     jPanel9.setLayout(verticalFlowLayout4);
338     _chkDeleteAllowed.addActionListener(new java.awt.event.ActionListener JavaDoc()
339     {
340       public void actionPerformed(ActionEvent JavaDoc e)
341       {
342         _chkDeleteAllowed_actionPerformed(e);
343       }
344     });
345     _chkDeleteAllowed.setText(Messages.getString("global.DeleteAllowed"));
346     jPanel12.setLayout(verticalFlowLayout5);
347     jLabel1.setText(" ");
348     _edtRowsDisplayed.setPreferredSize(new Dimension JavaDoc(40, 21));
349     _edtRowsDisplayed.setToolTipText(Messages.getString("EditorEditorPanel.RowsDsp"));
350     _edtRowsDisplayed.setText("5");
351     _edtRowsDisplayed.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
352     {
353       public void keyReleased(KeyEvent JavaDoc e)
354       {
355         _edtRowsDisplayed_keyReleased(e);
356       }
357     });
358     verticalFlowLayout5.setHorizontalFill(false);
359     jPanel13.setLayout(borderLayout3);
360     _butAddAll.setText(Messages.getString("EditorEditorPanel.AddAll"));
361     _butAddAll.addActionListener(new java.awt.event.ActionListener JavaDoc()
362     {
363       public void actionPerformed(ActionEvent JavaDoc e)
364       {
365         _butAddAll_actionPerformed(e);
366       }
367     });
368     jLabel2.setText(Messages.getString("global.ID"));
369     _edtNodeId.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
370     {
371       public void keyReleased(KeyEvent JavaDoc e)
372       {
373         _edtNodeId_keyReleased(e);
374       }
375     });
376     _pnlEditorStructure.setLayout(borderLayout8);
377     _scrProperties.setPreferredSize(new Dimension JavaDoc(10, 10));
378     jPanel20.setLayout(borderLayout13);
379     jPanel10.setLayout(flowLayout1);
380     flowLayout1.setAlignment(FlowLayout.RIGHT);
381     _butOk.setText(Messages.getString("global.Ok"));
382     _butOk.addActionListener(new java.awt.event.ActionListener JavaDoc()
383     {
384       public void actionPerformed(ActionEvent JavaDoc e)
385       {
386         _butOk_actionPerformed(e);
387       }
388     });
389     _butCancel.setText(Messages.getString("global.Cancel"));
390     _butCancel.addActionListener(new java.awt.event.ActionListener JavaDoc()
391     {
392       public void actionPerformed(ActionEvent JavaDoc e)
393       {
394         _butCancel_actionPerformed(e);
395       }
396     });
397     jPanel15.setLayout(borderLayout5);
398     jLabel3.setText(Messages.getString("EditorEditorPanel.EditorName") + " ");
399     jPanel16.setLayout(borderLayout7);
400     jPanel18.setLayout(verticalFlowLayout7);
401     jPanel17.setLayout(verticalFlowLayout6);
402     _edtEditorName.setPreferredSize(new Dimension JavaDoc(4, 21));
403     jLabel5.setText(Messages.getString("EditorEditorPanel.CustomImplementation"));
404     _chkCustomEditor.setText("");
405     _chkCustomEditor.addActionListener(new java.awt.event.ActionListener JavaDoc()
406     {
407       public void actionPerformed(ActionEvent JavaDoc e)
408       {
409         _chkCustomEditor_actionPerformed(e);
410       }
411     });
412     _edtCustomClassName.setPreferredSize(new Dimension JavaDoc(63, 21));
413     _edtCustomClassName.setToolTipText(Messages.getString("EditorEditorPanel.ImplementObjectEditor"));
414     _edtCustomClassName.setText("");
415     jPanel19.setLayout(borderLayout11);
416     _chkCustomEditor.setToolTipText(Messages.getString("EditorEditorPanel.UseCustomizedEditorClass"));
417     _chkCustomEditor.setText("");
418     jPanel7.add(jLabel6, null);
419     jPanel7.add(jLabel2, null);
420     jPanel7.add(jLabel4, null);
421     _tabs.add(_pnlEditorStructure, Messages.getString("EditorEditorPanel.EditorStructure"));
422     _tabs.add(_pnlScript, Messages.getString("EditorEditorPanel.Script"));
423     this.add(jPanel16, BorderLayout.SOUTH);
424     jPanel16.add(jPanel14, BorderLayout.EAST);
425     _pnlEditorStructure.add(jPanel20, BorderLayout.NORTH);
426     jPanel20.add(jScrollPane3, BorderLayout.WEST);
427     jPanel20.add(jPanel1, BorderLayout.CENTER);
428     jScrollPane3.getViewport().add(_tree, null);
429     jPanel4.add(jPanel3, BorderLayout.CENTER);
430     jPanel6.add(jPanel8, BorderLayout.CENTER);
431     jPanel8.add(_lblExtentName, null);
432     jPanel8.add(_edtNodeId, null);
433     jPanel8.add(_edtNodeTitle, null);
434     jPanel6.add(jPanel7, BorderLayout.WEST);
435     jPanel4.add(jPanel2, BorderLayout.WEST);
436     jPanel2.add(_chkEditAllowed, null);
437     jPanel2.add(_chkInsertAllowed, null);
438     jPanel4.add(jPanel6, BorderLayout.NORTH);
439     jPanel9.add(_chkDeleteAllowed, null);
440     jPanel9.add(_chkMultiRow, null);
441     jPanel3.add(jPanel12, BorderLayout.CENTER);
442     jPanel12.add(jLabel1, null);
443     jPanel12.add(_edtRowsDisplayed, null);
444     jPanel3.add(jPanel9, BorderLayout.WEST);
445     this.add(_tabs, BorderLayout.CENTER);
446     _pnlEditorStructure.add(jPanel11, BorderLayout.CENTER);
447     jPanel11.add(jPanel13, BorderLayout.SOUTH);
448     jPanel14.add(_butCancel, null);
449     jPanel14.add(_butOk, null);
450     jPanel13.add(jPanel10, BorderLayout.CENTER);
451     jPanel10.add(_butAddAll, null);
452     jPanel11.add(_scrProperties, BorderLayout.CENTER);
453     jPanel11.add(jPanel4, BorderLayout.NORTH);
454     _scrProperties.getViewport().add(_tabProperties, null);
455     jPanel1.add(jScrollPane5, BorderLayout.CENTER);
456     jPanel1.add(jPanel5, BorderLayout.WEST);
457     jScrollPane5.getViewport().add(_lstExtents, null);
458     jPanel5.add(_butAdd, null);
459     jPanel5.add(_butDelete, null);
460     jPanel5.add(_butUp, null);
461     jPanel5.add(_butDown, null);
462     jPanel20.add(jPanel15, BorderLayout.NORTH);
463     jPanel15.add(jPanel17, BorderLayout.WEST);
464     jPanel17.add(jLabel3, null);
465     jPanel17.add(jLabel5, null);
466     jPanel15.add(jPanel18, BorderLayout.CENTER);
467     jPanel18.add(_edtEditorName, null);
468     jPanel18.add(jPanel19, null);
469     jPanel19.add(_chkCustomEditor, BorderLayout.WEST);
470     jPanel19.add(_edtCustomClassName, BorderLayout.CENTER);
471
472     Util.sizeLabels(jPanel12, false);
473     Util.sizeLabels(jPanel17, false);
474     Util.sizeLabels(jPanel16, false);
475     Util.sizeLabels(jPanel2, false);
476     Util.sizeLabels(jPanel9, false);
477     Util.sizeButtons(this);
478   }
479
480   /**
481    * Returns the selectedNodes of the EditorEditor object
482    *
483    * @return The selectedNodes value
484    */

485   public ExtentUsageNode[] getSelectedNodes()
486   {
487     if (_tree.getSelectionPath() == null) return new ExtentUsageNode[0];
488     ArrayList JavaDoc result = new ArrayList JavaDoc(10);
489
490     TreePath JavaDoc[] tp = _tree.getSelectionPaths();
491
492     for (int qq = 0; qq < tp.length; qq++)
493     {
494       DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) (tp[qq].getLastPathComponent());
495       if (node instanceof ExtentUsageNode) result.add(node);
496     }
497     return (ExtentUsageNode[]) result.toArray(new ExtentUsageNode[0]);
498   }
499
500   void enableEditors(boolean b)
501   {
502     _chkDeleteAllowed.setEnabled(b);
503     _chkEditAllowed.setEnabled(b);
504     _chkInsertAllowed.setEnabled(b);
505     _chkMultiRow.setEnabled(b);
506     _butAdd.setEnabled(b);
507     _butDelete.setEnabled(b);
508     _butDown.setEnabled(b);
509     _butUp.setEnabled(b);
510     _edtNodeTitle.setEnabled(b);
511     _edtNodeId.setEnabled(b);
512     _edtRowsDisplayed.setEnabled(b);
513   }
514
515   void _tree_valueChanged(TreeSelectionEvent JavaDoc e)
516   {
517     ExtentUsageNode[] sels = getSelectedNodes();
518     String JavaDoc title = "";
519     String JavaDoc id = "";
520     ArrayList JavaDoc result = new ArrayList JavaDoc();
521
522     if (sels.length > 0)
523     {
524       DjExtent theExtent = sels[0].getExtent();
525
526       if (theExtent == null) return;
527
528       sels[0].sortPropertyUsages();
529
530       sels[0].shouldDeleteFromStructure(_modelEditor);
531       // Will also remove any invalid columns
532
_tabProperties.setModel(sels[0].getPropertyUsageModel());
533       sels[0].getPropertyUsageModel().addStatusListener(_modelEditor);
534       _modelEditor.setStatusMessage(ModelEditor.OK_MSG);
535
536       _chkEditAllowed.setSelected(sels[0].isEditAllowed());
537       _chkInsertAllowed.setSelected(sels[0].isInsertAllowed());
538       _chkDeleteAllowed.setSelected(sels[0].isDeleteAllowed());
539
540       if (sels[0].getExtent() != null)
541       {
542         if (sels[0].getVia() == null) _lblExtentName.setText(sels[0].getExtent().getName());
543         else _lblExtentName.setText(sels[0].getVia().toString());
544       }
545       else _lblExtentName.setText("");
546
547       title = sels[0].getTitle();
548       if (title == null) title = sels[0].toString();
549
550       id = sels[0].getId();
551       if (id == null) id = sels[0].toString();
552
553       enableEditors(true);
554
555       _chkMultiRow.setSelected(sels[0].isMultiRow());
556       _edtRowsDisplayed.setText(String.valueOf(sels[0].getRowsDisplayed()));
557
558       for (int i = 0; i < theExtent.getDetailRelationCount(); i++)
559       {
560         DjRelation rel = theExtent.getDetailRelation(i);
561
562         ArrayList JavaDoc lst = new ArrayList JavaDoc();
563         lst.add(rel.getDetailExtent());
564
565         DjExtent[] detailExtents = rel.getDetailExtent().getAllSpecializations();
566         for (int d = 0; d < detailExtents.length; d++)
567           lst.add(detailExtents[d]);
568
569         Iterator JavaDoc it = lst.iterator();
570         while (it.hasNext())
571         {
572           DjExtent detail = (DjExtent) it.next();
573           RelationDescriptor rd = new RelationDescriptor(rel, detail);
574           if (!sels[0].hasExtent(rd)) result.add(rd);
575         }
576       }
577
578       _butDelete.setEnabled(sels[0] != _root);
579       _butUp.setEnabled(sels[0] != _root);
580       _butDown.setEnabled(sels[0] != _root);
581     }
582     else _tabProperties.setModel(_emptyModel);
583
584     _edtRowsDisplayed.setEnabled(_chkMultiRow.isSelected() && _chkMultiRow.isEnabled());
585
586     Collections.sort(result, new DjStringComparator(false));
587     DefaultComboBoxModel JavaDoc mdl = new DefaultComboBoxModel JavaDoc(result.toArray());
588
589     _lstExtents.setModel(mdl);
590     _edtNodeTitle.setText(title);
591     _edtNodeId.setText(id);
592   }
593
594   void _lstExtents_mouseClicked(MouseEvent JavaDoc e)
595   {
596     if (e.getClickCount() >= 2) _butAdd_actionPerformed(null);
597   }
598
599   void _chkEditAllowed_actionPerformed(ActionEvent JavaDoc e)
600   {
601     ExtentUsageNode[] sels = getSelectedNodes();
602     if (sels.length > 0)
603     {
604       sels[0].setEditAllowed(_chkEditAllowed.isSelected());
605     }
606   }
607
608   void _chkInsertAllowed_actionPerformed(ActionEvent JavaDoc e)
609   {
610     ExtentUsageNode[] sels = getSelectedNodes();
611     if (sels.length > 0)
612     {
613       sels[0].setInsertAllowed(_chkInsertAllowed.isSelected());
614     }
615   }
616
617   void _chkDeleteAllowed_actionPerformed(ActionEvent JavaDoc e)
618   {
619     ExtentUsageNode[] sels = getSelectedNodes();
620     if (sels.length > 0)
621     {
622       sels[0].setDeleteAllowed(_chkDeleteAllowed.isSelected());
623     }
624   }
625
626   void _butAdd_actionPerformed(ActionEvent JavaDoc e)
627   {
628     try
629     {
630       Object JavaDoc[] sels = _lstExtents.getSelectedValues();
631       ExtentUsageNode[] nodes = getSelectedNodes();
632       if ((sels == null) || (nodes.length == 0)) return;
633
634       ExtentUsageNode focus = null;
635
636       for (int i = 0; i < sels.length; i++)
637       {
638         if (sels[i] instanceof DjExtent)
639         {
640           focus = (ExtentUsageNode) _root.addDetail((DjExtent) sels[i]);
641         }
642         else if (sels[i] instanceof RelationDescriptor)
643         {
644
645           focus = (ExtentUsageNode) nodes[0].addDetail((RelationDescriptor) sels[i], new ExtentUsage(), true);
646         }
647         else
648         {
649           System.err.println(Messages.getString("EditorEditorPanel.UnexpectedListElementType", sels[i].getClass()
650               .getName()));
651         }
652       }
653       if (sels.length > 0)
654       {
655         _treeModel.nodeStructureChanged(nodes[0]);
656       }
657       if (focus != null)
658       {
659         focus.initPropertyUsages();
660         nodes[0].focusChild(focus);
661       }
662     }
663     catch (Exception JavaDoc x)
664     {
665       DjLogger.log(x);
666     }
667   }
668
669   void _butDelete_actionPerformed(ActionEvent JavaDoc e)
670   {
671     try
672     {
673       ExtentUsageNode[] nodes = getSelectedNodes();
674       if (nodes.length == 0) return;
675       ExtentUsageNode focus = null;
676
677       for (int i = 0; i < nodes.length; i++)
678       {
679         if (nodes[i] != _root)
680         {
681           if (focus == null) focus = (ExtentUsageNode) nodes[i].getNextSibling();
682           if (focus == null) focus = (ExtentUsageNode) nodes[i].getPreviousSibling();
683           if (focus == null) focus = (ExtentUsageNode) nodes[i].getParentExtentNode();
684
685           nodes[i].removeFromparent();
686         }
687       }
688       _treeModel.nodeStructureChanged(nodes[0]);
689       if (focus == _root) _tree.setSelectionPath(new TreePath JavaDoc(new Object JavaDoc[]{_root}));
690       else if (focus != null)
691       {
692         if (focus.getParentExtentNode() != null)
693         {
694           focus.getParentExtentNode().focusChild(focus);
695         }
696       }
697       _tree_valueChanged(null);
698     }
699     catch (Exception JavaDoc x)
700     {
701       DjLogger.log(x);
702     }
703   }
704
705   void _butUp_actionPerformed(ActionEvent JavaDoc e)
706   {
707     ExtentUsageNode[] nodes = getSelectedNodes();
708     if (nodes.length == 0) return;
709     for (int i = 0; i < nodes.length; i++)
710       if (nodes[i].getPreviousSibling() == null) return;
711
712     TreePath JavaDoc[] selected = _tree.getSelectionPaths();
713
714     for (int i = 0; i < nodes.length; i++)
715     {
716       if (nodes[i] == _root) continue;
717
718       ExtentUsageNode parent = (ExtentUsageNode) nodes[i].getParentExtentNode();
719
720       int childCount = parent.getChildCount();
721       TreeNode JavaDoc[] list = new ExtentUsageNode[childCount];
722
723       for (int c = 0; c < childCount; c++)
724       {
725         list[c] = parent.getChildAt(c);
726       }
727       for (int c = 1; c < childCount; c++)
728       {
729         if (list[c] == nodes[i])
730         {
731           TreeNode JavaDoc temp = list[c - 1];
732           list[c - 1] = list[c];
733           list[c] = temp;
734           parent.getExtentUsage().moveDetailUp(c);
735           break;
736         }
737       }
738       parent.removeAllChildren();
739
740       for (int c = 0; c < childCount; c++)
741       {
742         parent.addDetail((ExtentUsageNode) list[c]);
743       }
744       _treeModel.nodeStructureChanged(parent);
745     }
746     _tree.setSelectionPaths(selected);
747   }
748
749   void _butDown_actionPerformed(ActionEvent JavaDoc e)
750   {
751     ExtentUsageNode[] nodes = getSelectedNodes();
752     if (nodes.length == 0) return;
753     for (int i = 0; i < nodes.length; i++)
754       if (nodes[i].getNextSibling() == null) return;
755
756     TreePath JavaDoc[] selected = _tree.getSelectionPaths();
757
758     for (int i = nodes.length - 1; i >= 0; i--)
759     {
760       if (nodes[i] == _root) continue;
761
762       ExtentUsageNode parent = (ExtentUsageNode) nodes[i].getParentExtentNode();
763
764       int childCount = parent.getChildCount();
765       TreeNode JavaDoc[] list = new ExtentUsageNode[childCount];
766       for (int c = 0; c < childCount; c++)
767       {
768         list[c] = parent.getChildAt(c);
769       }
770       for (int c = childCount - 2; c >= 0; c--)
771       {
772         if (list[c] == nodes[i])
773         {
774           TreeNode JavaDoc temp = list[c + 1];
775           list[c + 1] = list[c];
776           list[c] = temp;
777           parent.getExtentUsage().moveDetailDown(c);
778           break;
779         }
780       }
781       parent.removeAllChildren();
782       for (int c = 0; c < childCount; c++)
783       {
784         parent.addDetail((ExtentUsageNode) list[c]);
785       }
786       _treeModel.nodeStructureChanged(parent);
787     }
788     _tree.setSelectionPaths(selected);
789   }
790
791   public void setSelectedEditor(EditorDefinition editorDef)
792   {
793     _scratchEditorDefinition = editorDef;
794
795     ExtentUsage extentUsage = editorDef.getUsages();
796
797     _edtEditorName.setText(editorDef.getName());
798     String JavaDoc customClass = editorDef.getCustomEditorClass();
799     _chkCustomEditor.setSelected(customClass != null);
800     if (customClass != null) _edtCustomClassName.setText(customClass);
801     else _edtCustomClassName.setText("");
802
803     enableEditors(true);
804
805     _butDelete.setEnabled(false);
806     _butUp.setEnabled(false);
807     _butDown.setEnabled(false);
808
809     _root = new ExtentUsageNode(new ExtentUsage());
810     _root.setModel(new DefaultTreeModel JavaDoc(_root));
811     _root.setExtent(extentUsage.getExtent());
812     _root.setTitle(extentUsage.getTitle());
813     _root.setId(extentUsage.getId());
814
815     _root.setTree(_tree);
816
817     _tabProperties.setModel(_root.getPropertyUsageModel());
818
819     _root.setInsertAllowed(extentUsage.isInsertAllowed());
820     _root.setDeleteAllowed(extentUsage.isDeleteAllowed());
821     _root.setEditAllowed(extentUsage.isEditAllowed());
822
823     _treeModel = _root.getModel();
824     _tree.setModel(_treeModel);
825     _treeModel.nodeStructureChanged(_root);
826
827     createSubTree(_root, extentUsage);
828
829     expandTree();
830     _tree.setSelectionPath(new TreePath JavaDoc(_root.getPath()));
831
832     synchCustomClassStuff();
833     _pnlScript.setEditorDefinition(editorDef);
834   }
835
836   public void createSubTree(ExtentNode extentNode, ExtentUsage extentUsage)
837   {
838     extentNode.setExtentUsage(extentUsage);
839     for (int i = 0; i < extentUsage.getDetailRelationCount(); i++)
840     {
841       RelationUsage ru = extentUsage.getDetailRelation(i);
842       RelationDescriptor rdesc = new RelationDescriptor(extentUsage.getDetailRelation(i).getRelation());
843
844       // The structure is already built, we are using the structure to build
845
// the tree.
846
// So: instruct addDetail to NOT update the usage structure
847
ExtentNode detail = extentNode.addDetail(rdesc, ru.getDetail(), false);
848       // recurse the entire tree here
849
createSubTree(detail, ru.getDetail());
850     }
851   }
852
853   public void clear()
854   {
855     _root = new ExtentUsageNode(new ExtentUsage());
856     _root.setModel(new DefaultTreeModel JavaDoc(_root));
857     _treeModel = _root.getModel();
858     _treeModel.nodeStructureChanged(_root);
859     _tree.setModel(_treeModel);
860
861     enableEditors(false);
862   }
863
864   void _chkMultiRow_actionPerformed(ActionEvent JavaDoc e)
865   {
866     ExtentUsageNode[] sels = getSelectedNodes();
867     if (sels.length > 0)
868     {
869       sels[0].setMultiRow(_chkMultiRow.isSelected());
870     }
871     _edtRowsDisplayed.setEnabled(_chkMultiRow.isSelected());
872   }
873
874   /**
875    * Description of the Method
876    */

877   public void expandTree()
878   {
879     int row = 0;
880     while (row < _tree.getRowCount())
881     {
882       _tree.expandRow(row++);
883     }
884   }
885
886   void _scrProperties_mouseClicked(MouseEvent JavaDoc e)
887   {
888     doubleClick(e, _tabProperties);
889   }
890
891   /**
892    * Description of the Method
893    *
894    * @param e
895    * Description of the Parameter
896    * @param table
897    * Description of the Parameter
898    */

899   public void doubleClick(MouseEvent JavaDoc e, DjTable table)
900   {
901     table.requestFocus();
902     if (e.getClickCount() < 2) return;
903
904     try
905     {
906       table.insertRow();
907     }
908     catch (Exception JavaDoc x)
909     {
910       _modelEditor.setStatusMessage(x);
911     }
912
913   }
914
915   void _edtNodeTitle_keyReleased(KeyEvent JavaDoc e)
916   {
917     ExtentUsageNode[] sels = getSelectedNodes();
918     if (sels.length > 0)
919     {
920       String JavaDoc title = _edtNodeTitle.getText().trim();
921       if (!title.equals(sels[0].getTitle()))
922       {
923         sels[0].setTitle(title);
924         _treeModel.nodeChanged(sels[0]);
925       }
926     }
927   }
928
929   void _edtRowsDisplayed_keyReleased(KeyEvent JavaDoc e)
930   {
931     ExtentUsageNode[] sels = getSelectedNodes();
932     if (sels.length > 0)
933     {
934       try
935       {
936         int rows = Integer.parseInt(_edtRowsDisplayed.getText().trim());
937         if (sels[0].getRowsDisplayed() != rows)
938         {
939           sels[0].setRowsDisplayed(rows);
940         }
941       }
942       catch (Exception JavaDoc x)
943       {
944         // discard any problems during typing..
945
}
946       _treeModel.nodeChanged(sels[0]);
947     }
948   }
949
950   void _butAddAll_actionPerformed(ActionEvent JavaDoc e)
951   {
952     addAllProperties();
953   }
954
955   public void addAllProperties()
956   {
957     try
958     {
959       while (_tabProperties.insertRow() != -1);
960     }
961     catch (Exception JavaDoc x)
962     {
963       DjLogger.log(x);
964     }
965   }
966
967   void _edtNodeId_keyReleased(KeyEvent JavaDoc e)
968   {
969     ExtentUsageNode[] sels = getSelectedNodes();
970     if (sels.length > 0)
971     {
972       if (!_edtNodeId.getText().equals(sels[0].getId()))
973       {
974         sels[0].setId(_edtNodeId.getText());
975         _treeModel.nodeChanged(sels[0]);
976       }
977     }
978
979   }
980
981   void _butOk_actionPerformed(ActionEvent JavaDoc e)
982   {
983     if (!_pnlScript.apply(false)) return;
984
985     copyFieldsToScratch(false);
986
987     try
988     {
989       _scratchEditorDefinition.validate();
990
991       _currentEditorDefinition.copyFrom(_scratchEditorDefinition);
992       close();
993     }
994     catch (DjenericException dje)
995     {
996       _modelEditor.setStatusMessage(dje);
997     }
998   }
999
1000  private void copyFieldsToScratch(boolean ignoreErrors)
1001  {
1002    String JavaDoc name = _edtEditorName.getText().trim();
1003    if (name.length() == 0) name = Messages.getString("EditorEditorPanel.Unnamed");
1004
1005    _scratchEditorDefinition.setName(name);
1006
1007    String JavaDoc className = _edtCustomClassName.getText().trim();
1008    if (className.length() == 0) className = null;
1009    if (!_chkCustomEditor.isSelected()) className = null;
1010    _scratchEditorDefinition.setCustomEditorClass(className);
1011
1012    _pnlScript.apply(ignoreErrors);
1013  }
1014
1015  void _butCancel_actionPerformed(ActionEvent JavaDoc e)
1016  {
1017    if (canClose()) close();
1018  }
1019
1020  public boolean canClose()
1021  {
1022    copyFieldsToScratch(true);
1023
1024    if (_scratchEditorDefinition.equals(_currentEditorDefinition)) return true;
1025
1026    int result = JOptionPane.showOptionDialog(this, Messages.getString("EditorEditorPanel.DiscardChanges1"), Messages
1027        .getString("global.DiscardChanges"), JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
1028                                              new String JavaDoc[]{Messages.getString("global.Discard"),
1029                                                  Messages.getString("global.Cancel")}, null);
1030    return result == 0;
1031  }
1032
1033  public boolean close()
1034  {
1035    _closer.closeCloseable(this);
1036    return true;
1037  }
1038
1039  void _chkCustomEditor_actionPerformed(ActionEvent JavaDoc e)
1040  {
1041    synchCustomClassStuff();
1042    if (_chkCustomEditor.isSelected()) _edtCustomClassName.requestFocus();
1043  }
1044
1045  private void synchCustomClassStuff()
1046  {
1047    _edtCustomClassName.setEnabled(_chkCustomEditor.isSelected());
1048  }
1049
1050  void _tree_treeWillCollapse(TreeExpansionEvent JavaDoc e) throws ExpandVetoException JavaDoc
1051  {
1052    throw new ExpandVetoException JavaDoc(e);
1053  }
1054
1055}
Popular Tags