1 19 27 28 package org.netbeans.modules.xml.wsdl.ui.view.grapheditor.widget; 29 30 import java.util.ArrayList ; 31 import java.util.List ; 32 import org.netbeans.api.visual.model.ObjectScene; 33 import org.netbeans.api.visual.widget.Scene; 34 import org.netbeans.api.visual.widget.Widget; 35 import org.netbeans.modules.xml.wsdl.model.Fault; 36 import org.netbeans.modules.xml.wsdl.model.Input; 37 import org.netbeans.modules.xml.wsdl.model.Message; 38 import org.netbeans.modules.xml.wsdl.model.NotificationOperation; 39 import org.netbeans.modules.xml.wsdl.model.OneWayOperation; 40 import org.netbeans.modules.xml.wsdl.model.OperationParameter; 41 import org.netbeans.modules.xml.wsdl.model.Output; 42 import org.netbeans.modules.xml.wsdl.model.Part; 43 import org.netbeans.modules.xml.wsdl.model.PortType; 44 import org.netbeans.modules.xml.wsdl.model.RequestResponseOperation; 45 import org.netbeans.modules.xml.wsdl.model.SolicitResponseOperation; 46 import org.netbeans.modules.xml.wsdl.model.WSDLComponent; 47 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.PartnerLinkType; 48 import org.netbeans.modules.xml.wsdl.model.extensions.bpel.Role; 49 import org.openide.util.Lookup; 50 51 58 public class WidgetFactory { 59 60 private static WidgetFactory mFactory; 61 62 63 private WidgetFactory() { 64 } 65 66 71 public static WidgetFactory getInstance() { 72 if (mFactory == null) { 73 mFactory = new WidgetFactory(); 74 } 75 return mFactory; 76 } 77 78 85 public Widget createWidget(Scene scene, WSDLComponent component) { 86 return createWidget(scene, component, false); 87 } 88 89 97 public Widget createWidget(Scene scene, WSDLComponent component, 98 boolean reuse) { 99 return createWidget(scene, component, Lookup.EMPTY, reuse); 101 } 102 103 111 public Widget createWidget(Scene scene, WSDLComponent component, 112 Lookup lookup) { 113 return createWidget(scene, component, lookup, false); 114 } 115 116 125 public Widget createWidget(Scene scene, WSDLComponent component, 126 Lookup lookup, boolean reuse) { 127 Widget widget = null; 128 129 if (reuse) { 130 widget = ((PartnerScene) scene).findWidget(component); 131 if (widget != null) { 132 return widget; 133 } 134 } 135 136 if (component instanceof Fault) { 137 Fault fault = (Fault)component; 138 widget = new FaultWidget(scene, fault, lookup, 139 fault.getParent() instanceof SolicitResponseOperation ); 140 } else if (component instanceof Input) { 141 widget = new InputWidget(scene, (Input) component, lookup); 142 } else if (component instanceof Message) { 143 widget = new MessageWidget(scene, (Message) component, lookup); 144 } else if (component instanceof Part) { 145 widget = new PartWidget(scene, (Part) component, lookup); 146 } else if (component instanceof NotificationOperation) { 147 widget = new NotificationOperationWidget( 148 scene, (NotificationOperation) component, lookup); 149 } else if (component instanceof OneWayOperation) { 150 widget = new OneWayOperationWidget( 151 scene, (OneWayOperation) component, lookup); 152 } else if (component instanceof Output) { 153 widget = new OutputWidget(scene, (Output) component, lookup); 154 } else if (component instanceof PartnerLinkType) { 155 widget = new PartnerLinkTypeWidget( 156 scene, (PartnerLinkType) component, lookup); 157 } else if (component instanceof PortType) { 158 widget = new PortTypeWidget(scene, (PortType) component, lookup); 159 } else if (component instanceof RequestResponseOperation) { 160 widget = new RequestReplyOperationWidget( 161 scene, (RequestResponseOperation) component, lookup); 162 } else if (component instanceof Role) { 163 widget = new RoleWidget(scene, (Role) component, lookup); 164 } else if (component instanceof SolicitResponseOperation) { 165 widget = new SolicitResponseOperationWidget( 166 scene, (SolicitResponseOperation) component, lookup); 167 } 168 if (widget != null) { 169 prepareWidget(scene, widget, component); 170 } 171 return widget; 172 } 173 174 185 public Widget createWidget(Scene scene, Class <? extends WSDLComponent> type, 186 Lookup lookup) { 187 Widget widget = null; 188 189 if (Fault.class.isAssignableFrom(type)) { 190 widget = new FaultWidget(scene, null, lookup, false); 191 } else if (Input.class.isAssignableFrom(type)) { 192 widget = new InputWidget(scene, null, lookup); 193 } else if (Message.class.isAssignableFrom(type)) { 194 widget = new MessageWidget(scene, null, lookup); 195 } else if (NotificationOperation.class.isAssignableFrom(type)) { 196 widget = new NotificationOperationWidget(scene, null, lookup); 197 } else if (OneWayOperation.class.isAssignableFrom(type)) { 198 widget = new OneWayOperationWidget(scene, null, lookup); 199 } else if (Output.class.isAssignableFrom(type)) { 200 widget = new OutputWidget(scene, null, lookup); 201 } else if (PartnerLinkType.class.isAssignableFrom(type)) { 202 widget = new PartnerLinkTypeWidget(scene, null, lookup); 203 } else if (PortType.class.isAssignableFrom(type)) { 204 205 widget = new PortTypeWidget(scene, null, lookup); 206 } else if (RequestResponseOperation.class.isAssignableFrom(type)) { 207 widget = new RequestReplyOperationWidget(scene, null, lookup); 208 } else if (Role.class.isAssignableFrom(type)) { 209 widget = new RoleWidget(scene, null, lookup); 210 } else if (SolicitResponseOperation.class.isAssignableFrom(type)) { 211 widget = new SolicitResponseOperationWidget(scene, null, lookup); 212 } 213 if (widget != null) { 214 prepareWidget(scene, widget, null); 215 } 216 return widget; 217 } 218 219 230 public Widget createOperationParameterWidget(Scene scene, 231 OperationParameter component, Lookup lookup) { 232 Widget widget = new OperationParameterWidget(scene, component, lookup); 233 prepareWidget(scene, widget, component); 234 return widget; 235 } 236 237 245 private void prepareWidget(Scene scene, Widget widget, 246 WSDLComponent component) { 247 if (scene instanceof PartnerScene) { 248 widget.getActions().addAction(((PartnerScene) scene).getSelectAction()); 250 } 251 if (scene instanceof ObjectScene) { 252 ObjectScene os = (ObjectScene) scene; 253 if (component != null) { 254 List <Widget> widgets = os.findWidgets(component); 256 if (widgets == null) { 257 widgets = new ArrayList <Widget>(); 258 } else { 259 os.removeObject(component); 261 widgets = new ArrayList <Widget>(widgets); 263 } 264 widgets.add(widget); 265 os.addObject(component, widgets.toArray( 266 new Widget[widgets.size()])); 267 } 268 } 269 } 270 } 271 | Popular Tags |