Search in sources :

Example 31 with ListViewer

use of org.eclipse.jface.viewers.ListViewer in project hale by halestudio.

the class RuleStylePage method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    changed = false;
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(2, false));
    // DISABLED - this method seems to change the rule order - Rule[]
    // ruleArray = SLD.rules(getParent().getStyle());
    // use list instead:
    List<Rule> ruleList;
    try {
        ruleList = getParent().getStyle().featureTypeStyles().get(0).rules();
    } catch (Exception e) {
        ruleList = new ArrayList<Rule>();
    }
    // init index
    if (ruleList.size() > 0) {
        currentIndex = 0;
    } else {
        currentIndex = -1;
    }
    currentEditor = null;
    // populate rule map
    rules = new ArrayList<RuleItem>(ruleList.size() + 5);
    for (int i = 0; i < ruleList.size(); i++) {
        Rule rule = ruleList.get(i);
        if (rule != null) {
            rules.add(new RuleItem(rule));
        }
    }
    // rule list
    Composite ruleArea = new Composite(page, SWT.NONE);
    ruleArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    GridLayout leftLayout = new GridLayout(5, true);
    leftLayout.horizontalSpacing = 1;
    leftLayout.verticalSpacing = 1;
    ruleArea.setLayout(leftLayout);
    // label
    Label rulesLabel = new Label(ruleArea, SWT.NONE);
    rulesLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 5, 1));
    rulesLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    rulesLabel.setText(Messages.RuleStylePage_RuleLabelText);
    // viewer
    listViewer = new ListViewer(ruleArea);
    listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 5, 1));
    listViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // ignore
        }

        @Override
        public void dispose() {
        // ignore
        }

        @SuppressWarnings("unchecked")
        @Override
        public Object[] getElements(Object inputElement) {
            try {
                List<RuleItem> rules = (List<RuleItem>) inputElement;
                return rules.toArray();
            } catch (Exception e) {
                return null;
            }
        }
    });
    listViewer.setInput(rules);
    if (currentIndex >= 0 && currentIndex < rules.size()) {
        listViewer.setSelection(new StructuredSelection(rules.get(currentIndex)));
    }
    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            RuleItem item = (RuleItem) ((IStructuredSelection) event.getSelection()).getFirstElement();
            int newIndex = rules.indexOf(item);
            if (currentIndex != newIndex) {
                try {
                    updateCurrentRule();
                } catch (Exception e) {
                    log.userError("Invalid editor state, could not update rule.", e);
                    return;
                }
                currentIndex = newIndex;
                updateEditor();
            }
        }
    });
    // buttons
    addButton = new Button(ruleArea, SWT.PUSH);
    addButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    addButton.setImage(addImage);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    addButton.setToolTipText(Messages.RuleStylePage_AddRuleButtonToolTippText);
    removeButton = new Button(ruleArea, SWT.PUSH);
    removeButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    removeButton.setImage(removeImage);
    removeButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeCurrentRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    removeButton.setToolTipText(Messages.RuleStylePage_RemoveRuleButtonToolTippText);
    upButton = new Button(ruleArea, SWT.PUSH);
    upButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    upButton.setImage(upImage);
    upButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveCurrentRuleUp();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    upButton.setToolTipText(Messages.RuleStylePage_UpRuleButtonToolTippText);
    downButton = new Button(ruleArea, SWT.PUSH);
    downButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    downButton.setImage(downImage);
    downButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveCurrentRuleDown();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    downButton.setToolTipText(Messages.RuleStylePage_DownRuleButtonToolTippText);
    renameButton = new Button(ruleArea, SWT.PUSH);
    renameButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    renameButton.setImage(renameImage);
    renameButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            renameCurrentRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    renameButton.setToolTipText(Messages.RuleStylePage_RenameRuleButtonToolTippText);
    // editor area
    editorArea = new Composite(page, SWT.NONE);
    editorArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    editorArea.setLayout(new FillLayout());
    setControl(page);
    updateEditor();
}
Also used : ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ListViewer(org.eclipse.jface.viewers.ListViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Rule(org.geotools.styling.Rule) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 32 with ListViewer

use of org.eclipse.jface.viewers.ListViewer in project hale by halestudio.

the class ActionUIWizardPage method createViewer.

/**
 * @see ViewerWizardSelectionPage#createViewer(Composite)
 */
@Override
protected Pair<StructuredViewer, Control> createViewer(Composite parent) {
    ListViewer viewer = new ListViewer(parent);
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public Image getImage(Object element) {
            if (element instanceof ActionUIWizardNode) {
                return ((ActionUIWizardNode) element).getImage();
            }
            return super.getImage(element);
        }

        @Override
        public String getText(Object element) {
            if (element instanceof ActionUIWizardNode) {
                return ((ActionUIWizardNode) element).getActionUI().getDisplayName();
            }
            return super.getText(element);
        }
    });
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    List<ActionUI> list = ActionUIExtension.getInstance().getFactories(filter);
    List<ActionUIWizardNode> nodes = new ArrayList<ActionUIWizardNode>();
    for (ActionUI action : list) {
        nodes.add(new ActionUIWizardNode(action, getContainer()));
    }
    viewer.setInput(nodes);
    return new Pair<StructuredViewer, Control>(viewer, viewer.getControl());
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) ArrayList(java.util.ArrayList) ActionUI(eu.esdihumboldt.hale.ui.io.action.ActionUI) Image(org.eclipse.swt.graphics.Image) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Pair(eu.esdihumboldt.util.Pair)

Example 33 with ListViewer

use of org.eclipse.jface.viewers.ListViewer in project hale by halestudio.

the class TransformDataWizardSourcePage method createControl.

/**
 * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
 */
@Override
public void createControl(Composite parent) {
    Composite content = new Composite(parent, SWT.NONE);
    content.setLayout(GridLayoutFactory.swtDefaults().create());
    final ListViewer listViewer = new ListViewer(content);
    listViewer.getControl().setLayoutData(GridDataFactory.fillDefaults().grab(true, true).create());
    if (!useProjectData) {
        Button addButton = new Button(content, SWT.PUSH);
        addButton.setText("Add source file");
        addButton.setLayoutData(GridDataFactory.swtDefaults().align(SWT.END, SWT.CENTER).create());
        addButton.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                InstanceImportWizard importWizard = new InstanceImportWizard();
                TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
                // specifying null as actionId results in no call to
                // ProjectService.rememberIO
                importWizard.setAdvisor(advisor, null);
                if (new HaleWizardDialog(getShell(), importWizard).open() == Dialog.OK) {
                    if (advisor.getInstances() != null) {
                        sourceCollections.add(advisor.getInstances());
                        listViewer.add(advisor.getLocation());
                        getContainer().updateButtons();
                    }
                }
            }
        });
    } else {
        // initialize project source data
        IRunnableWithProgress op = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                monitor.beginTask("Prepare data sources", IProgressMonitor.UNKNOWN);
                ProjectService ps = PlatformUI.getWorkbench().getService(ProjectService.class);
                final List<URI> locations = new ArrayList<>();
                for (Resource resource : ps.getResources()) {
                    if (InstanceIO.ACTION_LOAD_SOURCE_DATA.equals(resource.getActionId())) {
                        // resource is source data
                        IOConfiguration conf = resource.copyConfiguration(true);
                        TransformDataImportAdvisor advisor = new TransformDataImportAdvisor();
                        ProjectResourcesUtil.executeConfiguration(conf, advisor, false, null);
                        if (advisor.getInstances() != null) {
                            sourceCollections.add(advisor.getInstances());
                            locations.add(advisor.getLocation());
                        }
                    }
                }
                PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        for (URI location : locations) {
                            listViewer.add(location);
                        }
                    }
                });
                monitor.done();
            }
        };
        try {
            ThreadProgressMonitor.runWithProgressDialog(op, false);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    setControl(content);
}
Also used : InstanceImportWizard(eu.esdihumboldt.hale.ui.io.instance.InstanceImportWizard) ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) IOConfiguration(eu.esdihumboldt.hale.common.core.io.project.model.IOConfiguration) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ArrayList(java.util.ArrayList) Resource(eu.esdihumboldt.hale.common.core.io.project.model.Resource) ProjectService(eu.esdihumboldt.hale.ui.service.project.ProjectService) URI(java.net.URI) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HaleWizardDialog(eu.esdihumboldt.hale.ui.util.wizard.HaleWizardDialog)

Example 34 with ListViewer

use of org.eclipse.jface.viewers.ListViewer in project Malai by arnobl.

the class WidgetEditor method createPages.

/**
 * This is the method used by the framework to install your own controls.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void createPages() {
    // Creates the model from the editor input
    // 
    createModel();
    // 
    if (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
        // Create a page for the selection tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            selectionViewer = (TreeViewer) viewerPane.getViewer();
            selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            selectionViewer.setInput(editingDomain.getResourceSet());
            selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
            viewerPane.setTitle(editingDomain.getResourceSet());
            new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
            createContextMenuFor(selectionViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_SelectionPage_label"));
        }
        // Create a page for the parent tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            parentViewer = (TreeViewer) viewerPane.getViewer();
            parentViewer.setAutoExpandLevel(30);
            parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory));
            parentViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(parentViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ParentPage_label"));
        }
        // This is the page for the list viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new ListViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            listViewer = (ListViewer) viewerPane.getViewer();
            listViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            listViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(listViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ListPage_label"));
        }
        // This is the page for the tree viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewer = (TreeViewer) viewerPane.getViewer();
            treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory);
            createContextMenuFor(treeViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreePage_label"));
        }
        // This is the page for the table viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TableViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            tableViewer = (TableViewer) viewerPane.getViewer();
            Table table = tableViewer.getTable();
            TableLayout layout = new TableLayout();
            table.setLayout(layout);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            TableColumn objectColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(3, 100, true));
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            TableColumn selfColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(2, 100, true));
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            tableViewer.setColumnProperties(new String[] { "a", "b" });
            tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            tableViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(tableViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TablePage_label"));
        }
        // This is the page for the table tree viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), WidgetEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewerWithColumns = (TreeViewer) viewerPane.getViewer();
            Tree tree = treeViewerWithColumns.getTree();
            tree.setLayoutData(new FillLayout());
            tree.setHeaderVisible(true);
            tree.setLinesVisible(true);
            TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            objectColumn.setWidth(250);
            TreeColumn selfColumn = new TreeColumn(tree, SWT.NONE);
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            selfColumn.setWidth(200);
            treeViewerWithColumns.setColumnProperties(new String[] { "a", "b" });
            treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(treeViewerWithColumns);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreeWithColumnsPage_label"));
        }
        getSite().getShell().getDisplay().asyncExec(new Runnable() {

            public void run() {
                setActivePage(0);
            }
        });
    }
    // Ensures that this editor will only display the page's tab
    // area if there are more than one page
    // 
    getContainer().addControlListener(new ControlAdapter() {

        boolean guard = false;

        @Override
        public void controlResized(ControlEvent event) {
            if (!guard) {
                guard = true;
                hideTabs();
                guard = false;
            }
        }
    });
    getSite().getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            updateProblemIndication();
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ListViewer(org.eclipse.jface.viewers.ListViewer) AdapterFactoryTreeEditor(org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ViewerPane(org.eclipse.emf.common.ui.ViewerPane) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Example 35 with ListViewer

use of org.eclipse.jface.viewers.ListViewer in project Malai by arnobl.

the class ActionEditor method createPages.

/**
 * This is the method used by the framework to install your own controls.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void createPages() {
    // Creates the model from the editor input
    // 
    createModel();
    // 
    if (!getEditingDomain().getResourceSet().getResources().isEmpty()) {
        // Create a page for the selection tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            selectionViewer = (TreeViewer) viewerPane.getViewer();
            selectionViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            selectionViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            selectionViewer.setInput(editingDomain.getResourceSet());
            selectionViewer.setSelection(new StructuredSelection(editingDomain.getResourceSet().getResources().get(0)), true);
            viewerPane.setTitle(editingDomain.getResourceSet());
            new AdapterFactoryTreeEditor(selectionViewer.getTree(), adapterFactory);
            createContextMenuFor(selectionViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_SelectionPage_label"));
        }
        // Create a page for the parent tree view.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    Tree tree = new Tree(composite, SWT.MULTI);
                    TreeViewer newTreeViewer = new TreeViewer(tree);
                    return newTreeViewer;
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            parentViewer = (TreeViewer) viewerPane.getViewer();
            parentViewer.setAutoExpandLevel(30);
            parentViewer.setContentProvider(new ReverseAdapterFactoryContentProvider(adapterFactory));
            parentViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(parentViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ParentPage_label"));
        }
        // This is the page for the list viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new ListViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            listViewer = (ListViewer) viewerPane.getViewer();
            listViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            listViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(listViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_ListPage_label"));
        }
        // This is the page for the tree viewer
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewer = (TreeViewer) viewerPane.getViewer();
            treeViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            new AdapterFactoryTreeEditor(treeViewer.getTree(), adapterFactory);
            createContextMenuFor(treeViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreePage_label"));
        }
        // This is the page for the table viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TableViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            tableViewer = (TableViewer) viewerPane.getViewer();
            Table table = tableViewer.getTable();
            TableLayout layout = new TableLayout();
            table.setLayout(layout);
            table.setHeaderVisible(true);
            table.setLinesVisible(true);
            TableColumn objectColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(3, 100, true));
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            TableColumn selfColumn = new TableColumn(table, SWT.NONE);
            layout.addColumnData(new ColumnWeightData(2, 100, true));
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            tableViewer.setColumnProperties(new String[] { "a", "b" });
            tableViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            tableViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(tableViewer);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TablePage_label"));
        }
        // This is the page for the table tree viewer.
        // 
        {
            ViewerPane viewerPane = new ViewerPane(getSite().getPage(), ActionEditor.this) {

                @Override
                public Viewer createViewer(Composite composite) {
                    return new TreeViewer(composite);
                }

                @Override
                public void requestActivation() {
                    super.requestActivation();
                    setCurrentViewerPane(this);
                }
            };
            viewerPane.createControl(getContainer());
            treeViewerWithColumns = (TreeViewer) viewerPane.getViewer();
            Tree tree = treeViewerWithColumns.getTree();
            tree.setLayoutData(new FillLayout());
            tree.setHeaderVisible(true);
            tree.setLinesVisible(true);
            TreeColumn objectColumn = new TreeColumn(tree, SWT.NONE);
            objectColumn.setText(getString("_UI_ObjectColumn_label"));
            objectColumn.setResizable(true);
            objectColumn.setWidth(250);
            TreeColumn selfColumn = new TreeColumn(tree, SWT.NONE);
            selfColumn.setText(getString("_UI_SelfColumn_label"));
            selfColumn.setResizable(true);
            selfColumn.setWidth(200);
            treeViewerWithColumns.setColumnProperties(new String[] { "a", "b" });
            treeViewerWithColumns.setContentProvider(new AdapterFactoryContentProvider(adapterFactory));
            treeViewerWithColumns.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory));
            createContextMenuFor(treeViewerWithColumns);
            int pageIndex = addPage(viewerPane.getControl());
            setPageText(pageIndex, getString("_UI_TreeWithColumnsPage_label"));
        }
        getSite().getShell().getDisplay().asyncExec(new Runnable() {

            public void run() {
                setActivePage(0);
            }
        });
    }
    // Ensures that this editor will only display the page's tab
    // area if there are more than one page
    // 
    getContainer().addControlListener(new ControlAdapter() {

        boolean guard = false;

        @Override
        public void controlResized(ControlEvent event) {
            if (!guard) {
                guard = true;
                hideTabs();
                guard = false;
            }
        }
    });
    getSite().getShell().getDisplay().asyncExec(new Runnable() {

        public void run() {
            updateProblemIndication();
        }
    });
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ListViewer(org.eclipse.jface.viewers.ListViewer) AdapterFactoryTreeEditor(org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ControlAdapter(org.eclipse.swt.events.ControlAdapter) ViewerPane(org.eclipse.emf.common.ui.ViewerPane) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) AdapterFactoryContentProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider) AdapterFactoryLabelProvider(org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) ListViewer(org.eclipse.jface.viewers.ListViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) FillLayout(org.eclipse.swt.layout.FillLayout) TableColumn(org.eclipse.swt.widgets.TableColumn) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) ControlEvent(org.eclipse.swt.events.ControlEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout)

Aggregations

ListViewer (org.eclipse.jface.viewers.ListViewer)69 Composite (org.eclipse.swt.widgets.Composite)49 Viewer (org.eclipse.jface.viewers.Viewer)34 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 GridData (org.eclipse.swt.layout.GridData)29 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)27 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)26 FillLayout (org.eclipse.swt.layout.FillLayout)26 TableViewer (org.eclipse.jface.viewers.TableViewer)23 TreeViewer (org.eclipse.jface.viewers.TreeViewer)23 GridLayout (org.eclipse.swt.layout.GridLayout)22 AdapterFactoryContentProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider)21 Table (org.eclipse.swt.widgets.Table)21 Tree (org.eclipse.swt.widgets.Tree)21 ViewerPane (org.eclipse.emf.common.ui.ViewerPane)20 AdapterFactoryTreeEditor (org.eclipse.emf.edit.ui.celleditor.AdapterFactoryTreeEditor)20 AdapterFactoryLabelProvider (org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider)20 ControlAdapter (org.eclipse.swt.events.ControlAdapter)20 ControlEvent (org.eclipse.swt.events.ControlEvent)20 ColumnWeightData (org.eclipse.jface.viewers.ColumnWeightData)19