blob: f7692790f1d2316423ccd136196d6dccb6e43cc5 [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.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.ICustomContext;
import org.eclipse.graphiti.features.custom.AbstractCustomFeature;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;
public class TutorialAssociateDiagramEClassFeature extends AbstractCustomFeature {
public TutorialAssociateDiagramEClassFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public String getName() {
return "&Associate diagram"; //$NON-NLS-1$
}
@Override
public String getDescription() {
return "Associate the diagram with this EClass"; //$NON-NLS-1$
}
@Override
public boolean canExecute(ICustomContext context) {
boolean ret = false;
PictogramElement[] pes = context.getPictogramElements();
if (pes != null && pes.length >= 1) {
ret = true;
for (PictogramElement pe : pes) {
Object bo = getBusinessObjectForPictogramElement(pe);
if (!(bo instanceof EClass)) {
ret = false;
}
}
}
return ret;
}
public void execute(ICustomContext context) {
PictogramElement[] pes = context.getPictogramElements();
EClass eClasses[] = new EClass[pes.length];
for (int i = 0; i < eClasses.length; i++) {
eClasses[i] = (EClass) getBusinessObjectForPictogramElement(pes[i]);
}
// associate selected EClass with diagram
link(getDiagram(), eClasses);
}
}