CustomerIdEditorSimple.java Sample

This topic inludes the source code for the CustomerIdEditorSimple.java Sample.

Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/ExtensionDevKit/ControlDevKit/ControlFeatures/propEditor/ide/

Sample Source Code


01 package propEditor.ide; 
02 
03 import java.util.StringTokenizer;
04 import java.awt.BorderLayout;
05 import java.awt.Component;
06 import javax.swing.JTextField;
07 import javax.swing.JLabel;
08 import javax.swing.JFormattedTextField;
09 import javax.swing.JPanel;
10 import com.bea.ide.control.EditorSupport;
11 import javax.swing.JTextPane;
12 import com.bea.ide.control.AttributeEditorSimple;
13 import com.bea.control.Issue;
14 import com.bea.control.DefaultIssue;
15 
16 /*
17  * Represents an attribute editing/validation dialog for the
18  * customer-id attribute. 
19  */
20 public class CustomerIdEditorSimple extends JPanel implements AttributeEditorSimple
21 
22     private JTextField m_field;
23     
24     /*
25      * Constructs this dialog using the existing value for 
26      * the customer-id attribute.
27      */
28     public CustomerIdEditorSimple(String origValue)
29     {
30         super(new BorderLayout());
31         m_field = new JTextField(origValue);
32         String messageText = "This sample supports the following values: \n" 
33                              "987654    987655 \n" +
34                              "987658    987659 \n"
35                              +"that's all \n";
36         JTextPane valueMessage = new JTextPane();
37         valueMessage.setText(messageText);
38         valueMessage.setBackground(null);
39         valueMessage.setEditable(false);
40         this.add(m_field, BorderLayout.SOUTH);
41         this.add(valueMessage, BorderLayout.NORTH);
42      
43     }
44 
45     public JFormattedTextField.AbstractFormatter getFormatter()
46     {
47         return null;
48     }
49 
50     /*
51      * Returns the component to use for the customer-id
52      * editing dialog. The IDE calls this method to display
53      * the dialog.
54      */
55     public Component getEditorComponent()
56     {
57         return this;
58     }
59 
60     /*
61      * Provides a way for the IDE to retrieve the newly
62      * entered attribute value.
63      */
64     public String getNewAttributeValue()
65     {
66         return m_field.getText();
67     }
68 
69     /*
70      * Provides a place for code that should execute when the
71      * user clicks OK. This method calls code that validates the
72      * attribute value, ensuring that it is a six-digit numeric
73      * value.
74      */
75     public Issue[] onFinish()
76     {
77         CustIdValidator cIdV = new CustIdValidator();
78         return cIdV.validateId(getNewAttributeValue());  
79     }
80 
81     /*
82      * Removes any nonnumeric characters in the new attribute value.
83      */
84     private String removeNonNumeric(String stringNumber) {
85         StringBuffer delimiters = new StringBuffer();
86         StringBuffer cleanString = new StringBuffer();
87 
88         for (int i = 0; i < stringNumber.length(); i++) {
89             if (stringNumber.charAt(i'0' || stringNumber.charAt(i'9')
90                 delimiters.append(stringNumber.charAt(i));
91         }
92         StringTokenizer tokens = new StringTokenizer(stringNumber, delimiters.toString());
93 
94         while(tokens.hasMoreTokens()) {
95             cleanString.append(tokens.nextToken());
96         }
97         return cleanString.toString();
98     }
99