KickJava   Java API By Example, From Geeks To Geeks.

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


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.Color JavaDoc;
34 import java.awt.Dimension JavaDoc;
35 import java.awt.FlowLayout JavaDoc;
36 import java.awt.event.ActionEvent JavaDoc;
37 import java.awt.event.ActionListener JavaDoc;
38 import java.awt.event.KeyAdapter JavaDoc;
39 import java.awt.event.KeyEvent JavaDoc;
40 import java.awt.event.MouseEvent JavaDoc;
41 import java.util.ArrayList JavaDoc;
42 import java.util.Collections JavaDoc;
43 import java.util.HashMap JavaDoc;
44 import java.util.Iterator JavaDoc;
45
46 import javax.swing.BorderFactory JavaDoc;
47 import javax.swing.DefaultComboBoxModel JavaDoc;
48 import javax.swing.JButton JavaDoc;
49 import javax.swing.JCheckBox JavaDoc;
50 import javax.swing.JComboBox JavaDoc;
51 import javax.swing.JLabel JavaDoc;
52 import javax.swing.JList JavaDoc;
53 import javax.swing.JOptionPane JavaDoc;
54 import javax.swing.JPanel JavaDoc;
55 import javax.swing.JScrollPane JavaDoc;
56 import javax.swing.JSplitPane JavaDoc;
57 import javax.swing.JTabbedPane JavaDoc;
58 import javax.swing.JTextArea JavaDoc;
59 import javax.swing.JTextField JavaDoc;
60 import javax.swing.JToolTip JavaDoc;
61 import javax.swing.JTree JavaDoc;
62 import javax.swing.border.Border JavaDoc;
63 import javax.swing.border.TitledBorder JavaDoc;
64 import javax.swing.event.TreeSelectionEvent JavaDoc;
65 import javax.swing.tree.DefaultMutableTreeNode JavaDoc;
66 import javax.swing.tree.DefaultTreeModel JavaDoc;
67 import javax.swing.tree.TreeNode JavaDoc;
68 import javax.swing.tree.TreePath JavaDoc;
69
70 import com.genimen.djeneric.language.Messages;
71 import com.genimen.djeneric.repository.DjExtent;
72 import com.genimen.djeneric.repository.DjProperty;
73 import com.genimen.djeneric.repository.DjRelation;
74 import com.genimen.djeneric.repository.exceptions.CatalogException;
75 import com.genimen.djeneric.repository.exceptions.DjenericException;
76 import com.genimen.djeneric.repository.exceptions.ObjectNotDefinedException;
77 import com.genimen.djeneric.structure.EditorDefinition;
78 import com.genimen.djeneric.structure.EditorDefinitionComparator;
79 import com.genimen.djeneric.structure.ExtentUsage;
80 import com.genimen.djeneric.structure.RelationDescriptor;
81 import com.genimen.djeneric.structure.RelationUsage;
82 import com.genimen.djeneric.structure.ResourceDefinition;
83 import com.genimen.djeneric.structure.ResourceDefinitionComparator;
84 import com.genimen.djeneric.structure.ScriptDefinition;
85 import com.genimen.djeneric.tools.io.DjenericDocumentHandler;
86 import com.genimen.djeneric.tools.modeler.ModelEditor;
87 import com.genimen.djeneric.tools.modeler.dialogs.ExtentSelectorDialog;
88 import com.genimen.djeneric.ui.DjCloseable;
89 import com.genimen.djeneric.ui.DjMultiLineToolTip;
90 import com.genimen.djeneric.ui.DjPropertyPathCompleter;
91 import com.genimen.djeneric.ui.DjVerticalFlowLayout;
92 import com.genimen.djeneric.ui.Util;
93 import com.genimen.djeneric.util.DjLogger;
94 import com.genimen.djeneric.util.DjStringComparator;
95
96 public class ViewEditor extends JPanel JavaDoc implements DjCloseable
97 {
98   private static final long serialVersionUID = 1L;
99   BorderLayout JavaDoc borderLayout1 = new BorderLayout JavaDoc();
100   JSplitPane JavaDoc _treeSplitter = new JSplitPane JavaDoc();
101   ExtentNode _root = new ExtentNode(new ExtentUsage());
102   DefaultTreeModel JavaDoc _treeModel = new DefaultTreeModel JavaDoc(_root);
103   ExtentNodeRenderer _treeCellRendrer = new ExtentNodeRenderer();
104   boolean _ignoreEditorChange = false;
105   boolean _ignoreImageIconChange = false;
106
107   DefaultTreeModel JavaDoc _editorTreeModel;
108
109   ModelEditor _modelEditor;
110   JPanel JavaDoc jPanel9 = new JPanel JavaDoc();
111   JScrollPane JavaDoc jScrollPane1 = new JScrollPane JavaDoc();
112   BorderLayout JavaDoc borderLayout8 = new BorderLayout JavaDoc();
113   JCheckBox JavaDoc _chkDeleteAllowed = new JCheckBox JavaDoc();
114   JCheckBox JavaDoc _chkInsertAllowed = new JCheckBox JavaDoc();
115   JPanel JavaDoc _pnlVisualRight = new JPanel JavaDoc();
116   JCheckBox JavaDoc _chkEditAllowed = new JCheckBox JavaDoc();
117   DjVerticalFlowLayout verticalFlowLayout2 = new DjVerticalFlowLayout();
118   JPanel JavaDoc _pnlVisualLeft = new JPanel JavaDoc();
119   DjVerticalFlowLayout verticalFlowLayout = new DjVerticalFlowLayout();
120   JTree JavaDoc _tree = new JTree JavaDoc();
121   JLabel JavaDoc _lblTitle = new JLabel JavaDoc();
122   JTextField JavaDoc _edtNodeTitle = new JTextField JavaDoc();
123   JLabel JavaDoc _lblExtent = new JLabel JavaDoc();
124   JLabel JavaDoc _lblExtentName = new JLabel JavaDoc();
125   JLabel JavaDoc _lblImageIcon = new JLabel JavaDoc();
126   JTextField JavaDoc _edtDescriptor = new JTextField JavaDoc()
127                                                    {
128                                                      private static final long serialVersionUID = 1L;
129
130                                                      public JToolTip JavaDoc createToolTip()
131                                                      {
132                                                        DjMultiLineToolTip tip = new DjMultiLineToolTip();
133                                                        tip.setComponent(this);
134                                                        return tip;
135                                                      }
136                                                    };
137   JLabel JavaDoc _lblId = new JLabel JavaDoc();
138   JTextField JavaDoc _edtNodeId = new JTextField JavaDoc();
139   JCheckBox JavaDoc _chkRecursive = new JCheckBox JavaDoc();
140   JTabbedPane JavaDoc _mainTab = new JTabbedPane JavaDoc();
141   JList JavaDoc _lstExtents = new JList JavaDoc();
142   JPanel JavaDoc _pnlExtents = new JPanel JavaDoc();
143   JButton JavaDoc _butStructureAdd = new JButton JavaDoc();
144   JButton JavaDoc _butStructureDelete = new JButton JavaDoc();
145   DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout();
146   JButton JavaDoc _butStructureUp = new JButton JavaDoc();
147   JPanel JavaDoc _pnlRightBelow = new JPanel JavaDoc();
148   JPanel JavaDoc jPanel3 = new JPanel JavaDoc();
149   JPanel JavaDoc _pnlButtons = new JPanel JavaDoc();
150   BorderLayout JavaDoc borderLayout3 = new BorderLayout JavaDoc();
151   BorderLayout JavaDoc borderLayout2 = new BorderLayout JavaDoc();
152   JButton JavaDoc _butStructureDown = new JButton JavaDoc();
153   JScrollPane JavaDoc _scrExtents = new JScrollPane JavaDoc();
154   JCheckBox JavaDoc _chkHideAddedExtents = new JCheckBox JavaDoc();
155   EditorEditor _pnlEditor = new EditorEditor();
156   ArrayList JavaDoc _allEditors = new ArrayList JavaDoc();
157   ArrayList JavaDoc _allScripts = new ArrayList JavaDoc();
158   ArrayList JavaDoc _allResources = new ArrayList JavaDoc();
159   BorderLayout JavaDoc borderLayout5 = new BorderLayout JavaDoc();
160   Border JavaDoc border1;
161   TitledBorder JavaDoc titledBorder1;
162   JLabel JavaDoc _lblOqlWhere = new JLabel JavaDoc();
163   JLabel JavaDoc _lblRecursive = new JLabel JavaDoc();
164   JComboBox JavaDoc _cbbEditor = new JComboBox JavaDoc();
165   JComboBox JavaDoc _cbbEditorTarget = new JComboBox JavaDoc();
166   JLabel JavaDoc _lblDescriptor = new JLabel JavaDoc();
167   JTextArea JavaDoc _edtOqlWhere = new JTextArea JavaDoc();
168   ResourceManagerPanel _pnlResources = new ResourceManagerPanel();
169   JLabel JavaDoc _lblEditorTarget = new JLabel JavaDoc();
170   JLabel JavaDoc _lblEditor = new JLabel JavaDoc();
171   JComboBox JavaDoc _cbbImageIcon = new JComboBox JavaDoc();
172   ScriptEditor _pnlScripts = new ScriptEditor();
173   boolean _isVersionSafeToSafe = true;
174   JPanel JavaDoc _pnlOptions = new JPanel JavaDoc();
175   FlowLayout JavaDoc flowLayoutCheckboxes = new FlowLayout JavaDoc();
176   JCheckBox JavaDoc _chkOnDiagramOnly = new JCheckBox JavaDoc();
177   DjPropertyPathCompleter _oqlCompleter = null;
178   DjPropertyPathCompleter _descriptorCompleter = null;
179   JTabbedPane JavaDoc _nodeTab = new JTabbedPane JavaDoc();
180   JPanel JavaDoc _pnlNodeVisuals = new JPanel JavaDoc();
181   JPanel JavaDoc _pnlNodeEditing = new JPanel JavaDoc();
182   JPanel JavaDoc _pnlNodeAdvanced = new JPanel JavaDoc();
183   BorderLayout JavaDoc borderLayout4 = new BorderLayout JavaDoc();
184   BorderLayout JavaDoc borderLayout6 = new BorderLayout JavaDoc();
185   BorderLayout JavaDoc borderLayout9 = new BorderLayout JavaDoc();
186   JPanel JavaDoc _pnlEditingLeft = new JPanel JavaDoc();
187   JPanel JavaDoc _pnlEditingRight = new JPanel JavaDoc();
188   JPanel JavaDoc _pnlAdvancedLeft = new JPanel JavaDoc();
189   JPanel JavaDoc _pnlAdvancedRight = new JPanel JavaDoc();
190   DjVerticalFlowLayout verticalFlowLayout3 = new DjVerticalFlowLayout();
191   DjVerticalFlowLayout verticalFlowLayout4 = new DjVerticalFlowLayout();
192   DjVerticalFlowLayout verticalFlowLayout5 = new DjVerticalFlowLayout();
193   DjVerticalFlowLayout verticalFlowLayout6 = new DjVerticalFlowLayout();
194   JLabel JavaDoc _lblCustomNodeClass = new JLabel JavaDoc();
195   JCheckBox JavaDoc _chkCustomNodeClass = new JCheckBox JavaDoc();
196   JLabel JavaDoc _lblCustomNodeClassChk = new JLabel JavaDoc();
197   JTextField JavaDoc _edtCustomNodeClass = new JTextField JavaDoc();
198   JPanel JavaDoc _pnlCustomNodeClass = new JPanel JavaDoc();
199   BorderLayout JavaDoc borderLayout7 = new BorderLayout JavaDoc();
200   JButton JavaDoc _butAddCustom = new JButton JavaDoc();
201   JScrollPane JavaDoc jScrollPane2 = new JScrollPane JavaDoc();
202   JPanel JavaDoc jPanel1 = new JPanel JavaDoc();
203   BorderLayout JavaDoc borderLayout10 = new BorderLayout JavaDoc();
204
205   public ViewEditor()
206   {
207   }
208
209   public ViewEditor(ModelEditor editor)
210   {
211     _modelEditor = editor;
212
213     try
214     {
215       _pnlEditor.setEditorReferences(this);
216       _pnlResources.setEditorReferences(this);
217       _pnlScripts.setEditorReferences(this);
218       jbInit();
219       _butAddCustom.setIcon(ModelEditor.getImageIcon("addcustom.gif"));
220       _butStructureAdd.setIcon(ModelEditor.getImageIcon("add.gif"));
221       _butStructureDelete.setIcon(ModelEditor.getImageIcon("remove.gif"));
222       _butStructureUp.setIcon(ModelEditor.getImageIcon("up.gif"));
223       _butStructureDown.setIcon(ModelEditor.getImageIcon("down.gif"));
224       _tree.putClientProperty("JTree.lineStyle", "Angled");
225       _cbbImageIcon.setRenderer(new ResourceListRenderer(false));
226
227       _oqlCompleter = new DjPropertyPathCompleter(null, _edtOqlWhere);
228       _oqlCompleter.addStatusListener(editor);
229
230       _descriptorCompleter = new DjPropertyPathCompleter(null, _edtDescriptor);
231       _descriptorCompleter.addStatusListener(editor);
232
233     }
234     catch (Exception JavaDoc ex)
235     {
236       JOptionPane.showMessageDialog(this, ex.getMessage());
237       DjLogger.log(ex);
238     }
239   }
240
241   void jbInit() throws Exception JavaDoc
242   {
243     flowLayoutCheckboxes.setAlignment(FlowLayout.LEFT);
244     border1 = BorderFactory.createEtchedBorder(Color.white, new Color JavaDoc(142, 142, 142));
245     titledBorder1 = new TitledBorder JavaDoc(border1, Messages.getString("ViewEditor.NodeSettings"));
246     this.setLayout(borderLayout1);
247     jPanel9.setLayout(borderLayout8);
248     _pnlVisualRight.setLayout(verticalFlowLayout2);
249     _pnlVisualLeft.setLayout(verticalFlowLayout1);
250     _tree.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener JavaDoc()
251     {
252       public void valueChanged(TreeSelectionEvent JavaDoc e)
253       {
254         _tree_valueChanged(e);
255       }
256     });
257     _tree.setCellRenderer(_treeCellRendrer);
258     _tree.setModel(_treeModel);
259     _tree.setShowsRootHandles(false);
260     _tree.setAutoscrolls(true);
261     _tree.setDoubleBuffered(true);
262     _tree.setToggleClickCount(0);
263     _lblTitle.setText(Messages.getString("global.Title"));
264     _edtNodeTitle.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
265     {
266       public void keyReleased(KeyEvent JavaDoc e)
267       {
268         _edtNodeTitle_keyReleased(e);
269       }
270     });
271     _chkEditAllowed.addActionListener(new java.awt.event.ActionListener JavaDoc()
272     {
273       public void actionPerformed(ActionEvent JavaDoc e)
274       {
275         _chkEditAllowed_actionPerformed(e);
276       }
277     });
278     _chkInsertAllowed.addActionListener(new java.awt.event.ActionListener JavaDoc()
279     {
280       public void actionPerformed(ActionEvent JavaDoc e)
281       {
282         _chkInsertAllowed_actionPerformed(e);
283       }
284     });
285     _chkDeleteAllowed.addActionListener(new java.awt.event.ActionListener JavaDoc()
286     {
287       public void actionPerformed(ActionEvent JavaDoc e)
288       {
289         _chkDeleteAllowed_actionPerformed(e);
290       }
291     });
292     _lblExtent.setText(Messages.getString("global.Extent"));
293     _lblRecursive.setText(Messages.getString("ViewEditor.Recursive"));
294     _chkEditAllowed.setText(Messages.getString("global.EditAllowed"));
295     _chkInsertAllowed.setText(Messages.getString("global.Insertallowed"));
296     _chkDeleteAllowed.setToolTipText("");
297     _chkDeleteAllowed.setText(Messages.getString("global.DeleteAllowed"));
298     _lblImageIcon.setText(Messages.getString("ViewEditor.ImageIcon"));
299     _edtDescriptor.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
300     {
301       public void keyReleased(KeyEvent JavaDoc e)
302       {
303         _edtDescriptor_keyReleased(e);
304       }
305     });
306     _edtDescriptor.setToolTipText(Messages.getString("global.Descriptor"));
307
308     _lblId.setText(Messages.getString("ViewEditor.ID"));
309     _lblId.setToolTipText(Messages.getString("ViewEditor.IDTooltip"));
310     _edtNodeId.setToolTipText(Messages.getString("ViewEditor.IDTooltip"));
311     _edtNodeId.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
312     {
313       public void keyReleased(KeyEvent JavaDoc e)
314       {
315         _edtNodeId_keyReleased(e);
316       }
317     });
318     _chkRecursive.setText("");
319     _lblRecursive.setToolTipText(Messages.getString("ViewEditor.RecursiveTooltip"));
320     _chkRecursive.setToolTipText(Messages.getString("ViewEditor.RecursiveTooltip"));
321     _chkRecursive.addActionListener(new java.awt.event.ActionListener JavaDoc()
322     {
323       public void actionPerformed(ActionEvent JavaDoc e)
324       {
325         _chkRecursive_actionPerformed(e);
326       }
327     });
328     _lstExtents.addMouseListener(new java.awt.event.MouseAdapter JavaDoc()
329     {
330       public void mouseClicked(MouseEvent JavaDoc e)
331       {
332         _lstExtents_mouseClicked(e);
333       }
334     });
335
336     _pnlExtents.setLayout(borderLayout3);
337     _butStructureAdd.setPreferredSize(new Dimension JavaDoc(24, 24));
338     _butStructureAdd.addActionListener(new java.awt.event.ActionListener JavaDoc()
339     {
340       public void actionPerformed(ActionEvent JavaDoc e)
341       {
342         _butStructureAdd_actionPerformed(e);
343       }
344     });
345     _butStructureDelete.setPreferredSize(new Dimension JavaDoc(24, 24));
346     _butStructureDelete.addActionListener(new java.awt.event.ActionListener JavaDoc()
347     {
348       public void actionPerformed(ActionEvent JavaDoc e)
349       {
350         _butStructureDelete_actionPerformed(e);
351       }
352     });
353     _butStructureUp.setPreferredSize(new Dimension JavaDoc(24, 24));
354     _butStructureUp.addActionListener(new java.awt.event.ActionListener JavaDoc()
355     {
356       public void actionPerformed(ActionEvent JavaDoc e)
357       {
358         _butStructureUp_actionPerformed(e);
359       }
360     });
361     _pnlRightBelow.setLayout(borderLayout5);
362     jPanel3.setLayout(borderLayout2);
363     _pnlButtons.setLayout(verticalFlowLayout);
364     _butStructureDown.setPreferredSize(new Dimension JavaDoc(24, 24));
365     _butStructureDown.addActionListener(new java.awt.event.ActionListener JavaDoc()
366     {
367       public void actionPerformed(ActionEvent JavaDoc e)
368       {
369         _butStructureDown_actionPerformed(e);
370       }
371     });
372     _chkHideAddedExtents.setSelected(true);
373     _chkHideAddedExtents.setText(Messages.getString("ViewEditor.HideAdded"));
374     _chkHideAddedExtents.addActionListener(new java.awt.event.ActionListener JavaDoc()
375     {
376       public void actionPerformed(ActionEvent JavaDoc e)
377       {
378         _chkHideAddedExtents_actionPerformed(e);
379       }
380     });
381     _lblOqlWhere.setText(Messages.getString("ViewEditor.OQLWhere"));
382     _cbbEditor.setPreferredSize(new Dimension JavaDoc(130, 21));
383     _cbbEditor.addActionListener(new java.awt.event.ActionListener JavaDoc()
384     {
385       public void actionPerformed(ActionEvent JavaDoc e)
386       {
387         _cbbEditor_actionPerformed(e);
388       }
389     });
390     _cbbEditorTarget.setPreferredSize(new Dimension JavaDoc(130, 21));
391     _cbbEditorTarget.addActionListener(new java.awt.event.ActionListener JavaDoc()
392     {
393       public void actionPerformed(ActionEvent JavaDoc e)
394       {
395         _cbb_cbbEditorTarget_actionPerformed(e);
396       }
397     });
398     _lblDescriptor.setText(Messages.getString("global.Descriptor"));
399     _edtOqlWhere.addKeyListener(new java.awt.event.KeyAdapter JavaDoc()
400     {
401       public void keyReleased(KeyEvent JavaDoc e)
402       {
403         _edtQBEFilter_keyReleased(e);
404       }
405     });
406     _edtOqlWhere.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 12));
407     _edtOqlWhere.setToolTipText(Messages.getString("ViewEditor.Oql2FilterWith"));
408
409     _edtDescriptor.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 12));
410     _lblEditorTarget.setText(Messages.getString("ViewEditor.EditorTarget"));
411     _lblEditor.setText(Messages.getString("ViewEditor.Editor"));
412     _cbbImageIcon.addActionListener(new java.awt.event.ActionListener JavaDoc()
413     {
414       public void actionPerformed(ActionEvent JavaDoc e)
415       {
416         _cbbImageIcon_actionPerformed(e);
417       }
418     });
419     _cbbImageIcon.setPreferredSize(new Dimension JavaDoc(130, 21));
420     _pnlOptions.setLayout(flowLayoutCheckboxes);
421     _chkOnDiagramOnly.setSelected(true);
422     _chkOnDiagramOnly.setText(Messages.getString("ViewEditor.DiagramExtentsOnly"));
423     _chkOnDiagramOnly.addActionListener(new java.awt.event.ActionListener JavaDoc()
424     {
425       public void actionPerformed(ActionEvent JavaDoc e)
426       {
427         _chkOnDiagramOnly_actionPerformed(e);
428       }
429     });
430     _pnlNodeVisuals.setLayout(borderLayout4);
431     _pnlNodeEditing.setLayout(borderLayout6);
432     _pnlNodeAdvanced.setLayout(borderLayout9);
433     _pnlEditingLeft.setLayout(verticalFlowLayout3);
434     _pnlEditingRight.setLayout(verticalFlowLayout4);
435     _pnlAdvancedRight.setLayout(verticalFlowLayout5);
436     _pnlAdvancedLeft.setLayout(verticalFlowLayout6);
437     _lblCustomNodeClass.setText(Messages.getString("ViewEditor.CustomNodeClass"));
438     _lblCustomNodeClassChk.setText(Messages.getString("ViewEditor.HasCustomNodeClass"));
439     _edtCustomNodeClass.setFont(new java.awt.Font JavaDoc("Monospaced", 0, 12));
440     _edtCustomNodeClass.setToolTipText(Messages.getString("ViewEditor.CustomNodeClassTooltip"));
441     _edtCustomNodeClass.addKeyListener(new KeyAdapter JavaDoc()
442     {
443       public void keyReleased(KeyEvent JavaDoc e)
444       {
445         _edtCustomNodeClass_keyReleased(e);
446       }
447     });
448     _chkCustomNodeClass.addActionListener(new ActionListener JavaDoc()
449     {
450       public void actionPerformed(ActionEvent JavaDoc e)
451       {
452         _chkCustomNodeClass_actionPerformed(e);
453       }
454     });
455     _pnlCustomNodeClass.setLayout(borderLayout7);
456     _butAddCustom.setToolTipText(Messages.getString("ViewEditor.AddCustom"));
457     _butAddCustom.addActionListener(new ActionListener JavaDoc()
458     {
459       public void actionPerformed(ActionEvent JavaDoc e)
460       {
461         _butAddCustom_actionPerformed(e);
462       }
463     });
464     _butAddCustom.setPreferredSize(new Dimension JavaDoc(24, 24));
465     jPanel1.setLayout(borderLayout10);
466     _pnlOptions.add(_chkOnDiagramOnly, null);
467     _pnlOptions.add(_chkHideAddedExtents, null);
468     jPanel3.add(_scrExtents, BorderLayout.CENTER);
469     jPanel3.add(_pnlButtons, BorderLayout.WEST);
470     _scrExtents.getViewport().add(_lstExtents);
471     _treeSplitter.add(jPanel9, JSplitPane.LEFT);
472     jPanel9.add(jScrollPane1, BorderLayout.CENTER);
473     _treeSplitter.add(_pnlExtents, JSplitPane.RIGHT);
474     _pnlExtents.add(jPanel3, BorderLayout.CENTER);
475     jScrollPane1.getViewport().add(_tree, null);
476     jPanel3.add(_pnlRightBelow, BorderLayout.SOUTH);
477     _pnlButtons.add(_butStructureAdd);
478     _pnlButtons.add(_butAddCustom);
479     _pnlButtons.add(_butStructureDelete);
480     _pnlButtons.add(_butStructureUp);
481     _pnlButtons.add(_butStructureDown);
482     _mainTab.add(_treeSplitter, Messages.getString("ViewEditor.TreeStructure"));
483     _mainTab.add(_pnlEditor, Messages.getString("ViewEditor.Editors"));
484     _mainTab.add(_pnlResources, Messages.getString("global.Resources"));
485     _mainTab.add(_pnlScripts, Messages.getString("ViewEditor.Scripts"));
486
487     _pnlVisualLeft.add(_lblExtent, null);
488     _pnlVisualLeft.add(_lblId, null);
489     _pnlVisualLeft.add(_lblTitle, null);
490     _pnlVisualLeft.add(_lblDescriptor, null);
491     _pnlVisualLeft.add(_lblImageIcon, null);
492     _pnlVisualLeft.add(_lblRecursive, null);
493
494     _pnlVisualRight.add(_lblExtentName, null);
495     _pnlVisualRight.add(_edtNodeId, null);
496     _pnlVisualRight.add(_edtNodeTitle, null);
497     _pnlVisualRight.add(_edtDescriptor, null);
498     _pnlVisualRight.add(_cbbImageIcon, null);
499     _pnlVisualRight.add(_chkRecursive);
500     _pnlNodeVisuals.add(_pnlVisualLeft, java.awt.BorderLayout.WEST);
501     this.add(_mainTab, BorderLayout.CENTER);
502     _pnlNodeVisuals.add(_pnlVisualRight, java.awt.BorderLayout.CENTER);
503     _pnlRightBelow.add(_pnlOptions, java.awt.BorderLayout.CENTER);
504     _pnlRightBelow.add(_nodeTab, java.awt.BorderLayout.SOUTH);
505     _nodeTab.add(_pnlNodeVisuals, Messages.getString("global.General"));
506     _nodeTab.add(_pnlNodeEditing, Messages.getString("global.Editing"));
507     _nodeTab.add(_pnlNodeAdvanced, Messages.getString("global.Advanced"));
508     _pnlNodeEditing.add(_pnlEditingLeft, java.awt.BorderLayout.WEST);
509     _pnlEditingLeft.add(_lblEditorTarget);
510     _pnlEditingLeft.add(_lblEditor);
511     _pnlEditingLeft.add(_chkInsertAllowed);
512     _pnlEditingLeft.add(_chkEditAllowed);
513     _pnlNodeEditing.add(_pnlEditingRight, java.awt.BorderLayout.CENTER);
514     _pnlEditingRight.add(_cbbEditorTarget);
515     _pnlEditingRight.add(_cbbEditor);
516     _pnlEditingRight.add(_chkDeleteAllowed);
517     _pnlNodeAdvanced.add(_pnlAdvancedLeft, java.awt.BorderLayout.WEST);
518     _pnlAdvancedLeft.add(_lblCustomNodeClassChk);
519     _pnlAdvancedLeft.add(_lblOqlWhere, null);
520     _pnlAdvancedRight.add(_pnlCustomNodeClass);
521     _pnlCustomNodeClass.add(_chkCustomNodeClass, java.awt.BorderLayout.WEST);
522     _pnlCustomNodeClass.add(_edtCustomNodeClass, java.awt.BorderLayout.CENTER);
523     jScrollPane2.getViewport().add(_edtOqlWhere);
524     _pnlNodeAdvanced.add(jPanel1, java.awt.BorderLayout.CENTER);
525     jPanel1.add(_pnlAdvancedRight, java.awt.BorderLayout.NORTH);
526     jPanel1.add(jScrollPane2, java.awt.BorderLayout.CENTER);
527     _treeSplitter.setDividerLocation(350);
528     _root.setTree(_tree);
529     _root.setModel(_treeModel);
530     Util.sizeLabels(_pnlVisualLeft);
531     Util.sizeLabels(_pnlVisualRight);
532     Util.sizeLabels(_pnlEditingLeft);
533     Util.sizeLabels(_pnlEditingRight);
534     Util.sizeLabels(_pnlAdvancedRight);
535     Util.sizeLabels(_pnlAdvancedLeft);
536   }
537
538   public ExtentNode[] getSelectedNodes()
539   {
540     if (_tree.getSelectionPath() == null) return new ExtentNode[0];
541     ArrayList JavaDoc result = new ArrayList JavaDoc(10);
542
543     TreePath JavaDoc[] tp = _tree.getSelectionPaths();
544
545     for (int qq = 0; qq < tp.length; qq++)
546     {
547       DefaultMutableTreeNode JavaDoc node = (DefaultMutableTreeNode JavaDoc) (tp[qq].getLastPathComponent());
548       if (node instanceof ExtentNode) result.add(node);
549     }
550     return (ExtentNode[]) result.toArray(new ExtentNode[0]);
551   }
552
553   void enableEditors(boolean b)
554   {
555     _edtNodeTitle.setEnabled(b);
556     _edtOqlWhere.setEnabled(b);
557     _edtDescriptor.setEnabled(b);
558     _chkDeleteAllowed.setEnabled(b);
559     _chkEditAllowed.setEnabled(b);
560     _chkInsertAllowed.setEnabled(b);
561     _chkRecursive.setEnabled(b);
562     _cbbEditor.setEnabled(b);
563     _cbbEditorTarget.setEnabled(b);
564     _cbbImageIcon.setEnabled(b);
565     _chkCustomNodeClass.setEnabled(b);
566     _edtCustomNodeClass.setEnabled(b && _chkCustomNodeClass.isSelected());
567   }
568
569   void _tree_valueChanged(TreeSelectionEvent JavaDoc e)
570   {
571     updateSelectedNodeData();
572   }
573
574   public void load(DjenericDocumentHandler dh) throws DjenericException
575   {
576     clear();
577     ExtentUsage[] usages = dh.getTreeStructure(_modelEditor.getPersistenceManager());
578     for (int i = 0; i < usages.length; i++)
579     {
580       ExtentNode aRoot = createRootExtent(usages[i].getExtent());
581       createSubTree(aRoot, usages[i], new HashMap JavaDoc(), 0);
582     }
583
584     EditorDefinition[] editors = dh.getEditors(_modelEditor.getPersistenceManager());
585
586     for (int i = 0; i < editors.length; i++)
587     {
588       _allEditors.add(editors[i]);
589     }
590     sortEditors();
591
592     ResourceDefinition[] resources = dh.getResources();
593
594     for (int i = 0; i < resources.length; i++)
595     {
596       _allResources.add(resources[i]);
597     }
598
599     sortResources();
600
601     ScriptDefinition[] scripts = dh.getScripts(_modelEditor);
602
603     for (int i = 0; i < scripts.length; i++)
604     {
605       _allScripts.add(scripts[i]);
606     }
607
608     synchronize();
609
610     _isVersionSafeToSafe = dh.isVersionSafeToSave();
611   }
612
613   public boolean isVersionSafeToSave()
614   {
615     return _isVersionSafeToSafe;
616   }
617
618   public EditorDefinition[] getEditors()
619   {
620     return (EditorDefinition[]) _allEditors.toArray(new EditorDefinition[0]);
621   }
622
623   public EditorDefinition getEditorByName(String JavaDoc name)
624   {
625     for (int i = 0; i < _allEditors.size(); i++)
626     {
627       if (((EditorDefinition) _allEditors.get(i)).getName().equalsIgnoreCase(name)) return (EditorDefinition) _allEditors
628           .get(i);
629     }
630     return null;
631   }
632
633   public ScriptDefinition[] getScripts()
634   {
635     return (ScriptDefinition[]) _allScripts.toArray(new ScriptDefinition[0]);
636   }
637
638   public ScriptDefinition getScriptByTitle(String JavaDoc title)
639   {
640     for (int i = 0; i < _allScripts.size(); i++)
641     {
642       if (((ScriptDefinition) _allScripts.get(i)).getTitle().equalsIgnoreCase(title)) return (ScriptDefinition) _allScripts
643           .get(i);
644     }
645     return null;
646   }
647
648   public ArrayList JavaDoc getScriptsList()
649   {
650     return _allScripts;
651   }
652
653   public void createSubTree(ExtentNode extentNode, ExtentUsage extentUsage, HashMap JavaDoc hitlist, int level)
654   {
655     if (hitlist.containsKey(extentUsage)) return;
656     hitlist.put(extentUsage, extentUsage);
657
658     extentNode.setExtentUsage(extentUsage);
659     if (!extentUsage.isRecursive())
660     {
661       for (int i = 0; i < extentUsage.getDetailRelationCount(); i++)
662       {
663         ExtentNode detailNode;
664         RelationUsage ru = extentUsage.getDetailRelation(i);
665         if (ru.getRelation() != null)
666         {
667           RelationDescriptor rdesc = new RelationDescriptor(ru.getRelation());
668           detailNode = extentNode.addDetail(rdesc, ru.getDetail(), false);
669         }
670         else detailNode = extentNode.addDetail(ru.getDetail().getExtent());
671
672         createSubTree(detailNode, ru.getDetail(), hitlist, level + 1);
673         // recurse the entire tree here
674
}
675     }
676   }
677
678   public void updateTargetCombo(DjExtent baseExtent, String JavaDoc target)
679   {
680     if (baseExtent == null) return;
681
682     try
683     {
684       _ignoreEditorChange = true;
685       if (target == null) target = "this";
686
687       ArrayList JavaDoc rels = new ArrayList JavaDoc();
688       rels.add("this");
689
690       // Add all properties that are in fact pointers to a master
691
DjProperty[] props = baseExtent.getPropertiesSorted();
692       for (int i = 0; i < props.length; i++)
693       {
694         if (props[i].getType() instanceof DjExtent) rels.add(props[i].getName());
695       }
696
697       int idx = 0;
698       for (int i = 0; i < rels.size(); i++)
699       {
700         if (rels.get(i).toString().equals(target)) idx = i;
701       }
702
703       DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc(rels.toArray(new String JavaDoc[0]));
704
705       _cbbEditorTarget.setModel(model);
706       _cbbEditorTarget.setSelectedIndex(idx);
707     }
708     finally
709     {
710       _ignoreEditorChange = false;
711     }
712   }
713
714   public void updateEditorCombo(DjExtent onlyForThisExtent, EditorDefinition currentEditor)
715   {
716     EditorDefinition noEditor = new EditorDefinition(Messages.getString("global.none"), null);
717
718     if (currentEditor != null && currentEditor.isMarkedForDelete()) currentEditor = null;
719
720     if (currentEditor == null) currentEditor = noEditor;
721
722     DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc();
723     EditorDefinition[] defs = getEditors();
724
725     int idx = 0;
726
727     model.addElement(noEditor);
728
729     for (int i = 0; i < defs.length; i++)
730     {
731       ExtentUsage usg = defs[i].getUsages();
732       if (onlyForThisExtent != null && usg != null && onlyForThisExtent.isInstanceof(usg.getExtent()))
733       {
734         model.addElement(defs[i]);
735         if (currentEditor == defs[i]) idx = model.getSize() - 1;
736       }
737     }
738     try
739     {
740       _ignoreEditorChange = true;
741       _cbbEditor.setModel(model);
742       _cbbEditor.setSelectedIndex(idx);
743     }
744     finally
745     {
746       _ignoreEditorChange = false;
747     }
748   }
749
750   public void updateImageIconCombo(ResourceDefinition currentDefinition)
751   {
752     ResourceDefinition noDefinition = new ResourceDefinition();
753     noDefinition.setName(Messages.getString("global.none"));
754
755     if (currentDefinition != null && currentDefinition.isMarkedForDelete()) currentDefinition = null;
756
757     if (currentDefinition == null) currentDefinition = noDefinition;
758
759     DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc();
760     sortResources();
761     ResourceDefinition[] defs = getResources();
762
763     int idx = 0;
764
765     model.addElement(noDefinition);
766
767     for (int i = 0; i < defs.length; i++)
768     {
769       if (defs[i].isImageIcon() && !defs[i].isMarkedForDelete())
770       {
771         model.addElement(defs[i]);
772         if (currentDefinition == defs[i]) idx = model.getSize() - 1;
773       }
774     }
775     try
776     {
777       _ignoreImageIconChange = true;
778       _cbbImageIcon.setModel(model);
779       _cbbImageIcon.setSelectedIndex(idx);
780     }
781     finally
782     {
783       _ignoreImageIconChange = false;
784     }
785   }
786
787   public void updateSelectedNodeData()
788   {
789     ExtentNode[] sels = getSelectedNodes();
790     ArrayList JavaDoc appropriateExtents = new ArrayList JavaDoc();
791
792     String JavaDoc title = "";
793     String JavaDoc qbeFilter = "";
794     String JavaDoc id = "";
795     String JavaDoc descriptor = "";
796
797     if (sels.length > 0)
798     {
799       boolean hideAddedExtents = _chkHideAddedExtents.isSelected();
800       boolean onDiagramOnly = _chkOnDiagramOnly.isSelected();
801       boolean isRecursive = sels[0].isRecursive();
802
803       _oqlCompleter.setRootExtent(sels[0].getExtent());
804       HashMap JavaDoc parameters = new HashMap JavaDoc();
805       ExtentNode parent = sels[0].getParentExtentNode();
806       if (parent != null) parent.collectParameters(parameters);
807       _oqlCompleter.setParameters(parameters);
808
809       _descriptorCompleter.setRootExtent(sels[0].getExtent());
810
811       DjExtent theExtent = sels[0].getExtent();
812       DjExtent targetExtent = theExtent;
813
814       updateTargetCombo(theExtent, sels[0].getEditorTarget());
815
816       String JavaDoc target = sels[0].getEditorTarget();
817       if (target != null) try
818       {
819         targetExtent = theExtent.resolveType(target);
820       }
821       catch (ObjectNotDefinedException e)
822       {
823         sels[0].setEditor(null);
824         DjLogger.log(e);
825       }
826
827       updateEditorCombo(targetExtent, sels[0].getEditor());
828       updateImageIconCombo(sels[0].getImageIconResource());
829
830       _chkEditAllowed.setSelected(sels[0].isEditAllowed());
831       _chkInsertAllowed.setSelected(sels[0].isInsertAllowed());
832       _chkDeleteAllowed.setSelected(sels[0].isDeleteAllowed());
833       _chkRecursive.setSelected(sels[0].isRecursive());
834       String JavaDoc nodeClassName = sels[0].getCustomNodeClass();
835       _chkCustomNodeClass.setSelected(nodeClassName != null);
836       if (nodeClassName == null) nodeClassName = "";
837       _edtCustomNodeClass.setText(nodeClassName);
838
839       validateQbeExpression(sels[0]);
840       validateDescriptorExpression(sels[0]);
841
842       if (sels[0].getExtent() != null)
843       {
844         if (sels[0].getVia() == null) _lblExtentName.setText(sels[0].getExtent().getName());
845         else _lblExtentName.setText(sels[0].getVia().toString());
846       }
847       else _lblExtentName.setText("");
848
849       title = sels[0].getTitle();
850       if (title == null) title = sels[0].toString();
851
852       qbeFilter = sels[0].getOqlFilter();
853       if (qbeFilter == null) qbeFilter = "";
854
855       id = sels[0].getId();
856
857       descriptor = sels[0].getDescriptorExpression();
858       if (descriptor == null) descriptor = "";
859
860       ArrayList JavaDoc onDiagram = _modelEditor.getExtentsOnDiagram();
861
862       if (theExtent == null)
863       {
864         // root node?
865
enableEditors(false);
866
867         DjExtent[] allExtents = _modelEditor.getPersistenceManager().getExtentsSorted();
868
869         for (int i = 0; i < allExtents.length; i++)
870         {
871           if (!isRecursive && (!sels[0].hasExtent(allExtents[i]) || !hideAddedExtents))
872           {
873             if (!onDiagramOnly || onDiagram.contains(allExtents[i])) appropriateExtents.add(allExtents[i]);
874           }
875         }
876       }
877       else
878       {
879         enableEditors(true);
880
881         for (int i = 0; i < theExtent.getDetailRelationCount(); i++)
882         {
883           DjRelation rel = theExtent.getDetailRelation(i);
884
885           ArrayList JavaDoc lst = new ArrayList JavaDoc();
886           lst.add(rel.getDetailExtent());
887
888           DjExtent[] detailExtents = rel.getDetailExtent().getAllSpecializations();
889
890           for (int d = 0; d < detailExtents.length; d++)
891             lst.add(detailExtents[d]);
892
893           Iterator JavaDoc it = lst.iterator();
894           while (it.hasNext())
895           {
896             DjExtent detail = (DjExtent) it.next();
897             RelationDescriptor rd = new RelationDescriptor(rel, detail);
898             if (!isRecursive && (!sels[0].hasExtent(rd) || !hideAddedExtents)) if (!onDiagramOnly
899                                                                                    || onDiagram.contains(rd
900                                                                                        .getDetailExtent())) appropriateExtents
901                 .add(rd);
902           }
903         }
904       }
905       if (isRecursive)
906       {
907         enableEditors(false);
908         _chkRecursive.setEnabled(true);
909         _edtNodeTitle.setEnabled(true);
910         _edtDescriptor.setEnabled(true);
911         _edtOqlWhere.setEnabled(true);
912       }
913     }
914     Collections.sort(appropriateExtents, new DjStringComparator(false));
915
916     DefaultComboBoxModel JavaDoc mdl = new DefaultComboBoxModel JavaDoc(appropriateExtents.toArray());
917     _lstExtents.setModel(mdl);
918     _edtNodeId.setText(id);
919     _edtNodeTitle.setText(title);
920     _edtOqlWhere.setText(qbeFilter);
921     _edtDescriptor.setText(descriptor);
922   }
923
924   /**
925    *
926    */

927   protected void validateQbeExpression(ExtentNode node)
928   {
929     try
930     {
931       node.validate(node.toString());
932       _edtOqlWhere.setForeground(Color.black);
933       _modelEditor.setStatusMessage("", false);
934     }
935     catch (DjenericException dje)
936     {
937       _edtOqlWhere.setForeground(Color.red);
938       _modelEditor.setStatusMessage(dje);
939     }
940   }
941
942   void _butStructureAdd_actionPerformed(ActionEvent JavaDoc e)
943   {
944     try
945     {
946       Object JavaDoc[] sels = _lstExtents.getSelectedValues();
947       ExtentNode[] nodes = getSelectedNodes();
948       if ((sels == null) || (nodes.length == 0)) return;
949
950       ExtentNode focus = null;
951
952       for (int i = 0; i < sels.length; i++)
953       {
954         if (sels[i] instanceof DjExtent)
955         {
956           focus = _root.addDetail((DjExtent) sels[i]);
957         }
958         else if (sels[i] instanceof RelationDescriptor)
959         {
960           focus = nodes[0].addDetail((RelationDescriptor) sels[i], new ExtentUsage(), true);
961         }
962         else
963         {
964           System.err.println(Messages.getString("ViewEditor.UnexpectedListElementType", sels[i].getClass().getName()));
965         }
966       }
967       if (sels.length > 0)
968       {
969         _treeModel.nodeStructureChanged(nodes[0]);
970       }
971       if (focus != null) nodes[0].focusChild(focus);
972     }
973     catch (Exception JavaDoc x)
974     {
975       DjLogger.log(x);
976     }
977   }
978
979   void _lstExtents_mouseClicked(MouseEvent JavaDoc e)
980   {
981     if (e.getClickCount() >= 2) _butStructureAdd_actionPerformed(null);
982   }
983
984   void _butStructureDelete_actionPerformed(ActionEvent JavaDoc e)
985   {
986     try
987     {
988       ExtentNode[] nodes = getSelectedNodes();
989       if (nodes.length == 0) return;
990       ExtentNode focus = null;
991
992       for (int i = 0; i < nodes.length; i++)
993       {
994         if (nodes[i] != _root)
995         {
996           if (focus == null) focus = (ExtentNode) nodes[i].getNextSibling();
997           if (focus == null) focus = (ExtentNode) nodes[i].getPreviousSibling();
998           if (focus == null) focus = nodes[i].getParentExtentNode();
999
1000          _treeModel.removeNodeFromParent(nodes[i]);
1001        }
1002      }
1003      _treeModel.nodeStructureChanged(nodes[0]);
1004      if (focus == _root) _tree.setSelectionPath(new TreePath JavaDoc(new Object JavaDoc[]{_root}));
1005      else if (focus != null)
1006      {
1007        if (focus.getParentExtentNode() != null)
1008        {
1009          focus.getParentExtentNode().focusChild(focus);
1010        }
1011      }
1012      _tree_valueChanged(null);
1013    }
1014    catch (Exception JavaDoc x)
1015    {
1016      DjLogger.log(x);
1017    }
1018  }
1019
1020  void _butStructureUp_actionPerformed(ActionEvent JavaDoc e)
1021  {
1022    ExtentNode[] nodes = getSelectedNodes();
1023    if (nodes.length == 0) return;
1024    for (int i = 0; i < nodes.length; i++)
1025      if (nodes[i].getPreviousSibling() == null) return;
1026
1027    TreePath JavaDoc[] selected = _tree.getSelectionPaths();
1028
1029    for (int i = 0; i < nodes.length; i++)
1030    {
1031      if (nodes[i] == _root) continue;
1032
1033      ExtentNode parent = nodes[i].getParentExtentNode();
1034
1035      int childCount = parent.getChildCount();
1036      TreeNode JavaDoc[] list = new ExtentNode[childCount];
1037      for (int c = 0; c < childCount; c++)
1038      {
1039        list[c] = parent.getChildAt(c);
1040      }
1041      for (int c = 1; c < childCount; c++)
1042      {
1043        if (list[c] == nodes[i])
1044        {
1045          TreeNode JavaDoc temp = list[c - 1];
1046          list[c - 1] = list[c];
1047          list[c] = temp;
1048          break;
1049        }
1050      }
1051      parent.removeAllChildren();
1052      for (int c = 0; c < childCount; c++)
1053      {
1054        parent.addDetail((ExtentNode) list[c]);
1055      }
1056      _treeModel.nodeStructureChanged(parent);
1057    }
1058    _tree.setSelectionPaths(selected);
1059  }
1060
1061  void _butStructureDown_actionPerformed(ActionEvent JavaDoc e)
1062  {
1063    ExtentNode[] nodes = getSelectedNodes();
1064    if (nodes.length == 0) return;
1065    for (int i = 0; i < nodes.length; i++)
1066      if (nodes[i].getNextSibling() == null) return;
1067
1068    TreePath JavaDoc[] selected = _tree.getSelectionPaths();
1069
1070    for (int i = nodes.length - 1; i >= 0; i--)
1071    {
1072      if (nodes[i] == _root) continue;
1073
1074      ExtentNode parent = nodes[i].getParentExtentNode();
1075
1076      int childCount = parent.getChildCount();
1077      TreeNode JavaDoc[] list = new ExtentNode[childCount];
1078      for (int c = 0; c < childCount; c++)
1079      {
1080        list[c] = parent.getChildAt(c);
1081      }
1082      for (int c = childCount - 2; c >= 0; c--)
1083      {
1084        if (list[c] == nodes[i])
1085        {
1086          TreeNode JavaDoc temp = list[c + 1];
1087          list[c + 1] = list[c];
1088          list[c] = temp;
1089          break;
1090        }
1091      }
1092      parent.removeAllChildren();
1093      for (int c = 0; c < childCount; c++)
1094      {
1095        parent.addDetail((ExtentNode) list[c]);
1096      }
1097      _treeModel.nodeStructureChanged(parent);
1098    }
1099    _tree.setSelectionPaths(selected);
1100  }
1101
1102  public ExtentNode[] getRootExtents()
1103  {
1104    return _root.getChildren();
1105  }
1106
1107  public void clear()
1108  {
1109    _root.removeAllChildren();
1110    _allEditors.clear();
1111    _allScripts.clear();
1112    _allResources.clear();
1113    _pnlEditor.clear();
1114    synchronize();
1115  }
1116
1117  public ExtentNode createRootExtent(DjExtent tab)
1118  {
1119    return _root.addDetail(tab);
1120  }
1121
1122  public void synchronize()
1123  {
1124    _treeModel.nodeStructureChanged(_root);
1125    //expandTree();
1126
_tree.setSelectionPath(new TreePath JavaDoc(_root.getPath()));
1127    _pnlEditor.synchronize();
1128    _pnlResources.synchronize();
1129    _pnlScripts.synchronize();
1130  }
1131
1132  void _chkEditAllowed_actionPerformed(ActionEvent JavaDoc e)
1133  {
1134    ExtentNode[] sels = getSelectedNodes();
1135    if (sels.length > 0)
1136    {
1137      sels[0].setEditAllowed(_chkEditAllowed.isSelected());
1138    }
1139  }
1140
1141  void _chkInsertAllowed_actionPerformed(ActionEvent JavaDoc e)
1142  {
1143    ExtentNode[] sels = getSelectedNodes();
1144    if (sels.length > 0)
1145    {
1146      sels[0].setInsertAllowed(_chkInsertAllowed.isSelected());
1147    }
1148  }
1149
1150  void _chkDeleteAllowed_actionPerformed(ActionEvent JavaDoc e)
1151  {
1152    ExtentNode[] sels = getSelectedNodes();
1153    if (sels.length > 0)
1154    {
1155      sels[0].setDeleteAllowed(_chkDeleteAllowed.isSelected());
1156    }
1157  }
1158
1159  public void expandTree()
1160  {
1161    int row = 0;
1162    while (row < _tree.getRowCount())
1163    {
1164      _tree.expandRow(row++);
1165    }
1166  }
1167
1168  public void fixInvalidReferences() throws DjenericException
1169  {
1170    // will delete all nodes based on tables not the model anymore
1171
_root.shouldDeleteFromStructure(_modelEditor);
1172
1173    EditorDefinition[] editors = getEditors();
1174    for (int i = 0; i < editors.length; i++)
1175    {
1176      editors[i].removeInvalidExtents();
1177    }
1178    _root.validate("");
1179  }
1180
1181  void _edtNodeTitle_keyReleased(KeyEvent JavaDoc e)
1182  {
1183    ExtentNode[] sels = getSelectedNodes();
1184    if (sels.length > 0)
1185    {
1186      String JavaDoc title = _edtNodeTitle.getText().trim();
1187      if (!title.equals(sels[0].getTitle()))
1188      {
1189        sels[0].setTitle(title);
1190        _treeModel.nodeChanged(sels[0]);
1191      }
1192    }
1193  }
1194
1195  void _edtDescriptor_keyReleased(KeyEvent JavaDoc e)
1196  {
1197    ExtentNode[] sels = getSelectedNodes();
1198    if (sels.length > 0)
1199    {
1200      String JavaDoc descr = _edtDescriptor.getText().trim();
1201      if (!descr.equals(sels[0].getDescriptorExpression()))
1202      {
1203        sels[0].setDescriptorExpression(descr);
1204      }
1205      validateDescriptorExpression(sels[0]);
1206    }
1207  }
1208
1209  void _butClose_actionPerformed(ActionEvent JavaDoc e)
1210  {
1211    _modelEditor.toggleViewDefinitionPanel();
1212  }
1213
1214  void _edtNodeId_keyTyped(KeyEvent JavaDoc e)
1215  {
1216
1217  }
1218
1219  void _edtNodeId_keyPressed(KeyEvent JavaDoc e)
1220  {
1221
1222  }
1223
1224  void _edtNodeId_keyReleased(KeyEvent JavaDoc e)
1225  {
1226    ExtentNode[] sels = getSelectedNodes();
1227    if (sels.length > 0)
1228    {
1229      String JavaDoc nodeId = _edtNodeId.getText().trim();
1230      if (!nodeId.equals(sels[0].getId()))
1231      {
1232        sels[0].setId(nodeId);
1233        _treeModel.nodeChanged(sels[0]);
1234      }
1235    }
1236
1237  }
1238
1239  void _chkRecursive_actionPerformed(ActionEvent JavaDoc e)
1240  {
1241    ExtentNode[] sels = getSelectedNodes();
1242    if (sels.length > 0)
1243    {
1244      try
1245      {
1246        sels[0].setRecursive(_chkRecursive.isSelected());
1247        updateSelectedNodeData();
1248        _treeModel.nodeChanged(sels[0]);
1249
1250      }
1251      catch (DjenericException dje)
1252      {
1253        _modelEditor.setStatusMessage(dje);
1254      }
1255    }
1256
1257  }
1258
1259  void _chkHideAddedExtents_actionPerformed(ActionEvent JavaDoc e)
1260  {
1261    updateSelectedNodeData();
1262  }
1263
1264  void _lstExtents_mousePressed(MouseEvent JavaDoc e)
1265  {
1266
1267  }
1268
1269  void _lstExtents_mouseReleased(MouseEvent JavaDoc e)
1270  {
1271
1272  }
1273
1274  void _lstExtents_mouseEntered(MouseEvent JavaDoc e)
1275  {
1276
1277  }
1278
1279  void _lstExtents_mouseExited(MouseEvent JavaDoc e)
1280  {
1281
1282  }
1283
1284  public void addEditor(EditorDefinition editor)
1285  {
1286    _allEditors.add(editor);
1287    sortEditors();
1288    updateSelectedNodeData();
1289  }
1290
1291  public void deleteEditor(EditorDefinition editor)
1292  {
1293    _allEditors.remove(editor);
1294    updateSelectedNodeData();
1295  }
1296
1297  public void addScript(ScriptDefinition script)
1298  {
1299    addScript(script, -1);
1300  }
1301
1302  public void addScript(ScriptDefinition script, int idx)
1303  {
1304    if (idx == -1 || idx > _allScripts.size()) idx = _allScripts.size();
1305    _allScripts.add(idx, script);
1306  }
1307
1308  public void deleteScript(ScriptDefinition script)
1309  {
1310    _allScripts.remove(script);
1311  }
1312
1313  public void addResource(ResourceDefinition def)
1314  {
1315    if (!def.isMarkedForDelete() && !_allResources.contains(def)) _allResources.add(def);
1316  }
1317
1318  public void deleteResource(ResourceDefinition def)
1319  {
1320    _allResources.remove(def);
1321  }
1322
1323  protected void sortEditors(ArrayList JavaDoc editors)
1324  {
1325    Collections.sort(editors, new EditorDefinitionComparator());
1326  }
1327
1328  public void sortEditors()
1329  {
1330    sortEditors(_allEditors);
1331  }
1332
1333  void _cbb_cbbEditorTarget_actionPerformed(ActionEvent JavaDoc e)
1334  {
1335    if (_ignoreEditorChange) return;
1336
1337    ExtentNode[] sels = getSelectedNodes();
1338    if (sels.length > 0)
1339    {
1340      String JavaDoc target = _cbbEditorTarget.getSelectedItem().toString();
1341      if ("this".equals(target)) target = null;
1342
1343      if (sels[0].getEditorTarget() != target)
1344      {
1345        sels[0].setEditorTarget(target);
1346
1347        DjExtent targetExtent = sels[0].getExtent();
1348        if (target != null) try
1349        {
1350          targetExtent = targetExtent.resolveType(target);
1351        }
1352        catch (ObjectNotDefinedException e1)
1353        {
1354          sels[0].setEditor(null);
1355          DjLogger.log(e1);
1356        }
1357        updateEditorCombo(targetExtent, sels[0].getEditor());
1358      }
1359    }
1360  }
1361
1362  void _cbbEditor_actionPerformed(ActionEvent JavaDoc e)
1363  {
1364    if (_ignoreEditorChange) return;
1365
1366    ExtentNode[] sels = getSelectedNodes();
1367    if (sels.length > 0)
1368    {
1369      EditorDefinition editor = (EditorDefinition) _cbbEditor.getSelectedItem();
1370      if (editor != null && editor.getUsages() == null) editor = null;
1371
1372      if (sels[0].getEditor() != editor)
1373      {
1374        sels[0].setEditor(editor);
1375      }
1376    }
1377
1378  }
1379
1380  void _edtQBEFilter_keyTyped(KeyEvent JavaDoc e)
1381  {
1382
1383  }
1384
1385  void _edtQBEFilter_keyPressed(KeyEvent JavaDoc e)
1386  {
1387
1388  }
1389
1390  void _edtQBEFilter_keyReleased(KeyEvent JavaDoc e)
1391  {
1392    ExtentNode[] sels = getSelectedNodes();
1393    if (sels.length > 0)
1394    {
1395      String JavaDoc filter = _edtOqlWhere.getText().trim();
1396      if (!filter.equals(sels[0].getOqlFilter()))
1397      {
1398        sels[0].setOqlFilter(filter);
1399        validateQbeExpression(sels[0]);
1400      }
1401    }
1402  }
1403
1404  protected void validateDescriptorExpression(ExtentNode node)
1405  {
1406    try
1407    {
1408      if (node != null && node.getExtent() != null) node.getExtent()
1409          .validateDescriptorExpression(node.getDescriptorExpression());
1410      _edtDescriptor.setForeground(Color.black);
1411    }
1412    catch (CatalogException ce)
1413    {
1414      _edtDescriptor.setForeground(Color.red);
1415    }
1416  }
1417
1418  public void renameEditor(EditorDefinition editor, String JavaDoc newName)
1419  {
1420    editor.setName(newName);
1421    sortEditors();
1422  }
1423
1424  public ResourceDefinition[] getResources()
1425  {
1426    return (ResourceDefinition[]) _allResources.toArray(new ResourceDefinition[0]);
1427  }
1428
1429  public ResourceDefinition getResourceByName(String JavaDoc absPath)
1430  {
1431    for (int i = 0; i < _allResources.size(); i++)
1432    {
1433      ResourceDefinition rd = (ResourceDefinition) _allResources.get(i);
1434      if (absPath.equals(rd.getAbsolutePath())) return rd;
1435    }
1436    return null;
1437  }
1438
1439  public void sortResources()
1440  {
1441    int i = 0;
1442    while (i < _allResources.size())
1443    {
1444      if (((ResourceDefinition) _allResources.get(i)).isMarkedForDelete()) _allResources.remove(i);
1445      else i++;
1446    }
1447    Collections.sort(_allResources, new ResourceDefinitionComparator());
1448  }
1449
1450  void _cbbImageIcon_actionPerformed(ActionEvent JavaDoc e)
1451  {
1452    if (_ignoreImageIconChange) return;
1453
1454    ExtentNode[] sels = getSelectedNodes();
1455    if (sels.length > 0)
1456    {
1457      ResourceDefinition res = (ResourceDefinition) _cbbImageIcon.getSelectedItem();
1458
1459      if (sels[0].getImageIconResource() != res)
1460      {
1461        sels[0].setImageIconResource(res);
1462      }
1463    }
1464
1465  }
1466
1467  public boolean canClose()
1468  {
1469    return true;
1470  }
1471
1472  public boolean close()
1473  {
1474    _modelEditor.toggleViewDefinitionPanel();
1475    return true;
1476  }
1477
1478  public ModelEditor getModelEditor()
1479  {
1480    return _modelEditor;
1481  }
1482
1483  public boolean hasEditorsOpen()
1484  {
1485    return _pnlEditor.hasEditorsOpen() || _pnlScripts.hasEditorsOpen();
1486  }
1487
1488  void _chkOnDiagramOnly_actionPerformed(ActionEvent JavaDoc e)
1489  {
1490    updateSelectedNodeData();
1491
1492  }
1493
1494  public void _chkCustomNodeClass_actionPerformed(ActionEvent JavaDoc e)
1495  {
1496    ExtentNode[] sels = getSelectedNodes();
1497    if (sels.length > 0)
1498    {
1499      sels[0].setEditAllowed(_chkCustomNodeClass.isSelected());
1500      _edtCustomNodeClass.setEnabled(_chkCustomNodeClass.isSelected());
1501      if (!_chkCustomNodeClass.isSelected())
1502      {
1503        _edtCustomNodeClass.setText("");
1504        sels[0].setCustomNodeClass(null);
1505      }
1506      _edtCustomNodeClass.requestFocus();
1507    }
1508  }
1509
1510  public void _edtCustomNodeClass_keyReleased(KeyEvent JavaDoc e)
1511  {
1512    ExtentNode[] sels = getSelectedNodes();
1513    if (sels.length > 0)
1514    {
1515      String JavaDoc className = _edtCustomNodeClass.getText();
1516      if (!_chkCustomNodeClass.isSelected()) className = null;
1517      sels[0].setCustomNodeClass(className);
1518    }
1519  }
1520
1521  public void _butAddCustom_actionPerformed(ActionEvent JavaDoc e)
1522  {
1523    ExtentSelectorDialog esd = new ExtentSelectorDialog(getModelEditor(), "Select extent", getModelEditor()
1524        .getPackages(), getModelEditor().getExtents(), new DjExtent[0]);
1525    esd.setShowSelectionRelated(false);
1526    esd.setMultiSelect(false);
1527    esd.setVisible(true);
1528    if (!esd.wasCancelled())
1529    {
1530      ExtentNode[] nodes = getSelectedNodes();
1531      if (nodes.length == 0) return;
1532
1533      ExtentNode focus = nodes[0];
1534      DjExtent extent = esd.getSelectedExtents()[0];
1535
1536      ExtentNode newNode = focus.addDetail(extent);
1537      _treeModel.nodeStructureChanged(focus);
1538      focus.focusChild(newNode);
1539    }
1540  }
1541}
1542
Popular Tags