1 56 package org.objectstyle.cayenne.modeler.editor; 57 58 import java.awt.BorderLayout ; 59 import java.awt.event.ActionEvent ; 60 import java.awt.event.ActionListener ; 61 import java.util.ArrayList ; 62 import java.util.Collections ; 63 import java.util.List ; 64 65 import javax.swing.DefaultComboBoxModel ; 66 import javax.swing.JCheckBox ; 67 import javax.swing.JComboBox ; 68 69 import org.objectstyle.cayenne.map.DataMap; 70 import org.objectstyle.cayenne.map.ObjEntity; 71 import org.objectstyle.cayenne.modeler.ProjectController; 72 import org.objectstyle.cayenne.modeler.util.CayenneWidgetFactory; 73 import org.objectstyle.cayenne.modeler.util.CellRenderers; 74 import org.objectstyle.cayenne.modeler.util.Comparators; 75 import org.objectstyle.cayenne.query.GenericSelectQuery; 76 77 import com.jgoodies.forms.builder.PanelBuilder; 78 import com.jgoodies.forms.layout.CellConstraints; 79 import com.jgoodies.forms.layout.FormLayout; 80 81 87 public abstract class RawQueryPropertiesPanel extends SelectPropertiesPanel { 88 89 protected JCheckBox dataObjects; 90 protected JComboBox entities; 91 92 public RawQueryPropertiesPanel(ProjectController mediator) { 93 super(mediator); 94 } 95 96 protected void initController() { 97 super.initController(); 98 dataObjects.addActionListener(new ActionListener () { 99 100 public void actionPerformed(ActionEvent event) { 101 setFetchingDataObjects(dataObjects.isSelected()); 102 } 103 }); 104 105 entities.addActionListener(new ActionListener () { 106 107 public void actionPerformed(ActionEvent event) { 108 ObjEntity entity = (ObjEntity) entities.getModel().getSelectedItem(); 109 setEntity(entity); 110 } 111 }); 112 } 113 114 protected void initView() { 115 super.initView(); 116 117 119 dataObjects = new JCheckBox (); 120 121 entities = CayenneWidgetFactory.createComboBox(); 122 entities.setRenderer(CellRenderers.listRendererWithIcons()); 123 124 CellConstraints cc = new CellConstraints(); 126 FormLayout layout = new FormLayout( 127 "right:max(80dlu;pref), 3dlu, left:max(10dlu;pref), " 128 + "3dlu, left:max(37dlu;pref), 3dlu, fill:max(147dlu;pref)", 129 "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p"); 130 PanelBuilder builder = new PanelBuilder(layout); 131 builder.setDefaultDialogBorder(); 132 133 builder.addSeparator("", cc.xywh(1, 1, 7, 1)); 134 135 builder.addLabel("Result Caching:", cc.xy(1, 3)); 136 builder.add(cachePolicy, cc.xywh(3, 3, 5, 1)); 137 builder.addLabel("Fetch Data Objects:", cc.xy(1, 7)); 138 builder.add(dataObjects, cc.xy(3, 7)); 139 builder.add(entities, cc.xywh(5, 7, 3, 1)); 140 builder.addLabel("Refresh Results:", cc.xy(1, 9)); 141 builder.add(refreshesResults, cc.xy(3, 9)); 142 builder.addLabel("Fetch Limit, Rows:", cc.xy(1, 11)); 143 builder.add(fetchLimit.getComponent(), cc.xywh(3, 11, 3, 1)); 144 builder.addLabel("Page Size:", cc.xy(1, 13)); 145 builder.add(pageSize.getComponent(), cc.xywh(3, 13, 3, 1)); 146 147 this.setLayout(new BorderLayout ()); 148 this.add(builder.getPanel(), BorderLayout.CENTER); 149 } 150 151 155 public void initFromModel(GenericSelectQuery query) { 156 super.initFromModel(query); 157 158 boolean fetchingDO = !query.isFetchingDataRows(); 159 dataObjects.setSelected(fetchingDO); 160 161 165 DataMap map = mediator.getCurrentDataMap(); 166 List objEntities = new ArrayList (); 167 objEntities.addAll(map.getObjEntities()); 168 169 if (objEntities.size() > 1) { 170 Collections.sort(objEntities, Comparators.getDataMapChildrenComparator()); 171 } 172 173 entities.setEnabled(fetchingDO && isEnabled()); 174 DefaultComboBoxModel model = new DefaultComboBoxModel (objEntities.toArray()); 175 model.setSelectedItem(getEntity(query)); 176 entities.setModel(model); 177 } 178 179 protected abstract void setEntity(ObjEntity selectedEntity); 180 181 protected abstract ObjEntity getEntity(GenericSelectQuery query); 182 183 protected void setFetchingDataObjects(boolean dataObjects) { 184 entities.setEnabled(dataObjects && isEnabled()); 185 186 if (!dataObjects) { 187 entities.getModel().setSelectedItem(null); 188 } 189 190 setQueryProperty("fetchingDataRows", dataObjects ? Boolean.FALSE : Boolean.TRUE); 191 } 192 } | Popular Tags |