Search in sources :

Example 91 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tdq-studio-se by Talend.

the class RefreshActionDelegate method selectionChanged.

@Override
public void selectionChanged(IAction action, ISelection selection) {
    if (selection != null && selection instanceof TreeSelection) {
        TreeSelection ts = (TreeSelection) selection;
        TreePath[] treepaths = ts.getPaths();
        if (treepaths.length >= 1) {
            int count = treepaths[0].getSegmentCount();
            for (int i = 0; i < count; i++) {
                Object o = treepaths[0].getSegment(i);
                if (o instanceof IFile) {
                    if (((IFile) o).getFileExtension().toLowerCase().equals("prv")) {
                        // $NON-NLS-1$
                        selectedFileObject = (IFile) o;
                    }
                } else if (o instanceof Schema) {
                    selectedSchema = (Schema) o;
                } else if (o instanceof Catalog) {
                    selectedCatalog = (Catalog) o;
                } else if (o instanceof Connection) {
                    selectedDataProvider = (Connection) o;
                }
            }
        }
        selectedObject = ts.getFirstElement();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Schema(orgomg.cwm.resource.relational.Schema) Connection(org.talend.core.model.metadata.builder.connection.Connection) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 92 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tdq-studio-se by Talend.

the class ModelElementTreeMenuProvider method createColumnAnalysis.

/**
 * DOC qiongli Comment method "createColumnAnalysis".bug 16252.
 *
 * @param newTree
 */
private void createColumnAnalysis(Tree newTree) {
    TreeItem[] items = newTree.getSelection();
    if (items.length > 0) {
        TreePath[] paths = new TreePath[items.length];
        for (int i = 0; i < items.length; i++) {
            // MOD klliu bug 20820 change TDcolum to IRepositoryNode, then solve NPE 2011-04-29
            // $NON-NLS-1$
            ModelElementIndicator data = (ModelElementIndicator) items[i].getData("MODELELEMENT_INDICATOR_KEY");
            IRepositoryNode modelElementRepositoryNode = data.getModelElementRepositoryNode();
            paths[i] = new TreePath(new Object[] { modelElementRepositoryNode });
        }
        CreateColumnAnalysisAction analysisAction = new CreateColumnAnalysisAction();
        analysisAction.setSelection(new TreeSelection(paths));
        analysisAction.run();
    }
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) IRepositoryNode(org.talend.repository.model.IRepositoryNode) TreeItem(org.eclipse.swt.widgets.TreeItem) CreateColumnAnalysisAction(org.talend.dataprofiler.core.ui.action.actions.predefined.CreateColumnAnalysisAction) TreeSelection(org.eclipse.jface.viewers.TreeSelection) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) ISubRepositoryObject(org.talend.core.model.repository.ISubRepositoryObject) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Example 93 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.

the class XSDSetAnnotationDescriptionsAction method doAction.

public IStatus doAction() {
    try {
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation)
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        } else
            xSDCom = (XSDComponent) selection.getFirstElement();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo2, xSDCom.getClass().getName()));
        }
        AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getDescriptions(), new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(), Messages.XSDSetAnnotationXX_SetDescOfThisItem);
        dlg.setBlockOnOpen(true);
        dlg.open();
        if (dlg.getReturnCode() == Window.OK) {
            // remove existing annotations with labels
            struc.removeAllDescriptions();
            // add the new ones
            LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap();
            Set<String> isoCodes = descriptions.keySet();
            for (Iterator iter = isoCodes.iterator(); iter.hasNext(); ) {
                String isoCode = (String) iter.next();
                struc.setDescription(isoCode, descriptions.get(isoCode));
            }
        } else {
            return Status.CANCEL_STATUS;
        }
        if (struc.hasChanged()) {
            page.markDirty();
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDSetAnnotationXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Iterator(java.util.Iterator) AnnotationLanguageLabelsDialog(com.amalto.workbench.dialogs.AnnotationLanguageLabelsDialog) XSDAnnotation(org.eclipse.xsd.XSDAnnotation)

Example 94 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.

the class XSDSetAnnotationFKFilterAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        String conceptName = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        if (xSDCom instanceof XSDElementDeclaration) {
            // $NON-NLS-1$
            conceptName = xSDCom.getElement().getAttributes().getNamedItem("name").getNodeValue();
        }
        if (xSDCom instanceof XSDParticle) {
        }
        XSDAnnotationsStructure struc = null;
        if (xSDCom != null) {
            struc = new XSDAnnotationsStructure(xSDCom);
        }
        if (struc == null || struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
        }
        fkd = getNewFKFilterDialog(page.getSite().getShell(), struc.getFKFilter(), page, conceptName);
        fkd.setDataModel(dataModelName);
        fkd.setLock(true);
        fkd.setBlockOnOpen(true);
        int ret = fkd.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        String fkfilter = fkd.getFilter();
        struc.setFKFilter(fkfilter);
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.ErrorFKFilter, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDComponent(org.eclipse.xsd.XSDComponent) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDParticle(org.eclipse.xsd.XSDParticle)

Example 95 with TreePath

use of org.eclipse.jface.viewers.TreePath in project tmdm-studio-se by Talend.

the class XSDSetAnnotationForeignKeyInfoAction method doAction.

@Override
public IStatus doAction() {
    try {
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
        }
        dlg = getNewAnnotaionOrderedListsDialog(struc.getForeignKeyInfos().values());
        dlg.setLock(true);
        dlg.setRetrieveFKinfos(struc.getRetrieveFKinfos());
        dlg.setFormatFKInfo(struc.getFormatForeignKeyInfo());
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        struc.setForeignKeyInfos(dlg.getXPaths());
        struc.setRetrieveFKinfos(dlg.isRetrieveFKinfos());
        struc.setFormatForeignKeyInfo(dlg.getFormatFKInfo());
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.ErrorForeignKey, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) XSDAnnotationsStructure(com.amalto.workbench.utils.XSDAnnotationsStructure) Element(org.w3c.dom.Element) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDAnnotation(org.eclipse.xsd.XSDAnnotation) XSDComponent(org.eclipse.xsd.XSDComponent)

Aggregations

TreePath (org.eclipse.jface.viewers.TreePath)104 TreeSelection (org.eclipse.jface.viewers.TreeSelection)55 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 ArrayList (java.util.ArrayList)20 ITreeSelection (org.eclipse.jface.viewers.ITreeSelection)18 XSDComponent (org.eclipse.xsd.XSDComponent)14 Test (org.junit.Test)14 Iterator (java.util.Iterator)13 XSDAnnotation (org.eclipse.xsd.XSDAnnotation)13 Element (org.w3c.dom.Element)13 XSDAnnotationsStructure (com.amalto.workbench.utils.XSDAnnotationsStructure)12 HashSet (java.util.HashSet)10 Set (java.util.Set)10 ConsoleConfiguration (org.hibernate.console.ConsoleConfiguration)10 List (java.util.List)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)7 EntityDefinition (eu.esdihumboldt.hale.common.align.model.EntityDefinition)6 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)6 IProject (org.eclipse.core.resources.IProject)5 DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)5