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.execution;
021:
022: import java.util.HashMap;
023: import java.util.Map;
024: import javax.swing.JToolTip;
025: import org.netbeans.modules.bpel.debugger.api.pem.PemEntity;
026: import org.netbeans.modules.bpel.debugger.api.psm.PsmEntity;
027: import org.netbeans.modules.bpel.debugger.ui.util.EditorUtil;
028: import org.netbeans.modules.bpel.debugger.ui.util.ModelUtil;
029: import org.netbeans.modules.bpel.model.api.BpelModel;
030: import org.netbeans.spi.debugger.ContextProvider;
031: import org.netbeans.spi.viewmodel.ModelListener;
032: import org.netbeans.spi.viewmodel.TableModel;
033: import org.netbeans.spi.viewmodel.UnknownTypeException;
034:
035: /**
036: * Model describing the table structure in the Process Execution View. Since
037: * the view contains only the tree column, this is an empty stub, which only
038: * performs some basic type verification.
039: *
040: * @author Alexander Zgursky
041: * @author Kirill Sorokin
042: */
043: public class ProcessExecutionTableModel implements TableModel {
044: private Map<PsmEntity, String> psm2Line = new HashMap<PsmEntity, String>();
045:
046: /**{@inheritDoc}*/
047: public ProcessExecutionTableModel(
048: final ContextProvider contextProvider) {
049: // Does nothing
050: }
051:
052: /**{@inheritDoc}*/
053: public Object getValueAt(final Object stuff, final String column)
054: throws UnknownTypeException {
055:
056: Object object = stuff;
057: boolean isTooltip = false;
058:
059: if (stuff instanceof JToolTip) {
060: isTooltip = true;
061: object = ((JToolTip) stuff)
062: .getClientProperty("getShortDescription");
063: }
064:
065: if (object instanceof ProcessExecutionTreeModel.Dummy) {
066: if (column
067: .equals(ProcessExecutionColumnModel_Thread.COLUMN_ID)) {
068: return "";
069: }
070:
071: if (column
072: .equals(ProcessExecutionColumnModel_Line.COLUMN_ID)) {
073: return "";
074: }
075:
076: if (column
077: .equals(ProcessExecutionColumnModel_XPath.COLUMN_ID)) {
078: return "";
079: }
080: }
081:
082: if (object instanceof PsmEntity) {
083: final PsmEntity psmEntity = (PsmEntity) object;
084:
085: if (column
086: .equals(ProcessExecutionColumnModel_Thread.COLUMN_ID)) {
087: return "";
088: }
089:
090: if (column
091: .equals(ProcessExecutionColumnModel_Line.COLUMN_ID)) {
092: if (psm2Line.get(psmEntity) == null) {
093: final String url = ModelUtil.getUrl(psmEntity
094: .getModel().getProcessQName());
095:
096: if (url == null) {
097: return "";
098: }
099:
100: final BpelModel model = EditorUtil
101: .getBpelModel(url);
102:
103: if (model == null) {
104: return "";
105: }
106:
107: final int lineNumber = ModelUtil.getLineNumber(
108: model, psmEntity.getXpath());
109:
110: final String line;
111: final int slashIndex = url.lastIndexOf("/");
112: if (slashIndex == -1) {
113: line = url + ":" + lineNumber;
114: } else {
115: line = url.substring(slashIndex + 1) + ":"
116: + lineNumber;
117: }
118:
119: psm2Line.put(psmEntity, line);
120:
121: return line;
122: }
123:
124: return psm2Line.get(psmEntity);
125: }
126:
127: if (column
128: .equals(ProcessExecutionColumnModel_XPath.COLUMN_ID)) {
129: return psmEntity.getXpath();
130: }
131: }
132:
133: if (object instanceof PemEntity) {
134: final PemEntity pemEntity = (PemEntity) object;
135:
136: if (column
137: .equals(ProcessExecutionColumnModel_Thread.COLUMN_ID)) {
138: final String branchId = ((PemEntity) object)
139: .getBranchId();
140:
141: final String tagName = ((PemEntity) object)
142: .getPsmEntity().getTag();
143:
144: if (tagName.equals("onEvent")
145: || tagName.equals("eventHandlers")) {
146: return "";
147: }
148:
149: return branchId == null ? "" : branchId;
150: }
151:
152: if (column
153: .equals(ProcessExecutionColumnModel_Line.COLUMN_ID)) {
154: return getValueAt(pemEntity.getPsmEntity(), column);
155: }
156:
157: if (column
158: .equals(ProcessExecutionColumnModel_XPath.COLUMN_ID)) {
159: return getValueAt(pemEntity.getPsmEntity(), column);
160: }
161: }
162:
163: throw new UnknownTypeException(object);
164: }
165:
166: /**{@inheritDoc}*/
167: public void setValueAt(final Object object, final String column,
168: final Object value) throws UnknownTypeException {
169:
170: // Does nothing
171: }
172:
173: /**{@inheritDoc}*/
174: public boolean isReadOnly(final Object object, final String column)
175: throws UnknownTypeException {
176:
177: return true;
178: }
179:
180: /**{@inheritDoc}*/
181: public void addModelListener(final ModelListener listener) {
182: // Does nothing
183: }
184:
185: /**{@inheritDoc}*/
186: public void removeModelListener(final ModelListener listener) {
187: // Does nothing
188: }
189: }
|