1 56 package org.objectstyle.cayenne.modeler.editor; 57 58 import java.awt.BorderLayout ; 59 import java.awt.CardLayout ; 60 import java.awt.Component ; 61 import java.awt.Container ; 62 import java.awt.Dimension ; 63 64 import javax.swing.JPanel ; 65 import javax.swing.JScrollPane ; 66 import javax.swing.JSplitPane ; 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 95 public class EditorView extends JPanel implements ObjEntityDisplayListener, 96 DbEntityDisplayListener, DomainDisplayListener, DataMapDisplayListener, 97 DataNodeDisplayListener, ProcedureDisplayListener, QueryDisplayListener { 98 99 private static final String EMPTY_VIEW = "Empty"; 100 private static final String DOMAIN_VIEW = "Domain"; 101 private static final String NODE_VIEW = "Node"; 102 private static final String DATA_MAP_VIEW = "DataMap"; 103 private static final String OBJ_VIEW = "ObjView"; 104 private static final String DB_VIEW = "DbView"; 105 private static final String PROCEDURE_VIEW = "ProcedureView"; 106 private static final String SELECT_QUERY_VIEW = "SelectQueryView"; 107 private static final String SQL_TEMPLATE_VIEW = "SQLTemplateView"; 108 private static final String PROCEDURE_QUERY_VIEW = "ProcedureQueryView"; 109 110 protected ProjectController eventController; 111 protected JSplitPane splitPane; 112 protected Container detailPanel; 113 114 protected CardLayout detailLayout; 115 116 public EditorView(ProjectController eventController) { 117 this.eventController = eventController; 118 initView(); 119 initController(); 120 } 121 122 private void initView() { 123 124 ProjectTreeView treePanel = new ProjectTreeView(eventController); 126 treePanel.setMinimumSize(new Dimension (50, 200)); 127 128 this.detailPanel = new JPanel (); 129 this.splitPane = new JSplitPane (JSplitPane.HORIZONTAL_SPLIT, true); 130 131 133 this.detailLayout = new CardLayout (); 134 detailPanel.setLayout(detailLayout); 135 136 140 detailPanel.add(new JPanel (), EMPTY_VIEW); 141 142 Component domainView = new DataDomainView(eventController); 143 detailPanel.add(new JScrollPane (domainView), DOMAIN_VIEW); 144 145 DataNodeEditor nodeController = new DataNodeEditor(eventController); 146 detailPanel.add(new JScrollPane (nodeController.getView()), NODE_VIEW); 147 148 Component dataMapView = new DataMapView(eventController); 149 detailPanel.add(new JScrollPane (dataMapView), DATA_MAP_VIEW); 150 151 Component procedureView = new ProcedureTabbedView(eventController); 152 detailPanel.add(procedureView, PROCEDURE_VIEW); 153 154 Component selectQueryView = new SelectQueryTabbedView(eventController); 155 detailPanel.add(selectQueryView, SELECT_QUERY_VIEW); 156 157 Component sqlTemplateView = new SQLTemplateTabbedView(eventController); 158 detailPanel.add(sqlTemplateView, SQL_TEMPLATE_VIEW); 159 160 Component procedureQueryView = new ProcedureQueryView(eventController); 161 detailPanel.add(new JScrollPane (procedureQueryView), PROCEDURE_QUERY_VIEW); 162 163 Component objDetailView = new ObjEntityTabbedView(eventController); 164 detailPanel.add(objDetailView, OBJ_VIEW); 165 166 Component dbDetailView = new DbEntityTabbedView(eventController); 167 detailPanel.add(dbDetailView, DB_VIEW); 168 169 splitPane.setLeftComponent(new JScrollPane (treePanel)); 170 splitPane.setRightComponent(detailPanel); 171 172 setLayout(new BorderLayout ()); 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 |