1 30 package com.genimen.djeneric.tools.common; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Component ; 34 import java.awt.Dimension ; 35 import java.awt.FlowLayout ; 36 import java.awt.Frame ; 37 import java.awt.Toolkit ; 38 import java.awt.event.ActionEvent ; 39 import java.util.ArrayList ; 40 import java.util.Arrays ; 41 import java.util.Collections ; 42 43 import javax.swing.DefaultComboBoxModel ; 44 import javax.swing.DefaultListCellRenderer ; 45 import javax.swing.JButton ; 46 import javax.swing.JComboBox ; 47 import javax.swing.JDialog ; 48 import javax.swing.JLabel ; 49 import javax.swing.JList ; 50 import javax.swing.JPanel ; 51 52 import com.genimen.djeneric.language.Messages; 53 import com.genimen.djeneric.repository.DjExtent; 54 import com.genimen.djeneric.repository.DjPackage; 55 import com.genimen.djeneric.tools.modeler.ModelEditor; 56 import com.genimen.djeneric.tools.modeler.dialogs.SelectionPanel; 57 import com.genimen.djeneric.ui.Util; 58 import com.genimen.djeneric.util.DjExtentComparator; 59 import com.genimen.djeneric.util.DjLogger; 60 import com.genimen.djeneric.util.DjStringComparator; 61 62 public class ExportSelectionDialog extends JDialog 63 { 64 private static final long serialVersionUID = 1L; 65 JPanel panel1 = new JPanel (); 66 BorderLayout borderLayout1 = new BorderLayout (); 67 JPanel jPanel1 = new JPanel (); 68 JButton _butOk = new JButton (); 69 JPanel jPanel4 = new JPanel (); 70 BorderLayout borderLayout2 = new BorderLayout (); 71 JButton _butCancel = new JButton (); 72 BorderLayout borderLayout3 = new BorderLayout (); 73 JPanel jPanel3 = new JPanel (); 74 boolean _canceled = true; 75 SelectionPanel _pnlExtents = new SelectionPanel(); 76 JPanel jPanel2 = new JPanel (); 77 FlowLayout flowLayout1 = new FlowLayout (); 78 JLabel _lblDomains = new JLabel (); 79 JComboBox _cbbDomainsHow = new JComboBox (); 80 boolean _showDomainChoice = true; 81 JPanel jPanel5 = new JPanel (); 82 JButton _butMinusPackage = new JButton (); 83 FlowLayout flowLayout2 = new FlowLayout (); 84 JComboBox _cbbPackageName = new JComboBox (); 85 JButton _butPlusPackage = new JButton (); 86 DjPackage _defaultPackage = new DjPackage("Default"); 87 88 public ExportSelectionDialog(Frame frame, DjExtent[] extents, boolean showDomainChoice, boolean selectAll) 89 { 90 super(frame, Messages.getString("ExportSelectionDialog.ExportModelSelection"), true); try 92 { 93 94 ArrayList allPackages = new ArrayList (); 95 for (int i = 0; i < extents.length; i++) 96 { 97 DjPackage pck = extents[i].getPackage(); 98 if (pck == null) pck = _defaultPackage; 99 if (!allPackages.contains(pck)) allPackages.add(pck); 100 } 101 Collections.sort(allPackages, new DjStringComparator(false)); 102 _cbbPackageName.setModel(new DefaultComboBoxModel (allPackages.toArray())); 103 104 _showDomainChoice = showDomainChoice; 105 jbInit(); 106 _cbbDomainsHow.setModel(new DefaultComboBoxModel (new String []{Messages.getString("ExportSelectionDialog.All"), 107 Messages.getString("ExportSelectionDialog.UsedOnly")})); 108 109 _pnlExtents.setCellRenderer(new ExtentRenderer()); 110 _pnlExtents.setComparator(new DjExtentComparator(true)); 111 112 _pnlExtents.setAvailable(Arrays.asList(extents)); 113 114 setSize(new Dimension (544, 400)); 115 116 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 117 Dimension frameSize = getSize(); 118 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 119 120 if (selectAll) 121 { 122 _pnlExtents.selectAll(); 123 } 124 125 setVisible(true); 126 } 127 catch (Exception ex) 128 { 129 DjLogger.log(ex); 130 } 131 } 132 133 public DjExtent[] getSelectedExtents() 134 { 135 return (DjExtent[]) _pnlExtents.getSelection().toArray(new DjExtent[0]); 136 } 137 138 public DjExtent[] getUnSelectedExtents() 139 { 140 return (DjExtent[]) _pnlExtents.getNegatedSelection().toArray(new DjExtent[0]); 141 } 142 143 public boolean shouldAddAllDomains() 144 { 145 return _cbbDomainsHow.getSelectedIndex() == 0; 146 } 147 148 private void jbInit() throws Exception 149 { 150 panel1.setLayout(borderLayout1); 151 jPanel1.setLayout(borderLayout2); 152 _butOk.setText(Messages.getString("global.Ok")); _butOk.addActionListener(new java.awt.event.ActionListener () 154 { 155 public void actionPerformed(ActionEvent e) 156 { 157 _butOk_actionPerformed(e); 158 } 159 }); 160 _butCancel.setText(Messages.getString("global.Cancel")); _butCancel.addActionListener(new java.awt.event.ActionListener () 162 { 163 public void actionPerformed(ActionEvent e) 164 { 165 _butCancel_actionPerformed(e); 166 } 167 }); 168 jPanel3.setLayout(borderLayout3); 169 jPanel2.setLayout(flowLayout1); 170 _lblDomains.setText(Messages.getString("ExportSelectionDialog.Domains")); 171 flowLayout1.setAlignment(FlowLayout.LEFT); 172 jPanel5.setLayout(flowLayout2); 173 flowLayout2.setHgap(0); 174 flowLayout2.setVgap(0); 175 _butMinusPackage.setPreferredSize(new Dimension (24, 24)); 176 _butMinusPackage.setText(""); 177 _butMinusPackage.addActionListener(new java.awt.event.ActionListener () 178 { 179 public void actionPerformed(ActionEvent e) 180 { 181 _butMinusPackage_actionPerformed(e); 182 } 183 }); 184 _butPlusPackage.setPreferredSize(new Dimension (24, 24)); 185 _butPlusPackage.setText(""); 186 _butPlusPackage.addActionListener(new java.awt.event.ActionListener () 187 { 188 public void actionPerformed(ActionEvent e) 189 { 190 _butPlusPackage_actionPerformed(e); 191 } 192 }); 193 _pnlExtents.setPreferredSize(new Dimension (534, 161)); 194 getContentPane().add(panel1); 195 panel1.add(jPanel1, BorderLayout.SOUTH); 196 jPanel1.add(jPanel3, BorderLayout.SOUTH); 197 jPanel3.add(jPanel4, BorderLayout.EAST); 198 jPanel4.add(_butCancel, null); 199 jPanel4.add(_butOk, null); 200 jPanel3.add(jPanel2, BorderLayout.CENTER); 201 jPanel1.add(jPanel5, BorderLayout.NORTH); 202 jPanel5.add(_butMinusPackage, null); 203 jPanel5.add(_cbbPackageName, null); 204 jPanel5.add(_butPlusPackage, null); 205 if (_showDomainChoice) 206 { 207 jPanel2.add(_lblDomains, null); 208 jPanel2.add(_cbbDomainsHow, null); 209 } 210 211 _butMinusPackage.setIcon(ModelEditor.getImageIcon("remove.gif")); 212 _butPlusPackage.setIcon(ModelEditor.getImageIcon("add.gif")); 213 214 panel1.add(_pnlExtents, BorderLayout.CENTER); Util.sizeButtons(jPanel4); 216 } 217 218 public boolean wasCanceled() 219 { 220 return _canceled; 221 } 222 223 void _butCancel_actionPerformed(ActionEvent e) 224 { 225 setVisible(false); 226 } 227 228 void _butOk_actionPerformed(ActionEvent e) 229 { 230 _canceled = false; 231 setVisible(false); 232 } 233 234 void _butMinusPackage_actionPerformed(ActionEvent e) 235 { 236 DjPackage pck = (DjPackage) _cbbPackageName.getSelectedItem(); 237 if (pck != null) 238 { 239 if (pck == _defaultPackage) pck = null; 240 241 ArrayList rems = new ArrayList (); 242 ArrayList sels = _pnlExtents.getSelection(); 243 for (int i = 0; i < sels.size(); i++) 244 { 245 DjExtent ext = (DjExtent) sels.get(i); 246 if (ext.getPackage() == pck) rems.add(ext); 247 } 248 sels.removeAll(rems); 249 _pnlExtents.setSelection(sels); 250 } 251 } 252 253 void _butPlusPackage_actionPerformed(ActionEvent e) 254 { 255 DjPackage pck = (DjPackage) _cbbPackageName.getSelectedItem(); 256 if (pck != null) 257 { 258 if (pck == _defaultPackage) pck = null; 259 260 ArrayList sels = _pnlExtents.getSelection(); 261 ArrayList notSels = _pnlExtents.getNegatedSelection(); 262 for (int i = 0; i < notSels.size(); i++) 263 { 264 DjExtent ext = (DjExtent) notSels.get(i); 265 if (ext.getPackage() == pck) sels.add(ext); 266 } 267 _pnlExtents.setSelection(sels); 268 } 269 } 270 } 271 272 class ExtentRenderer extends DefaultListCellRenderer 273 { 274 private static final long serialVersionUID = 1L; 275 276 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, 277 boolean cellHasFocus) 278 { 279 super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 280 281 String title = ((DjExtent) value).getQualifiedExtentName(); 282 setText(title); 283 return this; 284 } 285 } | Popular Tags |