KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > wsdl > ui > api > property > PartAttributeProperty


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.api.property;
21
22 import java.beans.PropertyEditor JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Collection JavaDoc;
25
26 import org.netbeans.modules.xml.wsdl.model.Message;
27 import org.netbeans.modules.xml.wsdl.model.Part;
28 import org.netbeans.modules.xml.wsdl.model.WSDLModel;
29 import org.netbeans.modules.xml.xam.ui.XAMUtils;
30 import org.openide.nodes.PropertySupport;
31
32 /**
33  *
34  * @author radval
35  *
36  */

37 public class PartAttributeProperty extends PropertySupport.Reflection {
38     
39     private MessageProvider messageProv;
40
41     private WSDLModel model;
42     
43     private boolean isMultiSelect = true;
44     
45     private ExtensibilityElementPropertyAdapter adapter;
46     public PartAttributeProperty(MessageProvider messageProv, WSDLModel model, ExtensibilityElementPropertyAdapter instance, Class JavaDoc valueType, String JavaDoc getter, String JavaDoc setter, boolean isMultiSelect) throws NoSuchMethodException JavaDoc {
47         super(instance, valueType, getter, setter);
48         this.messageProv = messageProv;
49         this.model = model;
50         this.isMultiSelect = isMultiSelect;
51         adapter = instance;
52     }
53     
54     @Override JavaDoc
55     public PropertyEditor JavaDoc getPropertyEditor() {
56         String JavaDoc[] parts = getAllMessageParts();
57         if (isMultiSelect) {
58             return new PartsSelectorPropertyEditor(parts, adapter.getValue());
59         }
60         
61         return new ComboBoxPropertyEditor(parts);
62     }
63     
64     private String JavaDoc[] getAllMessageParts() {
65         ArrayList JavaDoc<String JavaDoc> messageList = new ArrayList JavaDoc<String JavaDoc>();
66         Message message = PropertyUtil.getMessage(messageProv, model);
67         if (message != null) {
68             if (!isMultiSelect && adapter.isOptional()) {
69                 messageList.add(adapter.getMessageForUnSet());
70             }
71             //first get all messages in current wsdl document
72
messageList.addAll(getAllMessageParts(message));
73         }
74         
75         return messageList.toArray(new String JavaDoc[messageList.size()]);
76     }
77     
78     
79     
80     private ArrayList JavaDoc<String JavaDoc> getAllMessageParts(Message msg) {
81         ArrayList JavaDoc<String JavaDoc> allParts = new ArrayList JavaDoc<String JavaDoc>();
82         
83         if (msg == null) return allParts;
84         
85         Collection JavaDoc<Part> parts = msg.getParts();
86         if (parts != null) {
87             for (Part part : parts) {
88                 allParts.add(part.getName());
89             }
90         }
91         
92         return allParts;
93     }
94     
95     @Override JavaDoc
96     public boolean canWrite() {
97         return XAMUtils.isWritable(model);
98     }
99     
100 }
Popular Tags