KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > ui > models > ColumnModels


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.debugger.ui.models;
21
22 import java.beans.PropertyEditor JavaDoc;
23 import java.beans.PropertyEditorSupport JavaDoc;
24 import org.netbeans.api.debugger.Properties;
25 import org.netbeans.api.debugger.Session;
26 import org.netbeans.spi.debugger.ui.Constants;
27 import org.netbeans.spi.viewmodel.ColumnModel;
28 import org.openide.ErrorManager;
29 import org.openide.util.NbBundle;
30
31
32 /**
33  * Defines model for one table view column. Can be used together with
34  * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
35  * view representation.
36  *
37  * @author Jan Jancura
38  */

39 public class ColumnModels {
40     
41     /**
42      * Defines model for one table view column. Can be used together with
43      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
44      * table view representation.
45      */

46     private static class AbstractColumn extends ColumnModel {
47         
48         private String JavaDoc id;
49         private String JavaDoc displayName;
50         private String JavaDoc shortDescription;
51         private Class JavaDoc type;
52         private boolean defaultVisible;
53         private PropertyEditor JavaDoc propertyEditor;
54         
55         Properties properties = Properties.getDefault ().
56             getProperties ("debugger").getProperties ("views");
57
58         public AbstractColumn(String JavaDoc id, String JavaDoc displayName, String JavaDoc shortDescription,
59                               Class JavaDoc type) {
60             this(id, displayName, shortDescription, type, true);
61         }
62         
63         public AbstractColumn(String JavaDoc id, String JavaDoc displayName, String JavaDoc shortDescription,
64                               Class JavaDoc type, boolean defaultVisible) {
65             this(id, displayName, shortDescription, type, defaultVisible, null);
66         }
67         
68         public AbstractColumn(String JavaDoc id, String JavaDoc displayName, String JavaDoc shortDescription,
69                               Class JavaDoc type, boolean defaultVisible,
70                               PropertyEditor JavaDoc propertyEditor) {
71             this.id = id;
72             this.displayName = displayName;
73             this.shortDescription = shortDescription;
74             this.type = type;
75             this.defaultVisible = defaultVisible;
76             this.propertyEditor = propertyEditor;
77         }
78         
79         public String JavaDoc getID() {
80             return id;
81         }
82         
83         public String JavaDoc getDisplayName() {
84             return NbBundle.getBundle (ColumnModels.class).getString(displayName);
85         }
86
87         public Character JavaDoc getDisplayedMnemonic() {
88             return new Character JavaDoc(NbBundle.getBundle(ColumnModels.class).
89                     getString(displayName+"_Mnc").charAt(0)); // NOI18N
90
}
91         
92         public String JavaDoc getShortDescription() {
93             return NbBundle.getBundle (ColumnModels.class).getString(shortDescription);
94         }
95         
96         public Class JavaDoc getType() {
97             return type;
98         }
99         
100         /**
101          * Set true if column is visible.
102          *
103          * @param visible set true if column is visible
104          */

105         public void setVisible (boolean visible) {
106             properties.setBoolean (getID () + ".visible", visible);
107         }
108
109         /**
110          * Set true if column should be sorted by default.
111          *
112          * @param sorted set true if column should be sorted by default
113          */

114         public void setSorted (boolean sorted) {
115             properties.setBoolean (getID () + ".sorted", sorted);
116         }
117
118         /**
119          * Set true if column should be sorted by default in descending order.
120          *
121          * @param sortedDescending set true if column should be
122          * sorted by default in descending order
123          */

124         public void setSortedDescending (boolean sortedDescending) {
125             properties.setBoolean (
126                 getID () + ".sortedDescending",
127                 sortedDescending
128              );
129         }
130     
131         /**
132          * Should return current order number of this column.
133          *
134          * @return current order number of this column
135          */

136         public int getCurrentOrderNumber () {
137             return properties.getInt (getID () + ".currentOrderNumber", -1);
138         }
139
140         /**
141          * Is called when current order number of this column is changed.
142          *
143          * @param newOrderNumber new order number
144          */

145         public void setCurrentOrderNumber (int newOrderNumber) {
146             properties.setInt (
147                 getID () + ".currentOrderNumber",
148                 newOrderNumber
149             );
150         }
151
152         /**
153          * Return column width of this column.
154          *
155          * @return column width of this column
156          */

157         public int getColumnWidth () {
158             return properties.getInt (getID () + ".columnWidth", 150);
159         }
160
161         /**
162          * Is called when column width of this column is changed.
163          *
164          * @param newColumnWidth a new column width
165          */

166         public void setColumnWidth (int newColumnWidth) {
167             properties.setInt (getID () + ".columnWidth", newColumnWidth);
168         }
169
170         /**
171          * True if column should be visible by default.
172          *
173          * @return true if column should be visible by default
174          */

175         public boolean isVisible () {
176             return properties.getBoolean (getID () + ".visible", defaultVisible);
177         }
178
179         /**
180          * True if column should be sorted by default.
181          *
182          * @return true if column should be sorted by default
183          */

184         public boolean isSorted () {
185             return properties.getBoolean (getID () + ".sorted", false);
186         }
187
188         /**
189          * True if column should be sorted by default in descending order.
190          *
191          * @return true if column should be sorted by default in descending
192          * order
193          */

194         public boolean isSortedDescending () {
195             return properties.getBoolean (
196                 getID () + ".sortedDescending",
197                 false
198             );
199         }
200         
201         /**
202          * Returns {@link java.beans.PropertyEditor} to be used for
203          * this column. Default implementation returns <code>null</code> -
204          * means use default PropertyEditor.
205          *
206          * @return {@link java.beans.PropertyEditor} to be used for
207          * this column
208          */

209         public PropertyEditor JavaDoc getPropertyEditor() {
210             return propertyEditor;
211         }
212     }
213     
214     /**
215      * Defines model for one table view column. Can be used together with
216      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table view
217      * representation.
218      */

219     public static ColumnModel createDefaultBreakpointsColumn() {
220         return new AbstractColumn("DefaultBreakpointColumn",
221                 "CTL_BreakpointView_Column_Name_Name",
222                 "CTL_BreakpointView_Column_Name_Desc",
223                 null);
224     }
225     
226     /**
227      * Defines model for one table view column. Can be used together with
228      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table view
229      * representation.
230      */

231     public static ColumnModel createBreakpointEnabledColumn() {
232         return new AbstractColumn(Constants.BREAKPOINT_ENABLED_COLUMN_ID,
233                 "CTL_BreakpointView_Column_Enabled_Name",
234                 "CTL_BreakpointView_Column_Enabled_Desc",
235                 Boolean.TYPE);
236     }
237     
238     /**
239      * Defines model for one table view column. Can be used together with
240      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table view
241      * representation.
242      */

243     public static ColumnModel createDefaultCallStackColumn() {
244         return new AbstractColumn("DefaultCallStackColumn",
245                 "CTL_CallstackView_Column_Name_Name",
246                 "CTL_CallstackView_Column_Name_Desc",
247                 null);
248     }
249     
250     /**
251      * Defines model for one table view column. Can be used together with
252      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
253      * view representation.
254      */

255     public static ColumnModel createCallStackLocationColumn() {
256         return new AbstractColumn(Constants.CALL_STACK_FRAME_LOCATION_COLUMN_ID,
257                 "CTL_CallstackView_Column_Location_Name",
258                 "CTL_CallstackView_Column_Location_Desc",
259                 String JavaDoc.class,
260                 false);
261     }
262     
263     /**
264      * Defines model for one table view column. Can be used together with
265      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
266      * view representation.
267      */

268     public static ColumnModel createDefaultLocalsColumn() {
269         return new AbstractColumn("DefaultLocalsColumn",
270                 "CTL_LocalsView_Column_Name_Name",
271                 "CTL_LocalsView_Column_Name_Desc",
272                 null);
273     }
274     
275     /**
276      * Defines model for one table view column. Can be used together with
277      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
278      * view representation.
279      */

280     public static ColumnModel createLocalsToStringColumn() {
281         return new AbstractColumn(Constants.LOCALS_TO_STRING_COLUMN_ID,
282                 "CTL_LocalsView_Column_ToString_Name",
283                 "CTL_LocalsView_Column_ToString_Desc",
284                 String JavaDoc.class,
285                 false);
286     }
287     
288     /**
289      * Defines model for one table view column. Can be used together with
290      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
291      * table view representation.
292      */

293     public static ColumnModel createLocalsTypeColumn() {
294         return new AbstractColumn(Constants.LOCALS_TYPE_COLUMN_ID,
295                 "CTL_LocalsView_Column_Type_Name",
296                 "CTL_LocalsView_Column_Type_Desc",
297                 String JavaDoc.class,
298                 true);
299     }
300     /**
301      * Defines model for one table view column. Can be used together with
302      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
303      * view representation.
304      */

305     public static ColumnModel createLocalsValueColumn() {
306         return new AbstractColumn(Constants.LOCALS_VALUE_COLUMN_ID,
307                 "CTL_LocalsView_Column_Value_Name",
308                 "CTL_LocalsView_Column_Value_Desc",
309                 String JavaDoc.class,
310                 true);
311     }
312     /**
313      * Defines model for one table view column. Can be used together with
314      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
315      * view representation.
316      */

317     public static ColumnModel createDefaultSessionColumn() {
318         return new AbstractColumn("DefaultSessionColumn",
319                 "CTL_SessionsView_Column_Name_Name",
320                 "CTL_SessionsView_Column_Name_Desc",
321                 null);
322     }
323     
324     /**
325      * Defines model for one table view column. Can be used together with
326      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
327      * view representation.
328      */

329     public static ColumnModel createSessionHostNameColumn() {
330         return new AbstractColumn(Constants.SESSION_HOST_NAME_COLUMN_ID,
331                 "CTL_SessionsView_Column_HostName_Name",
332                 "CTL_SessionsView_Column_HostName_Desc",
333                 String JavaDoc.class,
334                 false);
335     }
336     
337     /**
338      * Defines model for one table view column. Can be used together with
339      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
340      * table view representation.
341      */

342     public static ColumnModel createSessionStateColumn () {
343         return new AbstractColumn(Constants.SESSION_STATE_COLUMN_ID,
344                 "CTL_SessionsView_Column_State_Name",
345                 "CTL_SessionsView_Column_State_Desc",
346                 String JavaDoc.class,
347                 true);
348     }
349
350     /**
351      * Defines model for one table view column. Can be used together with
352      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
353      * view representation.
354      */

355     public static ColumnModel createSessionLanguageColumn () {
356         return new AbstractColumn(Constants.SESSION_LANGUAGE_COLUMN_ID,
357                 "CTL_SessionsView_Column_Language_Name",
358                 "CTL_SessionsView_Column_Language_Desc",
359                 Session.class,
360                 true,
361                 new LanguagePropertyEditor ());
362     }
363
364     /**
365      * Defines model for one table view column. Can be used together with
366      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
367      * table view representation.
368      */

369     public static ColumnModel createDefaultThreadColumn() {
370         return new AbstractColumn("DefaultThreadColumn",
371                 "CTL_ThreadsView_Column_Name_Name",
372                 "CTL_ThreadsView_Column_Name_Desc",
373                 null);
374     }
375     
376     /**
377      * Defines model for one table view column. Can be used together with
378      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
379      * table view representation.
380      */

381     public static ColumnModel createThreadStateColumn() {
382         return new AbstractColumn(Constants.THREAD_STATE_COLUMN_ID,
383                 "CTL_ThreadsView_Column_State_Name",
384                 "CTL_ThreadsView_Column_State_Desc",
385                 String JavaDoc.class,
386                 true);
387     }
388     
389     /**
390      * Defines model for one table view column. Can be used together with
391      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
392      * table view representation.
393      */

394     public static ColumnModel createThreadSuspendedColumn() {
395         return new AbstractColumn(Constants.THREAD_SUSPENDED_COLUMN_ID,
396                 "CTL_ThreadsView_Column_Suspended_Name",
397                 "CTL_ThreadsView_Column_Suspended_Desc",
398                 Boolean.TYPE,
399                 false);
400     }
401
402     /**
403      * Defines model for one table view column. Can be used together with
404      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
405      * table view representation.
406      */

407     public static ColumnModel createDefaultWatchesColumn() {
408         return new AbstractColumn("DefaultWatchesColumn",
409                 "CTL_WatchesView_Column_Name_Name",
410                 "CTL_WatchesView_Column_Name_Desc",
411                 null);
412     }
413
414     /**
415      * Defines model for one table view column. Can be used together with
416      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
417      * table view representation.
418      */

419     public static ColumnModel createWatchToStringColumn() {
420         return new AbstractColumn(Constants.WATCH_TO_STRING_COLUMN_ID,
421                 "CTL_WatchesView_Column_ToString_Name",
422                 "CTL_WatchesView_Column_ToString_Desc",
423                 String JavaDoc.class,
424                 false);
425     }
426
427     /**
428      * Defines model for one table view column. Can be used together with
429      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
430      * table view representation.
431      */

432     public static ColumnModel createWatchTypeColumn() {
433         return new AbstractColumn(Constants.WATCH_TYPE_COLUMN_ID,
434                 "CTL_WatchesView_Column_Type_Name",
435                 "CTL_WatchesView_Column_Type_Desc",
436                 String JavaDoc.class,
437                 true);
438     }
439
440     /**
441      * Defines model for one table view column. Can be used together with
442      * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
443      * table view representation.
444      */

445     public static ColumnModel createWatchValueColumn() {
446         return new AbstractColumn(Constants.WATCH_VALUE_COLUMN_ID,
447                 "CTL_WatchesView_Column_Value_Name",
448                 "CTL_WatchesView_Column_Value_Desc",
449                 String JavaDoc.class,
450                 true);
451     }
452
453     private static class LanguagePropertyEditor extends PropertyEditorSupport JavaDoc {
454         
455         public void setValue(Object JavaDoc value) {
456             if (value != null && !(value instanceof Session)) {
457                 ErrorManager.getDefault().notify(
458                         new IllegalArgumentException JavaDoc("Value "+value+" is not an instance of Session!"));
459             }
460             super.setValue(value);
461         }
462
463         public String JavaDoc[] getTags () {
464             if (getValue () == null) return new String JavaDoc [0];
465             String JavaDoc[] s = ((Session) getValue ()).getSupportedLanguages ();
466             return s;
467         }
468         
469         public String JavaDoc getAsText () {
470             String JavaDoc s = ((Session) getValue ()).getCurrentLanguage ();
471             return s;
472         }
473         
474         public void setAsText (String JavaDoc text) {
475             ((Session) getValue ()).setCurrentLanguage (text);
476         }
477     }
478 }
479
Popular Tags