1 56 57 package org.objectstyle.cayenne.dataview.dvmodeler; 58 59 import java.awt.BorderLayout ; 60 import java.awt.CardLayout ; 61 import java.awt.Component ; 62 import java.awt.Insets ; 63 64 import javax.swing.AbstractButton ; 65 import javax.swing.Action ; 66 import javax.swing.ImageIcon ; 67 import javax.swing.JFrame ; 68 import javax.swing.JMenu ; 69 import javax.swing.JMenuBar ; 70 import javax.swing.JMenuItem ; 71 import javax.swing.JPanel ; 72 import javax.swing.JScrollPane ; 73 import javax.swing.JSplitPane ; 74 import javax.swing.JTabbedPane ; 75 import javax.swing.JTable ; 76 import javax.swing.JToolBar ; 77 import javax.swing.JTree ; 78 import javax.swing.ListSelectionModel ; 79 import javax.swing.WindowConstants ; 80 import javax.swing.plaf.basic.BasicSplitPaneDivider ; 81 import javax.swing.plaf.basic.BasicSplitPaneUI ; 82 import javax.swing.tree.DefaultTreeCellRenderer ; 83 import javax.swing.tree.TreeSelectionModel ; 84 85 import com.jgoodies.forms.factories.Borders; 86 import com.jgoodies.looks.HeaderStyle; 87 import com.jgoodies.looks.Options; 88 89 95 96 public class DVModelerFrame extends JFrame { 97 private DVModelerFrameHelper dvModelerFrameHelper; 98 99 private Action saveAction; 100 private Action openAction; 101 private Action addNewObjEntityViewAction; 102 private Action addNewFieldAction; 103 private Action addNewDataViewAction; 104 private Action deleteAction; 105 private JMenuItem close; 106 private JMenuItem loadErrors; 107 private JMenuItem saveErrors; 108 109 private JSplitPane fieldsSplitPane; 110 private JSplitPane splitPane; 111 112 private JTile browserTile; 113 private JTile topTile; 114 private JTile bottomTile; 115 116 private JTree dataViewTree; 117 private JTree dataMapTree; 118 119 private CardPanel topCardPanel; 120 private JPanel bottomCardPanel; 121 122 private JTabbedPane dataTabbedPane; 123 124 private JTable fieldsTable; 125 private JTable 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 ()); 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 menuBar = new JMenuBar (); 156 menuBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); 157 158 JMenu menuFile = new JMenu ("File"); 159 menuBar.add(menuFile); 160 menuFile.add(openAction); 161 saveAction.setEnabled(false); 162 menuFile.add(saveAction); 163 close = new JMenuItem ("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 ("Show Load Errors"); 172 loadErrors.addActionListener(dvModelerFrameHelper.getMenuItemLoadErrorsActionListenr()); 173 loadErrors.setEnabled(false); 174 menuFile.add(loadErrors); 175 176 saveErrors = new JMenuItem ("Show Save Errors"); 177 saveErrors.addActionListener(dvModelerFrameHelper.getMenuItemSaveErrorsActionListener()); 178 saveErrors.setEnabled(false); 179 menuFile.add(saveErrors); 180 181 menuFile.addSeparator(); 182 183 JMenuItem exit = new JMenuItem ("Exit"); 184 exit.addActionListener( 185 dvModelerFrameHelper.getMenuItemExitActionListener()); 186 menuFile.add(exit); 187 188 JMenu menuEdit = new JMenu ("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 toolBar = new JToolBar (); 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 buttonMargin = new Insets (0, 0, 0, 0); 218 int count = toolBar.getComponentCount(); 219 for (int i = 0; i < count; i++) { 220 Component c = toolBar.getComponentAtIndex(i); 221 if (c instanceof AbstractButton ) { 222 ((AbstractButton )c).setMargin(buttonMargin); 223 } 224 } 225 226 getContentPane().add(toolBar, BorderLayout.NORTH); 227 } 228 229 private void buildMainPanel(){ 230 JScrollPane mapsScrollPane = new JScrollPane (buildDataMapTree()); 231 mapsScrollPane.setBorder(Borders.EMPTY_BORDER); 232 JScrollPane viewsScrollPane = new JScrollPane (buildDataViewTree()); 233 viewsScrollPane.setBorder(Borders.EMPTY_BORDER); 234 dataTabbedPane = new JTabbedPane (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 (DVModelerFrame.class.getResource("images/dataview-node.gif")), 240 viewsScrollPane); 241 dataTabbedPane.addTab( 242 "Entities", 243 new ImageIcon (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 ( 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 divider = ((BasicSplitPaneUI )fieldsSplitPane.getUI()).getDivider(); 258 divider.setBorder(Borders.EMPTY_BORDER); 259 260 splitPane = new JSplitPane ( 261 JSplitPane.HORIZONTAL_SPLIT, 262 browserTile = new JTile(dataTabbedPane), 263 fieldsSplitPane); 264 265 splitPane.setDividerLocation(250); 266 267 divider = ((BasicSplitPaneUI )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 cardLayout = (CardLayout )bottomCardPanel.getLayout(); 274 cardLayout.show(bottomCardPanel, "emptyPanel"); 275 } 276 277 private JPanel buildBottomCardPanel(){ 278 JPanel bottomPanel = new JPanel (); 279 CardLayout bottomCardLayout = new CardLayout (); 280 bottomPanel.setLayout( bottomCardLayout ); 281 JPanel emptyPanel = new JPanel (); 282 bottomPanel.add(emptyPanel, "emptyPanel"); 283 284 fieldsTable = new JTable (); 285 fieldsTable.setModel(new FieldsTableModel()); 286 fieldsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 287 JScrollPane scrollPane = new JScrollPane (fieldsTable); 288 scrollPane.setBorder(Borders.EMPTY_BORDER); 289 bottomPanel.add(scrollPane, "fieldsTable"); 290 291 relationshipsTable = new JTable (new RelationshipsTableModel()); 292 relationshipsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 293 scrollPane = new JScrollPane (relationshipsTable); 294 scrollPane.setBorder(Borders.EMPTY_BORDER); 295 bottomPanel.add(scrollPane, "relationshipsTable"); 296 297 return bottomPanel; 298 } 299 300 private JTree buildDataMapTree(){ 301 dataMapTree = new JTree (new DataMapTreeModel()); 302 dataMapTree.setRootVisible(false); 303 dataMapTree.setShowsRootHandles(true); 304 dataMapTree.getSelectionModel().setSelectionMode( 305 TreeSelectionModel.SINGLE_TREE_SELECTION); 306 DefaultTreeCellRenderer renderer = new DVTreeCellRenderer(); 307 308 dataMapTree.setCellRenderer(renderer); 309 310 dataMapTree.addTreeSelectionListener( 311 dvModelerFrameHelper.getDataMapTreeTreeSelectionListener()); 312 return dataMapTree; 313 } 314 315 private JTree buildDataViewTree(){ 316 dataViewTree = new JTree (new DataViewTreeModel()); 317 dataViewTree.getSelectionModel().setSelectionMode( 318 TreeSelectionModel.SINGLE_TREE_SELECTION); 319 dataViewTree.setRootVisible(false); 320 dataViewTree.setShowsRootHandles(true); 321 DefaultTreeCellRenderer renderer = new DVTreeCellRenderer(); 322 323 dataViewTree.setCellRenderer(renderer); 324 325 dataViewTree.addTreeSelectionListener(dvModelerFrameHelper.getDataViewTreeTreeSelectionListener()); 326 return dataViewTree; 327 } 328 329 public JTree getDataViewTree(){ 330 return dataViewTree; 331 } 332 333 public JTree getDataMapTree(){ 334 return dataMapTree; 335 } 336 337 public CardPanel getTopCardPanel(){ 338 return topCardPanel; 339 } 340 341 public JPanel getBottomCardPanel(){ 342 return bottomCardPanel; 343 } 344 345 public JTabbedPane getDataTabbedPane(){ 346 return dataTabbedPane; 347 } 348 349 public JTable getFieldsTable(){ 350 return fieldsTable; 351 } 352 353 public JTable 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 getMenuItemClose(){ 370 return close; 371 } 372 public JMenuItem getMenuItemLoadErrors(){ 373 return loadErrors; 374 } 375 public JMenuItem getMenuItemSaveErrors(){ 376 return saveErrors; 377 } 378 379 380 381 382 383 384 } | Popular Tags |