Search in sources :

Example 1 with LinkedRequirementsLabelProvider

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

AdapterFactory (org.eclipse.emf.common.notify.AdapterFactory)1 EObject (org.eclipse.emf.ecore.EObject)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)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 GridData (org.eclipse.swt.layout.GridData)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 Category (org.obeonetwork.dsl.requirement.Category)1 Repository (org.obeonetwork.dsl.requirement.Repository)1 LinkedRequirementsLabelProvider (org.obeonetwork.tools.requirement.wizard.util.LinkedRequirementsLabelProvider)1 RequirementsRepositoriesContentProvider (org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider)1