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