Search in sources :

Example 36 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project hale by halestudio.

the class TypeEntityDialog method addToolBarActions.

/**
 * @see eu.esdihumboldt.hale.ui.function.common.EntityDialog#addToolBarActions(org.eclipse.jface.action.ToolBarManager)
 */
@Override
protected void addToolBarActions(ToolBarManager manager) {
    // filter to only show mapped types
    manager.add(new FilterAction("Hide unmapped types", "Show unmapped types", HALEUIPlugin.getImageDescriptor("icons/empty.gif"), getViewer(), new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            AlignmentService as = PlatformUI.getWorkbench().getService(AlignmentService.class);
            Alignment alignment = as.getAlignment();
            if (element instanceof TreePath)
                element = ((TreePath) element).getLastSegment();
            return isMapped((ITreeContentProvider) ((TreeViewer) viewer).getContentProvider(), element, alignment);
        }

        private boolean isMapped(ITreeContentProvider cp, Object element, Alignment align) {
            if (element instanceof EntityDefinition) {
                boolean mapped = AlignmentUtil.entityOrChildMapped((EntityDefinition) element, align);
                if (mapped)
                    return true;
            }
            // recursively check children
            Object[] children = cp.getChildren(element);
            if (children != null)
                for (Object child : children) if (isMapped(cp, child, align))
                    return true;
            return false;
        }
    }, true, true));
    // do not add choice if only mapping relevant types should be selected
    if (onlyMappingRelevant)
        return;
    manager.add(new Separator());
    // MappingRelevant types only, flat
    manager.add(new ContentProviderAction("Mapping relevant types as list", HALEUIPlugin.getImageDescriptor("icons/flat_relevant.png"), getViewer(), flatRelevantProvider, false));
    // MappingRelevant types only, hierarchical
    manager.add(new ContentProviderAction("Mapping relevant types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_relevant.png"), getViewer(), hierarchicalRelevantProvider, false));
    // Mappable types, flat
    manager.add(new ContentProviderAction("All types as list", HALEUIPlugin.getImageDescriptor("icons/flat_all.png"), getViewer(), flatAllProvider, true));
    // Mappable types, hierarchical
    manager.add(new ContentProviderAction("All types hierarchical", HALEUIPlugin.getImageDescriptor("icons/hierarchical_all.png"), getViewer(), hierarchicalAllProvider, false));
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ContentProviderAction(eu.esdihumboldt.hale.ui.service.entity.util.ContentProviderAction) Viewer(org.eclipse.jface.viewers.Viewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TypeEntityDefinition(eu.esdihumboldt.hale.common.align.model.impl.TypeEntityDefinition) EntityDefinition(eu.esdihumboldt.hale.common.align.model.EntityDefinition) Alignment(eu.esdihumboldt.hale.common.align.model.Alignment) TreePath(org.eclipse.jface.viewers.TreePath) AlignmentService(eu.esdihumboldt.hale.ui.service.align.AlignmentService) FilterAction(eu.esdihumboldt.hale.ui.util.viewer.FilterAction) Separator(org.eclipse.jface.action.Separator)

Example 37 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project translationstudio8 by heartsome.

the class ImportProjectWizardPage method createProjectsList.

/**
	 * Create the checkbox list for the found projects.
	 * 
	 * @param workArea
	 */
private void createProjectsList(Composite workArea) {
    Label title = new Label(workArea, SWT.NONE);
    title.setText(DataTransferMessages.WizardProjectsImportPage_ProjectsListTitle);
    Composite listComposite = new Composite(workArea, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginWidth = 0;
    layout.makeColumnsEqualWidth = false;
    listComposite.setLayout(layout);
    listComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH));
    projectsList = new CheckboxTreeViewer(listComposite, SWT.BORDER);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.widthHint = new PixelConverter(projectsList.getControl()).convertWidthInCharsToPixels(25);
    gridData.heightHint = new PixelConverter(projectsList.getControl()).convertHeightInCharsToPixels(10);
    projectsList.getControl().setLayoutData(gridData);
    projectsList.setContentProvider(new ITreeContentProvider() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java
			 * .lang.Object)
			 */
        public Object[] getChildren(Object parentElement) {
            return null;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.IStructuredContentProvider#getElements
			 * (java.lang.Object)
			 */
        public Object[] getElements(Object inputElement) {
            return getProjectRecords();
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java
			 * .lang.Object)
			 */
        public boolean hasChildren(Object element) {
            return false;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ITreeContentProvider#getParent(java
			 * .lang.Object)
			 */
        public Object getParent(Object element) {
            return null;
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see org.eclipse.jface.viewers.IContentProvider#dispose()
			 */
        public void dispose() {
        }

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse
			 * .jface.viewers.Viewer, java.lang.Object, java.lang.Object)
			 */
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    projectsList.setLabelProvider(new ProjectLabelProvider());
    projectsList.addCheckStateListener(new ICheckStateListener() {

        /*
			 * (non-Javadoc)
			 * 
			 * @see
			 * org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged
			 * (org.eclipse.jface.viewers.CheckStateChangedEvent)
			 */
        public void checkStateChanged(CheckStateChangedEvent event) {
            ProjectRecord element = (ProjectRecord) event.getElement();
            if (element.hasConflicts) {
                projectsList.setChecked(element, false);
            }
            setPageComplete(projectsList.getCheckedElements().length > 0);
        }
    });
    projectsList.setInput(this);
    projectsList.setComparator(new ViewerComparator());
    createSelectionButtons(listComposite);
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) Composite(org.eclipse.swt.widgets.Composite) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) Label(org.eclipse.swt.widgets.Label) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) PixelConverter(org.eclipse.jface.layout.PixelConverter) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 38 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project tdi-studio-se by Talend.

the class ExportItemWizardPage method collectNodes.

private void collectNodes(Map<String, Item> items, Object[] objects) {
    for (Object object : objects) {
        if (object instanceof RepositoryNode) {
            RepositoryNode repositoryNode = (RepositoryNode) object;
            IRepositoryViewObject repositoryObject = repositoryNode.getObject();
            if (repositoryObject != null) {
                if (repositoryObject.getRepositoryObjectType().isResourceItem()) {
                    Item item = repositoryObject.getProperty().getItem();
                    items.put(item.getProperty().getId(), item);
                }
            } else {
                if (repositoryNode.getParent() != null && repositoryNode.getParent().getObject() != null) {
                    Item item = repositoryNode.getParent().getObject().getProperty().getItem();
                    items.put(item.getProperty().getId(), item);
                }
            }
            if (filteredCheckboxTree != null && !isHadoopClusterNode(repositoryNode)) {
                IContentProvider contentProvider = filteredCheckboxTree.getViewer().getContentProvider();
                if (contentProvider instanceof ITreeContentProvider) {
                    // only check childrens of allowed items in this viewer
                    if (selectRepositoryNode(getItemsTreeViewer(), repositoryNode)) {
                        Object[] children = ((ITreeContentProvider) contentProvider).getChildren(repositoryNode);
                        List<Object> childrenNodes = getUnTestCaseChildren(children);
                        collectNodes(items, childrenNodes.toArray());
                    }
                }
            }
        } else {
            for (IExtendedRepositoryNodeHandler nodeHandler : RepositoryContentManager.getExtendedNodeHandler()) {
                Property property = nodeHandler.getProperty(object);
                if (property != null) {
                    items.put(property.getId(), property.getItem());
                }
            }
        }
    }
}
Also used : Item(org.talend.core.model.properties.Item) TreeItem(org.eclipse.swt.widgets.TreeItem) ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) IExtendedRepositoryNodeHandler(org.talend.core.model.repository.IExtendedRepositoryNodeHandler) IContentProvider(org.eclipse.jface.viewers.IContentProvider) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) RepositoryObject(org.talend.core.model.repository.RepositoryObject) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Property(org.talend.core.model.properties.Property)

Example 39 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project tdi-studio-se by Talend.

the class ImportItemWizardPage method createTreeViewer.

private TreeViewer createTreeViewer(Composite listComposite) {
    filteredCheckboxTree = new FilteredCheckboxTree(listComposite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI);
    CheckboxTreeViewer viewer = filteredCheckboxTree.getViewer();
    viewer.setContentProvider(new ITreeContentProvider() {

        @Override
        public Object[] getChildren(Object parentElement) {
            if (parentElement instanceof IContainerNode) {
                return ((IContainerNode) parentElement).getChildren().toArray();
            }
            return null;
        }

        @Override
        public Object[] getElements(Object inputElement) {
            // return getValidItems();
            return repositoryUtil.getTreeViewInput().toArray();
        }

        @Override
        public boolean hasChildren(Object element) {
            if (element instanceof IContainerNode) {
                return ((IContainerNode) element).hasChildren();
            }
            return false;
        }

        @Override
        public Object getParent(Object element) {
            return null;
        }

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    viewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof IContainerNode) {
                if (element instanceof ProjectNode) {
                    Project project = ((ProjectNode) element).getProject();
                    return ProjectManager.getProjectDisplayLabel(project);
                }
                return ((IContainerNode) element).getLabel();
            } else if (element instanceof ItemRecord) {
                return ((ItemRecord) element).getLabel();
            }
            return super.getText(element);
        }

        @Override
        public Image getImage(Object element) {
            if (element instanceof IContainerNode) {
                return ((IContainerNode) element).getImage();
            } else if (element instanceof ItemRecord) {
                return ((ItemRecord) element).getImage();
            }
            return super.getImage(element);
        }
    });
    viewer.setSorter(TreeBuilder.createSorter());
    viewer.setInput(this);
    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            filteredCheckboxTree.calculateCheckedLeafNodes();
            updateFinishStatus();
        }
    });
    filteredCheckboxTree.getViewer().addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            return selectRepositoryNode(viewer, element);
        }
    });
    return viewer;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) FilteredCheckboxTree(org.talend.core.ui.advanced.composite.FilteredCheckboxTree) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) TableViewer(org.eclipse.jface.viewers.TableViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Image(org.eclipse.swt.graphics.Image) IContainerNode(org.talend.repository.imports.TreeBuilder.IContainerNode) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) Project(org.talend.core.model.properties.Project) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) ProjectNode(org.talend.repository.imports.TreeBuilder.ProjectNode) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 40 with ITreeContentProvider

use of org.eclipse.jface.viewers.ITreeContentProvider in project tdi-studio-se by Talend.

the class AddResourceAction method run.

/**
     * Prompts for a jar to add.
     * 
     * @see IAction#run()
     */
@Override
public void run() {
    // ViewerFilter filter = new ArchiveFilter(getSelectedJars());
    ILabelProvider lp = new WorkbenchLabelProvider();
    ITreeContentProvider cp = new WorkbenchContentProvider();
    ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
    dialog.setValidator(validator);
    //$NON-NLS-1$
    dialog.setTitle(Messages.getString("AddResourceAction.JARSecection"));
    //$NON-NLS-1$
    dialog.setMessage(Messages.getString("AddResourceAction.ChooseResource"));
    dialog.setInput(ResourcesPlugin.getWorkspace().getRoot().getProject(PluginConstant.COMPONENT_PROJECT));
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        Object[] elements = dialog.getResult();
        List<ILibEntry> res = new ArrayList<ILibEntry>();
        for (int i = 0; i < elements.length; i++) {
            IResource elem = (IResource) elements[i];
            String name = elem.getName();
            if (name.matches("(?i).*\\.(jar)\\b")) {
                //$NON-NLS-1$
                res.add(new JarLibEntry(elem));
            }
            if (name.matches("(?i).*\\.(pm)\\b")) {
                //$NON-NLS-1$
                res.add(new PmLibEntry(elem));
            }
        }
        if (res.size() > 0) {
            ILibEntry[] entries = new ILibEntry[res.size()];
            getViewer().addEntries(res.toArray(entries));
        }
    }
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) JarLibEntry(org.talend.componentdesigner.model.libentry.JarLibEntry) ArrayList(java.util.ArrayList) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) ILibEntry(org.talend.componentdesigner.model.ILibEntry) PmLibEntry(org.talend.componentdesigner.model.libentry.PmLibEntry) IResource(org.eclipse.core.resources.IResource)

Aggregations

ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)68 Viewer (org.eclipse.jface.viewers.Viewer)32 LabelProvider (org.eclipse.jface.viewers.LabelProvider)19 GridData (org.eclipse.swt.layout.GridData)19 Composite (org.eclipse.swt.widgets.Composite)17 TreeViewer (org.eclipse.jface.viewers.TreeViewer)16 GridLayout (org.eclipse.swt.layout.GridLayout)15 Label (org.eclipse.swt.widgets.Label)13 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)12 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)12 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)11 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)11 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)11 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)11 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)11 ArrayList (java.util.ArrayList)10 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)9 ElementTreeSelectionDialog (org.eclipse.ui.dialogs.ElementTreeSelectionDialog)9 StructuredViewer (org.eclipse.jface.viewers.StructuredViewer)8 SourceViewer (org.eclipse.jface.text.source.SourceViewer)7