KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > navigation > vwmodel > Link


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * 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 package org.netbeans.modules.web.jsf.navigation.vwmodel;
20
21 import org.netbeans.modules.web.jsf.navigation.vwmodel.NavigableComponent;
22 import org.netbeans.modules.web.jsf.navigation.vwmodel.Page;
23 import org.netbeans.modules.visualweb.insync.faces.config.NavigationCase;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 public class Link { // graph edge
27
public Link(String JavaDoc outcome, Page from, Page to, NavigationCase navcase) {
28         this.setOutcome(outcome);
29         this.setFrom(from);
30         this.setTo(to);
31         this.setNavcase(navcase);
32     }
33     
34     private String JavaDoc outcome;
35     private Page from;
36     private Page to;
37     private NavigationCase navcase;
38     
39     // Layout information - for performance reasons provided here
40
// for direct manipulation by the layout algorithms so they don't
41
// have to duplicate data structures to annotate elements with
42
// layout info and temporary tags etc.
43

44 // protected int[] arcX;
45
// protected int[] arcY;
46
//
47
// // fx,fy,portnum are referring to the "from" page.
48
// protected int fx;
49
// protected int fy;
50
//
51
// // For the to page, links go to the closest edge.
52
// protected int tx;
53
// protected int ty;
54
//
55
// // dimensions of bounding box for the label
56
// protected int lx;
57
// protected int ly;
58
// protected int lw;
59
// protected int lh;
60
// protected int lby; // text baseline
61
// protected double la = 0.; // text angle in radians
62

63     int portnum; // which port number in the from page this has been assigned
64

65     public String JavaDoc toString() {
66         return "Link[" + getFrom().getName() +","+getTo().getName()+","+getOutcome()+","+portnum + "]";
67     }
68     
69     // Accessor/mutator methods. These really just delegate to the navcase, but gives us
70
// a chance to do helpful stuff, like recognize a link rename and try to update the
71
// action attributes too. That's much harder from a generic model change.
72

73     public String JavaDoc getFromOutcome() {
74         return getNavcase().getFromOutcome();
75     }
76     
77     private NavigableComponent fromComponent = null;
78     
79     public NavigableComponent getFromNavigableComponent() {
80         fromComponent = null;
81         List JavaDoc<NavigableComponent> navComps = getFrom().getBeans();
82         for(NavigableComponent pb : navComps ) {
83             if(pb.getAction() != null && pb.getAction().equals(getOutcome())) {
84                 getFrom().setCurrentBean(pb);
85                 fromComponent = pb;
86             }
87         }
88         return fromComponent;
89     }
90     
91     public void setFromOutcome(String JavaDoc s) {
92         // NOTE - not delegating to navcase!
93

94         //Set the current bean corresponding to this link
95
if(getFrom().getBeans().size() == 0)
96             getFrom().getDoc().updateBeans(getFrom());
97         
98         List JavaDoc<NavigableComponent> navComps = getFrom().getBeans();
99         for(NavigableComponent pb : navComps ) {
100             if(pb.getAction() != null && pb.getAction().equals(getOutcome())) {
101                 getFrom().setCurrentBean(pb);
102                 fromComponent = pb;
103                 break;
104             }
105         }
106         
107 // Iterator iter = getFrom().getBeans().iterator();
108
// while(iter.hasNext()){
109
// NavigableComponent pb = (NavigableComponent)iter.next();
110
// if(pb.getAction() != null && pb.getAction().equals(getOutcome())) {
111
// getFrom().setCurrentBean(pb);
112
// break;
113
// }
114
// }
115
getFrom().getDoc().setOutcome(this, s, true);
116     }
117     public String JavaDoc getFromView() {
118         return getNavcase().getRule().getFromView();
119     }
120     public void setFromView(String JavaDoc s) {
121         getNavcase().getRule().setFromView(s);
122     }
123     public String JavaDoc getToView() {
124         return getNavcase().getToView();
125     }
126     public void setToView(String JavaDoc s) {
127         getNavcase().setToView(s);
128     }
129     
130     
131     public Page getFromPage() {
132         return getFrom();
133     }
134     
135     public void setFromPage(Page fromPage) {
136         setFrom(fromPage);
137     }
138     
139     public Page getToPage() {
140         return getTo();
141     }
142     
143     public void setToPage(Page toPage) {
144         setTo(toPage);
145     }
146     
147     public String JavaDoc getOutcome() {
148         return outcome;
149     }
150     
151     public void setOutcome(String JavaDoc label) {
152         outcome = label;
153     }
154     
155     protected Page getFrom() {
156         return from;
157     }
158     
159     protected void setFrom(Page from) {
160         this.from = from;
161     }
162     
163     protected Page getTo() {
164         return to;
165     }
166     
167     protected void setTo(Page to) {
168         this.to = to;
169     }
170     
171     protected NavigationCase getNavcase() {
172         return navcase;
173     }
174     
175     protected void setNavcase(NavigationCase navcase) {
176         this.navcase = navcase;
177     }
178 }
179
Popular Tags