1 56 package org.objectstyle.cayenne.modeler.editor; 57 58 import javax.swing.JScrollPane ; 59 import javax.swing.JTabbedPane ; 60 import javax.swing.event.ChangeEvent ; 61 import javax.swing.event.ChangeListener ; 62 63 import org.objectstyle.cayenne.modeler.ProjectController; 64 import org.objectstyle.cayenne.modeler.event.QueryDisplayEvent; 65 import org.objectstyle.cayenne.modeler.event.QueryDisplayListener; 66 import org.objectstyle.cayenne.query.SelectQuery; 67 68 73 public class SelectQueryTabbedView extends JTabbedPane { 74 75 protected ProjectController mediator; 76 protected SelectQueryMainTab mainTab; 77 protected SelectQueryPrefetchTab prefetchTab; 78 protected SelectQueryOrderingTab orderingTab; 79 protected int lastSelectionIndex; 80 81 public SelectQueryTabbedView(ProjectController mediator) { 82 this.mediator = mediator; 83 84 initView(); 85 initController(); 86 } 87 88 private void initView() { 89 setTabPlacement(JTabbedPane.TOP); 90 91 this.mainTab = new SelectQueryMainTab(mediator); 92 addTab("General", new JScrollPane (mainTab)); 93 94 this.orderingTab = new SelectQueryOrderingTab(mediator); 95 addTab("Orderings", new JScrollPane (orderingTab)); 96 97 this.prefetchTab = new SelectQueryPrefetchTab(mediator); 98 addTab("Prefetches", new JScrollPane (prefetchTab)); 99 } 100 101 private void initController() { 102 mediator.addQueryDisplayListener(new QueryDisplayListener() { 103 104 public void currentQueryChanged(QueryDisplayEvent e) { 105 initFromModel(); 106 } 107 }); 108 109 this.addChangeListener(new ChangeListener () { 110 111 public void stateChanged(ChangeEvent e) { 112 lastSelectionIndex = getSelectedIndex(); 113 updateTabs(); 114 } 115 }); 116 } 117 118 void initFromModel() { 119 if (!(mediator.getCurrentQuery() instanceof SelectQuery)) { 120 setVisible(false); 121 return; 122 } 123 124 if (mediator.getCurrentQuery().getRoot() == null) { 126 lastSelectionIndex = 0; 127 } 128 129 if (getSelectedIndex() == lastSelectionIndex) { 131 updateTabs(); 132 } 133 else { 135 setSelectedIndex(lastSelectionIndex); 136 } 137 138 setVisible(true); 139 } 140 141 void updateTabs() { 142 switch (lastSelectionIndex) { 143 case 0: 144 mainTab.initFromModel(); 145 break; 146 case 1: 147 orderingTab.initFromModel(); 148 break; 149 case 2: 150 prefetchTab.initFromModel(); 151 break; 152 } 153 } 154 } | Popular Tags |