KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > docscan > TaskTagEditor


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-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.docscan;
21
22 import java.util.ArrayList JavaDoc;
23 import java.awt.Component JavaDoc;
24 import java.beans.FeatureDescriptor JavaDoc;
25 import java.beans.PropertyEditorSupport JavaDoc;
26
27 import org.openide.explorer.propertysheet.ExPropertyEditor;
28 import org.openide.explorer.propertysheet.PropertyEnv;
29 import org.openide.nodes.Node;
30
31 import org.netbeans.modules.tasklist.client.SuggestionPriority;
32 import org.netbeans.modules.tasklist.core.Task;
33
34 /**
35  * PropertyEditor for task tags
36  *
37  * @author Tor Norbye
38  */

39 public final class TaskTagEditor extends PropertyEditorSupport JavaDoc
40 implements ExPropertyEditor {
41     
42     public TaskTagEditor() {
43     }
44
45
46     /** sets new value */
47     public void setAsText(String JavaDoc s) {
48 // TaskTags tags = new TaskTags();
49
// int i = 0;
50
// int n = s.length();
51
// ArrayList list = new ArrayList();
52
// while (i < n) {
53
// if (s.charAt(i++) != '[') {
54
// return;
55
// }
56
// // Get token
57
// StringBuffer token = new StringBuffer();
58
// while (i < n) {
59
// char c = s.charAt(i++);
60
// boolean escaped = (c == '\\');
61
// if (escaped) {
62
// if (i == n) {
63
// break;
64
// }
65
// c = s.charAt(i++);
66
// }
67
// if (!escaped && ((c == ',') || (c == ']'))) {
68
// break;
69
// }
70
// token.append(c);
71
// }
72
// StringBuffer priostr = new StringBuffer();
73
// while (i < n) {
74
// char c = s.charAt(i++);
75
// boolean escaped = (c == '\\');
76
// if (escaped) {
77
// if (i == n) {
78
// break;
79
// }
80
// c = s.charAt(i++);
81
// }
82
// if (!escaped && ((c == ',') || (c == ']'))) {
83
// break;
84
// }
85
// priostr.append(c);
86
// }
87
// String prioString = priostr.toString();
88
// String[] prios = Task.getPriorityNames();
89
// SuggestionPriority priority = SuggestionPriority.MEDIUM;
90
// for (int j = 0; j < prios.length; j++) {
91
// if (prios[j].equals(prioString)) {
92
// priority = Task.getPriority(j+1);
93
// break;
94
// }
95
// }
96
// TaskTag tag = new TaskTag(token.toString(), priority);
97
// list.add(tag);
98
// if (i == n) {
99
// break;
100
// }
101
// if (s.charAt(i) == ']') {
102
// break;
103
// }
104
// if (s.charAt(i) == ',') {
105
// i++;
106
// } else {
107
// break;
108
// }
109
// }
110
// TaskTag[] tagArray = (TaskTag[])list.toArray(new TaskTag[list.size()]);
111
// tags.setTags(tagArray);
112
// setValue(tags);
113
}
114
115     public String JavaDoc getAsText() {
116         Object JavaDoc val = getValue();
117         if (val == null) {
118             return "";
119         } else {
120             TaskTags tags = (TaskTags)val;
121             return tags.getScanRegexp().pattern();
122 // StringBuffer sb = new StringBuffer(500);
123
// TaskTag[] tgs = tags.getTags();
124
// String[] prios = Task.getPriorityNames();
125
// for (int i = 0; i < tgs.length; i++) {
126
// if (i > 0) {
127
// sb.append(',');
128
// }
129
// sb.append('[');
130
//
131
// String s = tgs[i].getToken();
132
// int n = s.length();
133
// for (int j = 0; j < n; j++) {
134
// char c = s.charAt(j);
135
// // escape some metachars
136
// if ((c == ',') || (c == '\\') ||
137
// (c == '[') || (c == ']')) {
138
// sb.append('\\');
139
// }
140
// sb.append(c);
141
// }
142
// sb.append(',');
143
// sb.append(prios[tgs[i].getPriority().intValue()-1]);
144
// sb.append(']');
145
// }
146
// return sb.toString();
147
}
148     }
149
150
151     public boolean supportsCustomEditor () {
152         return true;
153     }
154
155     public Component JavaDoc getCustomEditor() {
156         TaskTags d = (TaskTags)getValue();
157         if (d == null) {
158             d = new TaskTags();
159             setValue(d);
160         }
161         return new TaskTagsPanel(d);
162     }
163
164     public void attachEnv(PropertyEnv env) {
165         FeatureDescriptor JavaDoc desc = env.getFeatureDescriptor();
166         if (desc instanceof Node.Property){
167             Node.Property prop = (Node.Property)desc;
168             editable = prop.canWrite();
169         }
170     }
171
172     // bugfix# 9219 added editable field and isEditable() "getter" to be used in StringCustomEditor
173
// TODO Tor - is the above relevant for our property editor?
174
private boolean editable=true;
175
176     /** gets information if the text in editor should be editable or not */
177     public boolean isEditable(){
178         return editable;
179     }
180 }
181
Popular Tags