KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > nodes > properties > MaxOccursEditor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * MaxOccursEditor.java
22  *
23  * Created on December 22, 2005, 12:58 PM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.abe.nodes.properties;
30
31 import java.beans.FeatureDescriptor JavaDoc;
32 import java.beans.PropertyEditorSupport JavaDoc;
33 import org.openide.ErrorManager;
34 import org.openide.explorer.propertysheet.ExPropertyEditor;
35 import org.openide.explorer.propertysheet.PropertyEnv;
36 import org.openide.util.NbBundle;
37
38 /**
39  *
40  * @author Jeri Lockhart
41  */

42 public class MaxOccursEditor extends PropertyEditorSupport JavaDoc
43         implements ExPropertyEditor
44 {
45     /** Creates a new instance of MaxOccursEditor */
46     public MaxOccursEditor() {
47     }
48
49 @Override JavaDoc
50     public String JavaDoc[] getTags() {
51             return new String JavaDoc[] {NbBundle.getMessage(MaxOccursEditor.class,"LBL_Unbounded")};
52     }
53
54 @Override JavaDoc
55     public void setAsText(String JavaDoc text) throws IllegalArgumentException JavaDoc {
56         if ( NbBundle.getMessage(MaxOccursEditor.class,"LBL_DefaultValueOne").equals(text) &&
57                 getValue() == null )
58             return;
59         // Allow positive integers, "unbounded" or *
60
if (text.matches("[0-9]*")) { //NOI18N
61
if (Integer.valueOf(text).intValue() < 0) {
62                 // if not an integer, NumberFormatException is thrown
63
throwError(text);
64                 }
65                 else {
66                     setValue(text);
67                 }
68         }
69         else {
70             // asterisk (*) means unbounded
71
if (text.equals("unbounded") || text.equals("*")){ //NOI18N
72
setValue("unbounded");
73             }
74             else {
75                 throwError(text);
76             }
77         }
78     }
79
80     private void throwError(String JavaDoc text){
81             String JavaDoc msg = NbBundle.getMessage(MaxOccursEditor.class, "LBL_Illegal_MaxOccurs_Value", text); //NOI18N
82
IllegalArgumentException JavaDoc iae = new IllegalArgumentException JavaDoc(msg);
83             ErrorManager.getDefault().annotate(iae, ErrorManager.USER,
84                             msg, msg, null, new java.util.Date JavaDoc());
85             throw iae;
86
87     }
88
89 @Override JavaDoc
90     public String JavaDoc getAsText() {
91             Object JavaDoc val = getValue();
92             return val==null?NbBundle.getMessage(MaxOccursEditor.class,"LBL_DefaultValueOne"):val.toString();
93     }
94
95     
96     
97     /**
98      *
99      * implement ExPropertyEditor
100      *
101      */

102     public void attachEnv(PropertyEnv env ) {
103         FeatureDescriptor JavaDoc desc = env.getFeatureDescriptor();
104         // make this an editable combo tagged editor
105
desc.setValue("canEditAsText", Boolean.TRUE); // NOI18N
106
}
107 }
108
Popular Tags