Search in sources :

Example 36 with TreePath

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

the class ColumnsSelectionDialog method addCheckedListener.

/*
     * (non-Javadoc)
     * 
     * @seeorg.talend.dataprofiler.core.ui.dialog.TwoPartCheckSelectionDialog# addCheckedListener()
     */
@Override
protected void addCheckedListener() {
    // When user checks a checkbox in the tree, check all its children
    getTreeViewer().addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            // Added TDQ-8718 20140506 yyin: should not load from db when checking
            DQDBFolderRepositoryNode.setCallingFromColumnDialog(true);
            DQDBFolderRepositoryNode.setLoadDBFromDialog(false);
            try {
                ColumnSelectionViewer columnViewer = (ColumnSelectionViewer) event.getSource();
                TreePath treePath = new TreePath(new Object[] { event.getElement() });
                columnViewer.setSelection(new TreeSelection(treePath));
                setOutput(event.getElement());
                RepositoryNode selectedNode = (RepositoryNode) event.getElement();
                if (selectedNode instanceof DBTableRepNode || selectedNode instanceof DBViewRepNode || selectedNode instanceof DFTableRepNode) {
                    handleTreeElementsChecked(selectedNode, event.getChecked());
                } else {
                    checkChildrenElements(selectedNode, event.getChecked());
                }
                getTreeViewer().setSubtreeChecked(event.getElement(), event.getChecked());
                updateStatusBySelection();
            } finally {
                // Added TDQ-8718 20140506 yyin
                DQDBFolderRepositoryNode.setCallingFromColumnDialog(false);
                DQDBFolderRepositoryNode.setLoadDBFromDialog(true);
            }
        }

        private void checkChildrenElements(RepositoryNode repNode, Boolean checkedFlag) {
            Set<?> keySet = modelElementCheckedMap.keySet();
            RepositoryNode[] repNodeArray = (RepositoryNode[]) modelElementCheckedMap.keySet().toArray(new RepositoryNode[keySet.size()]);
            for (RepositoryNode reposNode : repNodeArray) {
                RepositoryNode parentNode = reposNode.getParent();
                while (parentNode != null) {
                    if (repNode.equals(parentNode)) {
                        handleTreeElementsChecked(reposNode, checkedFlag);
                        break;
                    } else {
                        parentNode = parentNode.getParent();
                    }
                }
            }
        }
    });
    getTableViewer().addCheckStateListener(new ICheckStateListener() {

        public void checkStateChanged(CheckStateChangedEvent event) {
            handleTableElementsChecked((RepositoryNode) event.getElement(), event.getChecked());
            updateStatusBySelection();
        }
    });
}
Also used : DBTableRepNode(org.talend.dq.nodes.DBTableRepNode) Set(java.util.Set) TreePath(org.eclipse.jface.viewers.TreePath) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TreeSelection(org.eclipse.jface.viewers.TreeSelection) DFTableRepNode(org.talend.dq.nodes.DFTableRepNode) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) RepositoryNode(org.talend.repository.model.RepositoryNode) DQDBFolderRepositoryNode(org.talend.dq.nodes.DQDBFolderRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) DBViewRepNode(org.talend.dq.nodes.DBViewRepNode)

Example 37 with TreePath

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

the class RemoveAnalysisAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.jface.action.Action#run()
     */
@Override
public void run() {
    DQRespositoryView findView = CorePlugin.getDefault().getRepositoryView();
    if (findView == null) {
        return;
    }
    TreeSelection treeSelection = (TreeSelection) findView.getCommonViewer().getSelection();
    TreePath[] paths = treeSelection.getPaths();
    List<Analysis> analysisList;
    Analysis analysisObj = null;
    Map<TDQReportItem, List<Analysis>> removeMap = new HashMap<TDQReportItem, List<Analysis>>();
    for (TreePath path : paths) {
        Object lastSegment = path.getLastSegment();
        if (!(lastSegment instanceof ReportAnalysisRepNode)) {
            return;
        }
        // MOD sizhaoliu 2012-06-12 TDQ-5051 "Remove Anaysis" menu item is not in the right place
        ReportAnalysisRepNode repNode = (ReportAnalysisRepNode) lastSegment;
        analysisObj = repNode.getAnalysis();
        TDQReportItem reportItem = repNode.getReportItem();
        analysisList = removeMap.get(reportItem);
        if (analysisList == null) {
            analysisList = new ArrayList<Analysis>();
            analysisList.add(analysisObj);
            removeMap.put(reportItem, analysisList);
        } else {
            analysisList.add(analysisObj);
        }
    }
    if (analysisObj == null) {
        return;
    }
    String message = paths.length > 1 ? DefaultMessagesImpl.getString("RemoveAnalysisAction.areYouDeleteElement0", // $NON-NLS-1$
    paths.length) : // $NON-NLS-1$
    DefaultMessagesImpl.getString("RemoveAnalysisAction.areYouDeleteElement2", analysisObj.getName());
    boolean openConfirm = MessageDialog.openConfirm(null, DefaultMessagesImpl.getString("RemoveAnalysisAction.confirmResourceDelete"), // $NON-NLS-1$
    message);
    if (openConfirm) {
        Iterator<TDQReportItem> iterator = removeMap.keySet().iterator();
        while (iterator.hasNext()) {
            TDQReportItem reportItem = iterator.next();
            ReportHelper.removeAnalyses((TdReport) reportItem.getReport(), removeMap.get(reportItem));
            // save now modified resources (that contain the Dependency
            // objects)
            ElementWriterFactory.getInstance().createReportWriter().save(reportItem, true);
        }
        IFolder reportsFolder = ResourceManager.getReportsFolder();
        try {
            reportsFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
        } catch (CoreException e) {
            log.error(e, e);
        }
        findView.getCommonViewer().refresh();
    }
}
Also used : HashMap(java.util.HashMap) TreePath(org.eclipse.jface.viewers.TreePath) CoreException(org.eclipse.core.runtime.CoreException) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Analysis(org.talend.dataquality.analysis.Analysis) ArrayList(java.util.ArrayList) List(java.util.List) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView) ReportAnalysisRepNode(org.talend.dq.nodes.ReportAnalysisRepNode) TDQReportItem(org.talend.dataquality.properties.TDQReportItem) IFolder(org.eclipse.core.resources.IFolder)

Example 38 with TreePath

use of org.eclipse.jface.viewers.TreePath in project titan.EclipsePlug-ins by eclipse.

the class WorkingDirectoryFilter method filter.

@Override
public Object[] filter(final Viewer viewer, final Object parent, final Object[] elements) {
    workingDirectories = null;
    Object tempParent = parent;
    if (parent instanceof TreePath) {
        tempParent = ((TreePath) parent).getLastSegment();
    }
    if (!(tempParent instanceof IResource)) {
        return elements;
    }
    final IResource parentResource = (IResource) tempParent;
    final IProject project = parentResource.getProject();
    if (project == null) {
        return elements;
    }
    workingDirectories = ProjectBasedBuilder.getProjectBasedBuilder(project).getWorkingDirectoryResources(false);
    final int size = elements.length;
    final List<Object> out = new ArrayList<Object>(size);
    for (int i = 0; i < size; ++i) {
        final Object element = elements[i];
        if (specialSelect(viewer, tempParent, element)) {
            out.add(element);
        }
    }
    return out.toArray();
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) ArrayList(java.util.ArrayList) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject)

Example 39 with TreePath

use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.

the class GalleryViewerRow method getTreePath.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.jface.viewers.ViewerRow#getTreePath()
	 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public TreePath getTreePath() {
    LinkedList path = new LinkedList();
    path.add(item.getData());
    GalleryItem curItem = item;
    while (curItem.getParentItem() != null) {
        path.addFirst(curItem.getParentItem().getData());
        curItem = curItem.getParentItem();
    }
    return new TreePath(path.toArray());
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) LinkedList(java.util.LinkedList)

Example 40 with TreePath

use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.

the class GalleryTreeViewer method remove.

/**
 * Removes the element at the specified index of the parent. The selection
 * is updated if required.
 *
 * @param parentOrTreePath
 *            the parent element, the input element, or a tree path to the
 *            parent element
 * @param index
 *            child index
 * @since 3.3
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public void remove(final Object parentOrTreePath, final int index) {
    // if (isBusy())
    // return;
    final List oldSelection = new LinkedList(Arrays.asList(((TreeSelection) getSelection()).getPaths()));
    preservingSelection(new Runnable() {

        public void run() {
            TreePath removedPath = null;
            if (internalIsInputOrEmptyPath(parentOrTreePath)) {
                Gallery gallery = (Gallery) getControl();
                if (index < gallery.getItemCount()) {
                    GalleryItem item = gallery.getItem(index);
                    if (item.getData() != null) {
                        removedPath = getTreePathFromItem(item);
                        disassociate(item);
                    }
                    item.dispose();
                }
            } else {
                Widget[] parentItems = internalFindItems(parentOrTreePath);
                for (int i = 0; i < parentItems.length; i++) {
                    GalleryItem parentItem = (GalleryItem) parentItems[i];
                    if (index < parentItem.getItemCount()) {
                        GalleryItem item = parentItem.getItem(index);
                        if (item.getData() != null) {
                            removedPath = getTreePathFromItem(item);
                            disassociate(item);
                        }
                        item.dispose();
                    }
                }
            }
            if (removedPath != null) {
                boolean removed = false;
                for (Iterator it = oldSelection.iterator(); it.hasNext(); ) {
                    TreePath path = (TreePath) it.next();
                    if (path.startsWith(removedPath, getComparer())) {
                        it.remove();
                        removed = true;
                    }
                }
                if (removed) {
                    setSelection(new TreeSelection((TreePath[]) oldSelection.toArray(new TreePath[oldSelection.size()]), getComparer()), false);
                }
            }
        }
    });
}
Also used : TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) Gallery(org.netxms.nebula.widgets.gallery.Gallery) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) GalleryItem(org.netxms.nebula.widgets.gallery.GalleryItem) LinkedList(java.util.LinkedList)

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