blob: c50fd47ffb410b79f6f9cbb443d24baa38a4e859 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Lunifera GmbH (Gross Enzersdorf), Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Florian Pirchner (Lunifera GmbH) - initial implementation
*/
package org.eclipse.osbp.tools.graphical.entity.lib;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.osbp.dsl.semantic.common.types.LTypedPackage;
import org.eclipse.osbp.dsl.semantic.entity.LBean;
import org.eclipse.osbp.xtext.oxtype.oxtype.OXImportDeclaration;
import org.eclipse.osbp.xtext.oxtype.oxtype.OXtypeFactory;
import org.eclipse.sirius.tools.api.ui.IExternalJavaAction;
import org.eclipse.xtext.xtype.XImportSection;
public class LBeanInheritancePackageImport implements IExternalJavaAction {
public LBeanInheritancePackageImport() {
}
@Override
public void execute(Collection<? extends EObject> selections, Map<String, Object> parameters) {
LBean subtype = (LBean) new ArrayList<EObject>(selections).get(0);
LBean supertype = subtype.getSuperType();
LTypedPackage sourcePackage = (LTypedPackage) subtype.eContainer();
LTypedPackage targetPackage = (LTypedPackage) supertype.eContainer();
XImportSection section = Util.getImportSecion(sourcePackage);
if (targetPackage == sourcePackage) {
return;
} else {
OXImportDeclaration newImport = OXtypeFactory.eINSTANCE.createOXImportDeclaration();
newImport.setImportedFullyQualifiedName(Util.getFQN(supertype));
newImport.setFqnImport(true);
section.getImportDeclarations().add(newImport);
}
}
@Override
public boolean canExecute(Collection<? extends EObject> selections) {
return true;
}
}