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;
}
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);
}
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[] {};
}
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));
}
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);
}
Aggregations