1 19 package org.netbeans.modules.form.actions; 20 21 import java.awt.*; 22 import java.awt.event.*; 23 import java.beans.*; 24 import java.util.ResourceBundle ; 25 import javax.swing.*; 26 27 import org.openide.DialogDisplayer; 28 import org.openide.DialogDescriptor; 29 import org.openide.NotifyDescriptor; 30 import org.openide.awt.Mnemonics; 31 import org.openide.util.HelpCtx; 32 import org.openide.util.NbBundle; 33 import org.openide.explorer.propertysheet.editors.EnhancedCustomPropertyEditor; 34 35 import org.netbeans.modules.form.*; 36 37 42 public class PropertyAction extends AbstractAction { 43 private static final String OK_COMMAND = "OK"; private static final String CANCEL_COMMAND = "Cancel"; private static final String RESTORE_COMMAND = "Restore"; private RADProperty property; 47 private Dialog dialog; 48 49 public PropertyAction(RADProperty property) { 50 this.property = property; 51 String name = (String )property.getValue("actionName"); if (name == null) { 53 StringBuffer sb = new StringBuffer (property.getName()); 54 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); 55 name = sb.toString(); 56 } 57 putValue(Action.NAME, name); 58 } 59 60 public void actionPerformed(java.awt.event.ActionEvent e) { 61 try { 62 PropertyEditor propEd = property.getPropertyEditor(); 63 propEd.setValue(property.getValue()); 64 final Component custEditor = propEd.getCustomEditor(); 65 Object [] options = buttons(); 66 DialogDescriptor descriptor = new DialogDescriptor( 67 custEditor, 68 (String )getValue(Action.NAME), 69 true, 70 options, 71 DialogDescriptor.CANCEL_OPTION, 72 DialogDescriptor.DEFAULT_ALIGN, 73 HelpCtx.DEFAULT_HELP, 74 new ActionListener() { 75 public void actionPerformed(ActionEvent e) { 76 try { 77 String action = e.getActionCommand(); 78 if (OK_COMMAND.equals(action)) { 79 Object value = ((EnhancedCustomPropertyEditor)custEditor).getPropertyValue(); 80 property.setValue(value); 81 } else if (RESTORE_COMMAND.equals(action)) { 82 property.restoreDefaultValue(); 83 } 84 dialog.dispose(); 85 } catch (Exception ex) { 86 NotifyDescriptor descriptor = new NotifyDescriptor.Message( 87 NbBundle.getBundle(PropertyAction.class).getString("MSG_InvalidValue")); DialogDisplayer.getDefault().notify(descriptor); 89 } 90 } 91 }); 92 descriptor.setClosingOptions(new Object [0]); 93 dialog = DialogDisplayer.getDefault().createDialog(descriptor); 94 dialog.setVisible(true); 95 dialog = null; 96 } catch (Exception ex) { 97 ex.printStackTrace(); 98 } 99 } 100 101 private Object [] buttons() { 102 ResourceBundle bundle = NbBundle.getBundle(PropertyAction.class); 103 JButton okButton = new JButton(); 104 Mnemonics.setLocalizedText(okButton, bundle.getString("CTL_OK")); okButton.setActionCommand(OK_COMMAND); 106 JButton cancelButton = new JButton(); 107 Mnemonics.setLocalizedText(cancelButton, bundle.getString("CTL_Cancel")); cancelButton.setActionCommand(CANCEL_COMMAND); 109 if (property.isDefaultValue()) { 110 return new Object [] {okButton, cancelButton}; 111 } else { 112 JButton restoreButton = new JButton(); 113 Mnemonics.setLocalizedText(restoreButton, bundle.getString("CTL_RestoreDefault")); restoreButton.setActionCommand(RESTORE_COMMAND); 115 return new Object [] {okButton, restoreButton, cancelButton}; 116 } 117 } 118 119 } 120 | Popular Tags |