1 19 24 25 package org.netbeans.modules.j2ee.sun.share.configbean.customizers.common; 26 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.ResourceBundle ; 30 31 import java.beans.PropertyChangeEvent ; 32 import java.beans.PropertyChangeListener ; 33 34 import java.awt.BorderLayout ; 35 import java.awt.Dimension ; 36 import java.awt.Insets ; 37 38 import javax.swing.border.EmptyBorder ; 39 import javax.swing.JPanel ; 40 41 42 import org.netbeans.modules.j2ee.sun.share.Constants; 43 import org.netbeans.modules.j2ee.sun.validation.ValidationManager; 44 import org.netbeans.modules.j2ee.sun.validation.ValidationManagerFactory; 45 46 51 52 public abstract class BeanInputDialog extends InputDialog { 53 54 57 public static final String USER_DATA_CHANGED = Constants.USER_DATA_CHANGED; 59 private static final ResourceBundle bundle = ResourceBundle.getBundle( 60 "org.netbeans.modules.j2ee.sun.share.configbean.customizers.common.Bundle"); 62 private JPanel parentPanel; 64 private JPanel dialogPanel; 65 private boolean editmode; 66 67 protected ValidationSupport validationSupport;; 69 70 71 public BeanInputDialog(JPanel parent, String title, Object [] values) { 72 this(parent, title, false, values); 73 } 74 75 public BeanInputDialog(JPanel parent, String title, boolean showRequiredNote, Object [] values) { 76 super(parent, title, showRequiredNote); 77 78 editmode = true; 79 parentPanel = parent; 80 dialogPanel = getDialogPanel(values); 81 validationSupport = new ValidationSupport(); 82 83 initComponents(); 84 } 85 86 87 public BeanInputDialog(JPanel parent, String title) { 88 this(parent, title, false); 89 } 90 91 public BeanInputDialog(JPanel parent, String title, boolean showRequiredNote) { 92 super(parent, title, showRequiredNote); 93 editmode = false; 94 parentPanel = parent; 95 dialogPanel = getDialogPanel(); 96 validationSupport = new ValidationSupport(); 97 98 initComponents(); 99 } 100 101 private void initComponents() { 102 103 getContentPane().add(dialogPanel, BorderLayout.CENTER); 105 106 addListeners(); 108 109 adjustSize(); 111 112 pack(); 114 115 setLocationInside(parentPanel); 117 118 handleErrorDisplay(); 122 } 123 124 private void adjustSize(){ 127 int preferredWidth = parentPanel.getWidth()*3/4; 128 int noOfFields = getNOofFields(); 129 if(-1 != noOfFields){ 130 Dimension dm = getContentPane().getPreferredSize(); 134 int preferredHeight = (int)dialogPanel.getPreferredSize().getHeight(); 135 136 if(preferredWidth < dm.getWidth()) { 137 preferredWidth = (int)dm.getWidth(); 138 } 139 if(preferredHeight < dm.getHeight()) { 140 preferredHeight = (int)dm.getHeight(); 141 } 142 } 143 }; 144 145 protected int getNOofFields() { 147 return -1; 148 }; 149 150 protected abstract Object [] getValues(); 151 152 protected abstract Collection getErrors(); 153 154 protected abstract JPanel getDialogPanel(); 155 156 protected abstract JPanel getDialogPanel(Object [] values); 157 158 abstract protected String getHelpId(); 159 160 private void addListeners() { 162 dialogPanel.addPropertyChangeListener(USER_DATA_CHANGED, new PropertyChangeListener () { 163 public void propertyChange(PropertyChangeEvent evt) { 164 handleErrorDisplay(); 165 } 166 }); 167 } 168 169 private void handleErrorDisplay() { 170 ArrayList errors = new ArrayList (); 172 173 if(hasDuplicateEntry()) { 174 errors.add(bundle.getString("ERR_ObjectIsDuplicate")); 175 } else { 176 errors.addAll(getErrors()); 177 } 178 179 setErrors(errors); 180 } 181 182 protected boolean hasDuplicateEntry() { 183 boolean result = false; 184 185 if(parentPanel instanceof BeanTablePanel) { 186 BeanTablePanel beanPanel = (BeanTablePanel) parentPanel; 187 BeanTableModel model = beanPanel.getModel(); 188 Object [] newValues = getValues(); 189 190 if(!editmode) { 191 if(model.alreadyExists(newValues)) { 193 result = true; 194 } 195 } else { 196 } 204 } 205 206 return result; 207 } 208 209 protected BeanTableModel getModel(){ 210 BeanTableModel model = null; 211 if(parentPanel instanceof BeanTablePanel) { 212 BeanTablePanel beanPanel = (BeanTablePanel) parentPanel; 213 model = beanPanel.getModel(); 214 } 215 return model; 216 } 217 } 218 | Popular Tags |