KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > dataview > dvmodeler > DVModelerFrame


1 /* ====================================================================
2  *
3  * The ObjectStyle Group Software License, version 1.1
4  * ObjectStyle Group - http://objectstyle.org/
5  *
6  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
7  * of the software. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any,
22  * must include the following acknowlegement:
23  * "This product includes software developed by independent contributors
24  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
29  * or promote products derived from this software without prior written
30  * permission. For written permission, email
31  * "andrus at objectstyle dot org".
32  *
33  * 5. Products derived from this software may not be called "ObjectStyle"
34  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
35  * names without prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals and hosted on ObjectStyle Group web site. For more
53  * information on the ObjectStyle Group, please see
54  * <http://objectstyle.org/>.
55  */

56
57 package org.objectstyle.cayenne.dataview.dvmodeler;
58
59 import java.awt.BorderLayout JavaDoc;
60 import java.awt.CardLayout JavaDoc;
61 import java.awt.Component JavaDoc;
62 import java.awt.Insets JavaDoc;
63
64 import javax.swing.AbstractButton JavaDoc;
65 import javax.swing.Action JavaDoc;
66 import javax.swing.ImageIcon JavaDoc;
67 import javax.swing.JFrame JavaDoc;
68 import javax.swing.JMenu JavaDoc;
69 import javax.swing.JMenuBar JavaDoc;
70 import javax.swing.JMenuItem JavaDoc;
71 import javax.swing.JPanel JavaDoc;
72 import javax.swing.JScrollPane JavaDoc;
73 import javax.swing.JSplitPane JavaDoc;
74 import javax.swing.JTabbedPane JavaDoc;
75 import javax.swing.JTable JavaDoc;
76 import javax.swing.JToolBar JavaDoc;
77 import javax.swing.JTree JavaDoc;
78 import javax.swing.ListSelectionModel JavaDoc;
79 import javax.swing.WindowConstants JavaDoc;
80 import javax.swing.plaf.basic.BasicSplitPaneDivider JavaDoc;
81 import javax.swing.plaf.basic.BasicSplitPaneUI JavaDoc;
82 import javax.swing.tree.DefaultTreeCellRenderer JavaDoc;
83 import javax.swing.tree.TreeSelectionModel JavaDoc;
84
85 import com.jgoodies.forms.factories.Borders;
86 import com.jgoodies.looks.HeaderStyle;
87 import com.jgoodies.looks.Options;
88
89 /**
90  *
91  * @author Nataliya Kholodna
92  * @author Andriy Shapochka
93  * @version 1.0
94  */

95
96 public class DVModelerFrame extends JFrame JavaDoc {
97  private DVModelerFrameHelper dvModelerFrameHelper;
98
99   private Action JavaDoc saveAction;
100   private Action JavaDoc openAction;
101   private Action JavaDoc addNewObjEntityViewAction;
102   private Action JavaDoc addNewFieldAction;
103   private Action JavaDoc addNewDataViewAction;
104   private Action JavaDoc deleteAction;
105   private JMenuItem JavaDoc close;
106   private JMenuItem JavaDoc loadErrors;
107   private JMenuItem JavaDoc saveErrors;
108
109   private JSplitPane JavaDoc fieldsSplitPane;
110   private JSplitPane JavaDoc splitPane;
111
112   private JTile browserTile;
113   private JTile topTile;
114   private JTile bottomTile;
115
116   private JTree JavaDoc dataViewTree;
117   private JTree JavaDoc dataMapTree;
118
119   private CardPanel topCardPanel;
120   private JPanel JavaDoc bottomCardPanel;
121
122   private JTabbedPane JavaDoc dataTabbedPane;
123
124   private JTable JavaDoc fieldsTable;
125   private JTable JavaDoc relationshipsTable;
126
127   protected DVModelerFrame(){
128     super(" Data View Modeler ");
129
130     dvModelerFrameHelper = new DVModelerFrameHelper(this);
131
132     saveAction = dvModelerFrameHelper.getSaveAction();
133     openAction = dvModelerFrameHelper.getOpenAction();
134     addNewObjEntityViewAction = dvModelerFrameHelper.getAddNewObjEntityViewAction();
135     addNewFieldAction = dvModelerFrameHelper.getAddNewFieldAction();
136     addNewDataViewAction = dvModelerFrameHelper.getAddNewDataViewAction();
137     deleteAction = dvModelerFrameHelper.getDeleteAction();
138
139
140     getContentPane().setLayout(new BorderLayout JavaDoc());
141
142     buildMenuBar();
143     buildToolBar();
144     buildMainPanel();
145     setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
146
147
148     dvModelerFrameHelper.browserTabChanged();
149
150     this.addWindowListener(dvModelerFrameHelper.getDVModelerFrameWindowListener());
151
152   }
153
154   private void buildMenuBar(){
155     JMenuBar JavaDoc menuBar = new JMenuBar JavaDoc();
156     menuBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
157
158     JMenu JavaDoc menuFile = new JMenu JavaDoc("File");
159     menuBar.add(menuFile);
160     menuFile.add(openAction);
161     saveAction.setEnabled(false);
162     menuFile.add(saveAction);
163     close = new JMenuItem JavaDoc("Close Cayenne Project");
164     close.addActionListener(
165         dvModelerFrameHelper.getMenuItemCloseActionListener());
166     close.setEnabled(false);
167     menuFile.add(close);
168
169     menuFile.addSeparator();
170
171     loadErrors = new JMenuItem JavaDoc("Show Load Errors");
172     loadErrors.addActionListener(dvModelerFrameHelper.getMenuItemLoadErrorsActionListenr());
173     loadErrors.setEnabled(false);
174     menuFile.add(loadErrors);
175
176     saveErrors = new JMenuItem JavaDoc("Show Save Errors");
177     saveErrors.addActionListener(dvModelerFrameHelper.getMenuItemSaveErrorsActionListener());
178     saveErrors.setEnabled(false);
179     menuFile.add(saveErrors);
180
181     menuFile.addSeparator();
182
183     JMenuItem JavaDoc exit = new JMenuItem JavaDoc("Exit");
184     exit.addActionListener(
185       dvModelerFrameHelper.getMenuItemExitActionListener());
186     menuFile.add(exit);
187
188     JMenu JavaDoc menuEdit = new JMenu JavaDoc("Edit");
189     menuBar.add(menuEdit);
190     menuEdit.add(addNewDataViewAction);
191     menuEdit.add(addNewObjEntityViewAction);
192     menuEdit.add(addNewFieldAction);
193     menuEdit.addSeparator();
194     menuEdit.add(deleteAction);
195
196     setJMenuBar(menuBar);
197   }
198
199
200   private void buildToolBar(){
201     JToolBar JavaDoc toolBar = new JToolBar JavaDoc();
202     toolBar.setFloatable(false);
203     toolBar.setOrientation(JToolBar.HORIZONTAL);
204     toolBar.setRollover(true);
205     toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
206
207     toolBar.add(dvModelerFrameHelper.getOpenAction());
208     toolBar.add(dvModelerFrameHelper.getSaveAction());
209     toolBar.addSeparator();
210     toolBar.add(dvModelerFrameHelper.getAddNewDataViewAction());
211     toolBar.add(dvModelerFrameHelper.getAddNewObjEntityViewAction());
212     toolBar.add(dvModelerFrameHelper.getAddNewFieldAction());
213     toolBar.addSeparator();
214     toolBar.add(dvModelerFrameHelper.getDeleteAction());
215
216
217     Insets JavaDoc buttonMargin = new Insets JavaDoc(0, 0, 0, 0);
218     int count = toolBar.getComponentCount();
219     for (int i = 0; i < count; i++) {
220       Component JavaDoc c = toolBar.getComponentAtIndex(i);
221       if (c instanceof AbstractButton JavaDoc) {
222         ((AbstractButton JavaDoc)c).setMargin(buttonMargin);
223       }
224     }
225
226     getContentPane().add(toolBar, BorderLayout.NORTH);
227   }
228
229   private void buildMainPanel(){
230     JScrollPane JavaDoc mapsScrollPane = new JScrollPane JavaDoc(buildDataMapTree());
231     mapsScrollPane.setBorder(Borders.EMPTY_BORDER);
232     JScrollPane JavaDoc viewsScrollPane = new JScrollPane JavaDoc(buildDataViewTree());
233     viewsScrollPane.setBorder(Borders.EMPTY_BORDER);
234     dataTabbedPane = new JTabbedPane JavaDoc(JTabbedPane.BOTTOM);
235     dataTabbedPane.putClientProperty(Options.NO_CONTENT_BORDER_KEY, Boolean.TRUE);
236     dataTabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE);
237     dataTabbedPane.addTab(
238         "Views",
239         new ImageIcon JavaDoc(DVModelerFrame.class.getResource("images/dataview-node.gif")),
240         viewsScrollPane);
241     dataTabbedPane.addTab(
242         "Entities",
243         new ImageIcon JavaDoc(DVModelerFrame.class.getResource("images/datamap-node.gif")),
244         mapsScrollPane);
245     dataTabbedPane.addChangeListener(
246         dvModelerFrameHelper.getDataTabbedPaneChangeListener());
247     topCardPanel = new CardPanel();
248     bottomCardPanel = buildBottomCardPanel();
249
250
251     fieldsSplitPane = new JSplitPane JavaDoc(
252         JSplitPane.VERTICAL_SPLIT,
253         topTile = new JTile(topCardPanel),
254         bottomTile = new JTile(bottomCardPanel));
255     fieldsSplitPane.setDividerLocation(300);
256     fieldsSplitPane.setBorder(Borders.EMPTY_BORDER);
257     BasicSplitPaneDivider JavaDoc divider = ((BasicSplitPaneUI JavaDoc)fieldsSplitPane.getUI()).getDivider();
258     divider.setBorder(Borders.EMPTY_BORDER);
259
260     splitPane = new JSplitPane JavaDoc(
261         JSplitPane.HORIZONTAL_SPLIT,
262         browserTile = new JTile(dataTabbedPane),
263         fieldsSplitPane);
264
265     splitPane.setDividerLocation(250);
266
267     divider = ((BasicSplitPaneUI JavaDoc)splitPane.getUI()).getDivider();
268     divider.setBorder(Borders.EMPTY_BORDER);
269     splitPane.setBorder(Borders.DIALOG_BORDER);
270
271     getContentPane().add(splitPane, BorderLayout.CENTER);
272
273     CardLayout JavaDoc cardLayout = (CardLayout JavaDoc)bottomCardPanel.getLayout();
274     cardLayout.show(bottomCardPanel, "emptyPanel");
275   }
276
277   private JPanel JavaDoc buildBottomCardPanel(){
278     JPanel JavaDoc bottomPanel = new JPanel JavaDoc();
279     CardLayout JavaDoc bottomCardLayout = new CardLayout JavaDoc();
280     bottomPanel.setLayout( bottomCardLayout );
281     JPanel JavaDoc emptyPanel = new JPanel JavaDoc();
282     bottomPanel.add(emptyPanel, "emptyPanel");
283
284     fieldsTable = new JTable JavaDoc();
285     fieldsTable.setModel(new FieldsTableModel());
286     fieldsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
287     JScrollPane JavaDoc scrollPane = new JScrollPane JavaDoc(fieldsTable);
288     scrollPane.setBorder(Borders.EMPTY_BORDER);
289     bottomPanel.add(scrollPane, "fieldsTable");
290
291     relationshipsTable = new JTable JavaDoc(new RelationshipsTableModel());
292     relationshipsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
293     scrollPane = new JScrollPane JavaDoc(relationshipsTable);
294     scrollPane.setBorder(Borders.EMPTY_BORDER);
295     bottomPanel.add(scrollPane, "relationshipsTable");
296
297     return bottomPanel;
298   }
299
300   private JTree JavaDoc buildDataMapTree(){
301     dataMapTree = new JTree JavaDoc(new DataMapTreeModel());
302     dataMapTree.setRootVisible(false);
303     dataMapTree.setShowsRootHandles(true);
304     dataMapTree.getSelectionModel().setSelectionMode(
305                 TreeSelectionModel.SINGLE_TREE_SELECTION);
306     DefaultTreeCellRenderer JavaDoc renderer = new DVTreeCellRenderer();
307
308     dataMapTree.setCellRenderer(renderer);
309
310     dataMapTree.addTreeSelectionListener(
311       dvModelerFrameHelper.getDataMapTreeTreeSelectionListener());
312     return dataMapTree;
313   }
314
315   private JTree JavaDoc buildDataViewTree(){
316     dataViewTree = new JTree JavaDoc(new DataViewTreeModel());
317     dataViewTree.getSelectionModel().setSelectionMode(
318                 TreeSelectionModel.SINGLE_TREE_SELECTION);
319     dataViewTree.setRootVisible(false);
320     dataViewTree.setShowsRootHandles(true);
321     DefaultTreeCellRenderer JavaDoc renderer = new DVTreeCellRenderer();
322
323     dataViewTree.setCellRenderer(renderer);
324
325     dataViewTree.addTreeSelectionListener(dvModelerFrameHelper.getDataViewTreeTreeSelectionListener());
326     return dataViewTree;
327   }
328
329   public JTree JavaDoc getDataViewTree(){
330     return dataViewTree;
331   }
332
333   public JTree JavaDoc getDataMapTree(){
334     return dataMapTree;
335   }
336
337   public CardPanel getTopCardPanel(){
338     return topCardPanel;
339   }
340
341   public JPanel JavaDoc getBottomCardPanel(){
342     return bottomCardPanel;
343   }
344
345   public JTabbedPane JavaDoc getDataTabbedPane(){
346     return dataTabbedPane;
347   }
348
349   public JTable JavaDoc getFieldsTable(){
350     return fieldsTable;
351   }
352
353   public JTable JavaDoc getRelationshipsTable(){
354     return relationshipsTable;
355   }
356
357   public JTile getBrowserTile(){
358     return browserTile;
359   }
360
361   public JTile getTopTile(){
362     return topTile;
363   }
364
365   public JTile getBottomTile(){
366     return bottomTile;
367   }
368
369   public JMenuItem JavaDoc getMenuItemClose(){
370     return close;
371   }
372   public JMenuItem JavaDoc getMenuItemLoadErrors(){
373     return loadErrors;
374   }
375   public JMenuItem JavaDoc getMenuItemSaveErrors(){
376     return saveErrors;
377   }
378
379
380
381
382
383
384 }
Popular Tags