Search in sources :

Example 1 with RequirementsRepositoriesContentProvider

use of org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider in project InformationSystem by ObeoNetwork.

the class LinkRequirementsDialog method createRequirementsTreeViewer.

/**
 * Creates, in the given {@link Composite}, the {@link CheckBoxTreeViewer}
 * allowing users to select and unselect {@link Requirement Requirements} to
 * associate with the selected model element.
 *
 * @param parent
 *            the parent in which the {@link CheckboxTreeViewer} must be
 *            created.
 * @param adapterFactory
 *            the {@link IAdapterFactory}.
 * @param selectedEObject
 *            the contextual {@link EObject}.
 */
private static CheckboxTreeViewer createRequirementsTreeViewer(Composite parent, AdapterFactory adapterFactory, EObject selectedEObject) {
    CheckboxTreeViewer checkBoxTreeViewer = new CheckboxTreeViewer(parent, SWT.MULTI | SWT.BORDER | SWT.CHECK);
    // Layout
    GridData gd_tree = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
    gd_tree.heightHint = 208;
    Tree tree = checkBoxTreeViewer.getTree();
    tree.setLayoutData(gd_tree);
    // Contents
    checkBoxTreeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
    checkBoxTreeViewer.setContentProvider(new RequirementsRepositoriesContentProvider(adapterFactory));
    checkBoxTreeViewer.setInput(RequirementService.findRequirementsRepositories(selectedEObject));
    checkBoxTreeViewer.setCheckedElements(determineObjectsToCheck(RequirementService.getLinkedRequirementsSet(selectedEObject)).toArray());
    checkBoxTreeViewer.setGrayedElements(determineObjectsToGray(RequirementService.getLinkedRequirementsSet(selectedEObject)).toArray());
    // Expands the tree viewer up to all the checked elements. This way the
    // user can easily add or remove requirement links with requirements
    // which are located alongside already-checked requirements.
    expandTreeViewerUpToCheckedElements(checkBoxTreeViewer, Arrays.asList(RequirementService.getLinkedRequirements(selectedEObject)));
    checkBoxTreeViewer.addCheckStateListener(new LinkRequirementsCheckStateListener());
    return checkBoxTreeViewer;
}
Also used : CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) RequirementsRepositoriesContentProvider(org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider) GridData(org.eclipse.swt.layout.GridData) Tree(org.eclipse.swt.widgets.Tree) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)

Example 2 with RequirementsRepositoriesContentProvider

use of org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider 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)

Aggregations

GridData (org.eclipse.swt.layout.GridData)2 RequirementsRepositoriesContentProvider (org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider)2 AdapterFactory (org.eclipse.emf.common.notify.AdapterFactory)1 EObject (org.eclipse.emf.ecore.EObject)1 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Tree (org.eclipse.swt.widgets.Tree)1 Category (org.obeonetwork.dsl.requirement.Category)1 Repository (org.obeonetwork.dsl.requirement.Repository)1