/* * License (BSD Style License): * Copyright (c) 2011 * Software Engineering * Department of Computer Science * Technische Universität Darmstadt * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * - Neither the name of the Software Engineering Group or Technische * Universität Darmstadt nor the names of its contributors may be used to * endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ package de.tud.cs.st.vespucci.vespucci_model.diagram.part; import java.util.ArrayList; import java.util.List; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; 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; /** * @generated */ public class VespucciDiagramEditorPlugin extends AbstractUIPlugin { /** * @generated */ public static final String ID = "de.tud.cs.st.vespucci.diagram"; //$NON-NLS-1$ /** * @generated */ public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint(ID); /** * @generated */ private static VespucciDiagramEditorPlugin instance; /** * @generated */ private ComposedAdapterFactory adapterFactory; /** * @generated */ private de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciDocumentProvider documentProvider; /** * @generated */ private de.tud.cs.st.vespucci.vespucci_model.diagram.edit.policies.VespucciBaseItemSemanticEditPolicy.LinkConstraints linkConstraints; /** * @generated */ private de.tud.cs.st.vespucci.vespucci_model.diagram.providers.ElementInitializers initializers; /** * @generated */ private de.tud.cs.st.vespucci.vespucci_model.diagram.expressions.VespucciOCLFactory oclFactory; /** * @generated */ public VespucciDiagramEditorPlugin() { } /** * @generated */ public void start(BundleContext context) throws Exception { super.start(context); instance = this; PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, getPreferenceStore()); adapterFactory = createAdapterFactory(); } /** * @generated */ public void stop(BundleContext context) throws Exception { adapterFactory.dispose(); adapterFactory = null; linkConstraints = null; initializers = null; oclFactory = null; instance = null; super.stop(context); } /** * @generated */ public static VespucciDiagramEditorPlugin getInstance() { return instance; } /** * @generated */ protected ComposedAdapterFactory createAdapterFactory() { ArrayList<AdapterFactory> factories = new ArrayList<AdapterFactory>(); fillItemProviderFactories(factories); return new ComposedAdapterFactory(factories); } /** * @generated */ protected void fillItemProviderFactories(List<AdapterFactory> factories) { factories.add(new de.tud.cs.st.vespucci.vespucci_model.provider.Vespucci_modelItemProviderAdapterFactory()); 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); } /** * Respects images residing in any plug-in. If path is relative, * then this bundle is looked up for the image, otherwise, for absolute * path, first segment is taken as id of plug-in with image * * @generated * @param path the path to image, either absolute (with plug-in id as first segment), or relative for bundled images * @return the image descriptor */ public static ImageDescriptor findImageDescriptor(String path) { final IPath p = new Path(path); if (p.isAbsolute() && p.segmentCount() > 1) { return AbstractUIPlugin.imageDescriptorFromPlugin(p.segment(0), p.removeFirstSegments(1).makeAbsolute().toString()); } else { return getBundledImageDescriptor(p.makeAbsolute().toString()); } } /** * 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; } /** * Returns string from plug-in's resource bundle * * @generated */ public static String getString(String key) { return Platform.getResourceString(getInstance().getBundle(), "%" + key); //$NON-NLS-1$ } /** * @generated */ public de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciDocumentProvider getDocumentProvider() { if (documentProvider == null) { documentProvider = new de.tud.cs.st.vespucci.vespucci_model.diagram.part.VespucciDocumentProvider(); } return documentProvider; } /** * @generated */ public de.tud.cs.st.vespucci.vespucci_model.diagram.edit.policies.VespucciBaseItemSemanticEditPolicy.LinkConstraints getLinkConstraints() { return linkConstraints; } /** * @generated */ public void setLinkConstraints( de.tud.cs.st.vespucci.vespucci_model.diagram.edit.policies.VespucciBaseItemSemanticEditPolicy.LinkConstraints lc) { this.linkConstraints = lc; } /** * @generated */ public de.tud.cs.st.vespucci.vespucci_model.diagram.providers.ElementInitializers getElementInitializers() { return initializers; } /** * @generated */ public void setElementInitializers(de.tud.cs.st.vespucci.vespucci_model.diagram.providers.ElementInitializers i) { this.initializers = i; } /** * @generated */ public de.tud.cs.st.vespucci.vespucci_model.diagram.expressions.VespucciOCLFactory getVespucciOCLFactory() { return oclFactory; } /** * @generated */ public void setVespucciOCLFactory(de.tud.cs.st.vespucci.vespucci_model.diagram.expressions.VespucciOCLFactory f) { this.oclFactory = f; } /** * @generated */ public void logError(String error) { logError(error, null); } /** * @generated */ public void logError(String error, Throwable throwable) { if (error == null && throwable != null) { error = throwable.getMessage(); } getLog().log(new Status(IStatus.ERROR, VespucciDiagramEditorPlugin.ID, IStatus.OK, error, throwable)); debug(error, throwable); } /** * @generated */ public void logInfo(String message) { logInfo(message, null); } /** * @generated */ public void logInfo(String message, Throwable throwable) { if (message == null && throwable != null) { message = throwable.getMessage(); } getLog().log(new Status(IStatus.INFO, VespucciDiagramEditorPlugin.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(); } } }