/** * This returns CreateDeleteOperation.gif. * <!-- begin-user-doc --> * <!-- * end-user-doc --> * * @generated NOT * @param object the object for which to provide the label image * @return the image used to label the object */ @Override public Object getImage(Object object) { CreateDeleteOperation op = (CreateDeleteOperation) object; Object image = null; if (op.isDelete()) { image = getResourceLocator().getImage("full/obj16/DeleteOperation.png"); } else { image = getResourceLocator().getImage("full/obj16/CreateOperation.png"); } return overlayImage(object, image); }
/** * @see * org.eclipse.emf.emfstore.server.model.versioning.operations.provider.AbstractOperationItemProvider#getChildren(java.lang.Object) */ @Override public Collection<?> getChildren(Object object) { if (object instanceof CreateDeleteOperation) { CreateDeleteOperation operation = (CreateDeleteOperation) object; ArrayList<Object> ret = new ArrayList<Object>(); ret.add(operation.getModelElementId()); List<ReferenceOperation> subOps = operation.getSubOperations(); if (subOps.size() > 0) { OperationGroup operationGroup = OperationsFactory.eINSTANCE.createOperationGroup(); if (operation.isDelete()) { operationGroup.setName("Deleted Cross-References"); } else { operationGroup.setName("Created Cross-References"); } operationGroup.getOperations().addAll(subOps); ret.add(operationGroup); } return ret; } return super.getChildren(object); }
/** * This returns the label text for the adapted class. * <!-- begin-user-doc * --> * <!-- end-user-doc --> * * @generated NOT * @param object the object to be described * @return the description of the given object */ @Override public String getText(Object object) { if (object instanceof CreateDeleteOperation) { CreateDeleteOperation op = (CreateDeleteOperation) object; EObject modelElement = op.getModelElement(); int childrenCount = ModelUtil.getAllContainedModelElements(modelElement, false).size(); String description; StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append(modelElement.eClass().getName()); stringBuilder.append(getModelElementName(op.getModelElementId())); String elementClassAndName = stringBuilder.toString(); if (op.isDelete()) { description = "Deleted " + elementClassAndName; } else { description = "Created " + elementClassAndName; } if (childrenCount > 0) { description += " including " + childrenCount + " sibling(s)"; } EList<ReferenceOperation> subOperations = op.getSubOperations(); int subOperationCount = subOperations.size(); if (op.isDelete() && subOperationCount > 0) { ReferenceOperation referenceOperation = subOperations.get(subOperationCount - 1); if (referenceOperation.getContainmentType().equals(ContainmentType.CONTAINMENT)) { description += " from its parent " + getModelElementClassAndName(referenceOperation.getModelElementId()); } } return description; } return super.getText(object); }
/** * Test containment removing. * * @throws UnsupportedOperationException on test fail */ @Test public void removeContainment() throws UnsupportedOperationException { final Issue issue = RationaleFactory.eINSTANCE.createIssue(); final Proposal proposal = RationaleFactory.eINSTANCE.createProposal(); new EMFStoreCommand() { @Override protected void doRun() { proposal.setName("proposal"); getProject().addModelElement(issue); getProject().addModelElement(proposal); proposal.setIssue(issue); clearOperations(); assertEquals(1, issue.getProposals().size()); assertEquals(proposal, issue.getProposals().get(0)); assertEquals(issue, proposal.getIssue()); assertEquals(true, getProject().containsInstance(issue)); assertEquals(true, getProject().containsInstance(proposal)); assertEquals(getProject(), ModelUtil.getProject(issue)); assertEquals(getProject(), ModelUtil.getProject(proposal)); assertEquals(issue, proposal.eContainer()); } }.run(false); ModelElementId proposalId = ModelUtil.getProject(proposal).getModelElementId(proposal); new EMFStoreCommand() { @Override protected void doRun() { proposal.setIssue(null); } }.run(false); assertEquals(true, getProject().containsInstance(issue)); assertEquals(false, getProject().containsInstance(proposal)); assertEquals(getProject(), ModelUtil.getProject(issue)); // assertEquals(null, ModelUtil.getProject(proposal)); assertEquals(0, issue.getProposals().size()); assertEquals(null, proposal.getIssue()); // assertEquals(null, proposal.eContainer()); List<AbstractOperation> operations = getProjectSpace().getOperations(); assertEquals(1, operations.size()); ModelElementId issueId = ModelUtil.getProject(issue).getModelElementId(issue); assertEquals(true, operations.get(0) instanceof CreateDeleteOperation); CreateDeleteOperation deleteOperation = (CreateDeleteOperation) operations.get(0); assertEquals(true, deleteOperation.isDelete()); assertEquals(true, deleteOperation.getModelElement() instanceof Proposal); assertEquals("proposal", ((Proposal) deleteOperation.getModelElement()).getName()); assertEquals(proposalId, deleteOperation.getModelElementId()); List<ReferenceOperation> subOperations = ((CreateDeleteOperation) operations.get(0)).getSubOperations(); assertEquals(2, subOperations.size()); AbstractOperation op0 = subOperations.get(0); assertTrue(op0 instanceof MultiReferenceOperation); MultiReferenceOperation multiReferenceOperation = (MultiReferenceOperation) op0; assertEquals(multiReferenceOperation.getModelElementId(), issueId); assertFalse(multiReferenceOperation.isAdd()); assertEquals(multiReferenceOperation.getReferencedModelElements().get(0), proposalId); assertEquals(multiReferenceOperation.getReferencedModelElements().size(), 1); assertEquals(multiReferenceOperation.getIndex(), 0); AbstractOperation operation = subOperations.get(1); assertEquals(true, operation instanceof SingleReferenceOperation); SingleReferenceOperation singleReferenceOperation = (SingleReferenceOperation) operation; assertEquals(issueId, singleReferenceOperation.getOldValue()); assertEquals(null, singleReferenceOperation.getNewValue()); assertEquals( RationalePackage.eINSTANCE.getProposal_Issue().getName(), singleReferenceOperation.getFeatureName()); assertEquals(proposalId, singleReferenceOperation.getModelElementId()); assertEquals( RationalePackage.eINSTANCE.getIssue_Proposals().getName(), singleReferenceOperation.getOppositeFeatureName()); assertEquals(true, singleReferenceOperation.isBidirectional()); Set<ModelElementId> otherInvolvedModelElements = singleReferenceOperation.getOtherInvolvedModelElements(); assertEquals(1, otherInvolvedModelElements.size()); assertEquals(true, otherInvolvedModelElements.contains(issueId)); }