KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > refactoring > query > readers > ComplexTypeDerivationsReader


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
20 /*
21  * ComplexTypeDerivationsReader.java
22  *
23  * Created on October 26, 2005, 11:27 AM
24  *
25  * To change this template, choose Tools | Template Manager
26  * and open the template in the editor.
27  */

28
29 package org.netbeans.modules.xml.schema.refactoring.query.readers;
30
31 import java.awt.Color JavaDoc;
32 import java.awt.Image JavaDoc;
33 import java.beans.BeanInfo JavaDoc;
34 import java.text.MessageFormat JavaDoc;
35 import java.util.ArrayList JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.List JavaDoc;
39 import java.util.Map JavaDoc;
40 import java.util.Map.Entry;
41 import java.util.MissingResourceException JavaDoc;
42 import java.util.Set JavaDoc;
43 import java.util.concurrent.ExecutionException JavaDoc;
44 import org.netbeans.api.project.SourceGroup;
45 import org.netbeans.modules.xml.nbprefuse.AnalysisConstants;
46 import org.netbeans.modules.xml.refactoring.FindUsageResult;
47 import org.netbeans.modules.xml.refactoring.RefactoringManager;
48 import org.netbeans.modules.xml.refactoring.Usage;
49 import org.netbeans.modules.xml.refactoring.UsageGroup;
50 import org.netbeans.modules.xml.refactoring.UsageSet;
51 import org.netbeans.modules.xml.refactoring.spi.UIHelper;
52 import org.netbeans.modules.xml.refactoring.ui.util.AnalysisUtilities;
53 import org.netbeans.modules.xml.schema.model.ComplexContentRestriction;
54 import org.netbeans.modules.xml.schema.model.ComplexExtension;
55 import org.netbeans.modules.xml.schema.model.GlobalComplexType;
56 import org.netbeans.modules.xml.schema.refactoring.ui.DisplayInfoVisitor;
57 import org.netbeans.modules.xml.xam.Component;
58 import org.netbeans.modules.xml.xam.Model;
59 import org.netbeans.modules.xml.xam.Named;
60 import org.netbeans.modules.xml.xam.Referenceable;
61 import org.openide.ErrorManager;
62 import org.openide.awt.StatusDisplayer;
63 import org.openide.filesystems.FileObject;
64 import org.openide.filesystems.FileUtil;
65 import org.openide.util.NbBundle;
66 import prefuse.data.Edge;
67 import prefuse.data.Graph;
68 import prefuse.data.Node;
69
70
71 /**
72  *
73  * @author Jeri Lockhart
74  *
75  * Reader for Where Used query and Complex Type Derivations query
76  */

77 public class ComplexTypeDerivationsReader {
78     
79     
80     //Derivations view
81
private static final DisplayInfoVisitor div = new DisplayInfoVisitor();
82     
83     
84     public static final prefuse.data.Schema FIND_USAGES_NODES_SCHEMA =
85             new prefuse.data.Schema(); // prefuse graph schema
86
static {
87         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.LABEL,
88                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
89         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.ID,
90                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
91         FIND_USAGES_NODES_SCHEMA.addColumn(
92                 AnalysisConstants.COMPONENT_TYPE_NAME,
93                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
94         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.ELEMENT_TYPE,
95                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
96         // type of a GE, LE, GA, or LA
97

98         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.XML_FILENAME,
99                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
100         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.FILE_OBJECT,
101                 FileObject.class);
102         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.FILE_TYPE,
103                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
104         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.TOOLTIP,
105                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING); // name
106
FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.XAM_COMPONENT,
107                 Component.class);
108         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.OPENIDE_NODE,
109                 org.openide.nodes.Node.class);
110         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.JAVA_AWT_IMAGE,
111                 Image JavaDoc.class);
112         
113         // used to set node visible or not visible, depending on whether the
114
// file node is expanded or collapsed
115
// -1 = always visible, any other value matches a
116
// FILE_NODE_FILE_GROUP
117
// the file node itself has a FILE_GROUP of -1 because it is always
118
// visible
119
FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.FILE_GROUP,
120                 int.class, -1);
121         // a File Node has a positive value for this column, other nodes
122
// have a -1 value
123
FIND_USAGES_NODES_SCHEMA.addColumn(
124                 AnalysisConstants.FILE_NODE_FILE_GROUP, int.class, -1);
125         // assigned number of schema file group
126

127         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.IS_PRIMITIVE,
128                 boolean.class, false); // is builtin type
129
FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.IS_QUERY_NODE,
130                 boolean.class, false);
131         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.IS_USAGE_NODE,
132                 boolean.class, false);
133         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.IS_FILE_NODE,
134                 boolean.class, false);
135         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.IS_EXPANDED,
136                 boolean.class, false);
137         FIND_USAGES_NODES_SCHEMA.addColumn(AnalysisConstants.MOUSEOVER,
138                 boolean.class, false);
139     }
140     
141     
142     
143     public static final prefuse.data.Schema FIND_USAGES_EDGES_SCHEMA =
144             new prefuse.data.Schema(); // prefuse graph schema
145
static {
146         FIND_USAGES_EDGES_SCHEMA.addColumn(AnalysisConstants.LABEL,
147                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
148         FIND_USAGES_EDGES_SCHEMA.addColumn(AnalysisConstants.EDGE_TYPE,
149                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
150         // "file-edge-type" "generalization", "reference" "composition"
151

152         FIND_USAGES_EDGES_SCHEMA.addColumn(AnalysisConstants.TOOLTIP,
153                 String JavaDoc.class, AnalysisConstants.EMPTY_STRING);
154         // used to set edge visible or not visible, depending on whether the
155
// file node is expanded or collapsed
156
// -1 = always visible, any other value matches a
157
// FILE_NODE_FILE_GROUP
158
// the file node itself has a FILE_GROUP of -1 because it is
159
// always visible
160
FIND_USAGES_EDGES_SCHEMA.addColumn(AnalysisConstants.FILE_GROUP,
161                 int.class, -1);
162     }
163     
164     /**
165      * Creates a new instance of ComplexTypeDerivationsReader
166      */

167     public ComplexTypeDerivationsReader() {
168         
169     }
170     
171     
172     /**
173      * graph for CT Derivations view
174      *
175      */

176     
177     @SuppressWarnings JavaDoc("unchecked")
178     public Graph loadComplexTypeDerivationsGraph(
179             GlobalComplexType baseCT) {
180         // TODO implement interrupt when implementing project scope scanning
181
if (baseCT == null){
182             StatusDisplayer.getDefault().setStatusText(""); //NOI18N
183
ErrorManager.getDefault().log(
184                     "WhereUsedReader.loadComplexTypeDerivationsGraph()" +
185                     " found null query base CT"); //NOI18N
186
return null;
187         }
188         // not used yet
189
int fileGroupNumber = 0;
190         // tally restrictions and extensions for the status message
191
List JavaDoc<Integer JavaDoc> derivationsCount = new ArrayList JavaDoc<Integer JavaDoc>();
192         derivationsCount.add(Integer.valueOf(0)); // extensions
193
derivationsCount.add(Integer.valueOf(0)); // restrictions
194
Graph graph = new Graph(true); // isDirected
195
graph.getNodeTable().addColumns(FIND_USAGES_NODES_SCHEMA);
196         graph.getEdgeTable().addColumns(FIND_USAGES_EDGES_SCHEMA);
197         
198         List JavaDoc<Component> componentsInGraph = new ArrayList JavaDoc<Component>();
199         
200         org.openide.nodes.Node displayNode = null;
201         
202         Named ref = baseCT;
203         FindUsageResult result = RefactoringManager.getInstance().findUsages(baseCT,
204                 baseCT.getModel().getSchema());
205         UsageSet usageSet = null;
206         try {
207             usageSet = result.get();
208         } catch (InterruptedException JavaDoc ex) {
209             ErrorManager.getDefault().notify(ex);
210         } catch (ExecutionException JavaDoc ex) {
211             ErrorManager.getDefault().notify(ex);
212         }
213         
214         UIHelper queryUIHelper = getUIHelper(baseCT);
215         Node queryNode = createQueryNode(graph,
216                 baseCT,
217                 queryUIHelper,
218                 false,
219                 componentsInGraph,
220                 false,
221                 fileGroupNumber);
222         if (queryUIHelper != null){
223             displayNode = queryUIHelper.getDisplayNode(baseCT);
224         }
225         queryNode.set(AnalysisConstants.COMPONENT_TYPE_NAME,
226                 displayNode.getShortDescription()); // comp type
227
queryNode.set(AnalysisConstants.XAM_COMPONENT,
228                 baseCT);
229         queryNode.setString(AnalysisConstants.LABEL, displayNode.getName());
230         queryNode.setString(AnalysisConstants.ELEMENT_TYPE,
231                 displayNode.getDisplayName()); // element type
232

233         // Map of SourceGroups and their packages
234
Map JavaDoc<SourceGroup, Map JavaDoc<FileObject,Set JavaDoc<UsageGroup>>> sortedUses =
235                 usageSet.getSortedUsages();
236         Set JavaDoc<Entry<SourceGroup,Map JavaDoc<FileObject,Set JavaDoc<UsageGroup>>>> sgUses =
237                 sortedUses.entrySet();
238         int usagesCount = 0;
239         for (Entry<SourceGroup, Map JavaDoc<FileObject, Set JavaDoc<UsageGroup>>> sgUse:sgUses){
240             Set JavaDoc<Entry<FileObject,Set JavaDoc<UsageGroup>>> pkgUses = sgUse.getValue().entrySet();
241             for (Entry<FileObject, Set JavaDoc<UsageGroup>> pkgUse:pkgUses){
242                 Set JavaDoc<UsageGroup> usages = pkgUse.getValue();
243                 for (UsageGroup usage:usages){
244                     int count = usage.getItems().size();
245                     if (count < 1){
246                         continue;
247                     }
248                     usagesCount += count;
249                     fileGroupNumber++;
250                     addUsagesToGraph(true, // derivations of CTs only
251
usage,
252                             graph,
253                             false, // is primitive
254
componentsInGraph,
255                             baseCT.getModel(),
256                             baseCT,
257                             queryNode,
258                             fileGroupNumber,
259                             derivationsCount);
260                     
261                 }
262             }
263         }
264         
265         
266         writeDerivationsFoundStatusMessage(derivationsCount.get(0).intValue(),
267                 derivationsCount.get(1).intValue(), baseCT);
268         return graph;
269     }
270     
271     private void writeDerivationsFoundStatusMessage(final int extensionCount,
272             final int restrictionCount, GlobalComplexType baseCT)
273             throws MissingResourceException JavaDoc {
274         if (baseCT == null){
275             ErrorManager.getDefault().log(
276                     "WhereUsedReader.loadComplexTypeDerivationsGraph()" +
277                     " found null query base CT"); //NOI18N
278
}
279         
280         String JavaDoc extensionMsg = null;
281         if (extensionCount == 1){
282             extensionMsg = NbBundle.getMessage(ComplexTypeDerivationsReader.class,
283                     "LBL_Found_1_Extension");
284         } else {
285             extensionMsg = MessageFormat.format(NbBundle.getMessage(
286                     ComplexTypeDerivationsReader.class,
287                     "LBL_Found_Extensions"),
288                     new Object JavaDoc[] {
289                 extensionCount
290             }
291             ) ;
292         }
293         
294         String JavaDoc restrictionMsg = null;
295         if (restrictionCount == 1){
296             restrictionMsg = MessageFormat.format(NbBundle.getMessage(
297                     ComplexTypeDerivationsReader.class,
298                     "LBL_1_Restriction_On_Complex_Type"),
299                     new Object JavaDoc[] {
300                 baseCT.getName()
301             }
302             ) ;
303         } else {
304             restrictionMsg = MessageFormat.format(NbBundle.getMessage(
305                     ComplexTypeDerivationsReader.class,
306                     "LBL_Restrictions_On_Complex_Type"),
307                     new Object JavaDoc[] {
308                 restrictionCount,
309                 baseCT.getName()
310             }
311             ) ;
312         }
313         if (!(extensionMsg == null || restrictionMsg == null)){
314             StatusDisplayer.getDefault().setStatusText(
315                     extensionMsg + restrictionMsg);
316             
317         }
318     }
319     
320     
321     
322     
323     private UIHelper getUIHelper(Referenceable ref) {
324         return RefactoringManager.getInstance().getTargetComponentUIHelper(ref);
325     }
326
327     /**
328      *
329      * Get usages in one schema file
330      * For CT Derivations query and Primitive Usages query
331      * @param usage collection of Items found in one model
332      * @param graph the prefuse Graph
333      * @param schema the schema being scanned, not necessarily the MV schema file
334      * @param ref the query component
335      * @param isPrimitive is the query component a primitive type
336      * @param componentsInGraph the list of SchemaComponents that are already in the graph
337      * @param model the Model of this Multiview's schema file
338      *
339      */

340     private void addUsagesToGraph(boolean ctDerivationsOnly,
341             UsageGroup usage,
342             Graph graph,
343             boolean isPrimitive,
344             List JavaDoc<Component> componentsInGraph,
345             Model model,
346             Component queryComponent,
347             Node queryNode,
348             int fileGroupNumber,
349             List JavaDoc<Integer JavaDoc> derivationsCount) {
350         
351 // Map<Component, List<Component>> um =
352
Collection JavaDoc<Usage> items = usage.getItems();
353         UIHelper uiHelper = usage.getEngine().getUIHelper();
354         
355         // *****************************
356
// *** FILE NODE
357
// *****************************
358

359         // create a special edge from the file node to the query node
360
// that will be visible when the file node is collapsed
361
// This edge uses the default prefuse renderer, e.g.,
362
// a small solid arrow head
363
// When the file node is expanded, this edge will be
364
// hidden. See FindUsagesFocusControl (double click)
365
// Edge fileEdge = graph.addEdge(fileNode,queryNode);
366
// fileEdge.setString(AnalysisConstants.EDGE_TYPE,
367
// AnalysisConstants.FILE_EDGE_TYPE);
368
// fileEdge.setInt(AnalysisConstants.FILE_GROUP,
369
// fileGroupNumber);
370
Node fileNode = null;
371         for (Usage item:items){
372             if (ctDerivationsOnly){
373                 Component usageComponent = item.getComponent();
374                 if (usageComponent instanceof ComplexContentRestriction){
375                     derivationsCount.set(1,derivationsCount.get(1)+1);
376                 } else if (usageComponent instanceof ComplexExtension){
377                     derivationsCount.set(0,derivationsCount.get(0)+1);
378                 } else{
379                     continue; // continue to next Item
380
}
381             }
382         // create file node and attach it to the query node
383
if (fileNode == null){
384                 fileNode = createFileNode(graph,
385                         queryComponent,
386                         (FileObject)usage.getModel().getModelSource().getLookup().lookup(FileObject.class),
387                         queryNode,
388                         fileGroupNumber);
389             }
390             List JavaDoc<Component> aPath = uiHelper.getRelevantPathFromRoot(item);
391             Node parent = null;
392             for (int i = 0; i < aPath.size();i++){
393                 Component sc = aPath.get(i);
394                 Node pn = null;
395                 AnalysisUtilities.ToolTipLine topLine = null;
396                 
397                 if (componentsInGraph.contains(sc)){
398                     // there's already a Node for this Component,
399
// find it in Graph
400
pn = findDup(graph, sc);
401                     assert pn != null:"Cannot find Node for Component "
402                             +
403                             sc; //NOI18N
404
}
405                 
406                 if (pn == null){
407                     pn = createNode(graph,
408                             sc,
409                             uiHelper,
410                             false,
411                             componentsInGraph,
412                             queryComponent,
413                             fileGroupNumber);
414                 }
415                 
416                 if (i == 0){
417                     // connect top node to file node
418
AnalysisUtilities.ToolTipLine typeLine =
419                             new AnalysisUtilities.ToolTipLine(pn.getString(AnalysisConstants.COMPONENT_TYPE_NAME),
420                             100,
421                             Color.BLACK.getRGB(),
422                             AnalysisUtilities.ToolTipLine.
423                             HorizontalAlignment.CENTER);
424                     String JavaDoc toolTip = AnalysisUtilities.createHTMLToolTip(
425                             new AnalysisUtilities.ToolTipLine[] {topLine, typeLine});
426                     pn.setString(AnalysisConstants.TOOLTIP, toolTip);
427                     
428                     // connect the node to the File Node with compositon edge
429
Edge fileCompositionEdge = graph.addEdge(pn,fileNode);
430                     fileCompositionEdge.setString(AnalysisConstants.EDGE_TYPE,
431                             AnalysisConstants.COMPOSITION);
432                     // it's part of the group of nodes and edges that are
433
// visible or hidden, depending on whether the file node
434
// is expanded or collapsed
435
fileCompositionEdge.setInt(AnalysisConstants.FILE_GROUP,
436                             fileGroupNumber);
437                     
438                     // set the new parent node
439
parent = pn;
440                 } else {
441                     
442                     AnalysisUtilities.ToolTipLine typeLine =
443                             new AnalysisUtilities.ToolTipLine(getCompTypeDisplayName(pn),
444                             100,
445                             Color.BLACK.getRGB(),
446                             AnalysisUtilities.ToolTipLine.
447                             HorizontalAlignment.CENTER);
448                     String JavaDoc toolTip = AnalysisUtilities.createHTMLToolTip(
449                             new AnalysisUtilities.ToolTipLine[] {topLine, typeLine});
450                     pn.setString(AnalysisConstants.TOOLTIP, toolTip);
451                     
452                     
453                     // connect it to its parent (parent should not be null)
454
if (parent != null){
455                         addCompositionEdge(graph,
456                                 pn,
457                                 parent,
458                                 fileGroupNumber);
459                     }
460                     parent = pn;
461                 }
462                 
463                 
464                 // Usage node is last
465
if (i == aPath.size()-1){
466                     // this is the usage node
467
pn.setBoolean(
468                             AnalysisConstants.IS_USAGE_NODE, true);
469                     
470                     topLine = new AnalysisUtilities.ToolTipLine((
471                             MessageFormat.format(NbBundle.getMessage(
472                             ComplexTypeDerivationsReader.class, "LBL_Uses_Component"),
473                             new Object JavaDoc[] {queryNode.getString(
474                                     AnalysisConstants.LABEL) })),
475                             100,
476                             Color.BLACK.getRGB(),
477                             AnalysisUtilities.ToolTipLine.
478                             HorizontalAlignment.CENTER);
479                     // Connect this usage node to the Query Node
480
// with the appropriate edge (composition or reference)
481
addApppropriateEdge(graph,
482                             pn,
483                             queryNode,
484                             fileGroupNumber,
485                             item.getType());
486                     
487                 }// END if (i == aPath.size()-1)
488

489             }
490         }
491     }// end addUsagesToGraph()
492

493     
494     
495     private static String JavaDoc getCompTypeDisplayName(final Node pn) throws MissingResourceException JavaDoc {
496         String JavaDoc compType = null;
497         if (pn.canGetBoolean(AnalysisConstants.IS_PRIMITIVE) &&
498                 pn.getBoolean(AnalysisConstants.IS_PRIMITIVE)){
499             compType = NbBundle.getMessage(ComplexTypeDerivationsReader.class,
500                     "LBL_Primitive_Type");
501         } else {
502             compType = pn.getString(AnalysisConstants.COMPONENT_TYPE_NAME);
503         }
504         return compType;
505     }
506     
507     private void addCompositionEdge(Graph graph, Node part, Node whole,
508             int fileGroupNumber){
509         Edge edge = graph.addEdge(part, whole);
510         //edge.setBoolean(AnalysisConstants.SHOW, isVisible);
511
edge.setString(AnalysisConstants.EDGE_TYPE,
512                 AnalysisConstants.COMPOSITION);
513         edge.setInt(AnalysisConstants.FILE_GROUP, Integer.valueOf(fileGroupNumber));
514         
515     }
516     
517     /**
518      * Adds a Reference edge or Generalization edge from
519      * "from" node to the queryNode
520      *
521      *
522      */

523     private void addApppropriateEdge(Graph graph, Node from, Node queryNode,
524             int fileGroupNumber, Usage.Type edgeType){
525         Edge edge = graph.addEdge(from, queryNode);
526 // edge.setBoolean(AnalysisConstants.SHOW, isVisible);
527

528         edge.setInt(AnalysisConstants.FILE_GROUP, Integer.valueOf(fileGroupNumber));
529         if ( edgeType == Usage.Type.GENERALIZATION){
530             edge.setString(AnalysisConstants.EDGE_TYPE,
531                     AnalysisConstants.GENERALIZATION);
532         } else if ( edgeType == Usage.Type.REFERENCE){
533             edge.setString(AnalysisConstants.EDGE_TYPE,
534                     AnalysisConstants.REFERENCE);
535             from.setString(AnalysisConstants.LABEL,
536                     MessageFormat.format(NbBundle.getMessage(
537                     ComplexTypeDerivationsReader.class,
538                     "LBL_References_Ref"),
539                     new Object JavaDoc[]
540             {queryNode.getString(AnalysisConstants.LABEL)}));
541         }
542     }
543     
544     private Node findDup(Graph graph, Component sc){
545         Iterator JavaDoc it = graph.nodes();
546         while (it.hasNext()){
547             Node n= Node.class.cast(it.next());
548             Object JavaDoc nodeSC = n.get(AnalysisConstants.XAM_COMPONENT);
549             if ((n.canGetBoolean(AnalysisConstants.IS_FILE_NODE) &&
550                     n.getBoolean(AnalysisConstants.IS_FILE_NODE) == false)
551                     && nodeSC != null){
552                 if (nodeSC == sc){
553                     return n;
554                 }
555             }
556         }
557         return null;
558     }
559     
560     public static Node createQueryNode(Graph graph,
561             Component query,
562             UIHelper uiHelper,
563             boolean isPrimitive,
564             List JavaDoc<Component> componentsInGraph,
565             boolean showOnlyDerivations,
566             int fileGroupNumber
567             ) {
568         // TODO remove this temporary hack when UIHelper for query Component is available
569
Node queryNode = null;
570         if (uiHelper == null){
571             String JavaDoc name = ""; //NOI18N
572
if (query instanceof Named){
573                 name = ((Named)Named.class.cast(query)).getName();
574             }
575             queryNode = graph.addNode();
576             componentsInGraph.add(query);
577             queryNode.setBoolean(AnalysisConstants.IS_PRIMITIVE, isPrimitive);
578             queryNode.setString(AnalysisConstants.LABEL, name);
579             queryNode.setString(AnalysisConstants.COMPONENT_TYPE_NAME, "" ); //NOI18N
580
queryNode.set(AnalysisConstants.XAM_COMPONENT, query );
581             queryNode.setInt(AnalysisConstants.FILE_GROUP, fileGroupNumber);
582             
583         } else {
584             queryNode = createNode(graph, query, uiHelper, isPrimitive, componentsInGraph, query, fileGroupNumber);
585         }
586         
587         queryNode.setBoolean(AnalysisConstants.IS_QUERY_NODE, true);
588         // unset the FILE_GROUP because this node is always visible
589
queryNode.setInt(AnalysisConstants.FILE_GROUP,-1);
590         // reset IS_PRIMITIVE in case it is
591
queryNode.setBoolean(AnalysisConstants.IS_PRIMITIVE, isPrimitive);
592         
593         AnalysisUtilities.ToolTipLine topLine = new AnalysisUtilities.ToolTipLine((
594                 showOnlyDerivations?
595                     NbBundle.getMessage(ComplexTypeDerivationsReader.class,
596                 "LBL_Base_Complex_Type"):
597                     NbBundle.getMessage(ComplexTypeDerivationsReader.class,
598                 "LBL_Query_Component")),
599                 100,
600                 Color.BLACK.getRGB(),
601                 AnalysisUtilities.ToolTipLine.HorizontalAlignment.CENTER);
602         String JavaDoc compType = getCompTypeDisplayName(queryNode);
603         AnalysisUtilities.ToolTipLine typeLine = new AnalysisUtilities.ToolTipLine(
604                 compType,
605                 100,
606                 Color.BLACK.getRGB(),
607                 AnalysisUtilities.ToolTipLine.HorizontalAlignment.CENTER);
608         String JavaDoc toolTip = AnalysisUtilities.createHTMLToolTip(new AnalysisUtilities.ToolTipLine[] {
609             topLine, typeLine});
610         
611         queryNode.setString(AnalysisConstants.TOOLTIP, toolTip);
612         return queryNode;
613     }
614     
615     
616     private Node createFileNode(Graph graph, Component queryComp,
617             FileObject fobj, Node queryNode, int fileGroupNumber){
618         if (queryComp == null || fobj == null){
619             return null;
620         }
621         String JavaDoc fileType = AnalysisUtilities.getXmlFileType(fobj);
622         Node n = graph.addNode();
623         n.setString(AnalysisConstants.FILE_TYPE,fileType);
624         n.setInt(AnalysisConstants.FILE_NODE_FILE_GROUP, fileGroupNumber);
625         n.setBoolean(AnalysisConstants.IS_EXPANDED, false);
626         n.setBoolean(AnalysisConstants.IS_FILE_NODE, true);
627         n.set(AnalysisConstants.JAVA_AWT_IMAGE, AnalysisUtilities.getImage(fobj));
628         n.setString(AnalysisConstants.LABEL, fobj.getNameExt());
629         n.setString(AnalysisConstants.XML_FILENAME, fobj.getNameExt());
630         n.set(AnalysisConstants.FILE_OBJECT, fobj);
631
632         // "Schema file containing usages of XYZ"
633
AnalysisUtilities.ToolTipLine topLine = new AnalysisUtilities.ToolTipLine(
634                 MessageFormat.format(
635                 NbBundle.getMessage(ComplexTypeDerivationsReader.class,
636                 "LBL_Xml_File_With_Usages"),new Object JavaDoc[]{
637             AnalysisUtilities.getXmlFileTypeDisplayName(fileType),
638             queryNode.getString(AnalysisConstants.LABEL)}),
639                 100,
640                 Color.BLACK.getRGB(),
641                 AnalysisUtilities.ToolTipLine.HorizontalAlignment.CENTER);
642         AnalysisUtilities.ToolTipLine typeLine =
643                 new AnalysisUtilities.ToolTipLine(
644                 FileUtil.getFileDisplayName(fobj),
645                 100,
646                 Color.BLACK.getRGB(),
647                 AnalysisUtilities.ToolTipLine.HorizontalAlignment.CENTER);
648         String JavaDoc toolTip = AnalysisUtilities.createHTMLToolTip(
649                 new AnalysisUtilities.ToolTipLine[] {topLine, typeLine});
650
651         n.setString(AnalysisConstants.TOOLTIP,
652                 toolTip);
653         return n;
654     }
655     /**
656      *
657      *
658      */

659     public static Node createNode(Graph graph,
660             Component comp,
661             UIHelper uiHelper,
662             boolean isPrimitive,
663             List JavaDoc<Component> componentsInGraph,
664             Component queryComponent,
665             int fileGroupNumber
666             ){
667         Node n = graph.addNode();
668         if (componentsInGraph != null){
669             componentsInGraph.add(comp);
670         }
671 // DisplayInfo dInfo = div.getDisplayInfo(comp);
672
org.openide.nodes.Node displayNode = uiHelper.getDisplayNode(comp);
673         
674         // if the queryComponent node is a primitive,
675
// check if the usage node is also a primitive, i.e.,
676
// from the same model (the W3c Schema model)
677
if (isPrimitive){
678             if (comp.getModel() ==
679                     queryComponent.getModel()) {
680                 n.setBoolean(AnalysisConstants.IS_PRIMITIVE, true);
681             }
682         }
683         n.setBoolean(AnalysisConstants.IS_PRIMITIVE, false);
684         n.setString(AnalysisConstants.LABEL, displayNode.getName());
685         n.setString(AnalysisConstants.COMPONENT_TYPE_NAME, displayNode.getShortDescription() );
686         n.set(AnalysisConstants.XAM_COMPONENT, comp );
687         n.set(AnalysisConstants.OPENIDE_NODE, displayNode );
688         n.setInt(AnalysisConstants.FILE_GROUP, fileGroupNumber);
689         n.set(AnalysisConstants.JAVA_AWT_IMAGE, displayNode.getIcon(BeanInfo.ICON_COLOR_16x16));
690         
691         return n;
692     }
693     
694     
695 }
696
Popular Tags