001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.debugger.ui.models;
043:
044: import java.beans.PropertyEditor;
045: import java.beans.PropertyEditorSupport;
046: import org.netbeans.api.debugger.Properties;
047: import org.netbeans.api.debugger.Session;
048: import org.netbeans.spi.debugger.ui.Constants;
049: import org.netbeans.spi.viewmodel.ColumnModel;
050: import org.openide.ErrorManager;
051: import org.openide.util.NbBundle;
052:
053: /**
054: * Defines model for one table view column. Can be used together with
055: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
056: * view representation.
057: *
058: * @author Jan Jancura
059: */
060: public class ColumnModels {
061:
062: /**
063: * Defines model for one table view column. Can be used together with
064: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
065: * table view representation.
066: */
067: private static class AbstractColumn extends ColumnModel {
068:
069: private String id;
070: private String displayName;
071: private String shortDescription;
072: private Class type;
073: private boolean defaultVisible;
074: private PropertyEditor propertyEditor;
075: private boolean sortable;
076:
077: Properties properties = Properties.getDefault().getProperties(
078: "debugger").getProperties("views");
079:
080: public AbstractColumn(String id, String displayName,
081: String shortDescription, Class type) {
082: this (id, displayName, shortDescription, type, true);
083: }
084:
085: public AbstractColumn(String id, String displayName,
086: String shortDescription, Class type,
087: boolean defaultVisible) {
088: this (id, displayName, shortDescription, type,
089: defaultVisible, null);
090: }
091:
092: public AbstractColumn(String id, String displayName,
093: String shortDescription, Class type,
094: boolean defaultVisible, PropertyEditor propertyEditor) {
095: this (id, displayName, shortDescription, type,
096: defaultVisible, propertyEditor, true);
097: }
098:
099: public AbstractColumn(String id, String displayName,
100: String shortDescription, Class type,
101: boolean defaultVisible, PropertyEditor propertyEditor,
102: boolean sortable) {
103: this .id = id;
104: this .displayName = displayName;
105: this .shortDescription = shortDescription;
106: this .type = type;
107: this .defaultVisible = defaultVisible;
108: this .propertyEditor = propertyEditor;
109: this .sortable = sortable;
110: }
111:
112: public String getID() {
113: return id;
114: }
115:
116: public String getDisplayName() {
117: return NbBundle.getBundle(ColumnModels.class).getString(
118: displayName);
119: }
120:
121: public Character getDisplayedMnemonic() {
122: return new Character(NbBundle.getBundle(ColumnModels.class)
123: .getString(displayName + "_Mnc").charAt(0)); // NOI18N
124: }
125:
126: public String getShortDescription() {
127: return NbBundle.getBundle(ColumnModels.class).getString(
128: shortDescription);
129: }
130:
131: public Class getType() {
132: return type;
133: }
134:
135: /**
136: * Set true if column is visible.
137: *
138: * @param visible set true if column is visible
139: */
140: public void setVisible(boolean visible) {
141: properties.setBoolean(getID() + ".visible", visible);
142: }
143:
144: /**
145: * Set true if column should be sorted by default.
146: *
147: * @param sorted set true if column should be sorted by default
148: */
149: public void setSorted(boolean sorted) {
150: if (sortable) {
151: properties.setBoolean(getID() + ".sorted", sorted);
152: }
153: }
154:
155: /**
156: * Set true if column should be sorted by default in descending order.
157: *
158: * @param sortedDescending set true if column should be
159: * sorted by default in descending order
160: */
161: public void setSortedDescending(boolean sortedDescending) {
162: if (sortable) {
163: properties.setBoolean(getID() + ".sortedDescending",
164: sortedDescending);
165: }
166: }
167:
168: /**
169: * Should return current order number of this column.
170: *
171: * @return current order number of this column
172: */
173: public int getCurrentOrderNumber() {
174: return properties.getInt(getID() + ".currentOrderNumber",
175: -1);
176: }
177:
178: /**
179: * Is called when current order number of this column is changed.
180: *
181: * @param newOrderNumber new order number
182: */
183: public void setCurrentOrderNumber(int newOrderNumber) {
184: properties.setInt(getID() + ".currentOrderNumber",
185: newOrderNumber);
186: }
187:
188: /**
189: * Return column width of this column.
190: *
191: * @return column width of this column
192: */
193: public int getColumnWidth() {
194: return properties.getInt(getID() + ".columnWidth", 150);
195: }
196:
197: /**
198: * Is called when column width of this column is changed.
199: *
200: * @param newColumnWidth a new column width
201: */
202: public void setColumnWidth(int newColumnWidth) {
203: properties.setInt(getID() + ".columnWidth", newColumnWidth);
204: }
205:
206: /**
207: * True if column should be visible by default.
208: *
209: * @return true if column should be visible by default
210: */
211: public boolean isVisible() {
212: return properties.getBoolean(getID() + ".visible",
213: defaultVisible);
214: }
215:
216: public boolean isSortable() {
217: return sortable;
218: }
219:
220: /**
221: * True if column should be sorted by default.
222: *
223: * @return true if column should be sorted by default
224: */
225: public boolean isSorted() {
226: if (sortable) {
227: return properties
228: .getBoolean(getID() + ".sorted", false);
229: } else {
230: return false;
231: }
232: }
233:
234: /**
235: * True if column should be sorted by default in descending order.
236: *
237: * @return true if column should be sorted by default in descending
238: * order
239: */
240: public boolean isSortedDescending() {
241: if (sortable) {
242: return properties.getBoolean(getID()
243: + ".sortedDescending", false);
244: } else {
245: return false;
246: }
247: }
248:
249: /**
250: * Returns {@link java.beans.PropertyEditor} to be used for
251: * this column. Default implementation returns <code>null</code> -
252: * means use default PropertyEditor.
253: *
254: * @return {@link java.beans.PropertyEditor} to be used for
255: * this column
256: */
257: public PropertyEditor getPropertyEditor() {
258: return propertyEditor;
259: }
260: }
261:
262: /**
263: * Defines model for one table view column. Can be used together with
264: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table view
265: * representation.
266: */
267: public static ColumnModel createDefaultBreakpointsColumn() {
268: return new AbstractColumn("DefaultBreakpointColumn",
269: "CTL_BreakpointView_Column_Name_Name",
270: "CTL_BreakpointView_Column_Name_Desc", null);
271: }
272:
273: /**
274: * Defines model for one table view column. Can be used together with
275: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table view
276: * representation.
277: */
278: public static ColumnModel createBreakpointEnabledColumn() {
279: return new AbstractColumn(
280: Constants.BREAKPOINT_ENABLED_COLUMN_ID,
281: "CTL_BreakpointView_Column_Enabled_Name",
282: "CTL_BreakpointView_Column_Enabled_Desc", Boolean.TYPE);
283: }
284:
285: /**
286: * Defines model for one table view column. Can be used together with
287: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table view
288: * representation.
289: */
290: public static ColumnModel createDefaultCallStackColumn() {
291: return new AbstractColumn("DefaultCallStackColumn",
292: "CTL_CallstackView_Column_Name_Name",
293: "CTL_CallstackView_Column_Name_Desc", null, true, null,
294: false);
295: }
296:
297: /**
298: * Defines model for one table view column. Can be used together with
299: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
300: * view representation.
301: */
302: public static ColumnModel createCallStackLocationColumn() {
303: return new AbstractColumn(
304: Constants.CALL_STACK_FRAME_LOCATION_COLUMN_ID,
305: "CTL_CallstackView_Column_Location_Name",
306: "CTL_CallstackView_Column_Location_Desc", String.class,
307: false);
308: }
309:
310: /**
311: * Defines model for one table view column. Can be used together with
312: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
313: * view representation.
314: */
315: public static ColumnModel createDefaultLocalsColumn() {
316: return new AbstractColumn("DefaultLocalsColumn",
317: "CTL_LocalsView_Column_Name_Name",
318: "CTL_LocalsView_Column_Name_Desc", null);
319: }
320:
321: /**
322: * Defines model for one table view column. Can be used together with
323: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
324: * view representation.
325: */
326: public static ColumnModel createLocalsToStringColumn() {
327: return new AbstractColumn(Constants.LOCALS_TO_STRING_COLUMN_ID,
328: "CTL_LocalsView_Column_ToString_Name",
329: "CTL_LocalsView_Column_ToString_Desc", String.class,
330: false);
331: }
332:
333: /**
334: * Defines model for one table view column. Can be used together with
335: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
336: * table view representation.
337: */
338: public static ColumnModel createLocalsTypeColumn() {
339: return new AbstractColumn(Constants.LOCALS_TYPE_COLUMN_ID,
340: "CTL_LocalsView_Column_Type_Name",
341: "CTL_LocalsView_Column_Type_Desc", String.class, true);
342: }
343:
344: /**
345: * Defines model for one table view column. Can be used together with
346: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
347: * view representation.
348: */
349: public static ColumnModel createLocalsValueColumn() {
350: return new AbstractColumn(Constants.LOCALS_VALUE_COLUMN_ID,
351: "CTL_LocalsView_Column_Value_Name",
352: "CTL_LocalsView_Column_Value_Desc", String.class, true);
353: }
354:
355: /**
356: * Defines model for one table view column. Can be used together with
357: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
358: * view representation.
359: */
360: public static ColumnModel createDefaultSessionColumn() {
361: return new AbstractColumn("DefaultSessionColumn",
362: "CTL_SessionsView_Column_Name_Name",
363: "CTL_SessionsView_Column_Name_Desc", null);
364: }
365:
366: /**
367: * Defines model for one table view column. Can be used together with
368: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
369: * view representation.
370: */
371: public static ColumnModel createSessionHostNameColumn() {
372: return new AbstractColumn(
373: Constants.SESSION_HOST_NAME_COLUMN_ID,
374: "CTL_SessionsView_Column_HostName_Name",
375: "CTL_SessionsView_Column_HostName_Desc", String.class,
376: false);
377: }
378:
379: /**
380: * Defines model for one table view column. Can be used together with
381: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
382: * table view representation.
383: */
384: public static ColumnModel createSessionStateColumn() {
385: return new AbstractColumn(Constants.SESSION_STATE_COLUMN_ID,
386: "CTL_SessionsView_Column_State_Name",
387: "CTL_SessionsView_Column_State_Desc", String.class,
388: true);
389: }
390:
391: /**
392: * Defines model for one table view column. Can be used together with
393: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree table
394: * view representation.
395: */
396: public static ColumnModel createSessionLanguageColumn() {
397: return new AbstractColumn(Constants.SESSION_LANGUAGE_COLUMN_ID,
398: "CTL_SessionsView_Column_Language_Name",
399: "CTL_SessionsView_Column_Language_Desc", Session.class,
400: true, new LanguagePropertyEditor());
401: }
402:
403: /**
404: * Defines model for one table view column. Can be used together with
405: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
406: * table view representation.
407: */
408: public static ColumnModel createDefaultThreadColumn() {
409: return new AbstractColumn("DefaultThreadColumn",
410: "CTL_ThreadsView_Column_Name_Name",
411: "CTL_ThreadsView_Column_Name_Desc", 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 createThreadStateColumn() {
420: return new AbstractColumn(Constants.THREAD_STATE_COLUMN_ID,
421: "CTL_ThreadsView_Column_State_Name",
422: "CTL_ThreadsView_Column_State_Desc", String.class, true);
423: }
424:
425: /**
426: * Defines model for one table view column. Can be used together with
427: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
428: * table view representation.
429: */
430: public static ColumnModel createThreadSuspendedColumn() {
431: return new AbstractColumn(Constants.THREAD_SUSPENDED_COLUMN_ID,
432: "CTL_ThreadsView_Column_Suspended_Name",
433: "CTL_ThreadsView_Column_Suspended_Desc", Boolean.TYPE,
434: false);
435: }
436:
437: /**
438: * Defines model for one table view column. Can be used together with
439: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
440: * table view representation.
441: */
442: public static ColumnModel createDefaultWatchesColumn() {
443: return new AbstractColumn("DefaultWatchesColumn",
444: "CTL_WatchesView_Column_Name_Name",
445: "CTL_WatchesView_Column_Name_Desc", null);
446: }
447:
448: /**
449: * Defines model for one table view column. Can be used together with
450: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
451: * table view representation.
452: */
453: public static ColumnModel createWatchToStringColumn() {
454: return new AbstractColumn(Constants.WATCH_TO_STRING_COLUMN_ID,
455: "CTL_WatchesView_Column_ToString_Name",
456: "CTL_WatchesView_Column_ToString_Desc", String.class,
457: false);
458: }
459:
460: /**
461: * Defines model for one table view column. Can be used together with
462: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
463: * table view representation.
464: */
465: public static ColumnModel createWatchTypeColumn() {
466: return new AbstractColumn(Constants.WATCH_TYPE_COLUMN_ID,
467: "CTL_WatchesView_Column_Type_Name",
468: "CTL_WatchesView_Column_Type_Desc", String.class, true);
469: }
470:
471: /**
472: * Defines model for one table view column. Can be used together with
473: * {@link org.netbeans.spi.viewmodel.TreeModel} for tree
474: * table view representation.
475: */
476: public static ColumnModel createWatchValueColumn() {
477: return new AbstractColumn(Constants.WATCH_VALUE_COLUMN_ID,
478: "CTL_WatchesView_Column_Value_Name",
479: "CTL_WatchesView_Column_Value_Desc", String.class, true);
480: }
481:
482: private static class LanguagePropertyEditor extends
483: PropertyEditorSupport {
484:
485: public void setValue(Object value) {
486: if (value != null && !(value instanceof Session)) {
487: ErrorManager.getDefault().notify(
488: new IllegalArgumentException("Value " + value
489: + " is not an instance of Session!"));
490: }
491: super .setValue(value);
492: }
493:
494: public String[] getTags() {
495: if (getValue() == null)
496: return new String[0];
497: String[] s = ((Session) getValue()).getSupportedLanguages();
498: return s;
499: }
500:
501: public String getAsText() {
502: String s = ((Session) getValue()).getCurrentLanguage();
503: return s;
504: }
505:
506: public void setAsText(String text) {
507: ((Session) getValue()).setCurrentLanguage(text);
508: }
509: }
510: }
|