blob: 6431ab6b59a77a46da4eed83682f25f3c1bd968f [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2005, 2019 SAP SE
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* Contributors:
* SAP SE - initial API, implementation and documentation
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.graphiti.examples.tutorial.features;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EcoreFactory;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICreateContext;
import org.eclipse.graphiti.features.impl.AbstractCreateFeature;
import org.eclipse.graphiti.mm.pictograms.Diagram;
public class TutorialCreateEClassFeature extends AbstractCreateFeature {
public TutorialCreateEClassFeature(IFeatureProvider fp) {
// set name and description of the creation feature
super(fp, "EClass", "Create EClass"); //$NON-NLS-1$ //$NON-NLS-2$
}
public boolean canCreate(ICreateContext context) {
return context.getTargetContainer() instanceof Diagram;
}
public Object[] create(ICreateContext context) {
// create EClass
EClass newClass = EcoreFactory.eINSTANCE.createEClass();
// Add model element to resource.
// We add the model element to the resource of the diagram for
// simplicity's sake. Normally, a customer would use its own
// model persistence layer for storing the business model separately.
getDiagram().eResource().getContents().add(newClass);
// Use the following instead of the above line to store the model
// data in a seperate file parallel to the diagram file
// try {
// try {
// TutorialUtil.saveToModelFile(newClass, getDiagram());
// } catch (IOException e) {
// e.printStackTrace();
// }
// } catch (CoreException e) {
// e.printStackTrace();
// }
// do the add
addGraphicalRepresentation(context, newClass);
// activate direct editing after object creation
getFeatureProvider().getDirectEditingInfo().setActive(true);
// return newly created business object(s)
return new Object[] { newClass };
}
}