/* * StsToolDiagramEditorPlugin.java * * This file is part of the STS-Tool project. * Copyright (c) 2011-2012 "University of Trento - DISI" All rights reserved. * * Is strictly forbidden to remove this copyright notice from this source code. * * Disclaimer of Warranty: * STS-Tool (this software) is provided "as-is" and without warranty of any kind, * express, implied or otherwise, including without limitation, any warranty of * merchantability or fitness for a particular purpose. * In no event shall the copyright holder 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. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License version 3 * as published by the Free Software Foundation with the addition of the * following permission added to Section 15 as permitted in Section 7(a): * FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY * "University of Trento - DISI","University of Trento - DISI" DISCLAIMS THE * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. * * See the GNU Affero General Public License for more details. * You should have received a copy of the GNU Affero General Public License * along with this program; if not, see http://www.gnu.org/licenses or write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA, 02110-1301 USA, or download the license from the following URL: * http://www.sts-tool.eu/License.php * * For more information, please contact STS-Tool group at this * address: ststool@disi.unitn.it * */ package eu.aniketos.wp1.ststool.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; import eu.aniketos.wp1.ststool.provider.StstoolItemProviderAdapterFactory; /** * @generated */ public class StsToolDiagramEditorPlugin extends AbstractUIPlugin { /** * @generated */ public static final String ID = "eu.aniketos.wp1.ststool.diagram"; //$NON-NLS-1$ /** * @generated */ public static final PreferencesHint DIAGRAM_PREFERENCES_HINT = new PreferencesHint(ID); /** * @generated */ private static StsToolDiagramEditorPlugin instance; /** * @generated */ private ComposedAdapterFactory adapterFactory; /** * @generated */ private StsToolDocumentProvider documentProvider; /** * @generated */ public StsToolDiagramEditorPlugin() { } /** * @generated */ @Override public void start(BundleContext context) throws Exception{ super.start(context); instance = this; PreferencesHint.registerPreferenceStore(DIAGRAM_PREFERENCES_HINT, getPreferenceStore()); adapterFactory = createAdapterFactory(); } /** * @generated */ @Override public void stop(BundleContext context) throws Exception{ adapterFactory.dispose(); adapterFactory = null; instance = null; super.stop(context); } /** * @generated */ public static StsToolDiagramEditorPlugin 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 StstoolItemProviderAdapterFactory()); 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 StsToolDocumentProvider getDocumentProvider(){ if (documentProvider == null) { documentProvider = new StsToolDocumentProvider(); } return documentProvider; } /** * @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, StsToolDiagramEditorPlugin.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, StsToolDiagramEditorPlugin.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(); } } }