Search in sources :

Example 1 with RootElement

use of org.obeonetwork.graal.design.ui.providers.RootElement in project InformationSystem by ObeoNetwork.

the class CreateUseRelationshipDialog method createDialogArea.

/**
 * Create contents of the dialog.
 * @param parent
 */
@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);
    container.setLayout(new GridLayout(2, false));
    Label lblSource = new Label(container, SWT.NONE);
    lblSource.setText("Source :");
    Label lblTarget = new Label(container, SWT.NONE);
    lblTarget.setText("Target :");
    treeSourceViewer = new TreeViewer(container, SWT.BORDER | SWT.MULTI);
    treeSourceViewer.setContentProvider(new TasksContentProvider());
    treeSourceViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
    treeSourceViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("rawtypes")
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection().isEmpty()) {
                selectedTasksAsSource.clear();
            } else if (event.getSelection() instanceof IStructuredSelection) {
                selectedTasksAsSource.clear();
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                for (Iterator iterator = selection.iterator(); iterator.hasNext(); ) {
                    Object domain = (Object) iterator.next();
                    if (domain instanceof Task) {
                        selectedTasksAsSource.add((Task) domain);
                    }
                }
            }
            computeOkButtonState();
        }
    });
    treeSourceViewer.setInput(new RootElement(this.source));
    treeSourceViewer.setSelection(new StructuredSelection(this.source), true);
    Tree treeSource = treeSourceViewer.getTree();
    treeSource.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    treeTargetViewer = new TreeViewer(container, SWT.BORDER | SWT.MULTI);
    treeTargetViewer.setContentProvider(new TasksContentProvider());
    treeTargetViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
    treeTargetViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @SuppressWarnings("rawtypes")
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection().isEmpty()) {
                selectedTasksAsTarget.clear();
            } else if (event.getSelection() instanceof IStructuredSelection) {
                selectedTasksAsTarget.clear();
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                for (Iterator iterator = selection.iterator(); iterator.hasNext(); ) {
                    Object domain = (Object) iterator.next();
                    if (domain instanceof Task) {
                        selectedTasksAsTarget.add((Task) domain);
                    }
                }
            }
            computeOkButtonState();
        }
    });
    treeTargetViewer.setInput(new RootElement(this.target));
    treeTargetViewer.setSelection(new StructuredSelection(this.target), true);
    Tree treeTarget = treeTargetViewer.getTree();
    treeTarget.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    return container;
}
Also used : Task(org.obeonetwork.graal.Task) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) RootElement(org.obeonetwork.graal.design.ui.providers.RootElement) Iterator(java.util.Iterator) GridData(org.eclipse.swt.layout.GridData) TasksContentProvider(org.obeonetwork.graal.design.ui.providers.TasksContentProvider) Tree(org.eclipse.swt.widgets.Tree) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

Iterator (java.util.Iterator)1 EObject (org.eclipse.emf.ecore.EObject)1 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1 TreeViewer (org.eclipse.jface.viewers.TreeViewer)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Tree (org.eclipse.swt.widgets.Tree)1 Task (org.obeonetwork.graal.Task)1 RootElement (org.obeonetwork.graal.design.ui.providers.RootElement)1 TasksContentProvider (org.obeonetwork.graal.design.ui.providers.TasksContentProvider)1