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: * Portions Copyrighted 2007 Sun Microsystems, Inc.
027: */
028: package org.netbeans.modules.web.jsf.navigation.graph;
029:
030: import java.util.Collection;
031: import java.util.HashSet;
032: import java.util.Set;
033: import org.netbeans.api.visual.model.ObjectSceneEvent;
034: import org.netbeans.api.visual.model.ObjectSceneListener;
035: import org.netbeans.api.visual.model.ObjectState;
036: import org.netbeans.modules.web.jsf.navigation.NavigationCaseEdge;
037: import org.netbeans.modules.web.jsf.navigation.Page;
038: import org.netbeans.modules.web.jsf.navigation.Pin;
039: import org.openide.nodes.Node;
040:
041: /**
042: *
043: * @author joelle
044: */
045: public class PFObjectSceneListener implements ObjectSceneListener {
046:
047: private static final UnsupportedOperationException uoe = new UnsupportedOperationException(
048: "Not supported yet.");
049:
050: public PFObjectSceneListener() {
051: }
052:
053: public void objectAdded(ObjectSceneEvent event, Object addedObject) {
054: throw uoe;
055: }
056:
057: public void objectRemoved(ObjectSceneEvent event,
058: Object removedObject) {
059: throw uoe;
060: }
061:
062: public void objectStateChanged(ObjectSceneEvent event,
063: Object changedObject, ObjectState prevState,
064: ObjectState newState) {
065: throw uoe;
066: }
067:
068: public void selectionChanged(ObjectSceneEvent event,
069: Set<Object> prevSelection, Set<Object> newSelection) {
070: PageFlowScene scene = (PageFlowScene) event.getObjectScene();
071: Set<NavigationCaseEdge> releventEdges = new HashSet<NavigationCaseEdge>();
072: Set<Node> selected = new HashSet<Node>();
073: for (Object obj : newSelection) {
074: if (obj instanceof PageFlowSceneElement) {
075: PageFlowSceneElement element = (PageFlowSceneElement) obj;
076: selected.add(element.getNode());
077: releventEdges.addAll(getRelevantEdges(element, scene));
078: }
079: }
080: scene.setHighlightedObjects(releventEdges);
081: if (selected.isEmpty()) {
082: scene.getPageFlowView().setDefaultActivatedNode();
083: } else {
084: scene.getPageFlowView().setActivatedNodes(
085: selected.toArray(new Node[selected.size()]));
086: }
087: }
088:
089: public void highlightingChanged(ObjectSceneEvent event,
090: Set<Object> prevHighlighting, Set<Object> newHighlighting) {
091: throw uoe;
092: }
093:
094: public void hoverChanged(ObjectSceneEvent event,
095: Object prevHoveredObject, Object newHoveredObject) {
096: throw uoe;
097: }
098:
099: public void focusChanged(ObjectSceneEvent event,
100: Object prevFocusedObject, Object newFocusedObject) {
101: throw uoe;
102: }
103:
104: private Set<NavigationCaseEdge> getRelevantEdges(
105: PageFlowSceneElement element, PageFlowScene scene) {
106:
107: Set<NavigationCaseEdge> edgeSet = new HashSet<NavigationCaseEdge>();
108: if (element instanceof Page) {
109: Page page = (Page) element;
110: Collection<Pin> pins = scene.getNodePins(page);
111: for (Pin pin : pins) {
112: Collection<NavigationCaseEdge> edges = scene
113: .findPinEdges(pin, true, false);
114: edgeSet.addAll(edges);
115: }
116: } else if (element instanceof Pin) {
117: Collection<NavigationCaseEdge> edges = scene.findPinEdges(
118: (Pin) element, true, false);
119: edgeSet.addAll(edges);
120: }
121: return edgeSet;
122: }
123: }
|