| 1 | /* |
| 2 | *Copyright 2007, SDQ, IPD, U KA |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcm.gmf.allocation.part; |
| 5 | |
| 6 | import java.util.ArrayList; |
| 7 | import java.util.List; |
| 8 | |
| 9 | import org.eclipse.core.runtime.IPath; |
| 10 | import org.eclipse.core.runtime.IStatus; |
| 11 | import org.eclipse.core.runtime.Path; |
| 12 | import org.eclipse.core.runtime.Platform; |
| 13 | import org.eclipse.core.runtime.Status; |
| 14 | |
| 15 | import org.eclipse.emf.common.notify.AdapterFactory; |
| 16 | import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
| 17 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 18 | import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; |
| 19 | import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; |
| 20 | import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; |
| 21 | import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint; |
| 22 | import org.eclipse.jface.resource.ImageDescriptor; |
| 23 | import org.eclipse.swt.graphics.Image; |
| 24 | import org.eclipse.ui.plugin.AbstractUIPlugin; |
| 25 | import org.osgi.framework.BundleContext; |
| 26 | import de.uka.ipd.sdq.identifier.provider.IdentifierItemProviderAdapterFactory; |
| 27 | |
| 28 | import de.uka.ipd.sdq.pcm.allocation.provider.AllocationItemProviderAdapterFactory; |
| 29 | |
| 30 | import de.uka.ipd.sdq.pcm.core.composition.provider.CompositionItemProviderAdapterFactory; |
| 31 | |
| 32 | |
| 33 | |
| 34 | import de.uka.ipd.sdq.pcm.core.entity.provider.EntityItemProviderAdapterFactory; |
| 35 | |
| 36 | import de.uka.ipd.sdq.pcm.core.provider.CoreItemProviderAdapterFactory; |
| 37 | import de.uka.ipd.sdq.pcm.parameter.provider.ParameterItemProviderAdapterFactory; |
| 38 | |
| 39 | import de.uka.ipd.sdq.pcm.protocol.provider.ProtocolItemProviderAdapterFactory; |
| 40 | |
| 41 | import de.uka.ipd.sdq.pcm.qosannotations.provider.QosannotationsItemProviderAdapterFactory; |
| 42 | |
| 43 | import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory; |
| 44 | |
| 45 | import de.uka.ipd.sdq.pcm.resourceenvironment.provider.ResourceenvironmentItemProviderAdapterFactory; |
| 46 | |
| 47 | import de.uka.ipd.sdq.pcm.resourcetype.provider.ResourcetypeItemProviderAdapterFactory; |
| 48 | |
| 49 | import de.uka.ipd.sdq.pcm.seff.provider.SeffItemProviderAdapterFactory; |
| 50 | |
| 51 | import de.uka.ipd.sdq.pcm.system.provider.SystemItemProviderAdapterFactory; |
| 52 | |
| 53 | import de.uka.ipd.sdq.pcm.subsystem.provider.SubsystemItemProviderAdapterFactory; |
| 54 | |
| 55 | import de.uka.ipd.sdq.pcm.usagemodel.provider.UsagemodelItemProviderAdapterFactory; |
| 56 | |
| 57 | import de.uka.ipd.sdq.probfunction.provider.ProbfunctionItemProviderAdapterFactory; |
| 58 | |
| 59 | import de.uka.ipd.sdq.stoex.provider.StoexItemProviderAdapterFactory; |
| 60 | import de.uka.ipd.sdq.units.provider.UnitsItemProviderAdapterFactory; |
| 61 | |
| 62 | /** |
| 63 | * @generated |
| 64 | */ |
| 65 | public class PalladioComponentModelAllocationDiagramEditorPlugin extends |
| 66 | AbstractUIPlugin { |
| 67 | |
| 68 | /** |
| 69 | * @generated |
| 70 | */ |
| 71 | public static final String ID = "de.uka.ipd.sdq.pcm.gmf.allocation"; //$NON-NLS-1$ |
| 72 | |
| 73 | /** |
| 74 | * @generated |
| 75 | */ |
| 76 | public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint( |
| 77 | ID); |
| 78 | |
| 79 | /** |
| 80 | * @generated |
| 81 | */ |
| 82 | private static PalladioComponentModelAllocationDiagramEditorPlugin instance; |
| 83 | |
| 84 | /** |
| 85 | * @generated |
| 86 | */ |
| 87 | private ComposedAdapterFactory adapterFactory; |
| 88 | |
| 89 | /** |
| 90 | * @generated |
| 91 | */ |
| 92 | private PalladioComponentModelDocumentProvider documentProvider; |
| 93 | |
| 94 | /** |
| 95 | * @generated |
| 96 | */ |
| 97 | public PalladioComponentModelAllocationDiagramEditorPlugin() { |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @generated |
| 102 | */ |
| 103 | public void start(BundleContext context) throws Exception { |
| 104 | super.start(context); |
| 105 | instance = this; |
| 106 | PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, |
| 107 | getPreferenceStore()); |
| 108 | adapterFactory = createAdapterFactory(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * @generated |
| 113 | */ |
| 114 | public void stop(BundleContext context) throws Exception { |
| 115 | adapterFactory.dispose(); |
| 116 | adapterFactory = null; |
| 117 | instance = null; |
| 118 | super.stop(context); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @generated |
| 123 | */ |
| 124 | public static PalladioComponentModelAllocationDiagramEditorPlugin getInstance() { |
| 125 | return instance; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @generated |
| 130 | */ |
| 131 | protected ComposedAdapterFactory createAdapterFactory() { |
| 132 | List factories = new ArrayList(); |
| 133 | fillItemProviderFactories(factories); |
| 134 | return new ComposedAdapterFactory(factories); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * @generated |
| 139 | */ |
| 140 | protected void fillItemProviderFactories(List factories) { |
| 141 | factories.add(new CoreItemProviderAdapterFactory()); |
| 142 | factories.add(new EntityItemProviderAdapterFactory()); |
| 143 | factories.add(new CompositionItemProviderAdapterFactory()); |
| 144 | factories.add(new RepositoryItemProviderAdapterFactory()); |
| 145 | factories.add(new ProtocolItemProviderAdapterFactory()); |
| 146 | factories.add(new ParameterItemProviderAdapterFactory()); |
| 147 | factories.add(new SeffItemProviderAdapterFactory()); |
| 148 | factories.add(new ResourcetypeItemProviderAdapterFactory()); |
| 149 | factories.add(new AllocationItemProviderAdapterFactory()); |
| 150 | factories.add(new ResourceenvironmentItemProviderAdapterFactory()); |
| 151 | factories.add(new SystemItemProviderAdapterFactory()); |
| 152 | factories.add(new SubsystemItemProviderAdapterFactory()); |
| 153 | factories.add(new QosannotationsItemProviderAdapterFactory()); |
| 154 | factories.add(new UsagemodelItemProviderAdapterFactory()); |
| 155 | factories.add(new IdentifierItemProviderAdapterFactory()); |
| 156 | factories.add(new StoexItemProviderAdapterFactory()); |
| 157 | factories.add(new UnitsItemProviderAdapterFactory()); |
| 158 | factories.add(new ProbfunctionItemProviderAdapterFactory()); |
| 159 | factories.add(new ResourceItemProviderAdapterFactory()); |
| 160 | factories.add(new ReflectiveItemProviderAdapterFactory()); |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * @generated |
| 165 | */ |
| 166 | public AdapterFactory getItemProvidersAdapterFactory() { |
| 167 | return adapterFactory; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * @generated |
| 172 | */ |
| 173 | public ImageDescriptor getItemImageDescriptor(Object item) { |
| 174 | IItemLabelProvider labelProvider = (IItemLabelProvider) adapterFactory |
| 175 | .adapt(item, IItemLabelProvider.class); |
| 176 | if (labelProvider != null) { |
| 177 | return ExtendedImageRegistry.getInstance().getImageDescriptor( |
| 178 | labelProvider.getImage(item)); |
| 179 | } |
| 180 | return null; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Returns an image descriptor for the image file at the given |
| 185 | * plug-in relative path. |
| 186 | * |
| 187 | * @generated |
| 188 | * @param path the path |
| 189 | * @return the image descriptor |
| 190 | */ |
| 191 | public static ImageDescriptor getBundledImageDescriptor(String path) { |
| 192 | return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Respects images residing in any plug-in. If path is relative, |
| 197 | * then this bundle is looked up for the image, otherwise, for absolute |
| 198 | * path, first segment is taken as id of plug-in with image |
| 199 | * |
| 200 | * @generated |
| 201 | * @param path the path to image, either absolute (with plug-in id as first segment), or relative for bundled images |
| 202 | * @return the image descriptor |
| 203 | */ |
| 204 | public static ImageDescriptor findImageDescriptor(String path) { |
| 205 | final IPath p = new Path(path); |
| 206 | if (p.isAbsolute() && p.segmentCount() > 1) { |
| 207 | return AbstractUIPlugin.imageDescriptorFromPlugin(p.segment(0), p |
| 208 | .removeFirstSegments(1).makeAbsolute().toString()); |
| 209 | } else { |
| 210 | return getBundledImageDescriptor(p.makeAbsolute().toString()); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * Returns string from plug-in's resource bundle |
| 216 | * @generated |
| 217 | */ |
| 218 | public static String getString(String key) { |
| 219 | return Platform.getResourceString(getInstance().getBundle(), "%" + key); //$NON-NLS-1$ |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Returns an image for the image file at the given plug-in relative path. |
| 224 | * Client do not need to dispose this image. Images will be disposed automatically. |
| 225 | * |
| 226 | * @generated |
| 227 | * @param path the path |
| 228 | * @return image instance |
| 229 | */ |
| 230 | public Image getBundledImage(String path) { |
| 231 | Image image = getImageRegistry().get(path); |
| 232 | if (image == null) { |
| 233 | getImageRegistry().put(path, getBundledImageDescriptor(path)); |
| 234 | image = getImageRegistry().get(path); |
| 235 | } |
| 236 | return image; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @generated |
| 241 | */ |
| 242 | public PalladioComponentModelDocumentProvider getDocumentProvider() { |
| 243 | if (documentProvider == null) { |
| 244 | documentProvider = new PalladioComponentModelDocumentProvider(); |
| 245 | } |
| 246 | return documentProvider; |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * @generated |
| 251 | */ |
| 252 | public void logError(String error) { |
| 253 | logError(error, null); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * @param throwable actual error or null could be passed |
| 258 | * @generated |
| 259 | */ |
| 260 | public void logError(String error, Throwable throwable) { |
| 261 | if (error == null && throwable != null) { |
| 262 | error = throwable.getMessage(); |
| 263 | } |
| 264 | getLog().log( |
| 265 | new Status(IStatus.ERROR, |
| 266 | PalladioComponentModelAllocationDiagramEditorPlugin.ID, |
| 267 | IStatus.OK, error, throwable)); |
| 268 | debug(error, throwable); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @generated |
| 273 | */ |
| 274 | public void logInfo(String message) { |
| 275 | logInfo(message, null); |
| 276 | } |
| 277 | |
| 278 | /** |
| 279 | * @param throwable actual error or null could be passed |
| 280 | * @generated |
| 281 | */ |
| 282 | public void logInfo(String message, Throwable throwable) { |
| 283 | if (message == null && throwable != null) { |
| 284 | message = throwable.getMessage(); |
| 285 | } |
| 286 | getLog().log( |
| 287 | new Status(IStatus.INFO, |
| 288 | PalladioComponentModelAllocationDiagramEditorPlugin.ID, |
| 289 | IStatus.OK, message, throwable)); |
| 290 | debug(message, throwable); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * @generated |
| 295 | */ |
| 296 | private void debug(String message, Throwable throwable) { |
| 297 | if (!isDebugging()) { |
| 298 | return; |
| 299 | } |
| 300 | if (message != null) { |
| 301 | System.err.println(message); |
| 302 | } |
| 303 | if (throwable != null) { |
| 304 | throwable.printStackTrace(); |
| 305 | } |
| 306 | } |
| 307 | } |