Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'extraplugins/requirements/org.eclipse.papyrus.requirements.sysml.matrix.satisfiedBy.config/src/org/eclipse/papyrus/requirements/sysml/matrix/satisfiedBy/config/cellmanager/SatisfyMatrixCellManager.java')
-rw-r--r--extraplugins/requirements/org.eclipse.papyrus.requirements.sysml.matrix.satisfiedBy.config/src/org/eclipse/papyrus/requirements/sysml/matrix/satisfiedBy/config/cellmanager/SatisfyMatrixCellManager.java195
1 files changed, 195 insertions, 0 deletions
diff --git a/extraplugins/requirements/org.eclipse.papyrus.requirements.sysml.matrix.satisfiedBy.config/src/org/eclipse/papyrus/requirements/sysml/matrix/satisfiedBy/config/cellmanager/SatisfyMatrixCellManager.java b/extraplugins/requirements/org.eclipse.papyrus.requirements.sysml.matrix.satisfiedBy.config/src/org/eclipse/papyrus/requirements/sysml/matrix/satisfiedBy/config/cellmanager/SatisfyMatrixCellManager.java
new file mode 100644
index 00000000000..fedb9088eb6
--- /dev/null
+++ b/extraplugins/requirements/org.eclipse.papyrus.requirements.sysml.matrix.satisfiedBy.config/src/org/eclipse/papyrus/requirements/sysml/matrix/satisfiedBy/config/cellmanager/SatisfyMatrixCellManager.java
@@ -0,0 +1,195 @@
+/*****************************************************************************
+ * Copyright (c) 2016 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:
+ *
+ * Mauricio Alferez (mauricio.alferez@cea.fr) CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.requirements.sysml.matrix.satisfiedBy.config.cellmanager;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.DestroyElementRequest;
+import org.eclipse.papyrus.commands.wrappers.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.nattable.manager.cell.AbstractCellManager;
+import org.eclipse.papyrus.infra.nattable.manager.table.INattableModelManager;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxis.ITreeItemAxis;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableaxisconfiguration.AxisManagerRepresentation;
+import org.eclipse.papyrus.infra.nattable.model.nattable.nattableconfiguration.TableConfiguration;
+import org.eclipse.papyrus.infra.nattable.utils.AxisUtils;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+import org.eclipse.papyrus.requirements.sysml.common.I_SysMLStereotype;
+import org.eclipse.papyrus.requirements.sysml.matrix.satisfiedBy.config.Activator;
+import org.eclipse.papyrus.sysml.requirements.Requirement;
+import org.eclipse.uml2.uml.Abstraction;
+import org.eclipse.uml2.uml.Dependency;
+import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
+import org.eclipse.uml2.uml.Stereotype;
+import org.eclipse.uml2.uml.util.UMLUtil;
+
+@SuppressWarnings("deprecation")
+public class SatisfyMatrixCellManager extends AbstractCellManager {
+ public static final String SATISFY_MESSAGE = "satisfies";
+ public static final String CELL_MANAGER_ID = Activator.PLUGIN_ID + ".cellmanager";
+
+ @Override
+ public boolean handles(Object columnElement, Object rowElement) {
+ // Supports Requirement x Element
+ Object column = AxisUtils.getRepresentedElement(columnElement);
+ Object row = AxisUtils.getRepresentedElement(rowElement);
+ if (rowElement instanceof ITreeItemAxis) {
+ ITreeItemAxis axis = (ITreeItemAxis) rowElement;
+ AxisManagerRepresentation manager = axis.getManager();
+ TableConfiguration conf = (TableConfiguration) manager.eContainer().eContainer();
+ String type = conf.getType();
+ if (!type.equals("SatisfyMatrix")) {
+ return false;
+ }
+ }
+
+ if (column instanceof Element) {
+ Element colUMLElement = (Element) column;
+ if (UMLUtil.getStereotypeApplication(colUMLElement, Requirement.class) != null) {
+ if (row instanceof Element) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected Object doGetValue(Object columnElement, Object rowElement, INattableModelManager tableManager) {
+ Object column = AxisUtils.getRepresentedElement(columnElement);
+ Object row = AxisUtils.getRepresentedElement(rowElement);
+ EObject eObjectInRow = (EObject) row;
+ if (column instanceof Element) {
+ Element colUMLElement = (Element) column;
+ if (UMLUtil.getStereotypeApplication(colUMLElement, Requirement.class) != null) {
+ Stereotype reqStereotype = colUMLElement.getAppliedStereotype(I_SysMLStereotype.REQUIREMENT_STEREOTYPE);
+ Object listOfObjectsThatSatisfyRequirement = colUMLElement.getValue(reqStereotype, "satisfiedBy");
+ if (listOfObjectsThatSatisfyRequirement instanceof EList<?>) {
+ @SuppressWarnings("unchecked")
+ EList<EObject> list = (EList<EObject>) listOfObjectsThatSatisfyRequirement;
+ // check the list of elements that satisfy the requirement
+ // to see if the element in the current row in there
+ for (EObject eObjectThatSatisfiesRequirement : list) {
+ if (eObjectInRow.equals(eObjectThatSatisfiesRequirement)) {
+ return true;
+ }
+ }
+ }
+
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void setValue(TransactionalEditingDomain domain, Object columnElement, Object rowElement, Object newValue,
+ INattableModelManager tableManager) {
+ Object column = AxisUtils.getRepresentedElement(columnElement);
+ Object row = AxisUtils.getRepresentedElement(rowElement);
+ EObject eObjectInRow = (EObject) row;
+
+ if (column instanceof Element) {
+ Element colUMLElement = (Element) column;
+
+ if (Boolean.FALSE.equals(newValue)) {
+ if (UMLUtil.getStereotypeApplication(colUMLElement, Requirement.class) != null) {
+ Stereotype reqStereotype = colUMLElement
+ .getAppliedStereotype(I_SysMLStereotype.REQUIREMENT_STEREOTYPE);
+ Object listOfObjectsThatSatisfyRequirement = colUMLElement.getValue(reqStereotype, "satisfiedBy");
+ if (listOfObjectsThatSatisfyRequirement instanceof EList<?>) {
+ @SuppressWarnings("unchecked")
+ EList<EObject> list = (EList<EObject>) listOfObjectsThatSatisfyRequirement;
+ // check the list of elements that satisfy the
+ // requirement to see if the element in the current row
+ // in there
+ Dependency toDestroy = null;
+ for (EObject eObjectThatSatisfiesRequirement : list) {
+ if (toDestroy == null) {
+ if (eObjectInRow.equals(eObjectThatSatisfiesRequirement)) {
+ EList<Dependency> dependencies = ((NamedElement) eObjectThatSatisfiesRequirement)
+ .getClientDependencies();
+ Iterator<Dependency> iter = dependencies.iterator();
+ while (iter.hasNext() && toDestroy == null) {
+ Dependency dependency = iter.next();
+ if (dependency instanceof Abstraction) {
+ if (dependency
+ .getAppliedStereotype("SysML::Requirements::Satisfy") != null) {
+ if (dependency.getClients().contains(row)
+ && dependency.getSuppliers().contains(colUMLElement)) {
+ toDestroy = dependency;
+ }
+
+ }
+ }
+ }
+
+ }
+ }
+ }
+
+ if (toDestroy != null) {
+ DestroyElementRequest req = new DestroyElementRequest(toDestroy, false);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(toDestroy);
+ ICommand cmd = provider.getEditCommand(req);
+ if (cmd != null && cmd.canExecute()) {
+ domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
+ }
+ }
+ }
+ }
+ } else if (Boolean.TRUE.equals(newValue)
+ || (newValue instanceof Abstraction && ((Abstraction) newValue).eContainer() == null)) {
+ IElementType type = ElementTypeRegistry.getInstance().getType("org.eclipse.papyrus.sysml.Satisfy");
+ if (row instanceof Element) {
+ Element container = ((Element) row).getNearestPackage();
+ CreateRelationshipRequest request = new CreateRelationshipRequest(domain, container, (EObject) row,
+ colUMLElement, type);
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(container);
+ ICommand cmd = provider.getEditCommand(request);
+ // CreateR
+ if (cmd != null && cmd.canExecute()) {
+ domain.getCommandStack().execute(new GMFtoEMFCommandWrapper(cmd));
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public Command getSetValueCommand(TransactionalEditingDomain domain, Object columnElement, Object rowElement,
+ Object newValue, INattableModelManager tableManager) {
+ return super.getSetValueCommand(domain, columnElement, rowElement, newValue, tableManager);
+ }
+
+ @Override
+ public boolean isCellEditable(Object columnElement, Object rowElement) {
+ Object column = AxisUtils.getRepresentedElement(columnElement);
+ Object row = AxisUtils.getRepresentedElement(rowElement);
+ if (row instanceof NamedElement && column instanceof Element) {
+ return UMLUtil.getStereotypeApplication((Element) column, Requirement.class) != null;
+ }
+ return false;
+ }
+}

Back to the top