Search in sources :

Example 16 with Requirement

use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.

the class RequirementServices method relatedRequirementsWithSubtype.

/**
 * Returns the list of {@link Requirement} that reference the specified
 * eObject and which have the specified subtype.
 *
 * @param eObject
 * @param subtype Subtype that requirements should have. Could be null.
 * @return the list of {@link Requirement} instances that reference the
 *         specified eObject.
 */
public List<Requirement> relatedRequirementsWithSubtype(EObject eObject, String subtype) {
    List<Requirement> result = new ArrayList<>();
    List<Requirement> requirements = relatedRequirements(eObject);
    for (Requirement requirement : requirements) {
        if (isNullOrEmpty(subtype)) {
            if (isNullOrEmpty(requirement.getSubtype())) {
                result.add(requirement);
            }
        } else if (subtype.equals(requirement.getSubtype())) {
            result.add(requirement);
        }
    }
    return result;
}
Also used : Requirement(org.obeonetwork.dsl.requirement.Requirement) ArrayList(java.util.ArrayList)

Example 17 with Requirement

use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.

the class RequirementServices method relatedRequirements.

/**
 * Returns the list of {@link Requirement} that reference the specified
 * eObject. For the service to work, eObject must be present in a
 *
 * @param eObject
 * @return the list of {@link Requirement} instances that reference the
 *         specified eObject.
 */
public List<Requirement> relatedRequirements(EObject eObject) {
    Resource resource = eObject.eResource();
    List<Requirement> result = new ArrayList<Requirement>();
    if (resource != null) {
        ResourceSet resourceSet = resource.getResourceSet();
        if (resourceSet != null) {
            Collection<Setting> settings = EcoreUtil.UsageCrossReferencer.find(eObject, resourceSet);
            for (Setting setting : settings) {
                if (setting.getEObject() instanceof Requirement) {
                    result.add(((Requirement) setting.getEObject()));
                }
            }
        }
    }
    return result;
}
Also used : Requirement(org.obeonetwork.dsl.requirement.Requirement) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 18 with Requirement

use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.

the class RequirementsServices method copyRequirement.

/**
 * Copy Requirement.
 *
 * @param requirement
 */
public void copyRequirement(Requirement requirement) {
    Shell shell = getShell();
    CategorySelectionDialog dlg = new CategorySelectionDialog(shell, "Copy a requirement", "Select a container for the new requirement");
    dlg.setInput(SessionManager.INSTANCE.getSession(requirement));
    dlg.setInitialSelection(requirement.eContainer());
    dlg.setValidator(new ISelectionStatusValidator() {

        public IStatus validate(Object[] selection) {
            if (selection.length > 0 && selection[0] instanceof Category) {
                return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
            }
            return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Select a category");
        }
    });
    if (dlg.open() == Window.OK) {
        Object selectedObject = dlg.getFirstResult();
        if (selectedObject instanceof Category) {
            Category newContainer = (Category) selectedObject;
            // Check if there are referenced objects
            boolean keepReferencedObject = false;
            if (!requirement.getReferencedObject().isEmpty()) {
                keepReferencedObject = MessageDialog.openQuestion(shell, "Referenced objects", "Do you want to keep the referenced objects ?");
            }
            // Copy object
            Requirement newRequirement = EcoreUtil.copy(requirement);
            newRequirement.setId(getNewIdForCopiedRequirement(newContainer, newRequirement));
            if (!keepReferencedObject) {
                newRequirement.getReferencedObject().clear();
            }
            // Add to parent
            newContainer.getRequirements().add(newRequirement);
        }
    }
    ;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ObjectWithRequirement(org.obeonetwork.tools.requirement.ui.decorators.ObjectWithRequirement) Requirement(org.obeonetwork.dsl.requirement.Requirement) Shell(org.eclipse.swt.widgets.Shell) IStatus(org.eclipse.core.runtime.IStatus) Category(org.obeonetwork.dsl.requirement.Category) CategorySelectionDialog(org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject)

Example 19 with Requirement

use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.

the class UniqueIdConstraint method isRequirementIdUnique.

private boolean isRequirementIdUnique(Requirement requirement) {
    String searchedId = requirement.getId();
    if (searchedId == null || searchedId.equals("")) {
        // Id is not set we dont check for unicity
        return true;
    }
    boolean idAlreadyMet = false;
    ResourceSet set = requirement.eResource().getResourceSet();
    for (TreeIterator<Object> iter = EcoreUtil.getAllContents(set, true); iter.hasNext(); ) {
        Object content = iter.next();
        if (content instanceof Requirement) {
            String reqId = ((Requirement) content).getId();
            if (searchedId.equalsIgnoreCase(reqId)) {
                if (idAlreadyMet == false) {
                    // First time we encounter this id, it's normal it's probably the one we're analyzing
                    idAlreadyMet = true;
                } else {
                    // Second time we encounter this id, this is not normal
                    return false;
                }
            }
        }
        if (shouldGetChildren(content) == false) {
            iter.prune();
        }
    }
    return true;
}
Also used : Requirement(org.obeonetwork.dsl.requirement.Requirement) EObject(org.eclipse.emf.ecore.EObject) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 20 with Requirement

use of org.obeonetwork.dsl.requirement.Requirement in project InformationSystem by ObeoNetwork.

the class BusinessProjectImporter method importElementsIntoTargetProject.

public void importElementsIntoTargetProject(IProgressMonitor parentMonitor) throws CoreException {
    final SubMonitor monitor = SubMonitor.convert(parentMonitor, 5);
    // Ensure project is closed
    saveAndCloseEditorsOnTargetProject(monitor.newChild(1));
    initializeImportData();
    final Map<String, List<EObject>> requirementReferencesCache = cacheRequirementReferences();
    // Create command
    TransactionalEditingDomain editingDomain = targetSession.getTransactionalEditingDomain();
    RecordingCommand command = new RecordingCommand(editingDomain) {

        @Override
        protected void doExecute() {
            // At the end of the import, if there is no "requirement.Repository" object in the target MOE project, then create one named after the MOE project.
            // This verification is done *before* importing models from the MOA otherwise they get added onto the session.
            boolean repositoryExistsBeforeImporting = false;
            for (Resource semanticResource : SessionManager.INSTANCE.getExistingSession(targetProject.getMainRepresentationsFileURI(monitor).get()).getSemanticResources()) {
                repositoryExistsBeforeImporting = repositoryExistsBeforeImporting || EcoreUtil.getObjectByType(semanticResource.getContents(), RequirementPackage.Literals.REPOSITORY) != null;
            }
            // Delete the content of the impacted resources and the related representations
            final Collection<EObject> existingTargetSemanticRoots = getAllImpactedTargetSemanticRoots();
            if (!existingTargetSemanticRoots.isEmpty()) {
                // Delete related representations
                final Collection<DRepresentationDescriptor> existingRepresentationDescriptors = ImporterUtil.getRelatedRepresentationDescriptors(targetSession, ImporterUtil.getAllElementsWithChildren(existingTargetSemanticRoots));
                if (!existingRepresentationDescriptors.isEmpty()) {
                    for (DRepresentationDescriptor dRepresentationDescriptor : existingRepresentationDescriptors) {
                        DialectManager.INSTANCE.deleteRepresentation(dRepresentationDescriptor, targetSession);
                    }
                }
                // Delete existing objects
                for (EObject semanticRoot : existingTargetSemanticRoots) {
                    if (semanticRoot instanceof Repository) {
                        for (Requirement req : ImporterUtil.getAllContentsOfType(semanticRoot, Requirement.class)) {
                            req.getReferencedObject().clear();
                            SiriusUtil.delete(req, targetSession);
                        }
                    }
                    SiriusUtil.delete(semanticRoot, targetSession);
                }
            }
            // Create semantic resources and their content
            for (EObject sourceRoot : importData.getSourceRoots()) {
                EObject copyRoot = importData.getCopyEObject(sourceRoot);
                String targetPath = getTargetResourcePath(sourceRoot);
                addToSemanticResource(copyRoot, targetPath);
            }
            // Add representations
            for (DRepresentationDescriptor sourceRepresentationDescriptor : importData.getSourceRepresentationDescriptors()) {
                DRepresentationDescriptor copyRepresentationDescriptor = (DRepresentationDescriptor) importData.getCopyEObject(sourceRepresentationDescriptor);
                Viewpoint viewpoint = getViewpoint(copyRepresentationDescriptor);
                addRepresentationDescriptor(copyRepresentationDescriptor, viewpoint);
            }
            // Restore the local requirement references
            restoreRequirementReferences(requirementReferencesCache);
            // }
            if (!repositoryExistsBeforeImporting) {
                Repository requirementsRepository = RequirementFactory.eINSTANCE.createRepository();
                addToSemanticResource(requirementsRepository, targetProject.getProject().getName() + "/" + targetProject.getProject().getName() + ".requirement");
            }
        }
    };
    // Execute the command
    editingDomain.getCommandStack().execute(command);
    monitor.worked(3);
    // Save project
    targetSession.save(monitor.newChild(1));
}
Also used : SubMonitor(org.eclipse.core.runtime.SubMonitor) Resource(org.eclipse.emf.ecore.resource.Resource) DRepresentationDescriptor(org.eclipse.sirius.viewpoint.DRepresentationDescriptor) Requirement(org.obeonetwork.dsl.requirement.Requirement) Repository(org.obeonetwork.dsl.requirement.Repository) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Aggregations

Requirement (org.obeonetwork.dsl.requirement.Requirement)20 EObject (org.eclipse.emf.ecore.EObject)11 ArrayList (java.util.ArrayList)7 Category (org.obeonetwork.dsl.requirement.Category)6 Resource (org.eclipse.emf.ecore.resource.Resource)5 Repository (org.obeonetwork.dsl.requirement.Repository)5 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)3 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)2 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)2 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)2 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 SimpleDateFormat (java.text.SimpleDateFormat)1 HashMap (java.util.HashMap)1 IStatus (org.eclipse.core.runtime.IStatus)1