KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > breakpoints > BreakpointModel


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 package org.netbeans.modules.scripting.php.dbginterface.breakpoints;
21
22 import org.netbeans.modules.scripting.php.dbginterface.ModelSupport;
23 import org.netbeans.modules.scripting.php.dbginterface.Utils;
24 import org.netbeans.spi.viewmodel.NodeModel;
25 import org.netbeans.spi.viewmodel.TableModel;
26 import org.netbeans.spi.viewmodel.UnknownTypeException;
27 import org.netbeans.spi.debugger.ui.Constants;
28 import org.openide.filesystems.FileObject;
29 import org.openide.text.Line;
30
31 /**
32  *
33  * @author Matt Stevens (inspired by Ant Debugger)
34  * @author Peter Williams
35  */

36 public class BreakpointModel extends ModelSupport
37         implements NodeModel, TableModel { //, TreeModel {
38

39     public static final String JavaDoc LINE_BREAKPOINT =
40         "org/netbeans/modules/debugger/resources/editor/Breakpoint"; // NOI18N
41
public static final String JavaDoc LINE_BREAKPOINT_PC =
42         "org/netbeans/modules/debugger/resources/editor/Breakpoint+PC"; // NOI18N
43
public static final String JavaDoc DISABLED_LINE_BREAKPOINT =
44         "org/netbeans/modules/debugger/resources/editor/DisabledBreakpoint"; // NOI18N
45

46     // ------------------------------------------------------------------------
47
// NodeModel implementation
48
// ------------------------------------------------------------------------
49
public String JavaDoc getDisplayName(Object JavaDoc node) throws UnknownTypeException {
50         if (node instanceof PhpBreakpoint) {
51             PhpBreakpoint breakpoint = (PhpBreakpoint)node;
52             FileObject fileObject = (FileObject)breakpoint.getLine().getLookup().lookup(FileObject.class);
53             return fileObject.getNameExt() + ":" + (breakpoint.getLine().getLineNumber() + 1);
54         }
55         throw new UnknownTypeException(node);
56     }
57
58     public String JavaDoc getIconBase(Object JavaDoc node) throws UnknownTypeException {
59         if (node instanceof PhpBreakpoint) {
60             PhpBreakpoint breakpoint = (PhpBreakpoint)node;
61             if(!breakpoint.isEnabled()) {
62                 return DISABLED_LINE_BREAKPOINT;
63             }
64             Line line = Utils.getCurrentLine();
65             if(line != null && line.getLineNumber() == breakpoint.getLine().getLineNumber()) {
66                 return LINE_BREAKPOINT_PC;
67             }
68             return LINE_BREAKPOINT;
69         }
70
71         throw new UnknownTypeException(node);
72     }
73
74     public String JavaDoc getShortDescription(Object JavaDoc node) throws UnknownTypeException {
75         if (node instanceof PhpBreakpoint) {
76             return ((PhpBreakpoint)node).getLine().getDisplayName();
77         }
78
79         throw new UnknownTypeException(node);
80     }
81
82     // ------------------------------------------------------------------------
83
// TableModel implementation
84
// ------------------------------------------------------------------------
85
public Object JavaDoc getValueAt(Object JavaDoc node, String JavaDoc columnID) throws UnknownTypeException {
86         if (node instanceof PhpBreakpoint) {
87             if (columnID.equals(Constants.BREAKPOINT_ENABLED_COLUMN_ID)) {
88                 return Boolean.valueOf(((PhpBreakpoint)node).isEnabled());
89             } else {
90                 System.out.println("BreakpointModel.getValueAt(node=" + node + ", columnId=" + columnID + ")");
91             }
92         }
93
94         throw new UnknownTypeException(node);
95     }
96
97     public boolean isReadOnly(Object JavaDoc node, String JavaDoc columnID) throws UnknownTypeException {
98         if (node instanceof PhpBreakpoint) {
99             if (columnID.equals(Constants.BREAKPOINT_ENABLED_COLUMN_ID)) {
100                 return false;
101             } else {
102                 System.out.println("BreakpointModel.getValueAt(node=" + node + ", columnId=" + columnID + ")");
103             }
104         }
105
106         throw new UnknownTypeException(node);
107     }
108
109     public void setValueAt(Object JavaDoc node, String JavaDoc columnID, Object JavaDoc value) throws UnknownTypeException {
110         if(node instanceof PhpBreakpoint) {
111             if(columnID.equals(Constants.BREAKPOINT_ENABLED_COLUMN_ID)) {
112                 if(((Boolean JavaDoc)value).equals(Boolean.TRUE)) {
113                     ((PhpBreakpoint)node).enable();
114                 } else {
115                     ((PhpBreakpoint)node).disable();
116                 }
117             }
118         } else {
119             throw new UnknownTypeException(node);
120         }
121     }
122
123     // ------------------------------------------------------------------------
124
// TreeModel implementation
125
// ------------------------------------------------------------------------
126
// public Object getRoot() {
127
// }
128
//
129
// public Object[] getChildren(Object object, int i, int i0) throws UnknownTypeException {
130
// }
131
//
132
// public boolean isLeaf(Object object) throws UnknownTypeException {
133
// }
134
//
135
// public int getChildrenCount(Object object) throws UnknownTypeException {
136
// }
137
}
138
Popular Tags