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-2007 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.awt.datatransfer.Transferable;
045: import java.beans.PropertyChangeEvent;
046: import java.io.IOException;
047: import java.lang.ref.WeakReference;
048: import java.util.Vector;
049:
050: import org.netbeans.api.debugger.DebuggerManager;
051: import org.netbeans.api.debugger.DebuggerManagerAdapter;
052: import org.netbeans.api.debugger.Session;
053: import org.netbeans.spi.viewmodel.ExtendedNodeModel;
054: import org.netbeans.spi.viewmodel.ModelEvent;
055: import org.netbeans.spi.viewmodel.TreeModel;
056: import org.netbeans.spi.viewmodel.ModelListener;
057: import org.netbeans.spi.viewmodel.UnknownTypeException;
058:
059: import org.openide.util.NbBundle;
060: import org.openide.util.datatransfer.PasteType;
061:
062: /**
063: * @author Jan Jancura
064: */
065: public class SesionsNodeModel implements ExtendedNodeModel {
066:
067: public static final String SESSION = "org/netbeans/modules/debugger/resources/sessionsView/session_16.png";
068: public static final String CURRENT_SESSION = "org/netbeans/modules/debugger/resources/sessionsView/CurrentSession.gif";
069:
070: private Vector listeners = new Vector();
071: private Listener listener;
072:
073: public String getDisplayName(Object o) throws UnknownTypeException {
074: if (listener == null)
075: listener = new Listener(this );
076: if (o == TreeModel.ROOT) {
077: return NbBundle.getBundle(SesionsNodeModel.class)
078: .getString("CTL_SessionsModel_Column_Name_Name");
079: } else if (o instanceof Session) {
080: return ((Session) o).getName();
081: } else
082: throw new UnknownTypeException(o);
083: }
084:
085: public String getShortDescription(Object o)
086: throws UnknownTypeException {
087: if (listener == null)
088: listener = new Listener(this );
089: if (o == TreeModel.ROOT) {
090: return TreeModel.ROOT;
091: } else if (o instanceof Session) {
092: return null;
093: } else
094: throw new UnknownTypeException(o);
095: }
096:
097: public String getIconBase(Object o) throws UnknownTypeException {
098: throw new UnsupportedOperationException("Not supported.");
099: }
100:
101: public String getIconBaseWithExtension(Object node)
102: throws UnknownTypeException {
103: if (listener == null)
104: listener = new Listener(this );
105: if (node == TreeModel.ROOT) {
106: return SESSION;
107: } else if (node instanceof Session) {
108: if (node == DebuggerManager.getDebuggerManager()
109: .getCurrentSession())
110: return CURRENT_SESSION;
111: else
112: return SESSION;
113: } else
114: throw new UnknownTypeException(node);
115: }
116:
117: public boolean canRename(Object node) throws UnknownTypeException {
118: return false;
119: }
120:
121: public boolean canCopy(Object node) throws UnknownTypeException {
122: return false;
123: }
124:
125: public boolean canCut(Object node) throws UnknownTypeException {
126: return false;
127: }
128:
129: public Transferable clipboardCopy(Object node) throws IOException,
130: UnknownTypeException {
131: throw new UnsupportedOperationException("Not supported yet.");
132: }
133:
134: public Transferable clipboardCut(Object node) throws IOException,
135: UnknownTypeException {
136: throw new UnsupportedOperationException("Not supported yet.");
137: }
138:
139: public PasteType[] getPasteTypes(Object node, Transferable t)
140: throws UnknownTypeException {
141: return null;
142: }
143:
144: public void setName(Object node, String name)
145: throws UnknownTypeException {
146: throw new UnsupportedOperationException("Not supported yet.");
147: }
148:
149: /**
150: *
151: * @param l the listener to add
152: */
153: public void addModelListener(ModelListener l) {
154: listeners.add(l);
155: }
156:
157: /**
158: *
159: * @param l the listener to remove
160: */
161: public void removeModelListener(ModelListener l) {
162: listeners.remove(l);
163: }
164:
165: private void fireTreeChanged() {
166: Vector v = (Vector) listeners.clone();
167: int i, k = v.size();
168: for (i = 0; i < k; i++)
169: ((ModelListener) v.get(i))
170: .modelChanged(new ModelEvent.TreeChanged(this ));
171: }
172:
173: // innerclasses ............................................................
174:
175: /**
176: * Listens on DebuggerManager on PROP_CURRENT_SESSION.
177: */
178: private static class Listener extends DebuggerManagerAdapter {
179:
180: private WeakReference ref;
181:
182: public Listener(SesionsNodeModel rm) {
183: ref = new WeakReference(rm);
184: DebuggerManager.getDebuggerManager().addDebuggerListener(
185: DebuggerManager.PROP_CURRENT_SESSION, this );
186: }
187:
188: private SesionsNodeModel getModel() {
189: SesionsNodeModel rm = (SesionsNodeModel) ref.get();
190: if (rm == null) {
191: DebuggerManager.getDebuggerManager()
192: .removeDebuggerListener(
193: DebuggerManager.PROP_CURRENT_SESSION,
194: this );
195: }
196: return rm;
197: }
198:
199: public void propertyChange(PropertyChangeEvent e) {
200: SesionsNodeModel rm = getModel();
201: if (rm == null)
202: return;
203: rm.fireTreeChanged();
204: }
205: }
206: }
|