Search in sources :

Example 6 with Category

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

the class CategoryPropertiesEditionComponent 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 Category category = (Category) elt;
        final CategoryPropertiesEditionPart categoryPart = (CategoryPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(RequirementViewsRepository.Category.Category_.id))
            categoryPart.setId(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, category.getId()));
        if (isAccessible(RequirementViewsRepository.Category.Category_.name))
            categoryPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, category.getName()));
        if (isAccessible(RequirementViewsRepository.Category.Category_.requirements)) {
            requirementsSettings = new ReferencesTableSettings(category, RequirementPackage.eINSTANCE.getCategory_Requirements());
            categoryPart.initRequirements(requirementsSettings);
        }
        if (isAccessible(RequirementViewsRepository.Category.Category_.subCategories)) {
            subCategoriesSettings = new ReferencesTableSettings(category, RequirementPackage.eINSTANCE.getCategory_SubCategories());
            categoryPart.initSubCategories(subCategoriesSettings);
        }
        if (isAccessible(RequirementViewsRepository.Category.Category_.requirements)) {
            categoryPart.addFilterToRequirements(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 Requirement);
                }
            });
        // Start of user code for additional businessfilters for requirements
        // End of user code
        }
        if (isAccessible(RequirementViewsRepository.Category.Category_.subCategories)) {
            categoryPart.addFilterToSubCategories(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 subCategories
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : Requirement(org.obeonetwork.dsl.requirement.Requirement) Category(org.obeonetwork.dsl.requirement.Category) ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) CategoryPropertiesEditionPart(org.obeonetwork.dsl.requirement.parts.CategoryPropertiesEditionPart) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject)

Example 7 with Category

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

the class RequirementEditingOperation method doExecute.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.emf.eef.runtime.impl.operation.WizardEditingOperation#doExecute(org.eclipse.core.runtime.IProgressMonitor,
 *      org.eclipse.core.runtime.IAdaptable)
 */
@Override
protected IStatus doExecute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    editingContext.initializeRecorder();
    RequirementEditingWizard wizard = new RequirementEditingWizard(editingContext, editingContext.getAdapterFactory(), editingContext.getEObject());
    EEFWizardDialog wDialog = new EEFWizardDialog(EditingUtils.getShell(), wizard);
    int open = wDialog.open();
    ChangeDescription description = editingContext.getChangeRecorder().endRecording();
    if (open == Window.OK) {
        if (wizard.getOwningCategory() != null) {
            Category category = wizard.getOwningCategory();
            if (editingContext.getEObject().eContainer() != category) {
                category.getRequirements().add((Requirement) editingContext.getEObject());
            }
        }
        return Status.OK_STATUS;
    } else {
        description.applyAndReverse();
        return Status.CANCEL_STATUS;
    }
}
Also used : Category(org.obeonetwork.dsl.requirement.Category) EEFWizardDialog(org.eclipse.emf.eef.runtime.ui.wizards.EEFWizardDialog) ChangeDescription(org.eclipse.emf.ecore.change.ChangeDescription) RequirementEditingWizard(org.obeonetwork.tools.requirement.wizard.RequirementEditingWizard)

Example 8 with Category

use of org.obeonetwork.dsl.requirement.Category 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 9 with Category

use of org.obeonetwork.dsl.requirement.Category 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 10 with Category

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

the class CategoriesTreeContentProvider method getChildren.

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof CategoriesContainer) {
        CategoriesContainer categoriesContainer = (CategoriesContainer) parentElement;
        List<Category> ownedCategories = new ArrayList<Category>(categoriesContainer.getOwnedCategories());
        ownedCategories.removeAll(hiddenCategories);
        Collections.sort(ownedCategories, CategoryComparator.INSTANCE);
        return ownedCategories.toArray();
    }
    return new Object[] {};
}
Also used : CategoriesContainer(org.obeonetwork.dsl.requirement.CategoriesContainer) Category(org.obeonetwork.dsl.requirement.Category) ArrayList(java.util.ArrayList) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

Category (org.obeonetwork.dsl.requirement.Category)15 EObject (org.eclipse.emf.ecore.EObject)12 Repository (org.obeonetwork.dsl.requirement.Repository)7 Requirement (org.obeonetwork.dsl.requirement.Requirement)6 Resource (org.eclipse.emf.ecore.resource.Resource)4 ArrayList (java.util.ArrayList)3 Shell (org.eclipse.swt.widgets.Shell)3 CategorySelectionDialog (org.obeonetwork.dsl.requirement.design.selection.CategorySelectionDialog)3 List (java.util.List)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 EObjectPropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EObjectPropertiesEditionContext)2 EReferencePropertiesEditionContext (org.eclipse.emf.eef.runtime.context.impl.EReferencePropertiesEditionContext)2 PropertiesEditingPolicy (org.eclipse.emf.eef.runtime.policies.PropertiesEditingPolicy)2 CreateEditingPolicy (org.eclipse.emf.eef.runtime.policies.impl.CreateEditingPolicy)2 PropertiesEditingProvider (org.eclipse.emf.eef.runtime.providers.PropertiesEditingProvider)2 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)2 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)2