1 19 25 26 package org.netbeans.modules.web.jsf.navigation.graph; 27 28 import org.netbeans.modules.web.jsf.navigation.graph.NavigationGraphScene; 29 import org.netbeans.modules.web.jsf.navigation.vwmodel.Link; 30 import org.netbeans.modules.web.jsf.navigation.vwmodel.NavigableComponent; 31 import org.netbeans.modules.web.jsf.navigation.vwmodel.Page; 32 import org.netbeans.modules.web.jsf.navigation.vwmodel.Pin; 33 import org.netbeans.modules.web.jsf.navigation.vwmodel.NavigationModel; 34 import java.awt.Image ; 35 import java.util.Arrays ; 36 import java.util.List ; 37 import java.util.Set ; 38 import org.netbeans.api.visual.graph.GraphPinScene; 39 import org.netbeans.api.visual.layout.LayoutFactory; 40 import org.netbeans.api.visual.vmd.VMDNodeWidget; 41 import org.netbeans.api.visual.vmd.VMDPinWidget; 42 import org.netbeans.api.visual.widget.ConnectionWidget; 43 import org.netbeans.api.visual.widget.LabelWidget; 44 import org.netbeans.api.visual.widget.Widget; 45 import org.openide.DialogDisplayer; 46 import org.openide.NotifyDescriptor; 47 import org.openide.cookies.OpenCookie; 48 import org.openide.util.Utilities; 49 50 55 public class NavigationBridgeUtilities { 56 57 58 private static final Image IMAGE_LIST = null; 59 private static final Image IMAGE_CANVAS = Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/graph//resources/custom_displayable_32.png"); private static final Image IMAGE_COMMAND = Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/graph/resources/command_16.png"); private static final Image IMAGE_ITEM = Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/graph/resources/item_16.png"); private static final Image GLYPH_PRE_CODE = Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/graph/resources/preCodeGlyph.png"); private static final Image GLYPH_POST_CODE = Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/graph/resources/postCodeGlyph.png"); private static final Image GLYPH_CANCEL = Utilities.loadImage("org/netbeans/modules/web/jsf/navigation/graph/resources/cancelGlyph.png"); 66 private static int nodeID = 1; 67 private static int edgeID = 1; 68 69 70 private static NavigationBridgeUtilities instance; 71 73 private GraphPinScene graphScene; 75 76 private NavigationModel navModel = null; 77 78 public static final String PAGE = "page"; 79 public static final String LINK = "link"; 80 public static final int BUTTON = Page.BUTTON; 81 public static final int HYPERLINK = Page.HYPERLINK; 82 public static final int IMAGE_HYPERLINK = Page.IMAGE_HYPERLINK; 83 84 85 private NavigationBridgeUtilities() { 86 87 } 88 89 public static NavigationBridgeUtilities getInstance(){ 91 if (instance == null){ 92 instance = new NavigationBridgeUtilities(); 93 } 94 return instance; 95 } 96 97 public void setDocument(NavigationModel doc){ 98 navModel = doc; 99 } 100 101 public NavigationModel getNavigationModel(){ 102 return navModel; 103 } 104 105 113 public GraphPinScene getGraphScene() { 115 return this.graphScene; 116 } 117 118 private void loadPageComponents(Page page){ 119 List <NavigableComponent> navComponents = null; 120 navComponents = page.getBeans(); 121 for( NavigableComponent navComponent : navComponents ){ 122 createPin(graphScene, page, navComponent); 123 } 124 } 125 126 public void setGraphScene(GraphPinScene graphScene) { 128 this.graphScene = graphScene; 129 130 131 List <Page> pages = navModel.getPages(); 132 for (Page page: pages){ 133 createNode(graphScene, IMAGE_LIST, page, null, null); 134 navModel.updateBeans(page); 135 loadPageComponents(page); 136 } 137 138 List <Link> links = navModel.getLinks(); 139 for( Link link : links ){ 140 Page fromPage = link.getFromPage(); 141 Page toPage = link.getToPage(); 142 143 createEdge(graphScene, link); 144 } 146 147 156 157 158 164 if( graphScene instanceof NavigationGraphScene ) 165 { 166 ((NavigationGraphScene)graphScene).layoutScene(); 167 } 168 169 } 175 176 177 public void createWebPage() { 178 Page page = navModel.createWebPage(); 179 graphScene.addNode(page); 181 graphScene.validate(); 182 } 183 184 197 200 public void openPage(Widget node) { 201 Page page = (Page) graphScene.findObject(node); 202 OpenCookie ec = (OpenCookie)page.getDataObject().getCookie(OpenCookie.class); 203 if (ec != null) { 204 ec.open(); 205 } 206 return; 207 } 208 209 public void removeNode(Page page){ 210 navModel.removePage(page); 211 graphScene.removeNodeWithEdges(page); 214 graphScene.validate(); 215 226 } 227 228 public void removePin(Pin pin) { 229 navModel.removeNavigableComponent(pin.getNavComp()); 230 graphScene.removePin(pin); 232 graphScene.validate(); 233 } 234 235 236 237 238 241 public Link createLink(Page source, Page target, NavigableComponent navComp) { 242 243 Link link = navModel.addLink(source, target, navComp); 244 createEdge(graphScene, link); 246 247 248 return link; 249 250 } 251 252 256 263 266 public void removeLink(Link link) { 267 navModel.removeLink(link); 268 graphScene.removeEdge(link); 269 graphScene.validate(); 271 } 272 273 274 public boolean confirm(String message, String title){ 275 NotifyDescriptor desc = new NotifyDescriptor.Confirmation(message, title, NotifyDescriptor.YES_NO_OPTION); 276 return NotifyDescriptor.YES_OPTION.equals(DialogDisplayer.getDefault().notify(desc)); 277 } 278 279 public void addPageBean(Page page, int type) { 280 NavigableComponent navComp = null; 281 if ( page != null ) { 282 navComp = navModel.addPageBean(page, type); 283 if (navComp != null) { 284 this.createPin(graphScene, page, navComp); 285 } 286 } 287 graphScene.validate(); 288 } 289 290 public void openPage(Page page) { 291 page.getModel().openDefaultHandler(); 292 } 293 294 307 308 309 private VMDNodeWidget createNode(GraphPinScene graphScene, Image image, Page page, String type, List <Image > glyphs) { 310 VMDNodeWidget widget = (VMDNodeWidget) graphScene.addNode(page); 312 widget.setNodeProperties(image, page.getName(), type, glyphs); 315 graphScene.addPin(page, new Pin(page)); 317 return widget; 318 } 319 320 private VMDPinWidget createPin(GraphPinScene graphScene, Page page, NavigableComponent navComp) { 321 Pin pin = new Pin(page, navComp); 322 VMDPinWidget widget = (VMDPinWidget) graphScene.addPin(page, pin); 323 if( navComp != null ){ 325 widget.setProperties(navComp.getName(), Arrays.asList(navComp.getBufferedIcon())); 326 } 327 return widget; 328 } 329 330 private void createEdge(GraphPinScene graphScene, Link link) { 331 Page fromPage = link.getFromPage(); 332 Page toPage = link.getToPage(); 333 NavigableComponent navComp = link.getFromNavigableComponent(); 334 Set <Pin> pins = (Set ) graphScene.getPins(); 335 Pin sourcePin = null; 336 for ( Pin pin : pins ){ 337 if ( pin.equals(new Pin( fromPage, navComp))) { 338 sourcePin = pin; 339 break; 340 } 341 } 342 343 Pin targetPin = null; 344 for (Pin pin : pins ){ 345 if (pin.equals(new Pin(toPage))) { 346 targetPin = pin; 347 break; 348 } 349 } 350 351 ConnectionWidget widget = (ConnectionWidget)graphScene.addEdge(link); 352 String navCase = link.getFromOutcome(); 354 355 LabelWidget label = new LabelWidget(graphScene, navCase); 356 label.setOpaque(true); 357 widget.addChild(label); 358 widget.setConstraint(label, LayoutFactory.ConnectionWidgetLayoutAlignment.TOP_RIGHT, 10); 359 360 graphScene.setEdgeSource(link, targetPin); 361 graphScene.setEdgeTarget(link, targetPin); 362 363 366 367 } 368 369 370 371 372 } 373 | Popular Tags |