1 19 20 package org.netbeans.modules.xml.wsdl.ui.api.property; 21 22 import java.beans.PropertyEditor ; 23 import java.util.ArrayList ; 24 import java.util.Collection ; 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 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 valueType, String getter, String setter, boolean isMultiSelect) throws NoSuchMethodException { 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 55 public PropertyEditor getPropertyEditor() { 56 String [] parts = getAllMessageParts(); 57 if (isMultiSelect) { 58 return new PartsSelectorPropertyEditor(parts, adapter.getValue()); 59 } 60 61 return new ComboBoxPropertyEditor(parts); 62 } 63 64 private String [] getAllMessageParts() { 65 ArrayList <String > messageList = new ArrayList <String >(); 66 Message message = PropertyUtil.getMessage(messageProv, model); 67 if (message != null) { 68 if (!isMultiSelect && adapter.isOptional()) { 69 messageList.add(adapter.getMessageForUnSet()); 70 } 71 messageList.addAll(getAllMessageParts(message)); 73 } 74 75 return messageList.toArray(new String [messageList.size()]); 76 } 77 78 79 80 private ArrayList <String > getAllMessageParts(Message msg) { 81 ArrayList <String > allParts = new ArrayList <String >(); 82 83 if (msg == null) return allParts; 84 85 Collection <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 96 public boolean canWrite() { 97 return XAMUtils.isWritable(model); 98 } 99 100 } | Popular Tags |