Search in sources :

Example 1 with SchemaTreeContentProvider

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

the class XSDDeleteConceptWrapAction method populateAllOffspring.

/**
 * Author: Fliu this fun is to populate all offsprings for a specific object
 */
private Object[] populateAllOffspring(Object obj, ArrayList offspringList) {
    SchemaTreeContentProvider provider = (SchemaTreeContentProvider) viewer.getContentProvider();
    Object[] offersprings = provider.getChildren(obj);
    for (Object subObj : offersprings) {
        if (!offspringList.contains(subObj)) {
            offspringList.add(subObj);
            if (provider.hasChildren(subObj)) {
                populateAllOffspring(subObj, offspringList);
            }
        } else {
            continue;
        }
    }
    return offspringList.toArray();
}
Also used : SchemaTreeContentProvider(com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider)

Example 2 with SchemaTreeContentProvider

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

Example 3 with SchemaTreeContentProvider

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

the class TreeExpandHelper method getExpandedEntityElements.

// ///
private Object[] getExpandedEntityElements(DataModelMainPage mainPage) {
    TreeViewer elementsViewer = mainPage.getElementsViewer();
    SchemaTreeContentProvider contentProvider = (SchemaTreeContentProvider) elementsViewer.getContentProvider();
    Object[] xsdDeclarations = getChildren(contentProvider.getXsdSchema(), contentProvider);
    // 
    List<Object> result = new ArrayList<Object>();
    // 
    Deque<ExpandInfoNode> nodeStack = new LinkedList<ExpandInfoNode>();
    // 
    Deque<Object> elementStack = new LinkedList<Object>();
    // record entities
    Map<ExpandInfoNode, XSDElementDeclaration> expandedRoots = new HashMap<ExpandInfoNode, XSDElementDeclaration>();
    for (Object obj : xsdDeclarations) {
        if (obj instanceof XSDElementDeclaration) {
            XSDElementDeclaration decl = (XSDElementDeclaration) obj;
            String name = decl.getName();
            for (ExpandInfoNode node : expandedElements) {
                if (name.equals(node.name)) {
                    expandedRoots.put(node, decl);
                    result.add(decl);
                    // /
                    nodeStack.add(node);
                    // /
                    elementStack.add(decl);
                    break;
                }
            }
        }
    }
    while (!nodeStack.isEmpty() && !elementStack.isEmpty()) {
        ExpandInfoNode node = nodeStack.pollFirst();
        Object element = elementStack.pollFirst();
        List<ExpandInfoNode> nodes = node.childs;
        Object[] elementChildren = getChildren(element, contentProvider);
        if (nodes != null && nodes.size() > 0 && elementChildren != null) {
            Map<ExpandInfoNode, Object> nodeElementPairs = getNodeElementPairs(elementChildren, nodes);
            for (ExpandInfoNode node2 : nodeElementPairs.keySet()) {
                nodeStack.add(node2);
                elementStack.add(nodeElementPairs.get(node2));
                result.add(nodeElementPairs.get(node2));
            }
        }
    }
    return result.toArray();
}
Also used : HashMap(java.util.HashMap) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SchemaTreeContentProvider(com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration)

Example 4 with SchemaTreeContentProvider

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

the class EntityCommitHandler method updateReferenceForNewName.

private void updateReferenceForNewName(XSDElementDeclaration xsdElementDeclaration, String oldName) {
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IWorkbenchPartSite site = activePage.getActivePart().getSite();
    SchemaTreeContentProvider contentProvider = new SchemaTreeContentProvider(site, getCommitedObj().getSchema());
    Object[] objs = Util.getAllObject(site, new ArrayList<Object>(), contentProvider);
    Object[] allForeignKeyAndInfos = Util.getAllForeignKeyRelatedInfos(site, new ArrayList<Object>(), contentProvider, new HashSet<Object>());
    String newName = getCommitedObj().getName();
    Util.updateReference(xsdElementDeclaration, objs, allForeignKeyAndInfos, oldName, newName);
    EntitySyncProcessor.syncNameForAnnotation(xsdElementDeclaration, oldName, newName);
    xsdElementDeclaration.updateElement();
}
Also used : IWorkbenchPartSite(org.eclipse.ui.IWorkbenchPartSite) SchemaTreeContentProvider(com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 5 with SchemaTreeContentProvider

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

the class TreeExpandHelper method getExpandedTypeElements.

private Object[] getExpandedTypeElements(DataModelMainPage mainPage) {
    TreeViewer typesViewer = mainPage.getTypesViewer();
    SchemaTreeContentProvider contentProvider = (SchemaTreeContentProvider) typesViewer.getContentProvider();
    Object[] xsdDeclarations = getChildren(contentProvider.getXsdSchema(), contentProvider);
    // 
    List<Object> result = new ArrayList<Object>();
    // 
    Deque<ExpandInfoNode> nodeStack = new LinkedList<ExpandInfoNode>();
    // 
    Deque<Object> elementStack = new LinkedList<Object>();
    // record entities
    Map<ExpandInfoNode, XSDTypeDefinition> expandedRoots = new HashMap<ExpandInfoNode, XSDTypeDefinition>();
    for (Object obj : xsdDeclarations) {
        XSDTypeDefinition type = (XSDTypeDefinition) obj;
        String name = type.getName();
        for (ExpandInfoNode node : expandedTypes) {
            if (name.equals(node.name)) {
                expandedRoots.put(node, type);
                result.add(type);
                // /
                nodeStack.add(node);
                // /
                elementStack.add(type);
                break;
            }
        }
    }
    while (!nodeStack.isEmpty() && !elementStack.isEmpty()) {
        ExpandInfoNode node = nodeStack.pollFirst();
        Object element = elementStack.pollFirst();
        List<ExpandInfoNode> nodes = node.childs;
        Object[] elementChildren = getChildren(element, contentProvider);
        if (nodes != null && nodes.size() > 0 && elementChildren != null) {
            Map<ExpandInfoNode, Object> nodeElementPairs = getNodeElementPairs(elementChildren, nodes);
            for (ExpandInfoNode node2 : nodeElementPairs.keySet()) {
                nodeStack.add(node2);
                elementStack.add(nodeElementPairs.get(node2));
                result.add(nodeElementPairs.get(node2));
            }
        }
    }
    return result.toArray();
}
Also used : HashMap(java.util.HashMap) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) SchemaTreeContentProvider(com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider)

Aggregations

SchemaTreeContentProvider (com.amalto.workbench.providers.datamodel.SchemaTreeContentProvider)5 TreeViewer (org.eclipse.jface.viewers.TreeViewer)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 XSDTreeLabelProvider (com.amalto.workbench.providers.XSDTreeLabelProvider)1 SchemaNameFilter (com.amalto.workbench.providers.datamodel.SchemaNameFilter)1 SchemaRoleAccessFilter (com.amalto.workbench.providers.datamodel.SchemaRoleAccessFilter)1 SchemaUniqueElementFilter (com.amalto.workbench.providers.datamodel.SchemaUniqueElementFilter)1 DescAnnotationComposite (com.amalto.workbench.widgets.DescAnnotationComposite)1 IElementComparer (org.eclipse.jface.viewers.IElementComparer)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 KeyAdapter (org.eclipse.swt.events.KeyAdapter)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 MouseAdapter (org.eclipse.swt.events.MouseAdapter)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1 Color (org.eclipse.swt.graphics.Color)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1