1 56 57 package org.objectstyle.cayenne.modeler; 58 59 import java.awt.BorderLayout ; 60 import java.awt.FlowLayout ; 61 import java.awt.Font ; 62 63 import javax.swing.Box ; 64 import javax.swing.JFrame ; 65 import javax.swing.JLabel ; 66 import javax.swing.JMenu ; 67 import javax.swing.JMenuBar ; 68 import javax.swing.JPanel ; 69 import javax.swing.JToolBar ; 70 71 import org.objectstyle.cayenne.map.DerivedDbEntity; 72 import org.objectstyle.cayenne.modeler.action.AboutAction; 73 import org.objectstyle.cayenne.modeler.action.ConfigurePreferencesAction; 74 import org.objectstyle.cayenne.modeler.action.CreateAttributeAction; 75 import org.objectstyle.cayenne.modeler.action.CreateDataMapAction; 76 import org.objectstyle.cayenne.modeler.action.CreateDbEntityAction; 77 import org.objectstyle.cayenne.modeler.action.CreateDerivedDbEntityAction; 78 import org.objectstyle.cayenne.modeler.action.CreateDomainAction; 79 import org.objectstyle.cayenne.modeler.action.CreateNodeAction; 80 import org.objectstyle.cayenne.modeler.action.CreateObjEntityAction; 81 import org.objectstyle.cayenne.modeler.action.CreateProcedureAction; 82 import org.objectstyle.cayenne.modeler.action.CreateProcedureParameterAction; 83 import org.objectstyle.cayenne.modeler.action.CreateQueryAction; 84 import org.objectstyle.cayenne.modeler.action.CreateRelationshipAction; 85 import org.objectstyle.cayenne.modeler.action.DbEntitySyncAction; 86 import org.objectstyle.cayenne.modeler.action.DerivedEntitySyncAction; 87 import org.objectstyle.cayenne.modeler.action.ExitAction; 88 import org.objectstyle.cayenne.modeler.action.GenerateClassesAction; 89 import org.objectstyle.cayenne.modeler.action.GenerateDBAction; 90 import org.objectstyle.cayenne.modeler.action.ImportDataMapAction; 91 import org.objectstyle.cayenne.modeler.action.ImportDBAction; 92 import org.objectstyle.cayenne.modeler.action.ImportEOModelAction; 93 import org.objectstyle.cayenne.modeler.action.NavigateBackwardAction; 94 import org.objectstyle.cayenne.modeler.action.NavigateForwardAction; 95 import org.objectstyle.cayenne.modeler.action.NewProjectAction; 96 import org.objectstyle.cayenne.modeler.action.ObjEntitySyncAction; 97 import org.objectstyle.cayenne.modeler.action.OpenProjectAction; 98 import org.objectstyle.cayenne.modeler.action.ProjectAction; 99 import org.objectstyle.cayenne.modeler.action.RemoveAction; 100 import org.objectstyle.cayenne.modeler.action.RevertAction; 101 import org.objectstyle.cayenne.modeler.action.SaveAction; 102 import org.objectstyle.cayenne.modeler.action.SaveAsAction; 103 import org.objectstyle.cayenne.modeler.action.ValidateAction; 104 import org.objectstyle.cayenne.modeler.editor.EditorView; 105 import org.objectstyle.cayenne.modeler.event.AttributeDisplayEvent; 106 import org.objectstyle.cayenne.modeler.event.DataMapDisplayEvent; 107 import org.objectstyle.cayenne.modeler.event.DataMapDisplayListener; 108 import org.objectstyle.cayenne.modeler.event.DataNodeDisplayEvent; 109 import org.objectstyle.cayenne.modeler.event.DataNodeDisplayListener; 110 import org.objectstyle.cayenne.modeler.event.DbAttributeDisplayListener; 111 import org.objectstyle.cayenne.modeler.event.DbEntityDisplayListener; 112 import org.objectstyle.cayenne.modeler.event.DbRelationshipDisplayListener; 113 import org.objectstyle.cayenne.modeler.event.EntityDisplayEvent; 114 import org.objectstyle.cayenne.modeler.event.ObjAttributeDisplayListener; 115 import org.objectstyle.cayenne.modeler.event.ObjEntityDisplayListener; 116 import org.objectstyle.cayenne.modeler.event.ObjRelationshipDisplayListener; 117 import org.objectstyle.cayenne.modeler.event.ProcedureDisplayEvent; 118 import org.objectstyle.cayenne.modeler.event.ProcedureDisplayListener; 119 import org.objectstyle.cayenne.modeler.event.ProcedureParameterDisplayEvent; 120 import org.objectstyle.cayenne.modeler.event.ProcedureParameterDisplayListener; 121 import org.objectstyle.cayenne.modeler.event.QueryDisplayEvent; 122 import org.objectstyle.cayenne.modeler.event.QueryDisplayListener; 123 import org.objectstyle.cayenne.modeler.event.RelationshipDisplayEvent; 124 import org.objectstyle.cayenne.modeler.util.CayenneAction; 125 import org.objectstyle.cayenne.modeler.util.RecentFileMenu; 126 127 131 public class CayenneModelerFrame extends JFrame implements DataNodeDisplayListener, 132 DataMapDisplayListener, ObjEntityDisplayListener, DbEntityDisplayListener, 133 ObjAttributeDisplayListener, DbAttributeDisplayListener, 134 ObjRelationshipDisplayListener, DbRelationshipDisplayListener, 135 QueryDisplayListener, ProcedureDisplayListener, ProcedureParameterDisplayListener { 136 137 protected EditorView view; 138 protected RecentFileMenu recentFileMenu; 139 protected CayenneModelerController controller; 140 protected JLabel status; 141 142 public CayenneModelerFrame(CayenneModelerController controller) { 143 super(ModelerConstants.TITLE); 144 145 this.controller = controller; 146 147 initMenus(); 148 initToolbar(); 149 initStatusBar(); 150 } 151 152 155 public CayenneAction getAction(String key) { 156 return controller.getApplication().getAction(key); 157 } 158 159 protected void initMenus() { 160 getContentPane().setLayout(new BorderLayout ()); 161 162 JMenu fileMenu = new JMenu ("File"); 163 JMenu projectMenu = new JMenu ("Project"); 164 JMenu toolMenu = new JMenu ("Tools"); 165 JMenu helpMenu = new JMenu ("Help"); 166 167 fileMenu.add(getAction(NewProjectAction.getActionName()).buildMenu()); 168 fileMenu.add(getAction(OpenProjectAction.getActionName()).buildMenu()); 169 fileMenu.add(getAction(ProjectAction.getActionName()).buildMenu()); 170 fileMenu.add(getAction(ImportDataMapAction.getActionName()).buildMenu()); 171 fileMenu.addSeparator(); 172 fileMenu.add(getAction(SaveAction.getActionName()).buildMenu()); 173 fileMenu.add(getAction(SaveAsAction.getActionName()).buildMenu()); 174 fileMenu.add(getAction(RevertAction.getActionName()).buildMenu()); 175 fileMenu.addSeparator(); 176 177 recentFileMenu = new RecentFileMenu("Recent Files"); 178 recentFileMenu.rebuildFromPreferences(); 179 recentFileMenu.setEnabled(recentFileMenu.getMenuComponentCount() > 0); 180 fileMenu.add(recentFileMenu); 181 182 fileMenu.addSeparator(); 183 fileMenu.add(getAction(ExitAction.getActionName()).buildMenu()); 184 185 projectMenu.add(getAction(ValidateAction.getActionName()).buildMenu()); 186 projectMenu.addSeparator(); 187 projectMenu.add(getAction(CreateDomainAction.getActionName()).buildMenu()); 188 projectMenu.add(getAction(CreateNodeAction.getActionName()).buildMenu()); 189 projectMenu.add(getAction(CreateDataMapAction.getActionName()).buildMenu()); 190 191 projectMenu.add(getAction(CreateObjEntityAction.getActionName()).buildMenu()); 192 projectMenu.add(getAction(CreateDbEntityAction.getActionName()).buildMenu()); 193 projectMenu.add(getAction(CreateDerivedDbEntityAction.getActionName()) 194 .buildMenu()); 195 projectMenu.add(getAction(CreateProcedureAction.getActionName()).buildMenu()); 196 projectMenu.add(getAction(CreateQueryAction.getActionName()).buildMenu()); 197 projectMenu.addSeparator(); 198 projectMenu.add(getAction(ObjEntitySyncAction.getActionName()).buildMenu()); 199 projectMenu.add(getAction(DerivedEntitySyncAction.getActionName()).buildMenu()); 200 projectMenu.addSeparator(); 201 projectMenu.add(getAction(RemoveAction.getActionName()).buildMenu()); 202 203 toolMenu.add(getAction(ImportDBAction.getActionName()).buildMenu()); 204 toolMenu.add(getAction(ImportEOModelAction.getActionName()).buildMenu()); 205 toolMenu.addSeparator(); 206 toolMenu.add(getAction(GenerateClassesAction.getActionName()).buildMenu()); 207 toolMenu.add(getAction(GenerateDBAction.getActionName()).buildMenu()); 208 toolMenu.addSeparator(); 209 toolMenu.add(getAction(ConfigurePreferencesAction.getActionName()).buildMenu()); 210 211 helpMenu.add(getAction(AboutAction.getActionName()).buildMenu()); 212 213 JMenuBar menuBar = new JMenuBar (); 214 215 menuBar.add(fileMenu); 216 menuBar.add(projectMenu); 217 menuBar.add(toolMenu); 218 menuBar.add(helpMenu); 219 220 setJMenuBar(menuBar); 221 } 222 223 protected void initStatusBar() { 224 status = new JLabel (); 225 status.setFont(status.getFont().deriveFont(Font.PLAIN, 10)); 226 227 JPanel statusBar = new JPanel (new FlowLayout (FlowLayout.LEFT, 3, 1)); 228 statusBar.add(Box.createVerticalStrut(16)); 230 statusBar.add(status); 231 232 getContentPane().add(statusBar, BorderLayout.SOUTH); 233 } 234 235 236 protected void initToolbar() { 237 JToolBar toolBar = new JToolBar (); 238 toolBar.add(getAction(NewProjectAction.getActionName()).buildButton()); 239 toolBar.add(getAction(OpenProjectAction.getActionName()).buildButton()); 240 toolBar.add(getAction(SaveAction.getActionName()).buildButton()); 241 toolBar.add(getAction(RemoveAction.getActionName()).buildButton()); 242 243 toolBar.addSeparator(); 244 245 toolBar.add(getAction(CreateDomainAction.getActionName()).buildButton()); 246 toolBar.add(getAction(CreateNodeAction.getActionName()).buildButton()); 247 toolBar.add(getAction(CreateDataMapAction.getActionName()).buildButton()); 248 249 toolBar.addSeparator(); 250 251 toolBar.add(getAction(CreateDbEntityAction.getActionName()).buildButton()); 252 toolBar.add(getAction(CreateDerivedDbEntityAction.getActionName()).buildButton()); 253 toolBar.add(getAction(CreateProcedureAction.getActionName()).buildButton()); 254 255 toolBar.addSeparator(); 256 257 toolBar.add(getAction(CreateObjEntityAction.getActionName()).buildButton()); 258 toolBar.add(getAction(CreateQueryAction.getActionName()).buildButton()); 259 260 toolBar.addSeparator(); 261 262 toolBar.add(getAction(NavigateBackwardAction.getActionName()).buildButton()); 263 toolBar.add(getAction(NavigateForwardAction.getActionName()).buildButton()); 264 265 getContentPane().add(toolBar, BorderLayout.NORTH); 266 } 267 268 public void currentDataNodeChanged(DataNodeDisplayEvent e) { 269 enableDataNodeMenu(); 270 getAction(RemoveAction.getActionName()).setName("Remove DataNode"); 271 } 272 273 public void currentDataMapChanged(DataMapDisplayEvent e) { 274 enableDataMapMenu(); 275 getAction(RemoveAction.getActionName()).setName("Remove DataMap"); 276 } 277 278 public void currentObjEntityChanged(EntityDisplayEvent e) { 279 enableObjEntityMenu(); 280 getAction(RemoveAction.getActionName()).setName("Remove ObjEntity"); 281 } 282 283 public void currentDbEntityChanged(EntityDisplayEvent e) { 284 enableDbEntityMenu(); 285 getAction(RemoveAction.getActionName()).setName("Remove DbEntity"); 286 } 287 288 public void currentQueryChanged(QueryDisplayEvent e) { 289 enableDataMapMenu(); 290 291 if (e.getQuery() != null) { 292 getAction(RemoveAction.getActionName()).setName("Remove Query"); 293 } 294 } 295 296 public void currentProcedureChanged(ProcedureDisplayEvent e) { 297 enableProcedureMenu(); 298 299 if (e.getProcedure() != null) { 300 getAction(RemoveAction.getActionName()).setName("Remove Stored Procedure"); 301 } 302 } 303 304 public void currentDbAttributeChanged(AttributeDisplayEvent e) { 305 enableDbEntityMenu(); 306 if (e.getAttribute() != null) { 307 getAction(RemoveAction.getActionName()).setName("Remove DbAttribute"); 308 } 309 } 310 311 public void currentProcedureParameterChanged(ProcedureParameterDisplayEvent e) { 312 enableProcedureMenu(); 313 if (e.getProcedureParameter() != null) { 314 getAction(RemoveAction.getActionName()).setName("Remove Parameter"); 315 } 316 } 317 318 public void currentObjAttributeChanged(AttributeDisplayEvent e) { 319 enableObjEntityMenu(); 320 if (e.getAttribute() != null) { 321 getAction(RemoveAction.getActionName()).setName("Remove ObjAttribute"); 322 } 323 } 324 325 public void currentDbRelationshipChanged(RelationshipDisplayEvent e) { 326 enableDbEntityMenu(); 327 if (e.getRelationship() != null) { 328 getAction(RemoveAction.getActionName()).setName("Remove DbRelationship"); 329 } 330 } 331 332 public void currentObjRelationshipChanged(RelationshipDisplayEvent e) { 333 enableObjEntityMenu(); 334 if (e.getRelationship() != null) { 335 getAction(RemoveAction.getActionName()).setName("Remove ObjRelationship"); 336 } 337 } 338 339 private void enableDataMapMenu() { 340 if (controller.getProjectController().getCurrentDataNode() != null) 341 enableDataNodeMenu(); 342 else { 343 controller.getActionController().domainSelected( 345 controller.getProjectController().getCurrentDataDomain()); 346 } 347 348 getAction(GenerateClassesAction.getActionName()).setEnabled(true); 349 getAction(CreateObjEntityAction.getActionName()).setEnabled(true); 350 getAction(CreateDbEntityAction.getActionName()).setEnabled(true); 351 getAction(CreateDerivedDbEntityAction.getActionName()).setEnabled(true); 352 getAction(CreateQueryAction.getActionName()).setEnabled(true); 353 getAction(CreateProcedureAction.getActionName()).setEnabled(true); 354 getAction(GenerateDBAction.getActionName()).setEnabled(true); 355 356 getAction(CreateAttributeAction.getActionName()).setName("Create Attribute"); 358 } 359 360 private void enableObjEntityMenu() { 361 enableDataMapMenu(); 362 getAction(ObjEntitySyncAction.getActionName()).setEnabled(true); 363 getAction(CreateAttributeAction.getActionName()).setEnabled(true); 364 getAction(CreateRelationshipAction.getActionName()).setEnabled(true); 365 } 366 367 private void enableDbEntityMenu() { 368 enableDataMapMenu(); 369 getAction(CreateAttributeAction.getActionName()).setEnabled(true); 370 getAction(CreateRelationshipAction.getActionName()).setEnabled(true); 371 getAction(DbEntitySyncAction.getActionName()).setEnabled(true); 372 373 if (controller.getProjectController().getCurrentDbEntity() instanceof DerivedDbEntity) { 374 getAction(DerivedEntitySyncAction.getActionName()).setEnabled(true); 375 } 376 } 377 378 private void enableProcedureMenu() { 379 enableDataMapMenu(); 380 getAction(CreateProcedureParameterAction.getActionName()).setEnabled(true); 381 } 382 383 private void enableDataNodeMenu() { 384 controller.getActionController().domainSelected( 386 controller.getProjectController().getCurrentDataDomain()); 387 } 388 389 394 public EditorView getView() { 395 return view; 396 } 397 398 public JLabel getStatus() { 399 return status; 400 } 401 402 407 public RecentFileMenu getRecentFileMenu() { 408 return recentFileMenu; 409 } 410 411 414 public void setView(EditorView view) { 415 boolean change = false; 416 417 if (this.view != null) { 418 getContentPane().remove(this.view); 419 change = true; 420 } 421 422 this.view = view; 423 424 if (view != null) { 425 getContentPane().add(view, BorderLayout.CENTER); 426 change = true; 427 } 428 429 if (change) { 430 validate(); 431 } 432 } 433 } | Popular Tags |