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-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.debugger.ui.session;
021:
022: import java.beans.PropertyChangeEvent;
023: import java.beans.PropertyChangeListener;
024: import java.util.Vector;
025: import org.netbeans.api.debugger.DebuggerEngine;
026: import org.netbeans.api.debugger.Session;
027: import org.netbeans.modules.bpel.debugger.api.BpelDebugger;
028: import org.netbeans.spi.debugger.ContextProvider;
029: import org.netbeans.spi.debugger.ui.Constants;
030: import org.netbeans.spi.viewmodel.TableModel;
031: import org.netbeans.spi.viewmodel.ModelListener;
032: import org.netbeans.spi.viewmodel.UnknownTypeException;
033: import org.openide.util.NbBundle;
034:
035: /**
036: * @author Alexander Zgursky
037: */
038: public class BpelSessionView implements TableModel, Constants,
039: PropertyChangeListener {
040: private Vector listeners = new Vector();
041:
042: public BpelSessionView(ContextProvider contextProvider) {
043: BpelDebugger debugger = contextProvider.lookupFirst(null,
044: BpelDebugger.class);
045: debugger.addPropertyChangeListener(debugger.PROP_STATE, this );
046: }
047:
048: private static String loc(String key) {
049: return NbBundle.getBundle(BpelSessionView.class).getString(key);
050: }
051:
052: private static String getSessionState(Session s) {
053: DebuggerEngine e = s.getCurrentEngine();
054: if (e == null) {
055: return "";
056: }
057: BpelDebugger d = e.lookupFirst(null, BpelDebugger.class);
058: if (d != null) {
059: switch (d.getState()) {
060: case BpelDebugger.STATE_DISCONNECTED:
061: return loc("MSG_Session_State_Disconnected"); // NOI18N
062: case BpelDebugger.STATE_RUNNING:
063: return loc("MSG_Session_State_Running"); // NOI18N
064: case BpelDebugger.STATE_STARTING:
065: return loc("MSG_Session_State_Starting"); // NOI18N
066: }
067: }
068: return "";
069: }
070:
071: //*********************
072: // TableModel interface
073: //*********************
074:
075: public Object getValueAt(Object row, String columnID)
076: throws UnknownTypeException {
077: if (row instanceof Session) {
078: if (columnID.equals(SESSION_STATE_COLUMN_ID)) {
079: return getSessionState((Session) row);
080: } else if (columnID.equals(SESSION_LANGUAGE_COLUMN_ID)) {
081: return row;
082: } else if (columnID.equals(SESSION_HOST_NAME_COLUMN_ID)) {
083: return ((Session) row).getLocationName();
084: }
085: }
086: throw new UnknownTypeException(row);
087: }
088:
089: public boolean isReadOnly(Object row, String columnID)
090: throws UnknownTypeException {
091: if (row instanceof Session) {
092: return true;
093: }
094: throw new UnknownTypeException(row);
095: }
096:
097: public void setValueAt(Object row, String columnID, Object value)
098: throws UnknownTypeException {
099: throw new UnknownTypeException(row);
100: }
101:
102: //*********************************
103: // PropertyChangeListener interface
104: //*********************************
105:
106: public void propertyChange(PropertyChangeEvent e) {
107: fireTreeChanged();
108: if (e.getNewValue().equals(BpelDebugger.STATE_DISCONNECTED)) {
109: ((BpelDebugger) e.getSource())
110: .removePropertyChangeListener(
111: BpelDebugger.PROP_STATE, this );
112: }
113: }
114:
115: //*********************
116: // Other public methods
117: //*********************
118:
119: /**
120: * Registers given listener.
121: *
122: * @param l the listener to add
123: */
124: public void addModelListener(ModelListener l) {
125: listeners.add(l);
126: }
127:
128: /**
129: * Unregisters given listener.
130: *
131: * @param l the listener to remove
132: */
133: public void removeModelListener(ModelListener l) {
134: listeners.remove(l);
135: }
136:
137: //****************
138: // Private methods
139: //****************
140:
141: private void fireTreeChanged() {
142: Vector v = (Vector) listeners.clone();
143: int k = v.size();
144: for (int i = 0; i < k; i++)
145: ((ModelListener) v.get(i)).modelChanged(null);
146: }
147: }
|