1 14 package org.compiere.grid.ed; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 import java.util.*; 20 21 import org.compiere.apps.*; 22 import org.compiere.util.*; 23 import org.compiere.model.*; 24 import org.compiere.plaf.*; 25 import org.compiere.swing.*; 26 27 33 public class VLocationDialog extends JDialog implements ActionListener 34 { 35 42 public VLocationDialog (Frame frame, String title, MLocation mLocation) 43 { 44 super(frame, title, true); 45 try 46 { 47 jbInit(); 48 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 49 } 50 catch(Exception ex) 51 { 52 Log.error("VLocationDialog - " + ex.getMessage()); 53 } 54 m_mLocation = mLocation; 56 if (mLocation.getC_Location_ID() == 0) 57 setTitle(Msg.getMsg(Env.getCtx(), "LocationNew")); 58 else 59 setTitle(Msg.getMsg(Env.getCtx(), "LocationUpdate")); 60 61 fCountry = new CComboBox(MCountry.getCountries(Env.getCtx())); 63 fCountry.setSelectedItem(m_mLocation.getCountry()); 64 m_origCountry_ID = m_mLocation.getC_Country_ID(); 65 fRegion = new CComboBox(MRegion.getRegions(Env.getCtx(), m_origCountry_ID)); 67 if (m_mLocation.getCountry().isHasRegion()) 68 lRegion.setText(m_mLocation.getCountry().getRegionName()); fRegion.setSelectedItem(m_mLocation.getRegion()); 70 initLocation(); 72 fCountry.addActionListener(this); 73 AEnv.positionCenterWindow(frame, this); 74 } 76 private boolean m_change = false; 77 private MLocation m_mLocation; 78 private int m_origCountry_ID; 79 private int s_oldCountry_ID = 0; 80 81 private CPanel panel = new CPanel(); 82 private CPanel mainPanel = new CPanel(); 83 private CPanel southPanel = new CPanel(); 84 private BorderLayout panelLayout = new BorderLayout(); 85 private GridBagLayout gridBagLayout = new GridBagLayout(); 86 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 87 private BorderLayout southLayout = new BorderLayout(); 88 private JLabel lAddress1 = new JLabel(Msg.getMsg(Env.getCtx(), "Address")+ " 1"); 90 private JLabel lAddress2 = new JLabel(Msg.getMsg(Env.getCtx(), "Address")+ " 2"); 91 private JLabel lCity = new JLabel(Msg.getMsg(Env.getCtx(), "City")); 92 private JLabel lCountry = new JLabel(Msg.getMsg(Env.getCtx(), "Country")); 93 private JLabel lRegion = new JLabel(Msg.getMsg(Env.getCtx(), "Region")); 94 private JLabel lPostal = new JLabel(Msg.getMsg(Env.getCtx(), "Postal")); 95 private JLabel lPostalAdd = new JLabel(Msg.getMsg(Env.getCtx(), "PostalAdd")); 96 private CTextField fAddress1 = new CTextField(15); private CTextField fAddress2 = new CTextField(15); private CTextField fCity = new CTextField(10); private CComboBox fCountry; 100 private CComboBox fRegion; 101 private CTextField fPostal = new CTextField(5); private CTextField fPostalAdd = new CTextField(5); private GridBagConstraints gbc = new GridBagConstraints(); 105 private Insets labelInsets = new Insets(2,15,2,0); private Insets fieldInsets = new Insets(2,5,2,10); 107 108 112 void jbInit() throws Exception 113 { 114 CompiereColor.setBackground(this); 115 panel.setLayout(panelLayout); 116 southPanel.setLayout(southLayout); 117 mainPanel.setLayout(gridBagLayout); 118 panelLayout.setHgap(5); 119 panelLayout.setVgap(10); 120 getContentPane().add(panel); 121 panel.add(mainPanel, BorderLayout.CENTER); 122 panel.add(southPanel, BorderLayout.SOUTH); 123 southPanel.add(confirmPanel, BorderLayout.NORTH); 124 confirmPanel.addActionListener(this); 126 } 128 131 private void initLocation() 132 { 133 MCountry country = m_mLocation.getCountry(); 134 Log.trace(Log.l5_DData, "VLocationDialog.initLocation", 135 country.getName() + ", Region=" + country.isHasRegion() + " " + country.getDisplaySequence() 136 + ", C_Location_ID=" + m_mLocation.getC_Location_ID()); 137 if (m_mLocation.getC_Country_ID() != s_oldCountry_ID && country.isHasRegion()) 139 { 140 fRegion = new CComboBox(MRegion.getRegions(Env.getCtx(), country.getC_Country_ID())); 141 if (m_mLocation.getRegion() != null) 142 fRegion.setSelectedItem(m_mLocation.getRegion()); 143 lRegion.setText(country.getRegionName()); 144 s_oldCountry_ID = m_mLocation.getC_Country_ID(); 145 } 146 147 gbc.anchor = GridBagConstraints.NORTHWEST; 148 gbc.gridy = 0; gbc.gridx = 0; 150 gbc.gridwidth = 1; 151 gbc.insets = fieldInsets; 152 gbc.fill = GridBagConstraints.HORIZONTAL; 153 gbc.weightx = 0; 154 gbc.weighty = 0; 155 156 mainPanel.add(Box.createVerticalStrut(5), gbc); 158 int line = 1; 159 addLine(line++, lAddress1, fAddress1); 160 addLine(line++, lAddress2, fAddress2); 161 162 StringTokenizer st = new StringTokenizer(country.getDisplaySequence(), "@", false); 164 while (st.hasMoreTokens()) 165 { 166 String s = st.nextToken(); 167 if (s.startsWith("C")) 168 addLine(line++, lCity, fCity); 169 else if (s.startsWith("P")) 170 addLine(line++, lPostal, fPostal); 171 else if (s.startsWith("A")) 172 addLine(line++, lPostalAdd, fPostalAdd); 173 else if (s.startsWith("R") && m_mLocation.getCountry().isHasRegion()) 174 addLine(line++, lRegion, fRegion); 175 } 176 addLine(line++, lCountry, fCountry); 178 179 if (m_mLocation.getC_Location_ID() != 0) 181 { 182 fAddress1.setText(m_mLocation.getAddress1()); 183 fAddress2.setText(m_mLocation.getAddress2()); 184 fCity.setText(m_mLocation.getCity()); 185 fPostal.setText(m_mLocation.getPostal()); 186 fPostalAdd.setText(m_mLocation.getPostal_Add()); 187 if (m_mLocation.getCountry().isHasRegion()) 188 { 189 lRegion.setText(m_mLocation.getCountry().getRegionName()); 190 fRegion.setSelectedItem(m_mLocation.getRegion()); 191 } 192 fCountry.setSelectedItem(country); 193 } 194 pack(); 196 } 198 205 private void addLine(int line, JLabel label, JComponent field) 206 { 207 gbc.gridy = line; 208 gbc.insets = labelInsets; 210 gbc.gridx = 0; 211 gbc.fill = GridBagConstraints.HORIZONTAL; 212 label.setHorizontalAlignment(SwingConstants.RIGHT); 213 mainPanel.add(label, gbc); 214 gbc.insets = fieldInsets; 216 gbc.gridx = 1; 217 gbc.fill = GridBagConstraints.NONE; 218 mainPanel.add(field, gbc); 219 } 221 222 226 public void actionPerformed(ActionEvent e) 227 { 228 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 229 { 230 action_OK(); 231 m_change = true; 232 dispose(); 233 } 234 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 235 { 236 m_change = false; 237 dispose(); 238 } 239 240 else if (e.getSource() == fCountry) 242 { 243 MCountry c = (MCountry)fCountry.getSelectedItem(); 245 m_mLocation.setCountry(c); 246 mainPanel.removeAll(); 248 initLocation(); 249 fCountry.requestFocus(); } 251 } 253 256 private void action_OK() 257 { 258 m_mLocation.setAddress1(fAddress1.getText()); 259 m_mLocation.setAddress2(fAddress2.getText()); 260 m_mLocation.setCity(fCity.getText()); 261 m_mLocation.setPostal(fPostal.getText()); 262 m_mLocation.setPostal_Add(fPostalAdd.getText()); 263 MCountry c = (MCountry)fCountry.getSelectedItem(); 265 m_mLocation.setCountry(c); 266 if (m_mLocation.getCountry().isHasRegion()) 267 { 268 MRegion r = (MRegion)fRegion.getSelectedItem(); 269 m_mLocation.setRegion(r); 270 } 271 else 272 m_mLocation.setC_Region_ID(0); 273 m_mLocation.save(); 275 } 277 281 public boolean isChanged() 282 { 283 return m_change; 284 } 286 } | Popular Tags |