List of usage examples for org.eclipse.jface.viewers TreeViewer setContentProvider
@Override public void setContentProvider(IContentProvider provider)
TreeViewer
. From source file:org.eclipse.eatop.examples.graphicaleditor.depd.features.views.SafetyGoalTitleAreaDialogview.java
License:Open Source License
protected Control createDialogArea(Composite parent) { Composite composite = (Composite) super.createDialogArea(parent); // YOUR LINE HERE! Label line = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); line.setLayoutData(new GridData(SWT.FILL, SWT.END, true, true)); final TreeViewer viewer; viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); List<SafetyGoal> sgs = new ArrayList<SafetyGoal>(); sgs.add(saftyob);//from w ww. j a va 2 s . c o m // Provide the input to the ContentProvider viewer.setContentProvider(new RequirementsContentProvider(saftyob)); viewer.setLabelProvider(new RequirementsLabelProvider(saftyob)); viewer.setSorter(new RequirementSorter()); // Expand the tree viewer.setAutoExpandLevel(3); viewer.setInput(sgs.toArray()); viewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));// // viewer.getTree().setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true,1,1)); // Add a doubleclicklistenerObject[] elements;Object[] viewer.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { TreeViewer viewer = (TreeViewer) event.getViewer(); IStructuredSelection thisSelection = (IStructuredSelection) event.getSelection(); Object selectedNode = thisSelection.getFirstElement(); viewer.setExpandedState(selectedNode, !viewer.getExpandedState(selectedNode)); } }); viewer.getTree().addKeyListener(new KeyAdapter() { @Override public void keyReleased(final KeyEvent e) { if (e.keyCode == SWT.DEL) { final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection(); if (selection.getFirstElement() instanceof Requirement) { Requirement o = (Requirement) selection.getFirstElement(); // TODO Delete the selected element from the model } } } }); return composite; }
From source file:org.eclipse.eavp.viz.visit.VisitPlotViewer.java
License:Open Source License
/** * Initializes the provided TreeViewer based on the current ICEResource for * this PlotViewer./*from w ww.j av a 2 s . c o m*/ * * @param inputTreeViewer * The TreeViewer that should be configured to display the * currently selected plots for a VisIt-compatible ICEResource. */ private void initializeTreeViewer(TreeViewer inputTreeViewer) { // Set up the content provider and label provider for the TreeViewer. // The input should be of the type Entry[]. Elements should be the // entries themselves. // Set the content provider, which determines how the input (an Entry[]) // should produce elements in the TreeViewer. inputTreeViewer.setContentProvider(new ITreeContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { return; } @Override public void dispose() { // No image descriptors or non-textual resources to dispose. return; } @Override public boolean hasChildren(Object element) { // Currently, we do not have nested elements in the tree. return false; } @Override public Object getParent(Object element) { // Currently, we do not have nested elements in the tree. return null; } @Override public Object[] getElements(Object inputElement) { Object[] elements; if (inputElement instanceof Object[]) { elements = (Object[]) inputElement; } else { elements = new Object[] {}; } return elements; } @Override public Object[] getChildren(Object parentElement) { // Currently, we do not have nested elements in the tree. return null; } }); // Set up the label provider, which determines what string is displayed // for each element in the tree. Currently, this only needs to produce // a string for each Entry. inputTreeViewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); // Get a String from the Entry if possible. StyledString styledStr = new StyledString(); if (element instanceof VizEntry) { VizEntry entry = (VizEntry) element; // Get the name from the resource styledStr.append(entry.getName()); // Append the path stored as the Entry description styledStr.append(" [" + entry.getParent(), StyledString.QUALIFIER_STYLER); // Append the data type stored as the Entry parent styledStr.append("-" + entry.getDescription() + "]", StyledString.QUALIFIER_STYLER); } // If the element isn't an Entry, convert it to a String. else { styledStr.append(element.toString()); } // Set the text for the cell and call // StyledCellLabelProvider#update() cell.setText(styledStr.toString()); cell.setStyleRanges(styledStr.getStyleRanges()); super.update(cell); } }); return; }
From source file:org.eclipse.eavp.viz.VizFileViewer.java
License:Open Source License
/** * Initializes the provided TreeViewer based on the ResourceComponent for * this VizFileViewer./* w ww . ja v a 2 s. c om*/ * * @param inputTreeViewer * The TreeViewer that should be configured to display the * ICEResources in a ResourceComponent. */ private void initializeTreeViewer(TreeViewer inputTreeViewer) { inputTreeViewer.setContentProvider(new ITreeContentProvider() { @Override public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { return; } @Override public void dispose() { return; } @Override public boolean hasChildren(Object element) { // Make sure we have a VizResource if (element instanceof IVizResource) { // Cast it to make life easier IVizResource resource = (IVizResource) element; // If this resource has a valid fileset... if (resource.getFileSet() != null) { // Then return true if it is not empty return resource.getFileSet().length != 0; // If the fileset was null, but we have children // resources... } else if (resource.getChildrenResources() != null) { // then return true if the children list is not empty return !resource.getChildrenResources().isEmpty(); } } // All else, we have no children return false; } @Override public Object getParent(Object element) { return null; } @Override public Object[] getElements(Object inputElement) { // Local Declaration Object[] elements; // Convert the element to an ArrayList (it should be an // ArrayList<ICEResource>) and then get an Object array. if (inputElement instanceof ArrayList<?>) { elements = ((ArrayList<?>) inputElement).toArray(); } else { elements = new Object[] {}; } return elements; } @Override public Object[] getChildren(Object parentElement) { // Make sure this is a VizResource if (parentElement instanceof IVizResource) { // Cast to make life easier IVizResource resource = (IVizResource) parentElement; // If we have children... if (resource.getChildrenResources() != null && !resource.getChildrenResources().isEmpty()) { // Return all Child resources return resource.getChildrenResources().toArray(); } else if (resource.getFileSet() != null && resource.getFileSet().length != 0) { // If we didn't have VizResourc children, then check // that we // have file names to return ArrayList<IVizResource> children = new ArrayList<IVizResource>(); for (String filePath : resource.getFileSet()) { File file = new File(filePath); // Try to construct an ICEResource from the File, // then add it to // the viewer. try { IVizResource childResource = new VisualizationResource(file); childResource.setHost("localhost"); children.add(childResource); } catch (IOException e) { System.err.println("AddLocalFileAction error: Failed to " + "create an ICEResource for the file at \"" + filePath + "\"."); logger.error(getClass().getName() + " Exception!", e); } } return children.toArray(); } } // Otherwise return null return null; } }); inputTreeViewer.setLabelProvider(new StyledCellLabelProvider() { @Override public void update(ViewerCell cell) { Object element = cell.getElement(); // Get a String from the VizResource if possible. StyledString styledStr = new StyledString(); if (element instanceof IVizResource) { IVizResource resource = (IVizResource) element; // Get the name from the resource styledStr.append(resource.getName()); String host = resource.getHost(); URI pathFile = resource.getPath(); String path = null; if (pathFile != null) { pathFile.getPath(); } // Get the host from the resource and append it to the tree // entry String grayed-out and enclosed in square brackets. if (host != null && !host.isEmpty()) { styledStr.append(" [" + host, StyledString.QUALIFIER_STYLER); // Include the path with the host if available if (path != null && !path.isEmpty() && !resource.isRemote()) { styledStr.append(":" + path, StyledString.QUALIFIER_STYLER); } styledStr.append("]", StyledString.QUALIFIER_STYLER); } } // If the element isn't an VizResource, convert it to a String. else { styledStr.append(element.toString()); } // Set the text for the cell and call // StyledCellLabelProvider#update() cell.setText(styledStr.toString()); cell.setStyleRanges(styledStr.getStyleRanges()); super.update(cell); } }); return; }
From source file:org.eclipse.ecf.remoteservice.ui.serviceview.AbstractServicesView.java
License:Open Source License
protected TreeViewer createTreeViewer(Composite parent) { Composite composite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = layout.marginWidth = 0; composite.setLayout(layout);// www . j a v a 2s . c om composite.setLayoutData(new GridData(GridData.FILL_BOTH)); filteredTree = createFilteredTree(composite, SWT.H_SCROLL | SWT.V_SCROLL, new PatternFilter()); TreeViewer viewer = filteredTree.getViewer(); viewer.setContentProvider(contentProvider); viewer.setLabelProvider(new WorkbenchLabelProvider()); viewer.setUseHashlookup(true); viewer.setInput(getViewSite()); viewer.setComparator(new ViewerComparator() { @Override public int compare(Viewer viewer, Object e1, Object e2) { if (e1 instanceof ServiceNode && e2 instanceof ServiceNode) { return new Long(((ServiceNode) e2).getServiceId() - ((ServiceNode) e1).getServiceId()) .intValue(); } return super.compare(viewer, e1, e2); } }); getViewSite().setSelectionProvider(viewer); return viewer; }
From source file:org.eclipse.edt.ide.eunit.ui.testresult.ResultSummaryBlock.java
License:Open Source License
private void createResultSummarySection(final IManagedForm managedForm, Section section, FormToolkit toolkit) { Composite client = toolkit.createComposite(section, SWT.WRAP); GridLayout layout = new GridLayout(); layout.numColumns = 2;/*w ww . j ava 2s .co m*/ layout.marginWidth = 2; layout.marginHeight = 2; client.setLayout(layout); Tree tr = createResultSummaryTreeControl(client, toolkit); section.setClient(client); spart = new SectionPart(section); managedForm.addPart(spart); TreeViewer fTreeViewer = new TreeViewer(tr); fTreeViewer.setContentProvider(new RSTreeContentProvider()); fTreeViewer.setLabelProvider(new RSTreeLabelProvider()); TestResultRootNode rootNode = createNewRootNode(); managedForm.setInput(rootNode); fTreeViewer.setInput(managedForm); fTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { managedForm.fireSelectionChanged(spart, event.getSelection()); HandleTreeSelectionChanged(event); } }); fTreeViewer.setSorter(new ViewerSorter()); }
From source file:org.eclipse.edt.ide.rui.visualeditor.internal.editor.EvDesignOutlinePage.java
License:Open Source License
/** * Creates the visibile user interface./* w w w. ja va2s .co m*/ */ public void createControl(Composite parent) { super.createControl(parent); // Create actions //--------------- /* _actionRefreshView = new ISeriesEditorRefreshAction(); IActionBars actionBars = getSite().getActionBars(); IToolBarManager toolBar = actionBars.getToolBarManager(); toolBar.add( _actionRefreshView ); */ // Create a tree viewer for drag and drop //--------------------------------------- // treeViewer = new LanguageTreeViewer(new Tree(parent, SWT.BORDER + SWT.MULTI), this); TreeViewer treeViewer = getTreeViewer(); //add drag and drop support int ops = DND.DROP_MOVE; WidgetTransfer transfer = new WidgetTransfer(_designPage.getWidgetManager()); Transfer[] transfers = new Transfer[] { transfer }; treeViewer.addDragSupport(ops, transfers, new WidgetDragListener(treeViewer, transfer)); transfers = new Transfer[] { transfer, TemplateTransfer.getInstance() }; WidgetDropAdapter dropAdapter = new WidgetDropAdapter(treeViewer, _designPage, transfer, _designPage._overlay); treeViewer.addDropSupport(ops, transfers, dropAdapter); // Add tree viewer listeners //-------------------------- treeViewer.addSelectionChangedListener(this); treeViewer.getTree().addKeyListener(this); // Create content providers for the tree viewer //--------------------------------------------- EvDesignOutlineProvider provider = new EvDesignOutlineProvider(); treeViewer.setContentProvider(provider); treeViewer.setLabelProvider(provider); // Set initial expansion level //---------------------------- treeViewer.setAutoExpandLevel(4); // Give the root element to the tree viewer //----------------------------------------- _model = _designPage.getWidgetManager().getWidgetRoot(); if (_model != null) { treeViewer.setInput(_model); ISelection selection = new StructuredSelection(_model); setSelection(selection); } createContextMenu(); }
From source file:org.eclipse.edt.ide.ui.internal.refactoring.reorg.ReorgUserInputPage.java
License:Open Source License
private TreeViewer createViewer(Composite parent) { TreeViewer treeViewer = new TreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); GridData gd = new GridData(GridData.FILL_BOTH); gd.widthHint = convertWidthInCharsToPixels(40); gd.heightHint = convertHeightInCharsToPixels(15); treeViewer.getTree().setLayoutData(gd); treeViewer.setLabelProvider(new EGLElementLabelProvider(EGLElementLabelProvider.SHOW_SMALL_ICONS)); treeViewer.setContentProvider(new DestinationContentProvider(getDestinationValidator())); treeViewer.setSorter(new EGLElementSorter()); treeViewer.setInput(EGLCore.create(ResourcesPlugin.getWorkspace().getRoot())); return treeViewer; }
From source file:org.eclipse.edt.ide.ui.internal.search.EGLSearchResultPage.java
License:Open Source License
protected void configureTreeViewer(TreeViewer viewer) { viewer.setUseHashlookup(true);//from ww w . j a va2 s . co m viewer.setLabelProvider(new DecoratingLabelProvider( new EGLSearchResultLabelProvider(this, EGLSearchResultLabelProvider.SHOW_LABEL), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator())); viewer.setContentProvider(new EGLSearchResultTreeContentProvider(viewer)); fContentProvider = (EGLSearchResultContentProvider) viewer.getContentProvider(); }
From source file:org.eclipse.egit.ui.internal.commit.DiffEditorOutlinePage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); TreeViewer viewer = getTreeViewer(); viewer.setAutoExpandLevel(2);// w ww. j av a2 s . c o m viewer.setContentProvider(new DiffContentProvider()); viewer.setLabelProvider(new DiffLabelProvider()); viewer.addOpenListener(event -> fireOpenEvent(event)); if (input != null) { viewer.setInput(input); } createContextMenu(viewer); if (selection != null) { viewer.setSelection(selection); } }
From source file:org.eclipse.egit.ui.internal.dialogs.RevertFailureDialog.java
License:Open Source License
protected Control createCustomArea(Composite parent) { if (reasons == null || reasons.isEmpty()) return null; Composite fileArea = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, true).hint(SWT.DEFAULT, 80).applyTo(fileArea); GridLayoutFactory.fillDefaults().applyTo(fileArea); TreeViewer viewer = new TreeViewer(fileArea); viewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl()); viewer.setContentProvider(new WorkbenchContentProvider() { public Object[] getElements(Object element) { return ((Collection) element).toArray(); }/*from ww w.jav a 2 s . co m*/ }); final IStyledLabelProvider styleProvider = new WorkbenchStyledLabelProvider() { public StyledString getStyledText(Object element) { // TODO Replace with use of IWorkbenchAdapter3 when is no longer // supported if (element instanceof RevertFailure) return ((RevertFailure) element).getStyledText(element); if (element instanceof Path) return ((Path) element).getStyledText(element); return super.getStyledText(element); } }; viewer.setLabelProvider(new DelegatingStyledCellLabelProvider(styleProvider)); viewer.setSorter(new ViewerSorter()); Map<MergeFailureReason, RevertFailure> failures = new HashMap<MergeFailureReason, RevertFailure>(); for (Entry<String, MergeFailureReason> reason : reasons.entrySet()) { RevertFailure failure = failures.get(reason.getValue()); if (failure == null) { failure = new RevertFailure(reason.getValue()); failures.put(reason.getValue(), failure); } failure.add(reason.getKey()); } viewer.setInput(failures.values()); return fileArea; }