Search in sources :

Example 1 with XSDTreeLabelProvider

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

the class SelectImportedModulesDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    parent.getShell().setText(this.title);
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 2;
    SashForm form = new SashForm(composite, SWT.HORIZONTAL);
    GridData data = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
    data.widthHint = 400;
    data.heightHint = 300;
    form.setLayoutData(data);
    entityViewer = createTableViewer(form, "Entities", entityprovider, new XSDTreeLabelProvider());
    typeViewer = createTableViewer(form, "Types", typeprovider, new TypesLabelProvider());
    form.setWeights(new int[] { 3, 5 });
    Composite compositeBtn = new Composite(composite, SWT.FILL);
    compositeBtn.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
    compositeBtn.setLayout(new GridLayout(1, false));
    Button addXSDFromLocal = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
    addXSDFromLocal.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
    addXSDFromLocal.setText(Messages.AddXsdFromlocal);
    addXSDFromLocal.setToolTipText(Messages.AddXsdSchemaFromlocal);
    addXSDFromLocal.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            FileDialog fd = new FileDialog(shell.getShell(), SWT.SAVE);
            // $NON-NLS-1$
            fd.setFilterExtensions(new String[] { "*.xsd" });
            fd.setText(Messages.ImportXSDSchema);
            String filename = fd.open();
            if (filename == null) {
                return;
            }
            URL url = getSourceURL("file:///" + filename);
            addSchema(url, true);
        }
    });
    if (exAdapter != null) {
        exAdapter.createDialogArea(compositeBtn);
    }
    Button impXSDFromExchange = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
    impXSDFromExchange.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
    impXSDFromExchange.setText(Messages.ImportFromExchangeServer);
    impXSDFromExchange.setToolTipText(Messages.ImportSchemaFromServer);
    impXSDFromExchange.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            StringBuffer repository = new StringBuffer();
            ImportExchangeOptionsDialog dlg = new ImportExchangeOptionsDialog(shell.getShell(), null, false, repository);
            dlg.setBlockOnOpen(true);
            int ret = dlg.open();
            if (ret == Window.OK) {
                File dir = new File(repository.toString());
                File[] fs = dir.listFiles(new FileFilter() {

                    public boolean accept(File pathname) {
                        return pathname.getName().endsWith(".xsd");
                    }
                });
                if (null == fs || fs.length == 0) {
                    MessageDialog.openWarning(getShell(), Messages.import_schema_failed, Messages.no_schema_available);
                    return;
                }
                for (File file : fs) {
                    URL url = getSourceURL("file:///" + file.getPath());
                    addSchema(url, true);
                }
            }
        }
    });
    Button addXSDFromInputDlg = new Button(compositeBtn, SWT.PUSH | SWT.FILL);
    addXSDFromInputDlg.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false, 1, 1));
    addXSDFromInputDlg.setText(Messages.AddXsdFromOther);
    addXSDFromInputDlg.setToolTipText(Messages.AddFromOtherSite);
    addXSDFromInputDlg.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            InputDialog id = new InputDialog(shell.getShell(), Messages.AddXsdFromOther, Messages.EnterTextUrl, "", new // $NON-NLS-1$
            IInputValidator() {

                public String isValid(String newText) {
                    if ((newText == null) || "".equals(newText)) {
                        return Messages.NameNotEmpty;
                    }
                    return null;
                }
            });
            id.setBlockOnOpen(true);
            int ret = id.open();
            if (ret == Window.CANCEL) {
                return;
            }
            URL url = getSourceURL(id.getValue());
            addSchema(url, true);
        }
    });
    entityViewer.setInput(addContent);
    typeViewer.setInput(addContent);
    return composite;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) XSDTreeLabelProvider(com.amalto.workbench.providers.XSDTreeLabelProvider) TypesLabelProvider(com.amalto.workbench.providers.TypesLabelProvider) URL(java.net.URL) SashForm(org.eclipse.swt.custom.SashForm) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileFilter(java.io.FileFilter) FileDialog(org.eclipse.swt.widgets.FileDialog) File(java.io.File) SelectionListener(org.eclipse.swt.events.SelectionListener) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 2 with XSDTreeLabelProvider

use of com.amalto.workbench.providers.XSDTreeLabelProvider 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)

Example 3 with XSDTreeLabelProvider

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

the class DataModelMainPage method createSchemaTreeComp.

private void createSchemaTreeComp(Composite parent) {
    Composite schemaSash = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.verticalSpacing = 0;
    schemaSash.setLayout(layout);
    schemaSash.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    schemaSash.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    Composite compInfo = new Composite(schemaSash, SWT.NONE);
    layout = new GridLayout();
    layout.verticalSpacing = 0;
    compInfo.setLayout(layout);
    compInfo.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    compInfo.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    Composite compSchemaTree = new Composite(schemaSash, SWT.NONE);
    GridLayout glCompSchemaTree = new GridLayout();
    glCompSchemaTree.verticalSpacing = 0;
    glCompSchemaTree.marginWidth = 0;
    glCompSchemaTree.marginHeight = 0;
    glCompSchemaTree.horizontalSpacing = 0;
    compSchemaTree.setLayout(glCompSchemaTree);
    compSchemaTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    compSchemaTree.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    Label title = new Label(compInfo, SWT.VERTICAL);
    title.setText(Messages.DataModelEntities);
    title.setFont(FontUtils.getBoldFont(title.getFont()));
    Color blue = new Color(compInfo.getDisplay(), 0, 0, 255);
    title.setForeground(blue);
    title.setBackground(sash.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    ToolBar toolBarSchemaTree = createToolbarOnComposite(compSchemaTree);
    viewer = new TreeViewer(compSchemaTree, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    addToolItems2SchemaTreeToolBar(toolBarSchemaTree);
    toolBarSchemaTree.pack();
    drillDownAdapter = new DrillDownAdapter(viewer);
    schemaTreeContentProvider = new SchemaTreeContentProvider(this.getSite(), xsdSchema);
    viewer.setContentProvider(schemaTreeContentProvider);
    viewer.setFilters(new ViewerFilter[] { new SchemaRoleAccessFilter(null), new SchemaNameFilter(), new SchemaUniqueElementFilter() });
    viewer.getTree().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            isSchemaSelected = true;
        }
    });
    viewer.setLabelProvider(new XSDTreeLabelProvider());
    viewer.setSorter(schemaTreeSorter);
    // getViewSite());
    viewer.setInput(this.getSite());
    viewer.getTree().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            if (isReadOnly()) {
                return;
            }
            IStructuredSelection selection = ((IStructuredSelection) viewer.getSelection());
            // delete
            if ((e.stateMask == 0) && (e.keyCode == SWT.DEL)) {
                if (deleteConceptWrapAction.checkInDeletableType(selection.toArray())) {
                    deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
                    deleteConceptWrapAction.run();
                } else {
                    MessageDialog.openWarning(getSite().getShell(), Messages.Warning, Messages.SelectDeletableTry);
                }
            }
        }
    });
    viewer.setComparer(new ElementComparer());
}
Also used : DrillDownAdapter(org.eclipse.ui.part.DrillDownAdapter) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) DescAnnotationComposite(com.amalto.workbench.widgets.DescAnnotationComposite) XSDTreeLabelProvider(com.amalto.workbench.providers.XSDTreeLabelProvider) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IElementComparer(org.eclipse.jface.viewers.IElementComparer) Color(org.eclipse.swt.graphics.Color) KeyAdapter(org.eclipse.swt.events.KeyAdapter) Label(org.eclipse.swt.widgets.Label) MouseAdapter(org.eclipse.swt.events.MouseAdapter) SchemaNameFilter(com.amalto.workbench.providers.datamodel.SchemaNameFilter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SchemaTreeContentProvider(com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) SchemaRoleAccessFilter(com.amalto.workbench.providers.datamodel.SchemaRoleAccessFilter) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) SchemaUniqueElementFilter(com.amalto.workbench.providers.datamodel.SchemaUniqueElementFilter)

Aggregations

XSDTreeLabelProvider (com.amalto.workbench.providers.XSDTreeLabelProvider)3 GridData (org.eclipse.swt.layout.GridData)3 TreeViewer (org.eclipse.jface.viewers.TreeViewer)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 DrillDownAdapter (org.eclipse.ui.part.DrillDownAdapter)2 TreeObject (com.amalto.workbench.models.TreeObject)1 TypesLabelProvider (com.amalto.workbench.providers.TypesLabelProvider)1 XPathTreeContentProvider (com.amalto.workbench.providers.XPathTreeContentProvider)1 SchemaNameFilter (com.amalto.workbench.providers.datamodel.SchemaNameFilter)1 SchemaRoleAccessFilter (com.amalto.workbench.providers.datamodel.SchemaRoleAccessFilter)1 SchemaTreeContentProvider (com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider)1 SchemaUniqueElementFilter (com.amalto.workbench.providers.datamodel.SchemaUniqueElementFilter)1 DescAnnotationComposite (com.amalto.workbench.widgets.DescAnnotationComposite)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 URL (java.net.URL)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IElementComparer (org.eclipse.jface.viewers.IElementComparer)1