| package org.eclipse.gmf.examples.eclipsecon.diagram.part; |
| |
| import java.util.ArrayList; |
| import java.util.List; |
| |
| import org.eclipse.core.runtime.IStatus; |
| import org.eclipse.core.runtime.Status; |
| |
| import org.eclipse.emf.common.notify.AdapterFactory; |
| import org.eclipse.emf.edit.provider.ComposedAdapterFactory; |
| import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory; |
| import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory; |
| import org.eclipse.emf.edit.ui.provider.ExtendedImageRegistry; |
| import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint; |
| import org.eclipse.jface.resource.ImageDescriptor; |
| import org.eclipse.swt.graphics.Image; |
| import org.eclipse.ui.plugin.AbstractUIPlugin; |
| import org.osgi.framework.BundleContext; |
| import org.eclipse.gmf.examples.eclipsecon.EclipseconPackage; |
| |
| import org.eclipse.gmf.examples.eclipsecon.diagram.providers.EclipseconElementTypes; |
| |
| import org.eclipse.gmf.examples.eclipsecon.provider.EclipseconEditPlugin; |
| import org.eclipse.gmf.examples.eclipsecon.provider.EclipseconItemProviderAdapterFactory; |
| |
| import org.eclipse.gmf.runtime.emf.core.internal.util.MSLAdapterFactoryManager; |
| import org.eclipse.gmf.runtime.emf.core.internal.util.MetamodelManager; |
| |
| /** |
| * @generated |
| */ |
| public class EclipseconDiagramEditorPlugin extends AbstractUIPlugin { |
| |
| /** |
| * @generated |
| */ |
| public static final String ID = "org.eclipse.gmf.examples.eclipsecon.diagram"; //$NON-NLS-1$ |
| |
| /** |
| * @generated |
| */ |
| public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint( |
| ID); |
| |
| /** |
| * @generated |
| */ |
| private static EclipseconDiagramEditorPlugin instance; |
| |
| /** |
| * @generated |
| */ |
| private ComposedAdapterFactory adapterFactory; |
| |
| /** |
| * @generated |
| */ |
| public EclipseconDiagramEditorPlugin() { |
| } |
| |
| /** |
| * @generated |
| */ |
| public void start(BundleContext context) throws Exception { |
| super.start(context); |
| instance = this; |
| PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, |
| getPreferenceStore()); |
| MSLAdapterFactoryManager |
| .register(new EclipseconItemProviderAdapterFactory()); |
| MetamodelManager.register(EclipseconPackage.eINSTANCE, |
| EclipseconEditPlugin.INSTANCE); |
| EclipseconElementTypes.register(); |
| adapterFactory = createAdapterFactory(); |
| } |
| |
| /** |
| * @generated |
| */ |
| public void stop(BundleContext context) throws Exception { |
| adapterFactory.dispose(); |
| adapterFactory = null; |
| instance = null; |
| super.stop(context); |
| } |
| |
| /** |
| * @generated |
| */ |
| public static EclipseconDiagramEditorPlugin getInstance() { |
| return instance; |
| } |
| |
| /** |
| * @generated |
| */ |
| protected ComposedAdapterFactory createAdapterFactory() { |
| List factories = new ArrayList(); |
| fillItemProviderFactories(factories); |
| return new ComposedAdapterFactory(factories); |
| } |
| |
| /** |
| * @generated |
| */ |
| protected void fillItemProviderFactories(List factories) { |
| factories.add(new EclipseconItemProviderAdapterFactory()); |
| factories.add(new ResourceItemProviderAdapterFactory()); |
| factories.add(new ReflectiveItemProviderAdapterFactory()); |
| } |
| |
| /** |
| * @generated |
| */ |
| public AdapterFactory getItemProvidersAdapterFactory() { |
| return adapterFactory; |
| } |
| |
| /** |
| * @generated |
| */ |
| public ImageDescriptor getItemImageDescriptor(Object item) { |
| IItemLabelProvider labelProvider = (IItemLabelProvider) adapterFactory |
| .adapt(item, IItemLabelProvider.class); |
| if (labelProvider != null) { |
| return ExtendedImageRegistry.getInstance().getImageDescriptor( |
| labelProvider.getImage(item)); |
| } |
| return null; |
| } |
| |
| /** |
| * Returns an image descriptor for the image file at the given |
| * plug-in relative path. |
| * |
| * @generated |
| * @param path the path |
| * @return the image descriptor |
| */ |
| public static ImageDescriptor getBundledImageDescriptor(String path) { |
| return AbstractUIPlugin.imageDescriptorFromPlugin(ID, path); |
| } |
| |
| /** |
| * Returns an image for the image file at the given plug-in relative path. |
| * Client do not need to dispose this image. Images will be disposed automatically. |
| * |
| * @generated |
| * @param path the path |
| * @return image instance |
| */ |
| public Image getBundledImage(String path) { |
| Image image = getImageRegistry().get(path); |
| if (image == null) { |
| getImageRegistry().put(path, getBundledImageDescriptor(path)); |
| image = getImageRegistry().get(path); |
| } |
| return image; |
| } |
| |
| /** |
| * @generated |
| */ |
| public void logError(String error) { |
| logError(error, null); |
| } |
| |
| /** |
| * @param throwable actual error or null could be passed |
| * @generated |
| */ |
| public void logError(String error, Throwable throwable) { |
| if (error == null && throwable != null) { |
| error = throwable.getMessage(); |
| } |
| getLog().log( |
| new Status(IStatus.ERROR, EclipseconDiagramEditorPlugin.ID, |
| IStatus.OK, error, throwable)); |
| debug(error, throwable); |
| } |
| |
| /** |
| * @generated |
| */ |
| public void logInfo(String message) { |
| logInfo(message, null); |
| } |
| |
| /** |
| * @param throwable actual error or null could be passed |
| * @generated |
| */ |
| public void logInfo(String message, Throwable throwable) { |
| if (message == null && message != null) { |
| message = throwable.getMessage(); |
| } |
| getLog().log( |
| new Status(IStatus.INFO, EclipseconDiagramEditorPlugin.ID, |
| IStatus.OK, message, throwable)); |
| debug(message, throwable); |
| } |
| |
| /** |
| * @generated |
| */ |
| private void debug(String message, Throwable throwable) { |
| if (!isDebugging()) { |
| return; |
| } |
| if (message != null) { |
| System.err.println(message); |
| } |
| if (throwable != null) { |
| throwable.printStackTrace(); |
| } |
| } |
| |
| } |