001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008:
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.php.dbgp.models;
020:
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.HashMap;
024: import java.util.Iterator;
025: import java.util.LinkedList;
026: import java.util.List;
027: import java.util.Map;
028: import java.util.Set;
029: import java.util.concurrent.atomic.AtomicBoolean;
030:
031: import javax.swing.SwingUtilities;
032:
033: import org.netbeans.api.debugger.ActionsManager;
034: import org.netbeans.api.debugger.DebuggerEngine;
035: import org.netbeans.api.debugger.DebuggerManager;
036: import org.netbeans.modules.php.dbgp.DebugSession;
037: import org.netbeans.modules.php.dbgp.StartActionProviderImpl;
038: import org.netbeans.modules.php.dbgp.actions.AbstractActionProvider;
039: import org.netbeans.modules.php.dbgp.annotations.CurrentLineAnnotation;
040: import org.netbeans.modules.php.dbgp.annotations.DebuggerAnnotation;
041: import org.netbeans.modules.php.dbgp.api.SessionId;
042: import org.netbeans.modules.php.dbgp.breakpoints.BreakpointModel;
043: import org.netbeans.spi.debugger.ActionsProvider;
044: import org.netbeans.spi.viewmodel.TableModel;
045: import org.netbeans.spi.viewmodel.TreeModel;
046: import org.openide.text.Line;
047:
048: /**
049: * @author ads
050: *
051: */
052: public abstract class AbstractIDEBridge {
053:
054: public static final String LOCALS_VIEW_NAME = "LocalsView"; // NOI18N
055:
056: public static final String CALLSTACK_VIEW_NAME = "CallStackView"; // NOI18N
057:
058: public static final String WATCHES_VIEW_NAME = "WatchesView"; // NOI18N
059:
060: public static final String BREAKPOINTS_VIEW_NAME = "BreakpointsView";// NOI18N
061:
062: public static final String THREADS_VIEW_NAME = "ThreadsView"; // NOI18N
063:
064: protected AbstractIDEBridge() {
065: myAnnotations = new HashMap<String, List<DebuggerAnnotation>>();
066: isSuspended = new AtomicBoolean(false);
067: }
068:
069: public void hideAnnotations() {
070: Collection<List<DebuggerAnnotation>> annotations;
071: synchronized (myAnnotations) {
072: annotations = new ArrayList<List<DebuggerAnnotation>>(
073: myAnnotations.values());
074: myAnnotations.clear();
075: }
076:
077: for (List<DebuggerAnnotation> list : annotations) {
078: for (DebuggerAnnotation annotation : list) {
079: annotation.detach();
080: }
081: }
082: }
083:
084: public void showCurrentDebuggerLine(final Line line) {
085: if (line != null) {
086: annotate(new CurrentLineAnnotation(line));
087:
088: SwingUtilities.invokeLater(new Runnable() {
089: public void run() {
090: line.show(Line.SHOW_GOTO);
091: }
092: });
093: }
094: }
095:
096: public void annotate(DebuggerAnnotation annotation) {
097: String type = annotation.getAnnotationType();
098: synchronized (myAnnotations) {
099: List<DebuggerAnnotation> list = myAnnotations.get(type);
100: if (list == null) {
101: list = new LinkedList<DebuggerAnnotation>();
102: myAnnotations.put(type, list);
103: }
104: list.add(annotation);
105: }
106: }
107:
108: public VariablesModel getVariablesModel() {
109: if (getEngine() == null) {
110: return null;
111: }
112: return (VariablesModel) getEngine().lookupFirst(
113: LOCALS_VIEW_NAME, TreeModel.class);
114: }
115:
116: public CallStackModel getCallStackModel() {
117: if (getEngine() == null) {
118: return null;
119: }
120: return (CallStackModel) getEngine().lookupFirst(
121: CALLSTACK_VIEW_NAME, TreeModel.class);
122: }
123:
124: public WatchesModel getWatchesModel() {
125: return (WatchesModel) getEngine().lookupFirst(
126: WATCHES_VIEW_NAME, TreeModel.class);
127: }
128:
129: public BreakpointModel getBreakpointModel() {
130: Iterator it = DebuggerManager.getDebuggerManager().lookup(
131: BREAKPOINTS_VIEW_NAME, TableModel.class).iterator();
132:
133: while (it.hasNext()) {
134: TableModel model = (TableModel) it.next();
135: if (model instanceof BreakpointModel) {
136: return (BreakpointModel) model;
137: }
138: }
139:
140: return null;
141: }
142:
143: public ThreadsModel getThreadsModel() {
144: return (ThreadsModel) getEngine().lookupFirst(
145: THREADS_VIEW_NAME, TreeModel.class);
146: }
147:
148: public void setSuspended(boolean flag) {
149: isSuspended.set(flag);
150: synchronized (StartActionProviderImpl.getInstance()) {
151: SessionId id = getDebugSession().getSessionId();
152: if (id == null) {
153: return;
154: }
155: DebugSession current = StartActionProviderImpl
156: .getInstance().getCurrentSession(id);
157: if (!current.equals(getDebugSession())) {
158: return;
159: }
160: }
161: List list = getEngine().lookup(null, ActionsProvider.class);
162: for (Object object : list) {
163: assert object instanceof AbstractActionProvider;
164: AbstractActionProvider provider = (AbstractActionProvider) object;
165: Set set = provider.getActions();
166: for (Object obj : set) {
167: if (obj == ActionsManager.ACTION_CONTINUE
168: || obj == ActionsManager.ACTION_STEP_INTO
169: || obj == ActionsManager.ACTION_STEP_OVER
170: || obj == ActionsManager.ACTION_STEP_OUT
171: || obj == ActionsManager.ACTION_RUN_TO_CURSOR) {
172: provider.setEnabled(flag);
173: }
174: }
175: }
176: }
177:
178: public boolean isSuspended() {
179: return isSuspended.get();
180: }
181:
182: protected abstract DebuggerEngine getEngine();
183:
184: protected abstract DebugSession getDebugSession();
185:
186: private Map<String, List<DebuggerAnnotation>> myAnnotations;
187:
188: private AtomicBoolean isSuspended;
189:
190: }
|