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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039: package org.netbeans.modules.web.jsf.navigation.graph;
040:
041: import java.awt.EventQueue;
042: import java.lang.ref.WeakReference;
043: import java.util.ArrayList;
044: import java.util.Collection;
045: import java.util.logging.Logger;
046: import org.netbeans.api.visual.vmd.VMDColorScheme;
047: import org.netbeans.api.visual.vmd.VMDNodeWidget;
048: import org.netbeans.api.visual.widget.LabelWidget;
049: import org.netbeans.modules.web.jsf.navigation.NavigationCaseEdge;
050: import org.netbeans.modules.web.jsf.navigation.Page;
051: import org.netbeans.modules.web.jsf.navigation.PageFlowView;
052: import org.netbeans.modules.web.jsf.navigation.Pin;
053:
054: /**
055: *
056: * @author joelle
057: */
058: public class PFENodeWidget extends VMDNodeWidget {
059:
060: // private BlockingQueue<Runnable> runnables = new LinkedBlockingQueue<Runnable>();
061: // private ThreadPoolExecutor executor;
062: private static final Logger LOG = Logger
063: .getLogger(PFENodeWidget.class.getName());
064:
065: public PFENodeWidget(PageFlowScene scene, VMDColorScheme scheme) {
066: super (scene, scheme);
067:
068: // executor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS, runnables);
069: }
070:
071: private boolean previouslyMaximized = false;
072:
073: @Override
074: public void stateChanged() {
075: super .stateChanged();
076:
077: if (!previouslyMaximized && !isMinimized()) {
078: addLoadingWidget();
079: runPinSetup();
080: previouslyMaximized = true;
081: }
082:
083: }
084:
085: private final LabelWidget loadingWidget = new LabelWidget(
086: getScene(), "Loading...");
087:
088: private final void addLoadingWidget() {
089: addChild(loadingWidget);
090: getScene().validate();
091: }
092:
093: private final void removeLoadingWidget() {
094: removeChild(loadingWidget);
095: getScene().validate();
096: }
097:
098: /* This method was put into place to gather all the pin data for a given page.
099: * Although it may seem non-sensical for a non-jsp page, a vwp-page may need
100: * more processing time to determine it's compoenents. To prevent further delay
101: * in the drawing of the Page Flow Editor, I have added an executor in which
102: * it will run and get the conent items in the background.
103: * For the background process to start startBackgroundPinAddingProcess() must be called.
104: * If you no longer need the page to complete loading, you can call the clear equivalent.
105: **/
106: private void runPinSetup() {
107:
108: LOG.entering(PageFlowView.class.getName(), "runPinSetup");
109:
110: PageFlowScene scene = (PageFlowScene) getScene();
111: Object objPage = scene.findObject(this );
112: if (objPage != null && objPage instanceof Page) {
113: final WeakReference<Page> pageRef = new WeakReference<Page>(
114: (Page) objPage);
115:
116: // runnables.add(new Runnable() {
117: EventQueue.invokeLater(new Runnable() {
118:
119: public void run() {
120: /* This is called in redrawPins and edges setupPinsInNode(pageNode);*/
121: /* Need to do updateNodeWidgetActions after setupPinInNode because this is when the model is set. */
122: LOG.finest(" PFE: Inside Thread: "
123: + java.util.Calendar.getInstance()
124: .getTime());
125: //Page page = pageRef.get();
126: if (pageRef.get() == null) {
127: LOG
128: .finest(" PFE: runPinSetup will not completed because the page is now null. It may have been removed to reset graph.");
129: return;
130: }
131: if (!pageRef.get().isDataNode()) {
132: EventQueue.invokeLater(new Runnable() {
133:
134: public void run() {
135: if (getScene() != null) {
136: removeLoadingWidget();
137: }
138: }
139: });
140: return;
141: }
142: final java.util.Collection<Pin> newPinNodes = pageRef
143: .get().getPinNodes();
144:
145: LOG.finest(" PFE: Completed Nodes Setup: "
146: + java.util.Calendar.getInstance()
147: .getTime());
148:
149: // try {
150: EventQueue.invokeLater(new java.lang.Runnable() {
151:
152: public void run() {
153: LOG.finest(" PFE: Starting Redraw: "
154: + java.util.Calendar.getInstance()
155: .getTime());
156:
157: removeLoadingWidget();
158: PageFlowScene scene = (PageFlowScene) getScene();
159: Collection<NavigationCaseEdge> redrawCaseNodes = new ArrayList<NavigationCaseEdge>();
160: Collection<Pin> pinNodes = new ArrayList<Pin>(
161: scene.getPins());
162:
163: for (Pin pin : pinNodes) {
164: if (pin.getPage() == pageRef.get()) {
165: assert pin
166: .getPage()
167: .getDisplayName()
168: .equals(
169: pageRef
170: .get()
171: .getDisplayName());
172: java.util.Collection<NavigationCaseEdge> caseNodes = scene
173: .findPinEdges(pin, true,
174: false);
175: redrawCaseNodes.addAll(caseNodes);
176: if (!pin.isDefault()) {
177: scene.removePin(pin);
178: }
179: }
180: }
181: if (newPinNodes.size() > 0) {
182: for (org.netbeans.modules.web.jsf.navigation.Pin pinNode : newPinNodes) {
183: scene
184: .addPin(pageRef.get(),
185: pinNode);
186: }
187: }
188: for (org.netbeans.modules.web.jsf.navigation.NavigationCaseEdge caseNode : redrawCaseNodes) {
189: scene.getPageFlowView()
190: .setEdgeSourcePin(caseNode,
191: pageRef.get());
192: }
193: scene
194: .updateNodeWidgetActions(pageRef
195: .get());
196: scene.validate();
197: LOG.finest(" PFE: Ending Redraw: "
198: + java.util.Calendar.getInstance()
199: .getTime());
200: }
201: });
202: // } catch (InterruptedException ex) {
203: // Exceptions.printStackTrace(ex);
204: // } catch (InvocationTargetException ex) {
205: // if (getScene() == null) {
206: // /* It is okay suppress this exception because it is expected if the scene is deleted (closed)
207: // * before the page has finished loading.
208: // */
209: // LOG.finer("Scene is has been closed before page has finished loading.:" + ex);
210: // } else {
211: // Exceptions.printStackTrace(ex);
212: // }
213: // }
214: }
215: });
216: }
217: LOG.exiting(PageFlowView.class.getName(), "runPinSetup");
218: }
219: // public final VMDPinWidget createPin(Page pageNode, Pin pinNode) {
220: // VMDPinWidget widget = null;
221: // PageFlowScene scene = (PageFlowScene)getScene();
222: // /* Make sure scene still has this page. */
223: // if (pageNode != null && scene.isNode(pageNode)) {
224: // widget = (VMDPinWidget) scene.addPin(pageNode, pinNode);
225: // }
226: //
227: // return widget;
228: // }
229: }
|