01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * 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.bpel.debugger.ui.execution;
21:
22: import java.util.LinkedList;
23: import java.util.List;
24: import org.netbeans.modules.bpel.debugger.api.pem.PemEntity;
25: import org.netbeans.modules.bpel.debugger.api.psm.PsmEntity;
26: import org.netbeans.spi.viewmodel.TreeExpansionModel;
27: import org.netbeans.spi.viewmodel.UnknownTypeException;
28:
29: /**
30: * Model describing the tree expansion/collapse behavior of the tree column of
31: * the Process Execution View.
32: *
33: * @author Alexander Zgursky
34: * @author Kirill Sorokin
35: */
36: public class ProcessExecutionExpansionModel implements
37: TreeExpansionModel {
38:
39: private List<Object> expandedNodes = new LinkedList<Object>();
40: private List<Object> collapsedNodes = new LinkedList<Object>();
41:
42: /**{@inheritDoc}*/
43: public boolean isExpanded(final Object object)
44: throws UnknownTypeException {
45: synchronized (this ) {
46: if (expandedNodes.contains(object)) {
47: return true;
48: }
49:
50: if (collapsedNodes.contains(object)) {
51: return false;
52: }
53:
54: if (object instanceof PemEntity) {
55: final PemEntity pemEntity = (PemEntity) object;
56:
57: if (pemEntity.getState() == PemEntity.State.STARTED) {
58: return true;
59: }
60:
61: final PemEntity lastStarted = pemEntity.getModel()
62: .getLastStartedEntity();
63: if ((lastStarted != null)
64: && lastStarted.isInTree(pemEntity)) {
65: return true;
66: }
67:
68: return false;
69: }
70:
71: if (object instanceof PsmEntity) {
72: return false;
73: }
74: }
75:
76: throw new UnknownTypeException(object);
77: }
78:
79: /**{@inheritDoc}*/
80: public void nodeExpanded(Object object) {
81: synchronized (this ) {
82: expandedNodes.add(object);
83: collapsedNodes.remove(object);
84: }
85: }
86:
87: /**{@inheritDoc}*/
88: public void nodeCollapsed(Object object) {
89: synchronized (this) {
90: expandedNodes.remove(object);
91: collapsedNodes.add(object);
92: }
93: }
94: }
|