| 1 package org.eclipse.emf.codegen.ecore.templates.edit; 2 3 import java.util.*; 4 import org.eclipse.emf.codegen.ecore.genmodel.*; 5 6 public class ItemProviderAdapterFactory 7 { 8 protected static String nl; 9 public static synchronized ItemProviderAdapterFactory create(String lineSeparator) 10 { 11 nl = lineSeparator; 12 ItemProviderAdapterFactory result = new ItemProviderAdapterFactory(); 13 nl = null; 14 return result; 15 } 16 17 protected final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl; 18 protected final String TEXT_1 = ""; 19 protected final String TEXT_2 = "/**" + NL + " * <copyright>" + NL + " * </copyright>" + NL + " *" + NL + " * "; 20 protected final String TEXT_3 = "Id"; 21 protected final String TEXT_4 = NL + " */" + NL + "package "; 22 protected final String TEXT_5 = ";" + NL; 23 protected final String TEXT_6 = NL + NL + "/**" + NL + " * This is the factory that is used to provide the interfaces needed to support Viewers." + NL + " * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}." + NL + " * The adapters also support Eclipse property sheets." + NL + " * Note that most of the adapters are shared among multiple instances." + NL + " * <!-- begin-user-doc -->" + NL + " * <!-- end-user-doc -->" + NL + " * @generated" + NL + " */" + NL + "public class "; 24 protected final String TEXT_7 = " extends "; 25 protected final String TEXT_8 = " implements ComposeableAdapterFactory, IChangeNotifier"; 26 protected final String TEXT_9 = ", "; 27 protected final String TEXT_10 = NL + "{"; 28 protected final String TEXT_11 = NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic static final "; 29 protected final String TEXT_12 = " copyright = \""; 30 protected final String TEXT_13 = "\";"; 31 protected final String TEXT_14 = NL; 32 protected final String TEXT_15 = NL + "\t/**" + NL + "\t * This keeps track of the root adapter factory that delegates to this adapter factory." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected ComposedAdapterFactory parentAdapterFactory;" + NL + "" + NL + "\t/**" + NL + "\t * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected IChangeNotifier changeNotifier = new ChangeNotifier();" + NL; 33 protected final String TEXT_16 = NL + "\t/**" + NL + "\t * This keeps track of all the item providers created, so that they can be {@link #dispose disposed}." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected "; 34 protected final String TEXT_17 = " disposable = new Disposable();" + NL; 35 protected final String TEXT_18 = NL + "\t/**" + NL + "\t * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected Collection supportedTypes = new ArrayList();" + NL + "" + NL + "\t/**" + NL + "\t * This constructs an instance." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic "; 36 protected final String TEXT_19 = "()" + NL + "\t{"; 37 protected final String TEXT_20 = NL + "\t\tsupportedTypes.add("; 38 protected final String TEXT_21 = ".class);"; 39 protected final String TEXT_22 = "\t\t" + NL + "\t}" + NL; 40 protected final String TEXT_23 = NL + "\t/**" + NL + "\t * This keeps track of the factory to which to delegate adapter creation for objects from that package." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected "; 41 protected final String TEXT_24 = " "; 42 protected final String TEXT_25 = " = null;" + NL + "" + NL + "\t/**" + NL + "\t * This determines the delegate factory for the package." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected "; 43 protected final String TEXT_26 = " get"; 44 protected final String TEXT_27 = "()" + NL + "\t{" + NL + "\t\tif ("; 45 protected final String TEXT_28 = " == null)" + NL + "\t\t{" + NL + "\t\t\t"; 46 protected final String TEXT_29 = " rootAdapterFactory = getRootAdapterFactory();" + NL + "\t\t\tif (rootAdapterFactory instanceof ComposedAdapterFactory)" + NL + "\t\t\t{" + NL + "\t\t\t\t"; 47 protected final String TEXT_30 = " delegateAdapterFactory =" + NL + "\t\t\t\t\t((ComposedAdapterFactory)rootAdapterFactory).getFactoryForType("; 48 protected final String TEXT_31 = ".getPackage());" + NL + "\t\t\t\tif (delegateAdapterFactory instanceof "; 49 protected final String TEXT_32 = ")" + NL + "\t\t\t\t{" + NL + "\t\t\t\t\t"; 50 protected final String TEXT_33 = " = ("; 51 protected final String TEXT_34 = ")delegateAdapterFactory;" + NL + "\t\t\t\t}" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "\t\treturn "; 52 protected final String TEXT_35 = ";" + NL + "\t}" + NL; 53 protected final String TEXT_36 = NL + "\t/**" + NL + "\t * This keeps track of the one adapter used for all {@link "; 54 protected final String TEXT_37 = "} instances." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected "; 55 protected final String TEXT_38 = " "; 56 protected final String TEXT_39 = "ItemProvider;" + NL + "" + NL + "\t/**" + NL + "\t * This creates an adapter for a {@link "; 57 protected final String TEXT_40 = "}." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Adapter create"; 58 protected final String TEXT_41 = "Adapter()" + NL + "\t{" + NL + "\t\tif ("; 59 protected final String TEXT_42 = "ItemProvider == null)" + NL + "\t\t{" + NL + "\t\t\t"; 60 protected final String TEXT_43 = "ItemProvider = new "; 61 protected final String TEXT_44 = "(this);" + NL + "\t\t}" + NL + "" + NL + "\t\treturn "; 62 protected final String TEXT_45 = "ItemProvider;" + NL + "\t}" + NL; 63 protected final String TEXT_46 = NL + "\t/**" + NL + "\t * This creates an adapter for a {@link "; 64 protected final String TEXT_47 = "}." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Adapter create"; 65 protected final String TEXT_48 = "Adapter()" + NL + "\t{" + NL + "\t\treturn new "; 66 protected final String TEXT_49 = "(this);" + NL + "\t}" + NL; 67 protected final String TEXT_50 = NL + "\t/**" + NL + "\t * "; 68 protected final String TEXT_51 = " of "; 69 protected final String TEXT_52 = NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Adapter create"; 70 protected final String TEXT_53 = "Adapter()" + NL + "\t{" + NL + "\t\treturn" + NL + "\t\t\tget"; 71 protected final String TEXT_54 = " == null ?" + NL + "\t\t\t\tnull :" + NL + "\t\t\t\tget"; 72 protected final String TEXT_55 = "().create"; 73 protected final String TEXT_56 = "Adapter();" + NL + "\t}" + NL; 74 protected final String TEXT_57 = NL + "\t/**" + NL + "\t * This returns the root adapter factory that contains this factory." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic ComposeableAdapterFactory getRootAdapterFactory()" + NL + "\t{" + NL + "\t\treturn parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * This sets the composed adapter factory that contains this factory." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory)" + NL + "\t{" + NL + "\t\tthis.parentAdapterFactory = parentAdapterFactory;" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic boolean isFactoryForType(Object type)" + NL + "\t{" + NL + "\t\treturn supportedTypes.contains(type) || super.isFactoryForType(type);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * This implementation substitutes the factory itself as the key for the adapter." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Adapter adapt(Notifier notifier, Object type)" + NL + "\t{" + NL + "\t\treturn super.adapt(notifier, this);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic Object adapt(Object object, Object type)" + NL + "\t{" + NL + "\t\tif (isFactoryForType(type))" + NL + "\t\t{" + NL + "\t\t\tObject adapter = super.adapt(object, type);" + NL + "\t\t\tif (!(type instanceof Class) || (((Class)type).isInstance(adapter)))" + NL + "\t\t\t{" + NL + "\t\t\t\treturn adapter;" + NL + "\t\t\t}" + NL + "\t\t}" + NL + "" + NL + "\t\treturn null;" + NL + "\t}" + NL; 75 protected final String TEXT_58 = NL + "\t/**" + NL + "\t * Associates an adapter with a notifier via the base implementation, then records it to ensure it will be disposed." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tprotected void associate(Adapter adapter, Notifier target)" + NL + "\t{" + NL + "\t\tsuper.associate(adapter, target);" + NL + "\t\tif (adapter != null)" + NL + "\t\t{" + NL + "\t\t\tdisposable.add(adapter);" + NL + "\t\t}" + NL + "\t}" + NL; 76 protected final String TEXT_59 = NL + "\t/**" + NL + "\t * This adds a listener." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void addListener(INotifyChangedListener notifyChangedListener)" + NL + "\t{" + NL + "\t\tchangeNotifier.addListener(notifyChangedListener);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * This removes a listener." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void removeListener(INotifyChangedListener notifyChangedListener)" + NL + "\t{" + NL + "\t\tchangeNotifier.removeListener(notifyChangedListener);" + NL + "\t}" + NL + "" + NL + "\t/**" + NL + "\t * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}." + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void fireNotifyChanged(Notification notification)" + NL + "\t{" + NL + "\t\tchangeNotifier.fireNotifyChanged(notification);" + NL + "" + NL + "\t\tif (parentAdapterFactory != null)" + NL + "\t\t{" + NL + "\t\t\tparentAdapterFactory.fireNotifyChanged(notification);" + NL + "\t\t}" + NL + "\t}" + NL; 77 protected final String TEXT_60 = NL + "\t/**" + NL + "\t * This disposes all of the item providers created by this factory. " + NL + "\t * <!-- begin-user-doc -->" + NL + "\t * <!-- end-user-doc -->" + NL + "\t * @generated" + NL + "\t */" + NL + "\tpublic void dispose()" + NL + "\t{"; 78 protected final String TEXT_61 = NL + "\t\tdisposable.dispose();"; 79 protected final String TEXT_62 = NL + "\t\tif ("; 80 protected final String TEXT_63 = "ItemProvider != null) "; 81 protected final String TEXT_64 = "ItemProvider.dispose();"; 82 protected final String TEXT_65 = NL + "\t}" + NL; 83 protected final String TEXT_66 = NL + "}"; 84 protected final String TEXT_67 = NL; 85 86 public String generate(Object argument) 87 { 88 StringBuffer stringBuffer = new StringBuffer (); 89 90 104 105 GenPackage genPackage = (GenPackage)argument; GenModel genModel=genPackage.getGenModel(); 106 stringBuffer.append(TEXT_1); 107 stringBuffer.append(TEXT_2); 108 stringBuffer.append("$"); 109 stringBuffer.append(TEXT_3); 110 stringBuffer.append("$"); 111 stringBuffer.append(TEXT_4); 112 stringBuffer.append(genPackage.getProviderPackageName()); 113 stringBuffer.append(TEXT_5); 114 genModel.addImport("org.eclipse.emf.common.notify.Adapter"); 115 genModel.addImport("org.eclipse.emf.common.notify.Notification"); 116 genModel.addImport("org.eclipse.emf.common.notify.Notifier"); 117 genModel.addImport("org.eclipse.emf.edit.provider.ChangeNotifier"); 118 genModel.addImport("org.eclipse.emf.edit.provider.ComposeableAdapterFactory"); 119 genModel.addImport("org.eclipse.emf.edit.provider.ComposedAdapterFactory"); 120 genModel.addImport("org.eclipse.emf.edit.provider.IChangeNotifier"); 121 genModel.addImport("org.eclipse.emf.edit.provider.IEditingDomainItemProvider"); 122 genModel.addImport("org.eclipse.emf.edit.provider.IItemLabelProvider"); 123 genModel.addImport("org.eclipse.emf.edit.provider.IItemPropertySource"); 124 genModel.addImport("org.eclipse.emf.edit.provider.INotifyChangedListener"); 125 genModel.addImport("org.eclipse.emf.edit.provider.IStructuredItemContentProvider"); 126 genModel.addImport("org.eclipse.emf.edit.provider.ITreeItemContentProvider"); 127 genModel.addImport("java.util.ArrayList"); 128 genModel.addImport("java.util.Collection"); 129 genModel.markImportLocation(stringBuffer); 130 stringBuffer.append(TEXT_6); 131 stringBuffer.append(genPackage.getItemProviderAdapterFactoryClassName()); 132 stringBuffer.append(TEXT_7); 133 stringBuffer.append(genPackage.getImportedAdapterFactoryClassName()); 134 stringBuffer.append(TEXT_8); 135 if (genPackage.isDisposableProviderFactory()) { 136 stringBuffer.append(TEXT_9); 137 stringBuffer.append(genModel.getImportedName("org.eclipse.emf.edit.provider.IDisposable")); 138 } 139 stringBuffer.append(TEXT_10); 140 if (genModel.getCopyrightText() != null) { 141 stringBuffer.append(TEXT_11); 142 stringBuffer.append(genModel.getImportedName("java.lang.String")); 143 stringBuffer.append(TEXT_12); 144 stringBuffer.append(genModel.getCopyrightText()); 145 stringBuffer.append(TEXT_13); 146 stringBuffer.append(genModel.getNonNLS()); 147 stringBuffer.append(TEXT_14); 148 } 149 stringBuffer.append(TEXT_15); 150 if (genPackage.isDisposableProviderFactory() && genPackage.hasStatefulProvider()) { 151 stringBuffer.append(TEXT_16); 152 stringBuffer.append(genModel.getImportedName("org.eclipse.emf.edit.provider.Disposable")); 153 stringBuffer.append(TEXT_17); 154 } 155 stringBuffer.append(TEXT_18); 156 stringBuffer.append(genPackage.getItemProviderAdapterFactoryClassName()); 157 stringBuffer.append(TEXT_19); 158 for (Iterator i = genPackage.getProviderSupportedTypes().iterator(); i.hasNext(); ) { 159 stringBuffer.append(TEXT_20); 160 stringBuffer.append(genModel.getImportedName((String )i.next())); 161 stringBuffer.append(TEXT_21); 162 } 163 stringBuffer.append(TEXT_22); 164 for (Iterator i=genPackage.getAdapterDelegatePackages().iterator(); i.hasNext();) { GenPackage genDelegate = (GenPackage)i.next(); 165 stringBuffer.append(TEXT_23); 166 stringBuffer.append(genDelegate.getImportedAdapterFactoryClassName()); 167 stringBuffer.append(TEXT_24); 168 stringBuffer.append(genPackage.getUncapAdapterFactoryDelegateName(genDelegate)); 169 stringBuffer.append(TEXT_25); 170 stringBuffer.append(genDelegate.getImportedAdapterFactoryClassName()); 171 stringBuffer.append(TEXT_26); 172 stringBuffer.append(genPackage.getAdapterFactoryDelegateName(genDelegate)); 173 stringBuffer.append(TEXT_27); 174 stringBuffer.append(genPackage.getUncapAdapterFactoryDelegateName(genDelegate)); 175 stringBuffer.append(TEXT_28); 176 stringBuffer.append(genModel.getImportedName("org.eclipse.emf.common.notify.AdapterFactory")); 177 stringBuffer.append(TEXT_29); 178 stringBuffer.append(genModel.getImportedName("org.eclipse.emf.common.notify.AdapterFactory")); 179 stringBuffer.append(TEXT_30); 180 stringBuffer.append(genDelegate.getImportedAdapterFactoryClassName()); 181 stringBuffer.append(TEXT_31); 182 stringBuffer.append(genDelegate.getImportedAdapterFactoryClassName()); 183 stringBuffer.append(TEXT_32); 184 stringBuffer.append(genPackage.getUncapAdapterFactoryDelegateName(genDelegate)); 185 stringBuffer.append(TEXT_33); 186 stringBuffer.append(genDelegate.getImportedAdapterFactoryClassName()); 187 stringBuffer.append(TEXT_34); 188 stringBuffer.append(genPackage.getUncapAdapterFactoryDelegateName(genDelegate)); 189 stringBuffer.append(TEXT_35); 190 } 191 for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next(); 192 if (!genClass.isAbstract() && genClass.getProvider() != GenProviderKind.NONE_LITERAL) { 193 if (genClass.isProviderSingleton()) { 194 stringBuffer.append(TEXT_36); 195 stringBuffer.append(genClass.getQualifiedInterfaceName()); 196 stringBuffer.append(TEXT_37); 197 stringBuffer.append(genClass.getProviderClassName()); 198 stringBuffer.append(TEXT_38); 199 stringBuffer.append(genClass.getUncapName()); 200 stringBuffer.append(TEXT_39); 201 stringBuffer.append(genClass.getQualifiedInterfaceName()); 202 stringBuffer.append(TEXT_40); 203 stringBuffer.append(genClass.getName()); 204 stringBuffer.append(TEXT_41); 205 stringBuffer.append(genClass.getUncapName()); 206 stringBuffer.append(TEXT_42); 207 stringBuffer.append(genClass.getUncapName()); 208 stringBuffer.append(TEXT_43); 209 stringBuffer.append(genClass.getProviderClassName()); 210 stringBuffer.append(TEXT_44); 211 stringBuffer.append(genClass.getUncapName()); 212 stringBuffer.append(TEXT_45); 213 } else { 214 stringBuffer.append(TEXT_46); 215 stringBuffer.append(genClass.getQualifiedInterfaceName()); 216 stringBuffer.append(TEXT_47); 217 stringBuffer.append(genClass.getName()); 218 stringBuffer.append(TEXT_48); 219 stringBuffer.append(genClass.getProviderClassName()); 220 stringBuffer.append(TEXT_49); 221 } 222 } 223 } 224 for (Iterator i=genPackage.getAdapterDelegateSuperClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next(); 225 stringBuffer.append(TEXT_50); 226 stringBuffer.append(genClass.getName()); 227 stringBuffer.append(TEXT_51); 228 stringBuffer.append(genClass.getItemProviderAdapterFactoryClassName()); 229 stringBuffer.append(TEXT_52); 230 stringBuffer.append(genClass.getName()); 231 stringBuffer.append(TEXT_53); 232 stringBuffer.append(genClass.getItemProviderAdapterFactoryClassName()); 233 stringBuffer.append(TEXT_54); 234 stringBuffer.append(genClass.getItemProviderAdapterFactoryClassName()); 235 stringBuffer.append(TEXT_55); 236 stringBuffer.append(genClass.getName()); 237 stringBuffer.append(TEXT_56); 238 } 239 stringBuffer.append(TEXT_57); 240 if (genPackage.isDisposableProviderFactory() && genPackage.hasStatefulProvider()) { 241 stringBuffer.append(TEXT_58); 242 } 243 stringBuffer.append(TEXT_59); 244 if (genPackage.isDisposableProviderFactory()) { 245 stringBuffer.append(TEXT_60); 246 if (genPackage.hasStatefulProvider()) { 247 stringBuffer.append(TEXT_61); 248 } else { 249 for (Iterator i=genPackage.getGenClasses().iterator(); i.hasNext();) { GenClass genClass = (GenClass)i.next(); 250 if (!genClass.isAbstract() && genClass.isProviderSingleton()) { 251 stringBuffer.append(TEXT_62); 252 stringBuffer.append(genClass.getUncapName()); 253 stringBuffer.append(TEXT_63); 254 stringBuffer.append(genClass.getUncapName()); 255 stringBuffer.append(TEXT_64); 256 } 257 } 258 } 259 stringBuffer.append(TEXT_65); 260 } 261 stringBuffer.append(TEXT_66); 262 genModel.emitSortedImports(); 263 stringBuffer.append(TEXT_67); 264 return stringBuffer.toString(); 265 } 266 } 267 | Popular Tags |