Search in sources :

Example 1 with XPathTreeContentProvider

use of com.amalto.workbench.providers.XPathTreeContentProvider in project tmdm-studio-se by Talend.

the class XpathSelectDialog method provideViwerContent.

// changeDomTree(
protected void provideViwerContent(XSDSchema xsdSchema, String filter) {
    drillDownAdapter = new DrillDownAdapter(domViewer);
    domViewer.setLabelProvider(new XSDTreeLabelProvider(selectionFilter));
    XPathTreeContentProvider provider = new XPathTreeContentProvider(this.site, xsdSchema, parent, filter);
    // filter the entity with the filter text but not the concept name.
    // provider.setConceptName(this.conceptName);
    domViewer.setContentProvider(provider);
    domViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent e) {
            StructuredSelection sel = (StructuredSelection) e.getSelection();
            xpath = getXpath(sel);
            xpathText.setText(xpath);
            boolean enable = false;
            if (selectionFilter == null) {
                enable = xpath.length() > 0;
            } else {
                enable = xpath.length() > 0 && (selectionFilter.check(sel.getFirstElement()) == FilterResult.ENABLE);
            }
            getButton(IDialogConstants.OK_ID).setEnabled(enable);
        }
    });
    domViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    domViewer.setSorter(new ViewerSorter() {

        @Override
        public int category(Object element) {
            // SimpleTypeDefinition
            if (element instanceof XSDFacet) {
                return 100;
            }
            // unique keys after element declarations and before other keys
            if (element instanceof XSDIdentityConstraintDefinition) {
                XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) element;
                if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) {
                    return 300;
                } else if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.KEY_LITERAL)) {
                    return 301;
                } else {
                    return 302;
                }
            }
            return 200;
        }

        @Override
        public int compare(Viewer theViewer, Object e1, Object e2) {
            int cat1 = category(e1);
            int cat2 = category(e2);
            return cat1 - cat2;
        }
    });
    domViewer.setInput(site);
}
Also used : DrillDownAdapter(org.eclipse.ui.part.DrillDownAdapter) XSDTreeLabelProvider(com.amalto.workbench.providers.XSDTreeLabelProvider) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) XPathTreeContentProvider(com.amalto.workbench.providers.XPathTreeContentProvider) XSDFacet(org.eclipse.xsd.XSDFacet) GridData(org.eclipse.swt.layout.GridData) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) TreeObject(com.amalto.workbench.models.TreeObject)

Aggregations

TreeObject (com.amalto.workbench.models.TreeObject)1 XPathTreeContentProvider (com.amalto.workbench.providers.XPathTreeContentProvider)1 XSDTreeLabelProvider (com.amalto.workbench.providers.XSDTreeLabelProvider)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 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)1 GridData (org.eclipse.swt.layout.GridData)1 DrillDownAdapter (org.eclipse.ui.part.DrillDownAdapter)1 XSDFacet (org.eclipse.xsd.XSDFacet)1 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)1