001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.providers;
025:
026: import java.util.ArrayList;
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031: import org.eclipse.core.runtime.Assert;
032: import org.eclipse.emf.common.notify.AdapterFactory;
033: import org.eclipse.emf.ecore.EObject;
034: import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
035: import org.eclipse.emf.edit.provider.IItemPropertySource;
036: import org.eclipse.ui.views.properties.IPropertyDescriptor;
037: import org.eclipse.ui.views.properties.IPropertySource;
038: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HTTP;
039:
040: public abstract class ComponentFlowEditorBasicCompoundPropertySource
041: implements IPropertySource {
042: protected Map subSourcesMap;
043: /**
044: * This is the object for which this class is a property source.
045: */
046: protected Object object;
047: private List sources;
048: private List objectsOfsources;
049: protected AdapterFactory adapterFactory;
050:
051: public ComponentFlowEditorBasicCompoundPropertySource(
052: Object object, AdapterFactory adapterFactory) {
053: this .subSourcesMap = new HashMap();
054: this .object = object;
055: this .adapterFactory = adapterFactory;
056: }
057:
058: public void add(IItemPropertySource itemPropertySource, Object obj) {
059: if (itemPropertySource instanceof IItemPropertySource) {
060: if (sources == null)
061: sources = new ArrayList();
062: sources.add(itemPropertySource);
063: if (objectsOfsources == null)
064: objectsOfsources = new ArrayList();
065: objectsOfsources.add(obj);
066: }
067: }
068:
069: public Object getPropertyValue(Object id) {
070: // if (sources != null)
071: // for (Iterator i = sources.iterator(); i.hasNext(); ) {
072: // IItemPropertySource propertySource = (IItemPropertySource) i.next();
073: // int a =sources.indexOf(propertySource);
074: // Object obj = objectsOfsources.get(sources.indexOf(propertySource));
075: // Object x = propertySource.getPropertyDescriptor(obj, id);
076: // Object result = propertySource.getPropertyDescriptor(obj, id) == null ? null
077: // : propertySource.getPropertyDescriptor(obj, id)
078: // .getPropertyValue(obj);
079: // if (result != null)
080: // return result;
081: // }
082: // return null;
083: // Assert.isTrue(id instanceof PropertyDescriptorWithObjectedID);
084: if (id instanceof PropertyDescriptorWithObjectedID) {
085: Object obj = ((PropertyDescriptorWithObjectedID) id)
086: .getObject();
087: return ((PropertyDescriptorWithObjectedID) id)
088: .getItemPropertyDescriptor().getPropertyValue(obj);//id - is dummy!
089: }
090: return null;
091:
092: }
093:
094: public boolean isPropertySet(Object id) {
095: // if (sources != null)
096: // for (Iterator i = sources.iterator(); i.hasNext(); ) {
097: // IItemPropertySource propertySource = (IItemPropertySource) i.next();
098: // Object obj = objectsOfsources.get(sources.indexOf(propertySource));
099: // if (propertySource.getPropertyDescriptor(obj, id)==null)
100: // continue;
101: // if (propertySource.getPropertyDescriptor(obj, id).isPropertySet(obj))
102: // return true;
103: // }
104: // return false;
105: //Assert.isTrue(id instanceof PropertyDescriptorWithObjectedID);
106: if (id instanceof PropertyDescriptorWithObjectedID) {
107: Object obj = ((PropertyDescriptorWithObjectedID) id)
108: .getObject();
109: return ((PropertyDescriptorWithObjectedID) id)
110: .getItemPropertyDescriptor().isPropertySet(obj);//id - is dummy!
111: }
112: return false;
113: }
114:
115: public void resetPropertyValue(Object id) {
116: // if (sources != null)
117: // for (Iterator i = sources.iterator(); i.hasNext(); ) {
118: // IItemPropertySource propertySource = (IItemPropertySource) i.next();
119: // Object obj = objectsOfsources.get(sources.indexOf(propertySource));
120: // if (propertySource.getPropertyDescriptor(obj, id)!=null)
121: // propertySource.getPropertyDescriptor(obj, id).resetPropertyValue(obj);
122: // }
123: // Assert.isTrue(id instanceof PropertyDescriptorWithObjectedID);
124: if (id instanceof PropertyDescriptorWithObjectedID) {
125: Object obj = ((PropertyDescriptorWithObjectedID) id)
126: .getObject();
127: ((PropertyDescriptorWithObjectedID) id)
128: .getItemPropertyDescriptor()
129: .resetPropertyValue(obj);//id - is dummy!
130: }
131: }
132:
133: public void setPropertyValue(Object id, Object value) {
134: // if (sources != null)
135: // for (Iterator i = sources.iterator(); i.hasNext();) {
136: // IItemPropertySource propertySource = (IItemPropertySource) i.next();
137: // Object obj = objectsOfsources.get(sources
138: // .indexOf(propertySource));
139: // if (propertySource.getPropertyDescriptor(obj, id) != null)
140: // propertySource.getPropertyDescriptor(obj, id)
141: // .setPropertyValue(obj, value);
142: // }
143: // Assert.isTrue(id instanceof PropertyDescriptorWithObjectedID);
144: if (id instanceof PropertyDescriptorWithObjectedID) {
145: Object obj = ((PropertyDescriptorWithObjectedID) id)
146: .getObject();
147: ((PropertyDescriptorWithObjectedID) id)
148: .getItemPropertyDescriptor().setPropertyValue(obj,
149: value);//id - is dummy!
150: }
151: }
152:
153: public Object getEditableValue() {
154: // if (sources != null)
155: // for (Iterator i = sources.iterator(); i.hasNext(); ) {
156: // IItemPropertySource propertySource = (IItemPropertySource) i.next();
157: // Object obj = objectsOfsources.get(sources.indexOf(propertySource));
158: // Object o = propertySource.getEditableValue(obj);
159: // return o;
160: // }
161: return this ;
162: }
163:
164: public IPropertyDescriptor[] getPropertyDescriptors() {
165: List result = new ArrayList();
166: if (sources != null)
167: for (int i = 0; i < sources.size(); i++) {
168: IItemPropertySource propertySource = (IItemPropertySource) sources
169: .get(i);
170: Object obj = objectsOfsources.get(i);
171:
172: addPropertyDescriptorsFromPropertySource(result, obj,
173: propertySource);
174:
175: // if (obj instanceof HttpWSDLDocument) {
176:
177: // List httpWSDLDescriptorsList = new ArrayList();
178: // addPropertyDescriptorsFromPropertySource(httpWSDLDescriptorsList, obj, propertySource);
179: // IPropertyDescriptor[] httpWSDLDescriptors = (IPropertyDescriptor [])httpWSDLDescriptorsList.toArray(new IPropertyDescriptor [httpWSDLDescriptorsList.size()]);
180: // }
181: // List itemPropertyDescriptors = propertySource.getPropertyDescriptors(obj);
182: // if (itemPropertyDescriptors != null)
183: // {
184: // for (Iterator j = itemPropertyDescriptors.iterator(); j.hasNext(); )
185: // {
186: // IItemPropertyDescriptor itemPropertyDescriptor = (IItemPropertyDescriptor)j.next();
187: // result.add(createPropertyDescriptor(obj, itemPropertyDescriptor));
188: // }
189: // }
190: }
191: //add HTTPWSDL
192: List otherList = getSubLevelPropertyDescriptorList();
193: result.addAll(otherList);
194: //
195: IPropertyDescriptor[] x = (IPropertyDescriptor[]) result
196: .toArray(new IPropertyDescriptor[result.size()]);
197: return x;
198: }
199:
200: abstract protected List getSubLevelPropertyDescriptorList();
201:
202: abstract protected void updateSubSourcesMap();
203:
204: protected IItemPropertySource getIItemPropertySourceAdapter(
205: Object object) {
206: return (IItemPropertySource) (object instanceof EObject
207: && ((EObject) object).eClass() == null ? null
208: : adapterFactory.adapt(object,
209: IItemPropertySource.class));
210: }
211:
212: protected void addPropertyDescriptorsFromPropertySource(
213: List result, Object obj, IItemPropertySource propertySource) {
214: List itemPropertyDescriptors = propertySource
215: .getPropertyDescriptors(obj);
216: if (itemPropertyDescriptors != null) {
217: for (Iterator j = itemPropertyDescriptors.iterator(); j
218: .hasNext();) {
219: IItemPropertyDescriptor itemPropertyDescriptor = (IItemPropertyDescriptor) j
220: .next();
221: result.add(createPropertyDescriptor(obj,
222: itemPropertyDescriptor));
223: }
224: }
225: }
226:
227: protected IPropertyDescriptor createPropertyDescriptor(
228: Object object,
229: IItemPropertyDescriptor itemPropertyDescriptor) {
230: return new PropertyDescriptorWithObjectedID(object,
231: itemPropertyDescriptor);
232: }
233: }
|