Search in sources :

Example 6 with Repository

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

the class RequirementService method findRequirementsRepositories.

/**
 * @param context
 * @return the {@link Resource Resources} within the {@link Session} of
 *         {@code context} whose contents is a {@link Repository}.
 */
public static Collection<Resource> findRequirementsRepositories(EObject context) {
    final Collection<Resource> repositories = new ArrayList<Resource>();
    Session session = SessionManager.INSTANCE.getSession(context);
    if (session != null) {
        // Test resources containing requirements repositories
        for (Resource semanticResource : session.getSemanticResources()) {
            for (EObject object : semanticResource.getContents()) {
                if (object instanceof Repository) {
                    repositories.add(semanticResource);
                    break;
                }
            }
        }
    }
    return repositories;
}
Also used : Repository(org.obeonetwork.dsl.requirement.Repository) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) Session(org.eclipse.sirius.business.api.session.Session)

Example 7 with Repository

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

the class CategorySelectionPage method createControl.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 */
public void createControl(Composite parent) {
    Composite control = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(GridData.FILL_BOTH);
    control.setLayoutData(gd);
    GridLayout layout = new GridLayout();
    control.setLayout(layout);
    Label intro = new Label(control, SWT.NONE);
    // $NON-NLS-1$
    intro.setText(RequirementLinkerPlugin.getInstance().getString("CategorySelectionPage_label"));
    GridData labelData = new GridData(GridData.FILL_HORIZONTAL);
    intro.setLayoutData(labelData);
    categoriesViewer = new TreeViewer(control);
    categoriesViewer.getControl().setLayoutData(gd);
    AdapterFactory adapterFactory = ViewHelper.INSTANCE.createAdapterFactory();
    categoriesViewer.setLabelProvider(new LinkedRequirementsLabelProvider(adapterFactory));
    categoriesViewer.setContentProvider(new RequirementsRepositoriesContentProvider(adapterFactory) {

        @Override
        public Object[] getChildren(Object object) {
            if (object instanceof Category) {
                return ((Category) object).getSubCategories().toArray();
            }
            return super.getChildren(object);
        }

        @Override
        public boolean hasChildren(Object object) {
            if (object instanceof Category) {
                return !((Category) object).getSubCategories().isEmpty();
            }
            return super.hasChildren(object);
        }
    });
    categoriesViewer.setInput(getInput());
    categoriesViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            EObject selection = getTreeviewSelection();
            if (selection instanceof Category) {
                selectedCategory = (Category) selection;
                setPageComplete(true);
            } else {
                setPageComplete(false);
            }
            createCategorie.setEnabled(selection instanceof Category || selection instanceof Repository);
        }
    });
    createCategorie = new Button(control, SWT.PUSH);
    createCategorie.setText(// $NON-NLS-1$
    RequirementLinkerPlugin.getInstance().getString("CategorySelectionPage_CreateCategoryButton_title"));
    createCategorie.addSelectionListener(new SelectionAdapter() {

        /**
         * {@inheritDoc}
         *
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            InputDialog dialog = new InputDialog(getShell(), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
            "CategorySelectionPage_CreateCategoryDialog_title"), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
            "CategorySelectionPage_CreateCategoryDialog_description"), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
            "CategorySelectionPage_CreateCategoryDialog_defaultvalue"), null);
            int open = dialog.open();
            if (open == Window.OK) {
                Category category = RequirementFactory.eINSTANCE.createCategory();
                category.setName(dialog.getValue());
                if (getTreeviewSelection() instanceof Category) {
                    ((Category) getTreeviewSelection()).getSubCategories().add(category);
                } else if (getTreeviewSelection() instanceof Repository) {
                    ((Repository) getTreeviewSelection()).getMainCategories().add(category);
                }
            }
        }
    });
    createCategorie.setEnabled(false);
    if (currentValue != null) {
        categoriesViewer.reveal(currentValue);
        categoriesViewer.setSelection(new StructuredSelection(currentValue));
    }
    setControl(control);
}
Also used : Category(org.obeonetwork.dsl.requirement.Category) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) LinkedRequirementsLabelProvider(org.obeonetwork.tools.requirement.wizard.util.LinkedRequirementsLabelProvider) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Repository(org.obeonetwork.dsl.requirement.Repository) Button(org.eclipse.swt.widgets.Button) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) RequirementsRepositoriesContentProvider(org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider) EObject(org.eclipse.emf.ecore.EObject) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EObject(org.eclipse.emf.ecore.EObject)

Example 8 with Repository

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

the class RequirementsRepositoriesContentProvider method getChildren.

@Override
public Object[] getChildren(Object object) {
    if (object instanceof Resource) {
        List<Repository> repositories = new ArrayList<Repository>();
        // Get Repository instances
        for (EObject child : ((Resource) object).getContents()) {
            if (child instanceof Repository) {
                repositories.add((Repository) child);
            }
        }
        return repositories.toArray();
    } else if (object instanceof Repository) {
        Repository repository = (Repository) object;
        // Get categories
        List<Object> children = new ArrayList<Object>();
        children.addAll(repository.getOwnedCategories());
        // Get requirements
        children.addAll(repository.getOwnedRequirements());
        return children.toArray();
    } else if (object instanceof Category) {
        Category category = (Category) object;
        List<Object> children = new ArrayList<Object>();
        children.addAll(category.getOwnedCategories());
        children.addAll(category.getOwnedRequirements());
        return children.toArray();
    }
    return new Object[] {};
}
Also used : Repository(org.obeonetwork.dsl.requirement.Repository) Category(org.obeonetwork.dsl.requirement.Category) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) EObject(org.eclipse.emf.ecore.EObject)

Example 9 with Repository

use of org.obeonetwork.dsl.requirement.Repository 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)

Example 10 with Repository

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

the class RepositoryPropertiesEditionComponent method initPart.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
 *      org.eclipse.emf.ecore.resource.ResourceSet)
 */
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
        editingPart.setContext(elt, allResource);
        final Repository repository = (Repository) elt;
        final RepositoryPropertiesEditionPart repositoryPart = (RepositoryPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(RequirementViewsRepository.Repository.Repository_.name))
            repositoryPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, repository.getName()));
        if (isAccessible(RequirementViewsRepository.Repository.Repository_.mainCategories)) {
            mainCategoriesSettings = new ReferencesTableSettings(repository, RequirementPackage.eINSTANCE.getRepository_MainCategories());
            repositoryPart.initMainCategories(mainCategoriesSettings);
        }
        if (isAccessible(RequirementViewsRepository.Repository.Repository_.referencedObject)) {
            referencedObjectSettings = new ReferencesTableSettings(repository, RequirementPackage.eINSTANCE.getRepository_ReferencedObject());
            repositoryPart.initReferencedObject(referencedObjectSettings);
        }
        if (isAccessible(RequirementViewsRepository.Repository.Repository_.mainCategories)) {
            repositoryPart.addFilterToMainCategories(new ViewerFilter() {

                /**
                 * {@inheritDoc}
                 *
                 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
                 */
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof Category);
                }
            });
        // Start of user code for additional businessfilters for mainCategories
        // End of user code
        }
        if (isAccessible(RequirementViewsRepository.Repository.Repository_.referencedObject)) {
            repositoryPart.addFilterToReferencedObject(new ViewerFilter() {

                /**
                 * {@inheritDoc}
                 *
                 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
                 */
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    if (element instanceof EObject)
                        return (!repositoryPart.isContainedInReferencedObjectTable((EObject) element));
                    return element instanceof String && element.equals("");
                }
            });
            repositoryPart.addFilterToReferencedObject(new EObjectStrictFilter(EcorePackage.Literals.EOBJECT));
        // Start of user code for additional businessfilters for referencedObject
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : Repository(org.obeonetwork.dsl.requirement.Repository) RequirementViewsRepository(org.obeonetwork.dsl.requirement.parts.RequirementViewsRepository) RepositoryPropertiesEditionPart(org.obeonetwork.dsl.requirement.parts.RepositoryPropertiesEditionPart) EObjectStrictFilter(org.eclipse.emf.eef.runtime.impl.filters.EObjectStrictFilter) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) Category(org.obeonetwork.dsl.requirement.Category) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) EObject(org.eclipse.emf.ecore.EObject) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

Repository (org.obeonetwork.dsl.requirement.Repository)11 EObject (org.eclipse.emf.ecore.EObject)9 Category (org.obeonetwork.dsl.requirement.Category)7 Resource (org.eclipse.emf.ecore.resource.Resource)6 ArrayList (java.util.ArrayList)5 Requirement (org.obeonetwork.dsl.requirement.Requirement)5 List (java.util.List)4 LinkedList (java.util.LinkedList)2 RequirementViewsRepository (org.obeonetwork.dsl.requirement.parts.RequirementViewsRepository)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 AdapterFactory (org.eclipse.emf.common.notify.AdapterFactory)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 XMLResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl)1 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)1 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)1 EObjectStrictFilter (org.eclipse.emf.eef.runtime.impl.filters.EObjectStrictFilter)1