/******************************************************************************* | |
* <copyright> | |
* | |
* Copyright (c) 2013, 2013 SAP AG. | |
* All rights reserved. This program and the accompanying materials | |
* are made available under the terms of the Eclipse Public License v1.0 | |
* which accompanies this distribution, and is available at | |
* http://www.eclipse.org/legal/epl-v10.html | |
* | |
* Contributors: | |
* SAP AG - initial API, implementation and documentation | |
* | |
* </copyright> | |
* | |
*******************************************************************************/ | |
package org.eclipse.fmc.blockdiagram.editor.meta.diagram; | |
import java.util.Map; | |
import org.eclipse.core.runtime.CoreException; | |
import org.eclipse.core.runtime.IConfigurationElement; | |
import org.eclipse.core.runtime.IExtensionRegistry; | |
import org.eclipse.core.runtime.Platform; | |
import org.eclipse.emf.ecore.EObject; | |
import org.eclipse.emf.ecore.resource.Resource; | |
import org.eclipse.emf.ecore.xmi.XMLResource; | |
import org.eclipse.fmc.blockdiagram.editor.diagram.BlockDiagramTypeProvider; | |
import org.eclipse.fmc.blockdiagram.editor.meta.BlockDiagramMetaFeatureProvider; | |
import org.eclipse.fmc.blockdiagram.editor.meta.profile.IDiagramSaved; | |
import org.eclipse.fmc.blockdiagram.editor.util.FMCUtil; | |
import org.eclipse.fmc.mm.FMCModel; | |
import org.eclipse.graphiti.mm.pictograms.Diagram; | |
import org.eclipse.graphiti.mm.pictograms.Shape; | |
/** | |
* Diagram provider class. | |
* | |
* @author Patrick Jahnke | |
* | |
*/ | |
public class BlockDiagramMetaDiagramTypeProvider extends BlockDiagramTypeProvider { | |
/** | |
* The save options map. | |
*/ | |
private static Map<String, Object> saveOptions = new java.util.HashMap<String, Object>(); | |
static { | |
saveOptions.put(XMLResource.OPTION_SAVE_TYPE_INFORMATION, true); | |
} | |
/** | |
* Constructor which call the super constructor an set a feature provider. | |
*/ | |
public BlockDiagramMetaDiagramTypeProvider() { | |
super(); | |
setFeatureProvider(new BlockDiagramMetaFeatureProvider(this)); | |
this.setProviderId("org.eclipse.fmc.blockdiagram.providerMeta"); | |
} | |
/** | |
* If the Stereotype Extension is installed forward the diagramSaved info. | |
*/ | |
@Override | |
public void resourcesSaved(Diagram diagram, Resource[] savedResources) { | |
super.resourcesSaved(diagram, savedResources); | |
IExtensionRegistry reg = Platform.getExtensionRegistry(); | |
IConfigurationElement[] extensions = reg | |
.getConfigurationElementsFor("org.eclipse.fmc.blockdiagram.editor.meta.profile"); | |
if (extensions.length == 1) { | |
IDiagramSaved entry; | |
try { | |
entry = (IDiagramSaved) extensions[0] | |
.createExecutableExtension("diagramSaved"); | |
entry.diagramSaved(diagram, getFMCModel(), savedResources); | |
} catch (CoreException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
/** | |
* Get the FMCModel which is represent the diagram. | |
* | |
* @return | |
*/ | |
private FMCModel getFMCModel() { | |
for (Shape shape : this.getDiagram().getChildren()) { | |
EObject eObject = FMCUtil.getBO(shape); | |
if ((eObject != null) && (eObject.eContainer() != null) | |
&& (eObject.eContainer() instanceof FMCModel)) { | |
return (FMCModel) eObject.eContainer(); | |
} | |
} | |
return null; | |
} | |
} |