diff options
Diffstat (limited to 'extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src')
6 files changed, 0 insertions, 995 deletions
diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/Activator.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/Activator.java deleted file mode 100644 index 660f2e68655..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/Activator.java +++ /dev/null @@ -1,72 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 CEA LIST. - * - * 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.composites.utils; - -import org.eclipse.ui.IStartup; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.osgi.framework.BundleContext; - -/** - * The activator class controls the plug-in life cycle - */ -public class Activator extends AbstractUIPlugin implements IStartup { - - // The plug-in ID - public static final String PLUGIN_ID = "org.eclipse.papyrus.moka.composites.utils"; //$NON-NLS-1$ - - // The shared instance - private static Activator plugin; - - /** - * The constructor - */ - public Activator() { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) - */ - @Override - public void start(BundleContext context) throws Exception { - super.start(context); - plugin = this; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) - */ - @Override - public void stop(BundleContext context) throws Exception { - plugin = null; - super.stop(context); - } - - /** - * Returns the shared instance - * - * @return the shared instance - */ - public static Activator getDefault() { - return plugin; - } - - @Override - public void earlyStartup() { - // TODO Auto-generated method stub - - } - -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/AbstractCompositeUtilsHandler.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/AbstractCompositeUtilsHandler.java deleted file mode 100644 index ec757075f99..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/AbstractCompositeUtilsHandler.java +++ /dev/null @@ -1,93 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 CEA LIST. - * - * 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.composites.utils.handlers; - -import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.commands.ExecutionEvent; -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.papyrus.infra.emf.utils.EMFHelper; -import org.eclipse.ui.handlers.HandlerUtil; -import org.eclipse.uml2.uml.Behavior; -import org.eclipse.uml2.uml.Class; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.NamedElement; - -public abstract class AbstractCompositeUtilsHandler extends AbstractHandler { - - - /** - * Moka Modeling Utils menu are enable only if selected object refer as a Class - * - * (non-Javadoc) - * - * @see org.eclipse.core.commands.AbstractHandler#isEnabled() - */ - @Override - public boolean isEnabled() { - Element selectedElement = Utils.getSelection(); - if (selectedElement != null) { - return selectedElement instanceof Class && !(selectedElement instanceof Behavior); - } - return false; - } - - /** - * Return the class associated with the selection object or null whether - * no class could have been found - * - * @param selected - * @return Class - */ - protected Class getClassFromSelection(ISelection selected) { - if (selected.isEmpty()) { - return null; - } else { - // Every object retrieved from the model explorer is an IAdaptable - IAdaptable adaptableObj = (IAdaptable) ((IStructuredSelection) selected).getFirstElement(); - // Get the model object behind the adaptable object - EObject modelObj = (EObject) adaptableObj.getAdapter(org.eclipse.emf.ecore.EObject.class); - NamedElement nElem = (NamedElement) modelObj; - return nElem instanceof Class ? (Class) nElem : null; - } - } - - @Override - public Object execute(ExecutionEvent event) throws ExecutionException { - Class context = null; - context = this.getClassFromSelection(HandlerUtil.getCurrentSelection(event)); - if (context != null) { - this.start(context); - } - return null; - } - - /** - * Launch the ConstructorBehaviorCreationCompiler - * - * @param myClass - * which is the class who need to create the constructor - * - */ - public void start(Class myClass) { - TransactionalEditingDomain domain = (TransactionalEditingDomain) EMFHelper.resolveEditingDomain(myClass); - RecordingCommand updateCommand = this.getUpdateCommand(myClass, domain); - domain.getCommandStack().execute(updateCommand); - } - - public abstract RecordingCommand getUpdateCommand(Class myClass, TransactionalEditingDomain domain); -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateConstructorUsingFieldsHandler.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateConstructorUsingFieldsHandler.java deleted file mode 100644 index af4883b4783..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateConstructorUsingFieldsHandler.java +++ /dev/null @@ -1,57 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 CEA LIST. - * - * 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.composites.utils.handlers; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.papyrus.moka.composites.utils.ui.GenerateConstructorUsingFieldsDialog; -import org.eclipse.swt.widgets.Display; -import org.eclipse.uml2.uml.Class; - - -public class GenerateConstructorUsingFieldsHandler extends AbstractCompositeUtilsHandler { - - @Override - public RecordingCommand getUpdateCommand(Class context, TransactionalEditingDomain domain) { - return new GenerateConstructorUsingFieldsCommand(context, domain); - } - - /** - * A command that generates a Constructor for a Class, from a dialog box. - * - * @see GenerateConstructorUsingFieldsDialog - * - */ - protected class GenerateConstructorUsingFieldsCommand extends RecordingCommand { - - protected Class context; - - public GenerateConstructorUsingFieldsCommand(Class context, TransactionalEditingDomain domain) { - super(domain); - this.context = context; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor - * , org.eclipse.core.runtime.IAdaptable) - */ - @Override - protected void doExecute() { - GenerateConstructorUsingFieldsDialog dialog = new GenerateConstructorUsingFieldsDialog(Display.getCurrent().getActiveShell(), context); - dialog.open(); - } - } - -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateFactoryHandler.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateFactoryHandler.java deleted file mode 100644 index a9a16e219cb..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/GenerateFactoryHandler.java +++ /dev/null @@ -1,52 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 CEA LIST. - * - * 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.composites.utils.handlers; - -import org.eclipse.emf.transaction.RecordingCommand; -import org.eclipse.emf.transaction.TransactionalEditingDomain; -import org.eclipse.uml2.uml.Class; - - -public class GenerateFactoryHandler extends AbstractCompositeUtilsHandler { - - @Override - public RecordingCommand getUpdateCommand(Class context, TransactionalEditingDomain domain) { - return new GenerateFactoryCommand(context, domain); - } - - /** - * Command that generate factory for a given class. - * - * @see Utils.getFactory - */ - protected class GenerateFactoryCommand extends RecordingCommand { - - protected Class context; - - public GenerateFactoryCommand(Class context, TransactionalEditingDomain domain) { - super(domain); - this.context = context; - } - - /* - * (non-Javadoc) - * - * @see - * org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor - * , org.eclipse.core.runtime.IAdaptable) - */ - @Override - protected void doExecute() { - Utils.getFactory(context); - } - } -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/Utils.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/Utils.java deleted file mode 100644 index 0fce3355362..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/handlers/Utils.java +++ /dev/null @@ -1,289 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 CEA LIST. - * - * 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.composites.utils.handlers; - -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart; -import org.eclipse.gmf.runtime.notation.View; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.papyrus.uml.extensionpoints.profile.IRegisteredProfile; -import org.eclipse.papyrus.uml.extensionpoints.profile.RegisteredProfile; -import org.eclipse.papyrus.uml.extensionpoints.utils.Util; -import org.eclipse.papyrus.uml.tools.utils.PackageUtil; -import org.eclipse.ui.ISelectionService; -import org.eclipse.ui.PlatformUI; -import org.eclipse.uml2.uml.Activity; -import org.eclipse.uml2.uml.ActivityParameterNode; -import org.eclipse.uml2.uml.Behavior; -import org.eclipse.uml2.uml.CallOperationAction; -import org.eclipse.uml2.uml.Class; -import org.eclipse.uml2.uml.CreateObjectAction; -import org.eclipse.uml2.uml.Element; -import org.eclipse.uml2.uml.ForkNode; -import org.eclipse.uml2.uml.InputPin; -import org.eclipse.uml2.uml.LiteralInteger; -import org.eclipse.uml2.uml.ObjectFlow; -import org.eclipse.uml2.uml.Operation; -import org.eclipse.uml2.uml.OutputPin; -import org.eclipse.uml2.uml.Parameter; -import org.eclipse.uml2.uml.ParameterDirectionKind; -import org.eclipse.uml2.uml.Profile; -import org.eclipse.uml2.uml.StartObjectBehaviorAction; -import org.eclipse.uml2.uml.Stereotype; -import org.eclipse.uml2.uml.UMLFactory; -import org.eclipse.uml2.uml.UMLPackage; - -public class Utils { - - public static Profile standardProfile; - - public static String STANDARD_PROFILE_NAME = "Standard"; - - - /** - * Generates (or retrieve) a factory Activity for the given context Class. - * A factory Activity consists in a CreateObjectAction for the given context Class, - * followed by a CallOperationAction for the default constructor of this class. - * - * @param context - * The class for which a Factory is requested - * @return A factory Activity for the given context Class - */ - public static Activity getFactory(Class context) { - - // First try to retrieve the factory - // Retrieval is based on name. - Activity factory = null; - String contextName = context.getName() == null ? "" : context.getName(); - for (Iterator<Behavior> i = context.getOwnedBehaviors().iterator(); i.hasNext() && factory == null;) { - Behavior cddFactory = i.next(); - String cddName = cddFactory.getName() == null ? "" : cddFactory.getName(); - if (cddFactory instanceof Activity && cddName.equals(contextName + "_Factory")) { - factory = (Activity) cddFactory; - } - } - - Parameter returnParam = null; - // if the factory does not exist, then creates it, otherwise "cleans" it - if (factory == null) { - factory = (Activity) context.createOwnedBehavior(context.getName() + "_Factory", UMLPackage.eINSTANCE.getActivity()); - returnParam = factory.createOwnedParameter("result", context); - returnParam.setDirection(ParameterDirectionKind.RETURN_LITERAL); - } else { - factory.getNodes().clear(); - factory.getEdges().clear(); - for (Iterator<Parameter> i = factory.getOwnedParameters().iterator(); i.hasNext() && returnParam == null;) { - Parameter cddReturn = i.next(); - if (cddReturn.getDirection() == ParameterDirectionKind.RETURN_LITERAL) { - returnParam = cddReturn; - } - } - if (returnParam == null) { - returnParam = factory.createOwnedParameter("result", context); - returnParam.setDirection(ParameterDirectionKind.RETURN_LITERAL); - } - } - - ActivityParameterNode returnParamNode = (ActivityParameterNode) factory.createOwnedNode("resultParameterNode", UMLPackage.eINSTANCE.getActivityParameterNode()); - returnParamNode.setParameter(returnParam); - returnParamNode.setType(context); - LiteralInteger returnParamNodeUpperBound = UMLFactory.eINSTANCE.createLiteralInteger(); - returnParamNodeUpperBound.setValue(1); - returnParamNode.setUpperBound(returnParamNodeUpperBound); - - // Retrieves the default constructor of context - Operation defaultConstructor = getDefaultConstructor(context); - - CreateObjectAction createObject = (CreateObjectAction) factory.createOwnedNode("createObject", UMLPackage.eINSTANCE.getCreateObjectAction()); - OutputPin createObjectResultPin = createObject.createResult("result", context); - LiteralInteger createObjectResultPinUpperBound = UMLFactory.eINSTANCE.createLiteralInteger(); - createObjectResultPinUpperBound.setValue(1); - createObjectResultPin.setUpperBound(createObjectResultPinUpperBound); - createObject.setClassifier(context); - - CallOperationAction callConstructor = (CallOperationAction) factory.createOwnedNode("callConstructor", UMLPackage.eINSTANCE.getCallOperationAction()); - callConstructor.setOperation(defaultConstructor); - InputPin callConstructorTargetPin = callConstructor.createTarget("target", context); - LiteralInteger callConstructorTargetPinUpperBound = UMLFactory.eINSTANCE.createLiteralInteger(); - callConstructorTargetPinUpperBound.setValue(1); - callConstructorTargetPin.setUpperBound(callConstructorTargetPinUpperBound); - OutputPin callConstructorResultPin = callConstructor.createResult("result", context); - LiteralInteger callConstructorResultPinUpperBound = UMLFactory.eINSTANCE.createLiteralInteger(); - callConstructorResultPinUpperBound.setValue(1); - callConstructorResultPin.setUpperBound(callConstructorResultPinUpperBound); - - ObjectFlow createObjectAction_callConstructor = (ObjectFlow) factory.createEdge("createObjectAction to callConstructor", UMLPackage.eINSTANCE.getObjectFlow()); - createObjectAction_callConstructor.setSource(createObjectResultPin); - createObjectAction_callConstructor.setTarget(callConstructorTargetPin); - - ObjectFlow toReturnParamNode = (ObjectFlow) factory.createEdge("callConstructor to returnParamNode", UMLPackage.eINSTANCE.getObjectFlow()); - toReturnParamNode.setTarget(returnParamNode); - if (!context.isActive()) { - toReturnParamNode.setSource(callConstructorResultPin); - } else { - StartObjectBehaviorAction startBehavior = (StartObjectBehaviorAction) factory.createOwnedNode("start classifier behavior", UMLPackage.eINSTANCE.getStartObjectBehaviorAction()); - InputPin startBehaviorInputPin = startBehavior.createObject("object", context); - LiteralInteger startBehaviorInputPinUpperBound = UMLFactory.eINSTANCE.createLiteralInteger(); - startBehaviorInputPinUpperBound.setValue(1); - startBehaviorInputPin.setUpperBound(startBehaviorInputPinUpperBound); - /* - * // 439321: [Moka] The factory generator of oepm.composite.utils is invalid in the case of an Active class - * // https://bugs.eclipse.org/bugs/show_bug.cgi?id=439321 - * //OutputPin startBehaviorResultPin = startBehavior.createResult("result", context); - * //LiteralInteger startBehaviorResultPinUpperBound = UMLFactory.eINSTANCE.createLiteralInteger(); - * //startBehaviorResultPinUpperBound.setValue(1) ; - * //startBehaviorResultPin.setUpperBound(startBehaviorResultPinUpperBound) ; - * //toReturnParamNode.setSource(startBehaviorResultPin); - */ - ForkNode fork = (ForkNode) factory.createOwnedNode("forkInstanciatedObject", UMLPackage.eINSTANCE.getForkNode()); - toReturnParamNode.setSource(fork); - ObjectFlow forkToStartBehaviorInputPin = (ObjectFlow) factory.createEdge("fork to startbehavior input pin", UMLPackage.eINSTANCE.getObjectFlow()); - forkToStartBehaviorInputPin.setSource(fork); - forkToStartBehaviorInputPin.setTarget(startBehaviorInputPin); - // - ObjectFlow callConstructor_startBehavior = (ObjectFlow) factory.createEdge("callConstructor to startBehavior", UMLPackage.eINSTANCE.getObjectFlow()); - callConstructor_startBehavior.setSource(callConstructorResultPin); - callConstructor_startBehavior.setTarget(fork); - } - - return factory; - } - - /** - * Returns the default constructor of the given UML Class context. - * If the default constructor does not exist, it is the generated, with side effects - * on the given context Class (i.e., the generated constructor is added to the list of - * operations of the given context Class. - * A default constructor for a given context Class is a UML Operation with: - * - constructor.name == context.name - * - a single parameter p such that: p.direction == Return and p.type = context - * - * @param context - * A UML Class - * @return the default constructor Operation for the given context Class - */ - public static Operation getDefaultConstructor(Class context) { - // Returns the default constructor if it exists. - // Creates it otherwise. - Operation createdOp = null; - - // Find operation with "Create" Stereotype - for (int i = 0; i < context.getOwnedOperations().size() && createdOp == null; i++) { - Operation cddOperation = context.getOwnedOperations().get(i); - for (int j = 0; j < cddOperation.getAppliedStereotypes().size(); j++) { - Stereotype createStereotype = cddOperation.getAppliedStereotypes().get(j); - if (createStereotype.getName().equals("Create")) { - if (cddOperation.getName().equals(context.getName())) { - if (cddOperation.getOwnedParameters().size() == 1) { - Parameter returnParameter = cddOperation.getOwnedParameters().get(0); - if (returnParameter.getDirection().equals(ParameterDirectionKind.RETURN_LITERAL)) { - if (returnParameter.getType().getName().equals(context.getName())) { - createdOp = cddOperation; - } - } - } - } - - } - } - } - - // No operation with "Create" Stereotype found : => Creation of the operation. - if (createdOp == null) { - Stereotype appliedStereotype = null; - if (!isStandardProfileApplied(context)) { - PackageUtil.applyProfile(context.getModel(), standardProfile, true); - } - - createdOp = UMLFactory.eINSTANCE.createOperation(); - context.getOwnedOperations().add(createdOp); - - - - for (int j = 0; j < createdOp.getApplicableStereotypes().size() && appliedStereotype == null; j++) { - Stereotype cddStereotype = createdOp.getApplicableStereotypes().get(j); - if (cddStereotype.getName().equals("Create")) { - appliedStereotype = cddStereotype; - } - } - - Parameter result = UMLFactory.eINSTANCE.createParameter(); - result.setDirection(ParameterDirectionKind.RETURN_LITERAL); - result.setType(context); - result.setName("return"); - - createdOp.setName(context.getName()); - createdOp.getOwnedParameters().add(result); - createdOp.applyStereotype(appliedStereotype); - } - - return createdOp; - } - - /** - * Returns true if the Standard profile is applied on the Model containing the given element - * - * @param element - * A UML model element - * @return true if the Standard profile is applied on the Model containing the given element - */ - public static boolean isStandardProfileApplied(Element element) { - if (standardProfile == null) { - IRegisteredProfile registeredProfile = RegisteredProfile.getRegisteredProfile(STANDARD_PROFILE_NAME); - URI modelUri = registeredProfile.getUri(); - Resource modelResource = Util.createTemporaryResourceSet().getResource(modelUri, true); - if (modelResource.getContents().get(0) instanceof Profile) { - standardProfile = (Profile) modelResource.getContents().get(0); - } - } - List<Profile> appliedProfiles = element.getModel().getAppliedProfiles(); - return appliedProfiles.contains(standardProfile); - } - - /** - * Duplicated from SequoiaAbstractHandler. @author Patrick Tessier (CEA). - * getSelected element in the diagram or in hte model explorer - * - * @return Element or null - */ - public static Element getSelection() { - Element selectedElement = null; - ISelectionService selectionService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService(); - ISelection selection = selectionService.getSelection(); - - if (selection instanceof IStructuredSelection) { - Object selectedobject = ((IStructuredSelection) selection).getFirstElement(); - if (selectedobject instanceof GraphicalEditPart) { - Object graphicalElement = ((GraphicalEditPart) selectedobject).getModel(); - if ((graphicalElement instanceof View) && ((View) graphicalElement).getElement() instanceof org.eclipse.uml2.uml.Element) { - selectedElement = (org.eclipse.uml2.uml.Element) ((View) graphicalElement).getElement(); - } - } else if (selectedobject instanceof IAdaptable) { - EObject selectedEObject = (EObject) ((IAdaptable) selectedobject).getAdapter(EObject.class); - if (selectedEObject instanceof org.eclipse.uml2.uml.Element) { - selectedElement = (Element) selectedEObject; - } - } - - return selectedElement; - } - return null; - } - -} diff --git a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/ui/GenerateConstructorUsingFieldsDialog.java b/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/ui/GenerateConstructorUsingFieldsDialog.java deleted file mode 100644 index 11269cf6036..00000000000 --- a/extraplugins/moka/org.eclipse.papyrus.moka.composites.utils/src/org/eclipse/papyrus/moka/composites/utils/ui/GenerateConstructorUsingFieldsDialog.java +++ /dev/null @@ -1,432 +0,0 @@ -/***************************************************************************** - * Copyright (c) 2014 CEA LIST. - * - * 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: - * CEA LIST - Initial API and implementation - *****************************************************************************/ -package org.eclipse.papyrus.moka.composites.utils.ui; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.jface.dialogs.TrayDialog; -import org.eclipse.jface.viewers.BaseLabelProvider; -import org.eclipse.jface.viewers.CheckStateChangedEvent; -import org.eclipse.jface.viewers.CheckboxTableViewer; -import org.eclipse.jface.viewers.ICheckStateListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITableLabelProvider; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.papyrus.moka.composites.utils.handlers.Utils; -import org.eclipse.papyrus.moka.fuml.presentation.FUMLPresentationUtils; -import org.eclipse.papyrus.uml.tools.utils.PackageUtil; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.uml2.uml.Class; -import org.eclipse.uml2.uml.Operation; -import org.eclipse.uml2.uml.Parameter; -import org.eclipse.uml2.uml.ParameterDirectionKind; -import org.eclipse.uml2.uml.Property; -import org.eclipse.uml2.uml.Stereotype; -import org.eclipse.uml2.uml.UMLFactory; - -public class GenerateConstructorUsingFieldsDialog extends TrayDialog { - - protected Class context; - - protected CheckboxTableViewer viewer; - - private Button btUP; - - private Button btDown; - - private List<Object> checkList = new ArrayList<Object>(); - - public GenerateConstructorUsingFieldsDialog(Shell shell, Class context) { - super(shell); - setShellStyle(SWT.CLOSE | SWT.RESIZE); - this.context = context; - } - - @Override - protected Control createDialogArea(Composite parent) { - parent.getShell().setText("Generate Constructor Using Fields"); - parent.getShell().setMinimumSize(500, 500); - - /* - * Create composite which contains all controls, composites, & others - * stuff. - */ - Composite mainLayout = new Composite(parent, SWT.FILL); - mainLayout.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); - mainLayout.setLayout(new GridLayout(1, true)); - - // Create Label Using Fields - Label lblSelectFields = new Label(mainLayout, SWT.NONE); - lblSelectFields.setText("Select fields to initialize :"); - - /* Create composite which contains compositeCheckBox & compositeButtons */ - Composite cpCenter = new Composite(mainLayout, SWT.RESIZE); - - // Set Layout and position - GridData gdCenter = new GridData(SWT.FILL, SWT.FILL, true, true); - gdCenter.widthHint = 514; - gdCenter.heightHint = 274; - cpCenter.setLayoutData(gdCenter); - cpCenter.setLayout(new GridLayout(2, false)); - - /* Create left "panel" which contains bindings with check box controls */ - Composite cpCheckBox = new Composite(cpCenter, SWT.RESIZE | SWT.BORDER); - cpCheckBox.setLayout(new GridLayout(1, false)); - - // Set Layout and position - GridData gdCheckBox = new GridData(SWT.FILL, SWT.FILL, true, true); - gdCheckBox.widthHint = 370; - cpCheckBox.setLayoutData(gdCheckBox); - - /* Add all attributes on a CheckboxTableViewer */ - viewer = CheckboxTableViewer.newCheckList(cpCheckBox, SWT.FULL_SELECTION | SWT.FILL); - viewer.setContentProvider(new StruturedContentProvider()); - viewer.setLabelProvider(new TableLabelProvider()); - viewer.setInput(this.context.getOwnedAttributes()); - - // Listen which box is checked. - viewer.addCheckStateListener(new ICheckStateListener() { - - @Override - public void checkStateChanged(CheckStateChangedEvent event) { - if (event.getChecked() == true) { - viewer.setChecked(event.getElement(), true); - checkList.add(event.getElement()); - } else { - viewer.setChecked(event.getElement(), false); - checkList.remove(event.getElement()); - } - } - }); - - viewer.getTable().addSelectionListener(new SelectionListener() { - - @Override - public void widgetSelected(SelectionEvent event) { - List<?> elements = (List<?>) viewer.getInput(); - Property data = null; - - if (event.item.getData() instanceof Property) { - data = (Property) event.item.getData(); - - if (data == elements.get(0)) { - btUP.setEnabled(false); - btDown.setEnabled(true); - } else if (data == elements.get(elements.size() - 1)) { - btDown.setEnabled(false); - btUP.setEnabled(true); - } else { - btUP.setEnabled(true); - btDown.setEnabled(true); - } - } - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - } - }); - - viewer.setAllChecked(true); - Object[] tmp = viewer.getCheckedElements(); - for (int i = 0; i < tmp.length; i++) { - checkList.add(tmp[i]); - } - - /* Create right "panel" which contains Select/Deselect Buttons */ - Composite cpButtons = new Composite(cpCenter, SWT.RESIZE); - - // Set Layout and position - GridData gdButtons = new GridData(SWT.FILL, SWT.FILL, true, true); - gdButtons.widthHint = 144; - cpButtons.setLayoutData(gdButtons); - cpButtons.setLayout(new GridLayout(1, false)); - - /* Create Select-Deselect buttons */ - /* Push Button Select All */ - Button btSelect = new Button(cpButtons, SWT.PUSH); - btSelect.setText("Select All"); - - // Set size and position - GridData gdSelect = new GridData(SWT.FILL, SWT.FILL, false, false); - gdSelect.widthHint = 100; - gdSelect.heightHint = 25; - btSelect.setLayoutData(gdSelect); - - // Add Listener - btSelect.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent event) { - viewer.setAllChecked(true); - - if (checkList.size() != 0) { - checkList.removeAll(checkList); - Object[] tmp = viewer.getCheckedElements(); - for (int i = 0; i < tmp.length; i++) { - checkList.add(tmp[i]); - } - } - // System.out.println(event.toString()); - } - }); - - /* Push Button Deselect All */ - Button btDeSelect = new Button(cpButtons, SWT.PUSH); - btDeSelect.setText("Deselect All"); - - // Set size and position - GridData gdDeSelect = new GridData(SWT.FILL, SWT.FILL, false, false); - gdDeSelect.widthHint = 100; - gdDeSelect.heightHint = 25; - btDeSelect.setLayoutData(gdDeSelect); - - // Add Listener - btDeSelect.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent event) { - viewer.setAllChecked(false); - - if (checkList.size() != 0) { - checkList.removeAll(checkList); - } - - // System.out.println(event.toString()); - } - }); - - /* Create Up-Down buttons */ - /* Push Button Up */ - btUP = new Button(cpButtons, SWT.PUSH); - btUP.setText("Up"); - - // Set size and position - GridData gdUP = new GridData(SWT.FILL, SWT.FILL, false, false); - gdUP.widthHint = 100; - gdUP.heightHint = 25; - btUP.setLayoutData(gdUP); - btUP.setEnabled(false); - - btUP.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent event) { - viewer.setInput(getElementListUP()); - // System.out.println(event.toString()); - } - }); - - /* Push Button Down */ - btDown = new Button(cpButtons, SWT.PUSH); - btDown.setText("Down"); - - // Set size and position - GridData gdDown = new GridData(SWT.FILL, SWT.FILL, false, false); - gdDown.widthHint = 100; - gdDown.heightHint = 25; - btDown.setLayoutData(gdDown); - - btDown.addSelectionListener(new SelectionAdapter() { - - @Override - public void widgetSelected(SelectionEvent event) { - viewer.setInput(getElementListDown()); - // System.out.println(event.toString()); - } - }); - - return mainLayout; - } - - protected boolean isCreate(Operation operation) { - for (int j = 0; j < operation.getAppliedStereotypes().size(); j++) { - Stereotype st_tmp = operation.getAppliedStereotypes().get(j); - if (st_tmp.getName().equals("Create")) { - return true; - } - } - return false; - } - - static class StruturedContentProvider implements IStructuredContentProvider { - - @SuppressWarnings("unchecked") - @Override - public Object[] getElements(Object inputElement) { - ArrayList<Property> result = new ArrayList<Property>(); - if (inputElement instanceof List) { - result.addAll((Collection<? extends Property>) inputElement); - } - return result.toArray(); - } - - @Override - public void dispose() { - } - - @Override - public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { - } - } - - static class TableLabelProvider extends BaseLabelProvider implements ITableLabelProvider { - - @Override - public Image getColumnImage(Object element, int columnIndex) { - if (element instanceof Property) { - Property current = (Property) element; - switch (columnIndex) { - case 0: - FUMLPresentationUtils.init(current); - Image image = FUMLPresentationUtils.getImage(current); - return image; - default: - return null; - } - } - return null; - - } - - @Override - public String getColumnText(Object element, int columnIndex) { - if (element instanceof Property) { - Property current = (Property) element; - switch (columnIndex) { - case 0: - return current.getName(); - default: - return ""; - } - } - return ""; - } - - } - - protected List<?> getElementListUP() { - - List<?> elements = (List<?>) viewer.getInput(); - IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); - List<?> element = selection.toList(); - ArrayList<Object> elementList = new ArrayList<Object>(); - ArrayList<Object> elementListTMP = new ArrayList<Object>(); - - for (int i = 0; i < elements.size(); i++) { - if (element.get(0) == elements.get(i)) { - elementListTMP.remove(elements.get(i - 1)); - elementListTMP.add(element.get(0)); - elementListTMP.add(elements.get(i - 1)); - - } else { - elementListTMP.add(elements.get(i)); - - } - } - - elementList.addAll(elementListTMP); - return elementList; - } - - protected List<?> getElementListDown() { - - List<?> elements = (List<?>) viewer.getInput(); - IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); - List<?> element = selection.toList(); - ArrayList<Object> elementList = new ArrayList<Object>(); - ArrayList<Object> elementListTMP = new ArrayList<Object>(); - - for (int i = 0; i < elements.size(); i++) { - if (element.get(0) == elements.get(i)) { - elementListTMP.add(elements.get(i + 1)); - elementListTMP.add(element.get(0)); - i++; - } else { - elementListTMP.add(elements.get(i)); - } - } - - elementList.addAll(elementListTMP); - return elementList; - } - - @Override - protected void okPressed() { - // System.err.println("Ok pressed"); - - // Check if the right profile is applied. - // List<Profile> appliedProfiles = context.getModel().getAppliedProfiles(); - // for(int i = 0; i < appliedProfiles.size(); i++) { - // System.out.println(appliedProfiles.get(i).getQualifiedName()); - // } - - if (!Utils.isStandardProfileApplied(context)) { - PackageUtil.applyProfile(context.getModel(), Utils.standardProfile, true); - } - - // Creating operation and method with "Create" stereotype - Operation operation = Utils.getDefaultConstructor(context); - - int flagParamOp = 0; - - // Add parameters to instantiate - for (int i = 0; i < checkList.size(); i++) { - if (checkList.get(i) instanceof Property) { - Property prop = (Property) checkList.get(i); - Parameter in = UMLFactory.eINSTANCE.createParameter(); - in.setDirection(ParameterDirectionKind.IN_LITERAL); - in.setType(prop.getType()); - in.setName(prop.getName()); - - /* Check if parameter is already exist on the operation. */ - flagParamOp = 0; - - if (operation.getOwnedParameters().size() <= 1) { - operation.getOwnedParameters().add(operation.getOwnedParameters().size() - 1, in); - } - - else { - for (int j = 0; j < operation.getOwnedParameters().size() && flagParamOp == 0; j++) { - Parameter opParameter = operation.getOwnedParameters().get(j); - if (!opParameter.getName().equals(in.getName())) { - flagParamOp = 0; - } else { - flagParamOp = -1; - } - } - - if (flagParamOp == 0) { - operation.getOwnedParameters().add(operation.getOwnedParameters().size() - 1, in); - } - } - } - } - - super.okPressed(); - } - -} |