1 14 package org.compiere.grid.ed; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import java.beans.PropertyChangeEvent ; 19 import java.beans.PropertyVetoException ; 20 import java.sql.PreparedStatement ; 21 import java.sql.ResultSet ; 22 import java.text.DateFormat ; 23 import java.text.NumberFormat ; 24 25 import javax.swing.*; 26 27 import org.compiere.model.*; 28 import org.compiere.plaf.CompierePLAF; 29 import org.compiere.swing.CButton; 30 import org.compiere.util.*; 31 32 38 public class VPAttribute extends JComponent 39 implements VEditor, ActionListener 40 { 41 44 public VPAttribute() 45 { 46 this (false, false, true, 0, null); 47 } 49 57 public VPAttribute (boolean mandatory, boolean isReadOnly, boolean isUpdateable, int WindowNo, MPAttribute lookup) 58 { 59 super.setName("M_AttributeSetInstance_ID"); 60 m_WindowNo = WindowNo; 61 m_mPAttribute = lookup; 62 LookAndFeel.installBorder(this, "TextField.border"); 63 this.setLayout(new BorderLayout()); 64 this.setPreferredSize(m_text.getPreferredSize()); 66 int height = m_text.getPreferredSize().height; 67 68 m_text.setEditable(false); 70 m_text.setFocusable(false); 71 m_text.setBorder(null); 72 m_text.setHorizontalAlignment(JTextField.LEADING); 73 setMandatory(mandatory); 75 this.add(m_text, BorderLayout.CENTER); 76 77 m_button.setIcon(Env.getImageIcon("PAttribute10.gif")); 79 m_button.setMargin(new Insets(0, 0, 0, 0)); 80 m_button.setPreferredSize(new Dimension(height, height)); 81 m_button.addActionListener(this); 82 m_button.setFocusable(true); 83 this.add(m_button, BorderLayout.EAST); 84 85 this.setPreferredSize(this.getPreferredSize()); if (isReadOnly || !isUpdateable) 89 setReadWrite(false); 90 else 91 setReadWrite(true); 92 93 m_text.addMouseListener(new VPAttribute_mouseAdapter(this)); 95 menuEditor = new JMenuItem(Msg.getMsg(Env.getCtx(), "PAttribute"), Env.getImageIcon("Zoom16.gif")); 96 menuEditor.addActionListener(this); 97 popupMenu.add(menuEditor); 98 } 100 101 private Object m_value = new Object (); 102 103 private MPAttribute m_mPAttribute; 104 105 106 private JTextField m_text = new JTextField (VLookup.DISPLAY_LENGTH); 107 108 private CButton m_button = new CButton(); 109 110 JPopupMenu popupMenu = new JPopupMenu(); 111 private JMenuItem menuEditor; 112 113 private boolean m_readWrite; 114 private boolean m_mandatory; 115 private int m_WindowNo; 116 117 private boolean m_productWindow; 118 119 private boolean m_instanceWindow; 120 121 124 public void dispose() 125 { 126 m_text = null; 127 m_button = null; 128 m_mPAttribute.dispose(); 129 m_mPAttribute = null; 130 } 132 136 public void setMandatory (boolean mandatory) 137 { 138 m_mandatory = mandatory; 139 m_button.setMandatory(mandatory); 140 setBackground (false); 141 } 143 147 public boolean isMandatory() 148 { 149 return m_mandatory; 150 } 152 156 public void setReadWrite (boolean rw) 157 { 158 m_readWrite = rw; 159 m_button.setReadWrite(rw); 160 setBackground (false); 161 } 163 167 public boolean isReadWrite() 168 { 169 return m_readWrite; 170 } 172 176 public void setForeground (Color color) 177 { 178 m_text.setForeground(color); 179 } 181 185 public void setBackground (boolean error) 186 { 187 if (error) 188 setBackground(CompierePLAF.getFieldBackground_Error()); 189 else if (!m_readWrite) 190 setBackground(CompierePLAF.getFieldBackground_Inactive()); 191 else if (m_mandatory) 192 setBackground(CompierePLAF.getFieldBackground_Mandatory()); 193 else 194 setBackground(CompierePLAF.getFieldBackground_Normal()); 195 } 197 201 public void setBackground (Color color) 202 { 203 m_text.setBackground(color); 204 } 206 207 208 212 public void setValue(Object value) 213 { 214 if ((value == null && m_value == null) 216 || (value != null && value.equals(m_value)) ) 217 return; 218 Log.trace(8, "VPAttribute.setValue", value); 219 m_value = value; 220 m_text.setText(m_mPAttribute.getDisplay(value)); } 223 227 public Object getValue() 228 { 229 return m_value; 230 } 232 236 public String getDisplay() 237 { 238 return m_text.getText(); 239 } 241 242 243 247 public void setField(MField mField) 248 { 249 int AD_Column_ID = mField.getAD_Column_ID(); 250 m_productWindow = AD_Column_ID == 8418; m_instanceWindow = AD_Column_ID == 8772 || AD_Column_ID == 8552; } 257 261 public void addActionListener(ActionListener listener) 262 { 263 } 265 269 public void actionPerformed(ActionEvent e) 270 { 271 if (!m_button.isEnabled ()) 272 return; 273 m_button.setEnabled (false); 274 Integer oldValue = (Integer )getValue (); 276 int M_AttributeSetInstance_ID = oldValue == null ? 0 : oldValue.intValue (); 277 int M_Product_ID = Env.getContextAsInt (Env.getCtx (), m_WindowNo, "M_Product_ID"); 278 279 VPAttributeDialog vad = new VPAttributeDialog (Env.getFrame (this), M_AttributeSetInstance_ID, M_Product_ID, 281 m_productWindow, m_instanceWindow); 282 m_text.setText(vad.getM_AttributeSetInstanceName()); 283 M_AttributeSetInstance_ID = vad.getM_AttributeSetInstance_ID(); 284 285 if (M_AttributeSetInstance_ID != vad.getM_AttributeSetInstance_ID()) 287 { 288 m_value = new Object (); if (M_AttributeSetInstance_ID == 0) 291 setValue(null); 292 else 293 setValue(new Integer (M_AttributeSetInstance_ID)); 294 try 295 { 296 fireVetoableChange("M_AttributeSetInstance_ID", new Object (), getValue()); 297 } 298 catch (PropertyVetoException pve) 299 { 300 Log.error("VPAttribute.actionPerformed", pve); 301 } 302 } 303 m_button.setEnabled(true); 304 requestFocus(); 305 } 307 311 public void propertyChange (PropertyChangeEvent evt) 312 { 313 if (evt.getPropertyName().equals(org.compiere.model.MField.PROPERTY)) 314 setValue(evt.getNewValue()); 315 } 317 } 319 322 final class VPAttribute_mouseAdapter extends MouseAdapter 323 { 324 328 VPAttribute_mouseAdapter(VPAttribute adaptee) 329 { 330 this.adaptee = adaptee; 331 } 333 private VPAttribute adaptee; 334 335 339 public void mouseClicked(MouseEvent e) 340 { 341 if (e.getClickCount() > 1) 343 adaptee.actionPerformed(new ActionEvent(e.getSource(), e.getID(), "Mouse")); 344 if (SwingUtilities.isRightMouseButton(e)) 346 adaptee.popupMenu.show((Component)e.getSource(), e.getX(), e.getY()); 347 } 349 } | Popular Tags |