KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > modeler > editor > EditorView


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 package org.objectstyle.cayenne.modeler.editor;
57
58 import java.awt.BorderLayout JavaDoc;
59 import java.awt.CardLayout JavaDoc;
60 import java.awt.Component JavaDoc;
61 import java.awt.Container JavaDoc;
62 import java.awt.Dimension JavaDoc;
63
64 import javax.swing.JPanel JavaDoc;
65 import javax.swing.JScrollPane JavaDoc;
66 import javax.swing.JSplitPane JavaDoc;
67
68 import org.objectstyle.cayenne.modeler.ProjectController;
69 import org.objectstyle.cayenne.modeler.ProjectTreeView;
70 import org.objectstyle.cayenne.modeler.editor.datanode.DataNodeEditor;
71 import org.objectstyle.cayenne.modeler.event.DataMapDisplayEvent;
72 import org.objectstyle.cayenne.modeler.event.DataMapDisplayListener;
73 import org.objectstyle.cayenne.modeler.event.DataNodeDisplayEvent;
74 import org.objectstyle.cayenne.modeler.event.DataNodeDisplayListener;
75 import org.objectstyle.cayenne.modeler.event.DbEntityDisplayListener;
76 import org.objectstyle.cayenne.modeler.event.DomainDisplayEvent;
77 import org.objectstyle.cayenne.modeler.event.DomainDisplayListener;
78 import org.objectstyle.cayenne.modeler.event.EntityDisplayEvent;
79 import org.objectstyle.cayenne.modeler.event.ObjEntityDisplayListener;
80 import org.objectstyle.cayenne.modeler.event.ProcedureDisplayEvent;
81 import org.objectstyle.cayenne.modeler.event.ProcedureDisplayListener;
82 import org.objectstyle.cayenne.modeler.event.QueryDisplayEvent;
83 import org.objectstyle.cayenne.modeler.event.QueryDisplayListener;
84 import org.objectstyle.cayenne.modeler.pref.ComponentGeometry;
85 import org.objectstyle.cayenne.pref.Domain;
86 import org.objectstyle.cayenne.query.ProcedureQuery;
87 import org.objectstyle.cayenne.query.Query;
88 import org.objectstyle.cayenne.query.SQLTemplate;
89 import org.objectstyle.cayenne.query.SelectQuery;
90
91 /**
92  * Main display area split into the project navigation tree on the left and selected
93  * object editor on the right.
94  */

95 public class EditorView extends JPanel JavaDoc implements ObjEntityDisplayListener,
96         DbEntityDisplayListener, DomainDisplayListener, DataMapDisplayListener,
97         DataNodeDisplayListener, ProcedureDisplayListener, QueryDisplayListener {
98
99     private static final String JavaDoc EMPTY_VIEW = "Empty";
100     private static final String JavaDoc DOMAIN_VIEW = "Domain";
101     private static final String JavaDoc NODE_VIEW = "Node";
102     private static final String JavaDoc DATA_MAP_VIEW = "DataMap";
103     private static final String JavaDoc OBJ_VIEW = "ObjView";
104     private static final String JavaDoc DB_VIEW = "DbView";
105     private static final String JavaDoc PROCEDURE_VIEW = "ProcedureView";
106     private static final String JavaDoc SELECT_QUERY_VIEW = "SelectQueryView";
107     private static final String JavaDoc SQL_TEMPLATE_VIEW = "SQLTemplateView";
108     private static final String JavaDoc PROCEDURE_QUERY_VIEW = "ProcedureQueryView";
109
110     protected ProjectController eventController;
111     protected JSplitPane JavaDoc splitPane;
112     protected Container JavaDoc detailPanel;
113
114     protected CardLayout JavaDoc detailLayout;
115
116     public EditorView(ProjectController eventController) {
117         this.eventController = eventController;
118         initView();
119         initController();
120     }
121
122     private void initView() {
123
124         // init widgets
125
ProjectTreeView treePanel = new ProjectTreeView(eventController);
126         treePanel.setMinimumSize(new Dimension JavaDoc(50, 200));
127
128         this.detailPanel = new JPanel JavaDoc();
129         this.splitPane = new JSplitPane JavaDoc(JSplitPane.HORIZONTAL_SPLIT, true);
130
131         // assemble...
132

133         this.detailLayout = new CardLayout JavaDoc();
134         detailPanel.setLayout(detailLayout);
135
136         // some but not all panels must be wrapped in a scroll pane
137
// those that are not wrapped usually have there own scrollers
138
// in subpanels...
139

140         detailPanel.add(new JPanel JavaDoc(), EMPTY_VIEW);
141
142         Component JavaDoc domainView = new DataDomainView(eventController);
143         detailPanel.add(new JScrollPane JavaDoc(domainView), DOMAIN_VIEW);
144
145         DataNodeEditor nodeController = new DataNodeEditor(eventController);
146         detailPanel.add(new JScrollPane JavaDoc(nodeController.getView()), NODE_VIEW);
147
148         Component JavaDoc dataMapView = new DataMapView(eventController);
149         detailPanel.add(new JScrollPane JavaDoc(dataMapView), DATA_MAP_VIEW);
150
151         Component JavaDoc procedureView = new ProcedureTabbedView(eventController);
152         detailPanel.add(procedureView, PROCEDURE_VIEW);
153
154         Component JavaDoc selectQueryView = new SelectQueryTabbedView(eventController);
155         detailPanel.add(selectQueryView, SELECT_QUERY_VIEW);
156
157         Component JavaDoc sqlTemplateView = new SQLTemplateTabbedView(eventController);
158         detailPanel.add(sqlTemplateView, SQL_TEMPLATE_VIEW);
159
160         Component JavaDoc procedureQueryView = new ProcedureQueryView(eventController);
161         detailPanel.add(new JScrollPane JavaDoc(procedureQueryView), PROCEDURE_QUERY_VIEW);
162
163         Component JavaDoc objDetailView = new ObjEntityTabbedView(eventController);
164         detailPanel.add(objDetailView, OBJ_VIEW);
165
166         Component JavaDoc dbDetailView = new DbEntityTabbedView(eventController);
167         detailPanel.add(dbDetailView, DB_VIEW);
168
169         splitPane.setLeftComponent(new JScrollPane JavaDoc(treePanel));
170         splitPane.setRightComponent(detailPanel);
171
172         setLayout(new BorderLayout JavaDoc());
173         add(splitPane, BorderLayout.CENTER);
174     }
175
176     private void initController() {
177         eventController.addDomainDisplayListener(this);
178         eventController.addDataNodeDisplayListener(this);
179         eventController.addDataMapDisplayListener(this);
180         eventController.addObjEntityDisplayListener(this);
181         eventController.addDbEntityDisplayListener(this);
182         eventController.addProcedureDisplayListener(this);
183         eventController.addQueryDisplayListener(this);
184
185         Domain domain = eventController.getApplicationPreferenceDomain().getSubdomain(
186                 this.getClass());
187         ComponentGeometry geometry = (ComponentGeometry) domain.getDetail(
188                 "splitPane.divider",
189                 ComponentGeometry.class,
190                 true);
191
192         geometry.bindIntProperty(splitPane, JSplitPane.DIVIDER_LOCATION_PROPERTY, 150);
193     }
194
195     public void currentProcedureChanged(ProcedureDisplayEvent e) {
196         if (e.getProcedure() == null)
197             detailLayout.show(detailPanel, EMPTY_VIEW);
198         else
199             detailLayout.show(detailPanel, PROCEDURE_VIEW);
200     }
201
202     public void currentDomainChanged(DomainDisplayEvent e) {
203         if (e.getDomain() == null)
204             detailLayout.show(detailPanel, EMPTY_VIEW);
205         else
206             detailLayout.show(detailPanel, DOMAIN_VIEW);
207     }
208
209     public void currentDataNodeChanged(DataNodeDisplayEvent e) {
210         if (e.getDataNode() == null)
211             detailLayout.show(detailPanel, EMPTY_VIEW);
212         else
213             detailLayout.show(detailPanel, NODE_VIEW);
214     }
215
216     public void currentDataMapChanged(DataMapDisplayEvent e) {
217         if (e.getDataMap() == null)
218             detailLayout.show(detailPanel, EMPTY_VIEW);
219         else
220             detailLayout.show(detailPanel, DATA_MAP_VIEW);
221     }
222
223     public void currentObjEntityChanged(EntityDisplayEvent e) {
224         if (e.getEntity() == null)
225             detailLayout.show(detailPanel, EMPTY_VIEW);
226         else
227             detailLayout.show(detailPanel, OBJ_VIEW);
228     }
229
230     public void currentDbEntityChanged(EntityDisplayEvent e) {
231         if (e.getEntity() == null)
232             detailLayout.show(detailPanel, EMPTY_VIEW);
233         else
234             detailLayout.show(detailPanel, DB_VIEW);
235     }
236
237     public void currentQueryChanged(QueryDisplayEvent e) {
238         Query query = e.getQuery();
239
240         if (query instanceof SelectQuery) {
241             detailLayout.show(detailPanel, SELECT_QUERY_VIEW);
242         }
243         else if (query instanceof SQLTemplate) {
244             detailLayout.show(detailPanel, SQL_TEMPLATE_VIEW);
245         }
246         else if (query instanceof ProcedureQuery) {
247             detailLayout.show(detailPanel, PROCEDURE_QUERY_VIEW);
248         }
249         else {
250             detailLayout.show(detailPanel, EMPTY_VIEW);
251         }
252     }
253 }
Popular Tags