KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > view > treeeditor > WSDLElementNode


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 package org.netbeans.modules.xml.wsdl.ui.view.treeeditor;
21
22 import java.awt.Dialog JavaDoc;
23 import java.awt.datatransfer.Transferable JavaDoc;
24 import java.beans.PropertyChangeEvent JavaDoc;
25 import java.beans.PropertyChangeListener JavaDoc;
26 import java.io.IOException JavaDoc;
27 import java.lang.ref.Reference JavaDoc;
28 import java.lang.ref.WeakReference JavaDoc;
29 import java.util.Collections JavaDoc;
30 import java.util.Iterator JavaDoc;
31 import java.util.LinkedList JavaDoc;
32 import java.util.List JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.Set JavaDoc;
35 import java.util.Map.Entry;
36 import java.util.logging.Level JavaDoc;
37 import java.util.logging.Logger JavaDoc;
38 import javax.swing.Action JavaDoc;
39 import javax.xml.namespace.QName JavaDoc;
40 import org.netbeans.modules.refactoring.api.ui.RefactoringActionsFactory;
41 import org.netbeans.modules.xml.refactoring.ui.ReferenceableProvider;
42 import org.netbeans.modules.xml.wsdl.model.Definitions;
43 import org.netbeans.modules.xml.wsdl.model.WSDLComponent;
44 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
45 import org.netbeans.modules.xml.wsdl.ui.actions.ActionHelper;
46 import org.netbeans.modules.xml.wsdl.ui.commands.CommonAttributePropertyAdapter;
47 import org.netbeans.modules.xml.wsdl.ui.commands.OtherAttributePropertyAdapter;
48 import org.netbeans.modules.xml.wsdl.ui.commands.XMLAttributePropertyAdapter;
49 import org.netbeans.modules.xml.wsdl.ui.cookies.RemoveWSDLElementCookie;
50 import org.netbeans.modules.xml.wsdl.ui.cookies.SaveCookieDelegate;
51 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLAttributeCookie;
52 import org.netbeans.modules.xml.wsdl.ui.cookies.WSDLElementCookie;
53 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.UIUtilities;
54 import org.netbeans.modules.xml.wsdl.ui.netbeans.module.Utility;
55 import org.netbeans.modules.xml.wsdl.ui.view.DesignGotoType;
56 import org.netbeans.modules.xml.wsdl.ui.view.StructureGotoType;
57 import org.netbeans.modules.xml.wsdl.ui.view.property.BaseAttributeProperty;
58 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.DocumentationNewType;
59 import org.netbeans.modules.xml.wsdl.ui.view.treeeditor.newtype.NewTypesFactory;
60 import org.netbeans.modules.xml.xam.Component;
61 import org.netbeans.modules.xml.xam.ComponentEvent;
62 import org.netbeans.modules.xml.xam.ComponentListener;
63 import org.netbeans.modules.xml.xam.Model;
64 import org.netbeans.modules.xml.xam.Named;
65 import org.netbeans.modules.xml.xam.Referenceable;
66 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent;
67 import org.netbeans.modules.xml.xam.dom.Attribute;
68 import org.netbeans.modules.xml.xam.ui.ComponentPasteType;
69 import org.netbeans.modules.xml.xam.ui.XAMUtils;
70 import org.netbeans.modules.xml.xam.ui.actions.GoToAction;
71 import org.netbeans.modules.xml.xam.ui.actions.GotoType;
72 import org.netbeans.modules.xml.xam.ui.actions.SourceGotoType;
73 import org.netbeans.modules.xml.xam.ui.actions.SuperGotoType;
74 import org.netbeans.modules.xml.xam.ui.cookies.CountChildrenCookie;
75 import org.netbeans.modules.xml.xam.ui.cookies.GotoCookie;
76 import org.netbeans.modules.xml.xam.ui.customizer.Customizer;
77 import org.netbeans.modules.xml.xam.ui.customizer.CustomizerProvider;
78 import org.netbeans.modules.xml.xam.ui.highlight.Highlight;
79 import org.netbeans.modules.xml.xam.ui.highlight.HighlightManager;
80 import org.netbeans.modules.xml.xam.ui.highlight.Highlighted;
81 import org.openide.DialogDescriptor;
82 import org.openide.DialogDisplayer;
83 import org.openide.ErrorManager;
84 import org.openide.actions.CopyAction;
85 import org.openide.actions.CutAction;
86 import org.openide.actions.DeleteAction;
87 import org.openide.actions.NewAction;
88 import org.openide.actions.PasteAction;
89 import org.openide.actions.PropertiesAction;
90 import org.openide.actions.ReorderAction;
91 import org.openide.loaders.DataObject;
92 import org.openide.nodes.AbstractNode;
93 import org.openide.nodes.Children;
94 import org.openide.nodes.Node;
95 import org.openide.nodes.Sheet;
96 import org.openide.util.HelpCtx;
97 import org.openide.util.NbBundle;
98 import org.openide.util.WeakListeners;
99 import org.openide.util.actions.SystemAction;
100 import org.openide.util.datatransfer.NewType;
101 import org.openide.util.datatransfer.PasteType;
102 import org.openide.util.lookup.AbstractLookup;
103 import org.openide.util.lookup.InstanceContent;
104
105 /**
106  * Base class for all Nodes used in the WSDL editor.
107  *
108  * @author radval
109  */

110 public abstract class WSDLElementNode extends AbstractNode
111         implements ComponentListener, ReferenceableProvider, Highlighted,
112         CountChildrenCookie, PropertyChangeListener JavaDoc, GotoCookie {
113     
114     protected static final Logger JavaDoc mLogger = Logger.getLogger(WSDLElementNode.class.getName());
115     
116     private WSDLComponent mElement;
117     /** Customizer soft reference; */
118     private Reference JavaDoc<Customizer> customizerReference;
119     private NewTypesFactory mNewTypesFactory;
120     
121     public static final String JavaDoc WSDL_NAMESPACE = "http://schemas.xmlsoap.org/wsdl/";//NOI18N
122
private InstanceContent mLookupContents;
123     protected Sheet mSheet;
124     private PropertyChangeListener JavaDoc weakModelListener;
125     private ComponentListener weakComponentListener;
126     /** Used for the highlighting API. */
127     private Set JavaDoc<Component> referenceSet;
128     /** Ordered list of highlights applied to this node. */
129     private List JavaDoc<Highlight> highlights;
130     
131     /** cached so that during destroy all listeners can be cleaned up, nullified in destroy*/
132     private WSDLModel wsdlmodel;
133     
134     private static final SystemAction[] ACTIONS = new SystemAction[] {
135         SystemAction.get(CutAction.class),
136         SystemAction.get(CopyAction.class),
137         SystemAction.get(PasteAction.class),
138         null,
139         SystemAction.get(NewAction.class),
140         SystemAction.get(DeleteAction.class),
141         SystemAction.get(ReorderAction.class),
142         null,
143         SystemAction.get(GoToAction.class),
144         //SystemAction.get(FindUsagesAction.class),
145
(SystemAction)RefactoringActionsFactory.whereUsedAction(),
146         null,
147         (SystemAction)RefactoringActionsFactory.editorSubmenuAction(),
148         null,
149         SystemAction.get(PropertiesAction.class),
150     };
151
152     private static final GotoType[] GOTO_TYPES = new GotoType[] {
153         new SourceGotoType(),
154         new StructureGotoType(),
155         new DesignGotoType(),
156         new SuperGotoType(),
157     };
158     
159     public WSDLElementNode(Children children, WSDLComponent element, NewTypesFactory newTypesFactory) {
160         this(children, element);
161         this.mNewTypesFactory = newTypesFactory;
162     }
163
164     public WSDLElementNode(Children children, WSDLComponent element) {
165         this(children, element, new InstanceContent());
166     }
167
168     /**
169      * Constructor hack to allow creating our own Lookup.
170      *
171      * @param children Node children.
172      * @param element WSDL component.
173      * @param contents Lookup contents.
174      */

175     private WSDLElementNode(Children children, WSDLComponent element,
176             InstanceContent contents) {
177         super(children, new AbstractLookup(contents));
178         mElement = element;
179         mLookupContents = contents;
180
181         // Add various objects to the lookup.
182
// Keep this node and its cookie implementation at the top of the
183
// lookup, as they provide cookies needed elsewhere, and we want
184
// this node to provide them, not the currently selected node.
185
contents.add(this);
186         contents.add(new WSDLElementCookie(mElement));
187         // Include the data object in order for the Navigator to
188
// show the structure of the current document.
189
DataObject dobj = ActionHelper.getDataObject(element.getModel());
190         if (dobj != null) {
191             contents.add(dobj);
192         }
193         contents.add(new SaveCookieDelegate(dobj));
194         contents.add(new RemoveWSDLElementCookie(mElement));
195         contents.add(element);
196         
197         wsdlmodel = element.getModel();
198         
199         weakModelListener = WeakListeners.propertyChange(this, wsdlmodel);
200         wsdlmodel.addPropertyChangeListener(weakModelListener);
201         weakComponentListener = (ComponentListener) WeakListeners.create(
202                 ComponentListener.class, this, wsdlmodel);
203         wsdlmodel.addComponentListener(weakComponentListener);
204         addNodeListener(new WSDLNodeListener(this));
205         mSheet = new Sheet();
206         // Let the node try to update its display name.
207
updateDisplayName();
208         
209         referenceSet = Collections.singleton((Component) element);
210         highlights = new LinkedList JavaDoc<Highlight>();
211         HighlightManager.getDefault().addHighlighted(this);
212     }
213     
214     public NewTypesFactory getNewTypesFactory() {
215         if (mNewTypesFactory != null)
216             return mNewTypesFactory;
217         
218         
219         mNewTypesFactory = new NewTypesFactory() {
220         
221             public NewType[] getNewTypes(WSDLComponent component) {
222                 if (component.getDocumentation() == null) {
223                     return new NewType[] {new DocumentationNewType(getWSDLComponent())};
224                 }
225                 return new NewType[] {};
226             }
227         
228         };
229         return mNewTypesFactory;
230     }
231     
232     @Override JavaDoc
233     public Action JavaDoc[] getActions(boolean context) {
234         return ACTIONS;
235     }
236     
237     @Override JavaDoc
238     public void destroy() throws IOException JavaDoc {
239         //get the stored model.
240
if (wsdlmodel != null) {
241             //remove the xml element listener when node is destroyed
242
wsdlmodel.removePropertyChangeListener(weakModelListener);
243             wsdlmodel.removeComponentListener(weakComponentListener);
244             //remove reference for WSDLModel
245
wsdlmodel = null;
246         }
247         
248         WSDLModel model = getWSDLComponent() != null ? getWSDLComponent().getModel() : null;
249         if (model != null) {
250             //if we can get the model from wsdlcomponent, then delete the wsdlcomponent from model and appropriately select the node.
251
WSDLComponent parent = getWSDLComponent().getParent();
252             //try to select the parent.
253
WSDLComponent nextSelection = parent;
254             if (parent == null) {
255                 return;
256             }
257
258             if (parent.getChildren() != null) {
259                 int size = parent.getChildren().size();
260                 if (size > 0) {
261                     int currentPos = parent.getChildren().indexOf(getWSDLComponent());
262                     if (currentPos + 1 < size) {
263                         nextSelection = parent.getChildren().get(currentPos + 1);
264                     } else if (currentPos - 1 >= 0) {
265                         nextSelection = parent.getChildren().get(currentPos - 1);
266                     }
267                 }
268                 if (parent instanceof Definitions) {
269                     //need to find a way to get the folder nodes selected
270
//for now select the root node.
271
if (!getWSDLComponent().getClass().isAssignableFrom(nextSelection.getClass())) {
272                         nextSelection = parent;
273                     }
274                 }
275             }
276
277             try {
278                 model.startTransaction();
279                 model.removeChildComponent(getWSDLComponent());
280             } finally {
281                 model.endTransaction();
282             }
283             ActionHelper.selectNode(nextSelection);
284         }
285         super.destroy();
286     }
287
288     @Override JavaDoc
289     public boolean canCopy() {
290         return true;
291     }
292
293     @Override JavaDoc
294     public boolean canCut() {
295         return isEditable();
296     }
297
298     @Override JavaDoc
299     protected void createPasteTypes(Transferable JavaDoc transferable, List JavaDoc list) {
300         // Make sure this node is still valid.
301
if (mElement != null && mElement.getModel() != null && isEditable()) {
302             PasteType type = ComponentPasteType.getPasteType(
303                     mElement, transferable, null);
304             if (type != null) {
305                 list.add(type);
306             }
307         }
308     }
309
310     @Override JavaDoc
311     public PasteType getDropType(Transferable JavaDoc transferable, int action, int index) {
312         // Make sure this node is still valid.
313
if (mElement != null && mElement.getModel() != null && isEditable()) {
314             PasteType type = ComponentPasteType.getDropType(
315                     mElement, transferable, null, action, index);
316             if (type != null) {
317                 return type;
318             }
319         }
320         return null;
321     }
322
323     @Override JavaDoc
324     public boolean canDestroy() {
325         WSDLModel model = mElement.getModel();
326         if (model != null && isSameAsMyWSDLElement(model.getDefinitions()) && !isEditable()) {
327             return false;
328         }
329         return isEditable();
330     }
331     
332     public WSDLComponent getWSDLComponent() {
333         return this.mElement;
334     }
335     
336     @Override JavaDoc
337     public final NewType[] getNewTypes()
338     {
339         if (isEditable()) {
340             return getNewTypesFactory().getNewTypes(getWSDLComponent());
341         }
342         return new NewType[] {};
343     }
344
345     public GotoType[] getGotoTypes() {
346         return GOTO_TYPES;
347     }
348
349     /**
350      * Subclasses wishing to provide a customizer must override this
351      * method and supply a customizer provider, and override the
352      * hasCustomizer() method to return true.
353      *
354      * @return customizer provider.
355      */

356     protected CustomizerProvider getCustomizerProvider() {
357         return null;
358     }
359
360     @Override JavaDoc
361     public java.awt.Component JavaDoc getCustomizer() {
362         if (!hasCustomizer() || !isEditable()) {
363             return null;
364         }
365         Customizer customizer = customizerReference == null ? null :
366             customizerReference.get();
367         if (customizer == null) {
368             CustomizerProvider cp = getCustomizerProvider();
369             if (cp == null) {
370                 return null;
371             }
372             customizer = cp.getCustomizer();
373             if (customizer == null || customizer.getComponent() == null) {
374                 return null;
375             }
376             customizerReference = new WeakReference JavaDoc<Customizer>(customizer);
377         } else {
378             customizer.reset();
379         }
380         DialogDescriptor descriptor = UIUtilities.getCustomizerDialog(
381                 customizer, getTypeDisplayName(), isEditable());
382         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(descriptor);
383         dlg.getAccessibleContext().setAccessibleDescription(dlg.getTitle());
384         return dlg;
385     }
386
387     /**
388      * call this method before any method of XMLElementListener to check
389      * if this is the same source.
390      * @param node
391      * @return
392      */

393     public boolean isSameAsMyWSDLElement(Component node) {
394         if(node != null && node.equals(this.getWSDLComponent())) {
395             return true;
396         }
397         
398         return false;
399     }
400
401     public void childrenAdded(ComponentEvent evt) {
402     }
403
404     public void childrenDeleted(ComponentEvent evt) {
405     }
406
407     public void valueChanged(ComponentEvent evt) {
408         if (!isSameAsMyWSDLElement((Component) evt.getSource())) {
409             return;
410         }
411         updateDisplayName();
412         refreshSheet();
413         //fire a propertysets change so that property sheet can be refreshed
414
firePropertySetsChange(new Node.PropertySet[] {}, getPropertySets());
415     }
416
417     public void propertyChange(PropertyChangeEvent JavaDoc event) {
418         if (isValid() && event.getSource() == mElement) {
419             try {
420                 updateDisplayName();
421                 String JavaDoc propName = event.getPropertyName();
422                 Sheet.Set propertySet = getSheet().get(Sheet.PROPERTIES);
423                 if (propertySet != null) {
424                     if (propertySet.get(propName) != null) {
425                         firePropertyChange(propName, event.getOldValue(),
426                                 event.getNewValue());
427                     } else {
428                         ErrorManager.getDefault().log(ErrorManager.INFORMATIONAL,
429                                 propName + " property is not defined in " +
430                                 getTypeDisplayName());
431                     }
432                 }
433             } catch (IllegalStateException JavaDoc ise) {
434                 // Component is not in the model.
435
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ise);
436             } catch (NullPointerException JavaDoc npe) {
437                 // Does not reproduce reliably, but catch and log regardless.
438
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, npe);
439             }
440         }
441     }
442
443     /**
444      * Determines if this node represents a component that is contained
445      * in a valid (non-null) model.
446      *
447      * @return true if model is valid, false otherwise.
448      */

449     protected boolean isValid() {
450         return mElement.getModel() != null;
451     }
452
453     /**
454      * Used by subclasses to update the display name as needed. The default
455      * implementation updates the display name for named WSDL components.
456      * Note, this method may be called from the constructor, so be sure to
457      * avoid using member variables!
458      */

459     protected void updateDisplayName() {
460         // Need a component connected to a model to work properly.
461
if (isValid()) {
462             // Automatically keep the name in sync for named components.
463
if (mElement instanceof Named) {
464                 String JavaDoc name = ((Named) mElement).getName();
465                 // Prevent getting an NPE from ExplorerManager.
466
super.setName(name == null ? "" : name);
467                 if (name == null || name.length() == 0) {
468                     name = mElement.getPeer().getLocalName();
469                 }
470                 setDisplayName(name);
471             }
472         }
473     }
474
475     @Override JavaDoc
476     protected final Sheet createSheet() {
477         refreshSheet();
478         return mSheet;
479     }
480
481     protected InstanceContent getLookupContents() {
482         return mLookupContents;
483     }
484
485     private final void refreshSheet() {
486         if (getWSDLComponent() != null && !getWSDLComponent().isInDocumentModel()) return;
487         refreshAttributesSheetSet();
488         refreshOtherAttributesSheetSet();
489         Cookie cookie = getCookie(WSDLAttributeCookie.class);
490         if (hasOtherAttributesProperties()) {
491             mLookupContents.add(new WSDLAttributeCookie("attribute", getWSDLComponent()));//NOI18N
492
} else if (cookie != null) {
493             mLookupContents.remove(cookie);
494         }
495     }
496     
497     private final boolean hasOtherAttributesProperties() {
498         Map JavaDoc<QName JavaDoc,String JavaDoc> attributesMap = getWSDLComponent().getAttributeMap();
499         if(attributesMap != null) {
500             Iterator JavaDoc<Map.Entry JavaDoc<QName JavaDoc, String JavaDoc>> it = attributesMap.entrySet().iterator();
501             while(it.hasNext()) {
502                 Entry<QName JavaDoc, String JavaDoc> entry = it.next();
503                 QName JavaDoc attrQName = entry.getKey();
504                 String JavaDoc ns = attrQName.getNamespaceURI();
505                 //if attribute are from non wsdl namespace
506
//in that case we will have a namspace
507
//for wsdl namspace attribute ns is empty string
508
if(ns != null && !ns.trim().equals("") && !ns.equals(WSDL_NAMESPACE)) {
509                     return true;
510                 }
511             }
512         }
513         return false;
514     }
515     
516     
517     
518     protected void refreshAttributesSheetSet() {
519         Sheet.Set ss = createPropertiesSheetSet();
520
521         try {
522             AbstractDocumentComponent adc = (AbstractDocumentComponent) getWSDLComponent();
523             QName JavaDoc elementQName = adc.getQName();
524             String JavaDoc namespace = elementQName.getNamespaceURI();
525             //here we go throw all the attributes which are specified so at least user cand
526
//see them. wsdl spec element may not allow attributes apart from what is specified
527
//in schema, but if a wsdl document have them we still should show and then
528
//schema validation will catch the error
529
Map JavaDoc<QName JavaDoc, String JavaDoc> attrMap = getWSDLComponent().getAttributeMap();
530             for (QName JavaDoc attrQName : attrMap.keySet()) {
531                 String JavaDoc ns = attrQName.getNamespaceURI();
532                 
533                 Node.Property attrValueProperty = createAttributeProperty(attrQName);
534                 if(attrValueProperty != null) {
535                     //if attribute are from non wsdl namespace
536
//in that case we will have a namspace
537
//for wsdl namspace attribute ns is empty string
538
if(ns == null || ns.trim().equals("") || ns.equals(namespace)) {
539                         ss.put(attrValueProperty);
540                     }
541                 }
542             }
543             
544             List JavaDoc<Node.Property> properties = createAlwaysPresentAttributeProperty();
545             if(properties != null) {
546                 Iterator JavaDoc<Node.Property> itP = properties.iterator();
547                 while(itP.hasNext()) {
548                     Node.Property property = itP.next();
549                     //if property is not present then add it
550
if(ss.get(property.getName()) == null) {
551                         ss.put(property);
552                     }
553                 }
554             }
555             
556         } catch(Exception JavaDoc ex) {
557             mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
558         }
559         
560     }
561     
562     protected org.openide.nodes.Sheet.Set createOtherPropertiesSheetSet() {
563         String JavaDoc otherAttributeSetName = NbBundle.getMessage(DefinitionsNode.class, "PROP_SHEET_CATEGORY_Other_Attributes");
564         mSheet.remove(otherAttributeSetName);
565         Sheet.Set otherAttributesSheetSet = new Sheet.Set();
566         otherAttributesSheetSet.setName(otherAttributeSetName);
567         otherAttributesSheetSet.setDisplayName(otherAttributeSetName);
568         mSheet.put(otherAttributesSheetSet);
569         return otherAttributesSheetSet;
570     }
571
572     protected Sheet.Set createPropertiesSheetSet() {
573         mSheet.remove(Sheet.PROPERTIES);
574         Sheet.Set ss = Sheet.createPropertiesSet();
575         mSheet.put(ss);
576         return ss;
577     }
578
579     //
580
/**
581      * Return a List of Node.Property which should be always present.
582      * these attributes are always present and are not from extension namespace
583      */

584     protected List JavaDoc<Node.Property> createAlwaysPresentAttributeProperty() throws Exception JavaDoc {
585         return Collections.emptyList();
586     }
587     
588     protected Node.Property createAttributeProperty(QName JavaDoc attrQName) {
589         Node.Property attrValueProperty = null;
590         
591         try {
592             WSDLComponent component = getWSDLComponent();
593             AbstractDocumentComponent adc = (AbstractDocumentComponent) component;
594             QName JavaDoc elementQName = adc.getQName();
595             String JavaDoc namespace = elementQName.getNamespaceURI();
596             String JavaDoc ns = attrQName.getNamespaceURI();
597             //if attribute are from non wsdl namespace
598
//in that case we will have a namspace
599
//for wsdl namspace attribute ns is empty string
600
if(ns == null || ns.trim().equals("") || ns.equals(namespace)) {
601                 XMLAttributePropertyAdapter propertyAdapter =
602                     new XMLAttributePropertyAdapter(attrQName.getLocalPart(), component);
603                 attrValueProperty = getAttributeNodeProperty(attrQName.getLocalPart(), propertyAdapter);
604                 
605             } else {
606                 OtherAttributePropertyAdapter propertyAdapter =
607                     new OtherAttributePropertyAdapter(attrQName, component);
608                 //attributes
609
attrValueProperty = getOtherAttributeNodeProperty(attrQName, propertyAdapter);
610                 
611             }
612         } catch(Exception JavaDoc ex) {
613             // mLogger.log(Level.SEVERE, "failed to create property sheet for "+ getWSDLComponent(), ex);
614
ErrorManager.getDefault().notify(ex);
615         }
616         
617         return attrValueProperty;
618     }
619
620     protected Node.Property getAttributeNodeProperty(String JavaDoc attrName,
621             XMLAttributePropertyAdapter propertyAdapter) throws NoSuchMethodException JavaDoc {
622         Node.Property attrValueProperty = new BaseAttributeProperty(propertyAdapter, String JavaDoc.class,
623                 CommonAttributePropertyAdapter.VALUE);
624         attrValueProperty.setName(attrName);
625         
626         
627         String JavaDoc desc = getAttributeShortDescription(attrName);
628         if(desc != null && !desc.trim().equals("")) {
629             attrValueProperty.setShortDescription(desc);
630         } else {
631             attrValueProperty.setShortDescription(attrName);
632         }
633         
634         return attrValueProperty;
635     }
636     
637     protected Node.Property getOtherAttributeNodeProperty(QName JavaDoc attrQName,
638             OtherAttributePropertyAdapter propertyAdapter) throws NoSuchMethodException JavaDoc {
639         Node.Property attrValueProperty = new BaseAttributeProperty(propertyAdapter, String JavaDoc.class, CommonAttributePropertyAdapter.VALUE);
640         attrValueProperty.setName(Utility.fromQNameToString(attrQName));
641         String JavaDoc desc = getAttributeShortDescription(attrQName);
642         if(desc != null && !(desc.trim().length() == 0)) {
643             attrValueProperty.setShortDescription(desc);
644         } else {
645             attrValueProperty.setShortDescription(attrQName.toString());
646         }
647         
648         return attrValueProperty;
649     }
650
651     
652     protected String JavaDoc getAttributeShortDescription(QName JavaDoc attrQName) {
653         return attrQName.toString();
654     }
655     
656     protected String JavaDoc getAttributeShortDescription(String JavaDoc attrName) {
657         return attrName;
658     }
659     
660     protected void refreshOtherAttributesSheetSet() {
661         Sheet.Set otherAttributesSheetSet = createOtherPropertiesSheetSet();
662         addOtherAttributesProperties(otherAttributesSheetSet);
663     }
664      
665         
666     public static class QNameAttribute implements Attribute {
667         private QName JavaDoc qName;
668         QNameAttribute(QName JavaDoc q) {
669             this.qName = q;
670         }
671         public String JavaDoc getName() {
672             return Utility.fromQNameToString(qName);
673         }
674         public Class JavaDoc getType() { return String JavaDoc.class; }
675         public Class JavaDoc getMemberType() { return String JavaDoc.class; }
676     }
677         
678     private void addOtherAttributesProperties(Sheet.Set ss) {
679         Map JavaDoc<QName JavaDoc,String JavaDoc> attributesMap = getWSDLComponent().getAttributeMap();
680         if(attributesMap != null) {
681             Iterator JavaDoc<Map.Entry JavaDoc<QName JavaDoc, String JavaDoc>> it = attributesMap.entrySet().iterator();
682             while(it.hasNext()) {
683                 Entry<QName JavaDoc, String JavaDoc> entry = it.next();
684                 QName JavaDoc attrQName = entry.getKey();
685                 String JavaDoc ns = attrQName.getNamespaceURI();
686                 //if attribute are from non wsdl namespace
687
//in that case we will have a namspace
688
//for wsdl namspace attribute ns is empty string
689
if(ns != null && !ns.trim().equals("") && !ns.equals(WSDL_NAMESPACE)) {
690                     //String value = entry.getValue();
691
OtherAttributePropertyAdapter propertyAdapter = new OtherAttributePropertyAdapter(attrQName,
692                             getWSDLComponent());
693                     //attributes
694
Node.Property attrValueProperty;
695                     try {
696                         attrValueProperty = getOtherAttributeNodeProperty(attrQName, propertyAdapter);
697                         ss.put(attrValueProperty);
698                     } catch (NoSuchMethodException JavaDoc e) {
699                         ErrorManager.getDefault().notify(e);
700                     }
701                 }
702             }
703         }
704     }
705       
706     /**
707      * Determines if this node represents a component that is contained
708      * is editable
709      *
710      * @return true if component is editable, false otherwise.
711      */

712     
713     protected boolean isEditable() {
714         Model model = mElement.getModel();
715         return model != null && XAMUtils.isWritable(model);
716     }
717
718     /**
719      *
720      *
721      * @returns Referenceable to be used by Refactoring Find Usage, Safe Delete,
722      * and Rename
723      */

724     public Referenceable getReferenceable() {
725         return (mElement instanceof Referenceable)?Referenceable.class.cast(mElement):null;
726     }
727     
728     public Set JavaDoc<Component> getComponents() {
729         return referenceSet;
730     }
731
732     public int getChildCount() {
733         return getWSDLComponent().getChildren().size();
734     }
735     
736     public void highlightAdded(Highlight hl) {
737         highlights.add(hl);
738         fireDisplayNameChange("TempName", getDisplayName());
739     }
740
741     public void highlightRemoved(Highlight hl) {
742         highlights.remove(hl);
743         fireDisplayNameChange("TempName", getDisplayName());
744     }
745
746     /**
747      * Given a display name, add the appropriate HTML tags to highlight
748      * the display name as dictated by any Highlights associated with
749      * this node.
750      *
751      * @param name current display name.
752      * @return marked up display name.
753      */

754     protected String JavaDoc applyHighlights(String JavaDoc name) {
755         int count = highlights.size();
756         if (count > 0) {
757             // Apply the last highlight that was added to our list.
758
Highlight hl = highlights.get(count - 1);
759             String JavaDoc type = hl.getType();
760             String JavaDoc code = null;
761             if (type.equals(Highlight.SEARCH_RESULT)) {
762                 code = "e68b2c";
763             } else if (type.equals(Highlight.SEARCH_RESULT_PARENT)) {
764                 code = "ffc73c";
765             } else if (type.equals(Highlight.FIND_USAGES_RESULT_PARENT)) {
766                 code = "B5E682"; // was c7ff3c chartreuse
767
}else if (type.equals(Highlight.FIND_USAGES_RESULT)) {
768                 code = "8be62c"; // darker green
769
}
770             name = "<strong><font color=\"#" + code + "\">" + name +
771                     "</font></strong>";
772         }
773         return name;
774     }
775
776     @Override JavaDoc
777     public String JavaDoc getDisplayName() {
778         String JavaDoc instanceName = getDefaultDisplayName();
779         if (getTypeDisplayName() == null) {
780             return instanceName;
781         }
782         return instanceName.length()==0 ? instanceName :
783            instanceName + " " + "[" + getTypeDisplayName() + "]"; // NOI18N
784
}
785     
786     public String JavaDoc getDefaultDisplayName() {
787     String JavaDoc instanceName = super.getDisplayName();
788         return instanceName == null || instanceName.length() == 0
789         ? "" : instanceName;
790     }
791     
792     @Override JavaDoc
793     public String JavaDoc getHtmlDisplayName() {
794         String JavaDoc name = getDefaultDisplayName();
795         // Need to escape any HTML meta-characters in the name.
796
if(name!=null)
797             name = name.replace("<", "&lt;").replace(">", "&gt;");
798         return applyHighlights(name);
799     }
800     
801     @Override JavaDoc
802     public HelpCtx getHelpCtx() {
803         //TODO:SKINI change this after documentation has been added for individual nodes
804
//return new HelpCtx(getClass().getName());
805
return new HelpCtx("org.netbeans.modules.xml.wsdlui.about");
806     }
807     
808     
809     /**
810     *
811     *
812     */

813    public abstract String JavaDoc getTypeDisplayName();
814
815    
816 }
817
Popular Tags