package kr.co.apexsoft.stella.modeler.explorer; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Set; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.edit.EMFEditPlugin; import org.eclipse.emf.facet.infra.browser.Messages; import org.eclipse.emf.facet.infra.browser.custom.MetamodelView; import org.eclipse.emf.facet.infra.browser.custom.TypeView; import org.eclipse.emf.facet.infra.browser.custom.core.CustomizationsCatalog; import org.eclipse.emf.facet.infra.browser.uicore.CustomizationManager; import org.eclipse.emf.facet.infra.facet.Facet; import org.eclipse.emf.facet.infra.facet.FacetSet; import org.eclipse.emf.facet.infra.facet.core.FacetSetCatalog; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osgi.util.NLS; import org.eclipse.papyrus.infra.core.log.LogHelper; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.osgi.framework.BundleContext; public class Activator extends AbstractUIPlugin implements org.eclipse.ui.IStartup { /** The plug-in ID */ public static final String PLUGIN_ID = "kr.co.apexsoft.stella.modeler.explorer"; //$NON-NLS-1$ /** The plug-in shared instance */ private static Activator plugin; /** The log service */ public static LogHelper log; private CustomizationManager fCustomizationManager; /* * (non-Javadoc) * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ public void start(BundleContext bundleContext) throws Exception { super.start(bundleContext); plugin = this; log = new LogHelper(plugin); EMFEditPlugin.getComposedAdapterFactoryDescriptorRegistry(); } /* * (non-Javadoc) * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext bundleContext) throws Exception { plugin = null; super.stop(bundleContext); } @Override public void earlyStartup() { // TODO Auto-generated method stub } /** * get the image descriptor from a string path * * @param pathString * path of the image * @return the image descriptor */ public static ImageDescriptor getImageDescriptor(String pathString) { IPath path = new Path(pathString); URL uri = FileLocator.find(Activator.plugin.getBundle(), path, null); if(uri == null) { return null; } return ImageDescriptor.createFromURL(uri); } /** * Returns the shared instance * * @return the shared instance */ public static Activator getDefault() { return plugin; } /** * * @return the customization manager in charge to adapt element in modisco */ public CustomizationManager getCustomizationManager() { // return org.eclipse.papyrus.infra.emf.Activator.getDefault().getCustomizationManager(); if(this.fCustomizationManager == null) { this.fCustomizationManager = new CustomizationManager(); init(this.fCustomizationManager); } return this.fCustomizationManager; } private void init(final CustomizationManager customizationManager) { // the appearance can be customized here: customizationManager.setShowDerivedLinks(true); //to hide the blue arrow overlay customizationManager.setDecorateExternalResources(false); try { // load customizations defined as default through the customization // extension List<MetamodelView> registryDefaultCustomizations = CustomizationsCatalog.getInstance().getRegistryDefaultCustomizations(); for(MetamodelView metamodelView : registryDefaultCustomizations) { customizationManager.registerCustomization(metamodelView); } customizationManager.loadCustomizations(); loadFacetsForCustomizations(registryDefaultCustomizations,customizationManager); } catch (Throwable e) { Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error initializing customizations", e)); //$NON-NLS-1$ } } /** * load the facets * * @param customizations * list of customization * @param customizationManager * the Customization Manager */ protected void loadFacetsForCustomizations( final List<MetamodelView> customizations, final CustomizationManager customizationManager) { final Set<Facet> referencedFacets = new HashSet<Facet>(); final Collection<FacetSet> facetSets = FacetSetCatalog.getSingleton() .getAllFacetSets(); for (MetamodelView customization : customizations) { String metamodelURI = customization.getMetamodelURI(); // find customized FacetSet FacetSet customizedFacetSet = null; if (metamodelURI != null) { for (FacetSet facetSet : facetSets) { if (metamodelURI.equals(facetSet.getNsURI())) { customizedFacetSet = facetSet; break; } } } if (customizedFacetSet == null) { continue; } // find customized Facets EList<TypeView> types = customization.getTypes(); for (TypeView typeView : types) { String metaclassName = typeView.getMetaclassName(); Facet facet = findFacetWithFullyQualifiedName(metaclassName, customizedFacetSet); if (facet != null) { referencedFacets.add(facet); } else { Activator.log.warn(NLS .bind( Messages.BrowserActionBarContributor_missingRequiredFacet, new Object[] { metaclassName, customizedFacetSet .getName(), customization.getName() })); } } for (Facet referencedFacet : referencedFacets) { customizationManager.loadFacet(referencedFacet); } } // // for modified facets // customizationManager.getInstancesForMetaclasses().buildDerivationTree(); // customizationManager.getAppearanceConfiguration().touch(); // customizationManager.refreshDelayed(true); } /** * fin a facet from * * @param metaclassName * @param customizedFacetSet * @return */ private Facet findFacetWithFullyQualifiedName(final String metaclassName, final FacetSet customizedFacetSet) { EList<Facet> facets = customizedFacetSet.getFacets(); for (Facet facet : facets) { String facetName = getMetaclassQualifiedName(facet); if (metaclassName.equals(facetName)) { return facet; } } return null; } /** @return the qualified name of the given metaclass */ public static String getMetaclassQualifiedName(final EClassifier eClass) { final ArrayList<String> qualifiedNameParts = new ArrayList<String>(); final StringBuilder builder = new StringBuilder(); EPackage ePackage = eClass.getEPackage(); while (ePackage != null) { qualifiedNameParts.add(ePackage.getName()); ePackage = ePackage.getESuperPackage(); } for (int i = qualifiedNameParts.size() - 1; i >= 0; i--) { builder.append(qualifiedNameParts.get(i) + "."); //$NON-NLS-1$ } builder.append(eClass.getName()); return builder.toString(); } public static ImageDescriptor getIDEImageDescriptor(String imagePath) { return AbstractUIPlugin.imageDescriptorFromPlugin(Activator.PLUGIN_ID, imagePath); } }