List of usage examples for org.eclipse.jface.viewers TreeViewer getControl
@Override
public Control getControl()
From source file:org.eclipse.team.examples.filesystem.ui.NonSyncModelMergePage.java
License:Open Source License
private void hookContextMenu(final TreeViewer viewer) { final MenuManager menuMgr = new MenuManager(); menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { fillContextMenu(manager);/* w ww . j a v a2s .co m*/ } }); Menu menu = menuMgr.createContextMenu(viewer.getControl()); viewer.getControl().setMenu(menu); }
From source file:org.eclipse.team.internal.ccvs.ui.tags.TagSelectionArea.java
License:Open Source License
protected TreeViewer createTree(Composite parent) { Tree tree = new Tree(parent, SWT.SINGLE | SWT.BORDER); GridData data = new GridData(GridData.FILL_BOTH); tree.setLayoutData(data);// w w w . j a v a2s .c o m TreeViewer result = new TreeViewer(tree); initialize(result); result.getControl().addKeyListener(new KeyListener() { public void keyPressed(KeyEvent event) { handleKeyPressed(event); } public void keyReleased(KeyEvent event) { handleKeyReleased(event); } }); result.setInput(createUnfilteredInput()); createTreeMenu(result); return result; }
From source file:org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage.java
License:Open Source License
protected TreeViewer createResourceSelectionTree(Composite composite, int types, int span) { TreeViewer tree = new TreeViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); tree.setUseHashlookup(true);/*from w w w . j a v a 2s.c o m*/ tree.setContentProvider(getResourceProvider(types)); tree.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelProvider(), CVSUIPlugin.getPlugin().getWorkbench().getDecoratorManager().getLabelDecorator())); tree.setComparator(new ResourceComparator(ResourceComparator.NAME)); GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL); data.heightHint = LIST_HEIGHT_HINT; data.horizontalSpan = span; tree.getControl().setLayoutData(data); return tree; }
From source file:org.eclipse.team.internal.ccvs.ui.wizards.RestoreFromRepositoryFileSelectionPage.java
License:Open Source License
protected TreeViewer createFileSelectionTree(CompareViewerPane composite) { TreeViewer tree = new TreeViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); tree.setUseHashlookup(true);//from www . jav a 2s . co m tree.setContentProvider(treeInput.getTreeContentProvider()); tree.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelProvider() { protected String decorateText(String input, Object element) { String text; if (element instanceof IFolder && element.equals(folder)) { text = super.decorateText(folder.getProjectRelativePath().toString(), element); } else { ILogEntry entry = (ILogEntry) filesToRestore.get(element); text = super.decorateText(input, element); if (entry != null) { text = NLS.bind(CVSUIMessages.RestoreFromRepositoryFileSelectionPage_fileToRestore, new String[] { text, entry.getRevision() }); } } return text; } }, CVSUIPlugin.getPlugin().getWorkbench().getDecoratorManager().getLabelDecorator())); tree.setComparator(new ResourceComparator(ResourceComparator.NAME)); tree.setInput(treeInput); GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL); tree.getTree().setLayoutData(data); tree.addPostSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { handleFileSelection(event); } }); composite.setContent(tree.getControl()); return tree; }
From source file:org.eclipse.tm4e.languageconfiguration.internal.wizards.SelectLanguageConfigurationWizardPage.java
License:Open Source License
private void createContentTypeTreeViewer(Composite composite) { TreeViewer contentTypesViewer = new TreeViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); contentTypesViewer.getControl().setFont(composite.getFont()); contentTypesViewer.setContentProvider(new ContentTypesContentProvider()); contentTypesViewer.setLabelProvider(new ContentTypesLabelProvider()); contentTypesViewer.setComparator(new ViewerComparator()); contentTypesViewer.setInput(Platform.getContentTypeManager()); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.horizontalSpan = 2;// w w w .j a v a 2 s . c om contentTypesViewer.getControl().setLayoutData(data); contentTypesViewer.addSelectionChangedListener(event -> contentTypeText .setText(((IContentType) event.getStructuredSelection().getFirstElement()).toString())); }
From source file:org.eclipse.ui.internal.dialogs.CustomizePerspectiveDialog.java
License:Open Source License
private Composite createActionSetAvailabilityPage(Composite parent) { GridData data;// ww w. jav a 2s . co m Composite actionSetsComposite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); actionSetsComposite.setLayout(layout); // Select... label Label label = new Label(actionSetsComposite, SWT.WRAP); label.setText(NLS.bind(WorkbenchMessages.ActionSetSelection_selectActionSetsLabel, perspective.getDesc().getLabel())); data = new GridData(SWT.FILL, SWT.CENTER, true, false); label.setLayoutData(data); Label sep = new Label(actionSetsComposite, SWT.HORIZONTAL | SWT.SEPARATOR); sep.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); SashForm sashComposite = new SashForm(actionSetsComposite, SWT.HORIZONTAL); data = new GridData(SWT.FILL, SWT.FILL, true, true); sashComposite.setLayoutData(data); // Action Set List Composite Composite actionSetGroup = new Composite(sashComposite, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; actionSetGroup.setLayout(layout); actionSetGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); label = new Label(actionSetGroup, SWT.WRAP); label.setText(WorkbenchMessages.ActionSetSelection_availableActionSets); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final CheckboxTableViewer actionSetsViewer = CheckboxTableViewer.newCheckList(actionSetGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); actionSetAvailabilityTable = actionSetsViewer; actionSetsViewer.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); actionSetsViewer.setLabelProvider(new LabelProvider()); actionSetsViewer.setContentProvider(new ArrayContentProvider()); actionSetsViewer.setComparator(new WorkbenchViewerComparator()); actionSetsViewer.setCheckStateProvider(new ICheckStateProvider() { public boolean isChecked(Object element) { return ((ActionSet) element).isActive(); } public boolean isGrayed(Object element) { return false; } }); actionSetsViewer.setInput(actionSets.toArray()); Table table = actionSetsViewer.getTable(); new TableToolTip(table); final ActionSet[] selectedActionSet = { null }; // Filter to show only branches necessary for the selected action set. final ViewerFilter setFilter = new ViewerFilter() { public boolean select(Viewer viewer, Object parentElement, Object element) { if (selectedActionSet[0] == null) return false; return includeInSetStructure((DisplayItem) element, selectedActionSet[0]); } }; // Updates the check state of action sets actionSetsViewer.addCheckStateListener(new ICheckStateListener() { public void checkStateChanged(CheckStateChangedEvent event) { final ActionSet actionSet = (ActionSet) event.getElement(); if (event.getChecked()) { actionSet.setActive(true); for (Iterator i = actionSet.contributionItems.iterator(); i.hasNext();) { DisplayItem item = (DisplayItem) i.next(); item.setCheckState(true); } } else { actionSet.setActive(false); } } }); // Menu and toolbar composite Composite actionGroup = new Composite(sashComposite, SWT.NONE); layout = new GridLayout(); layout.numColumns = 2; layout.makeColumnsEqualWidth = true; layout.marginHeight = 0; layout.marginWidth = 0; layout.horizontalSpacing = 0; actionGroup.setLayout(layout); actionGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); Composite menubarGroup = new Composite(actionGroup, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; menubarGroup.setLayout(layout); menubarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); label = new Label(menubarGroup, SWT.WRAP); label.setText(WorkbenchMessages.ActionSetSelection_menubarActions); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final TreeViewer actionSetMenuViewer = new TreeViewer(menubarGroup); actionSetMenuViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); actionSetMenuViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); actionSetMenuViewer.setUseHashlookup(true); actionSetMenuViewer.setContentProvider(TreeManager.getTreeContentProvider()); actionSetMenuViewer.setLabelProvider(TreeManager.getLabelProvider()); actionSetMenuViewer.addFilter(setFilter); actionSetMenuViewer.setInput(menuItems); Tree tree = actionSetMenuViewer.getTree(); new ItemDetailToolTip(actionSetMenuViewer, tree, false, true, setFilter); Composite toolbarGroup = new Composite(actionGroup, SWT.NONE); layout = new GridLayout(); layout.marginHeight = 0; layout.marginWidth = 0; toolbarGroup.setLayout(layout); toolbarGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); label = new Label(toolbarGroup, SWT.WRAP); label.setText(WorkbenchMessages.ActionSetSelection_toolbarActions); label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); final TreeViewer actionSetToolbarViewer = new TreeViewer(toolbarGroup); actionSetToolbarViewer.setAutoExpandLevel(AbstractTreeViewer.ALL_LEVELS); actionSetToolbarViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); actionSetToolbarViewer.setContentProvider(TreeManager.getTreeContentProvider()); actionSetToolbarViewer.setLabelProvider(TreeManager.getLabelProvider()); actionSetToolbarViewer.addFilter(setFilter); actionSetToolbarViewer.setInput(toolBarItems); tree = actionSetToolbarViewer.getTree(); new ItemDetailToolTip(actionSetToolbarViewer, tree, false, true, setFilter); // Updates the menu item and toolbar items tree viewers when the // selection changes actionSetsViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { selectedActionSet[0] = (ActionSet) ((IStructuredSelection) event.getSelection()).getFirstElement(); actionSetMenuViewer.setInput(menuItems); actionSetToolbarViewer.setInput(toolBarItems); } }); sashComposite.setWeights(new int[] { 30, 70 }); return actionSetsComposite; }
From source file:org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog.java
License:Open Source License
protected Control createTreeAreaContents(Composite parent) { Composite leftArea = new Composite(parent, SWT.NONE); leftArea.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND)); leftArea.setFont(parent.getFont());/* w ww .j a v a 2 s . co m*/ GridLayout leftLayout = new GridLayout(); leftLayout.numColumns = 1; leftLayout.marginHeight = 0; leftLayout.marginTop = IDialogConstants.VERTICAL_MARGIN; leftLayout.marginWidth = IDialogConstants.HORIZONTAL_MARGIN; leftLayout.horizontalSpacing = 0; leftLayout.verticalSpacing = 0; leftArea.setLayout(leftLayout); // Build the tree an put it into the composite. TreeViewer viewer = createTreeViewer(leftArea); setTreeViewer(viewer); updateTreeFont(JFaceResources.getDialogFont()); GridData viewerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_VERTICAL); viewer.getControl().getParent().setLayoutData(viewerData); layoutTreeAreaControl(leftArea); return leftArea; }
From source file:org.eclipse.ui.internal.dialogs.ShowViewDialog.java
License:Open Source License
/** * Create a new filtered tree viewer in the parent. * // ww w .j a va2 s . c o m * @param parent the parent <code>Composite</code>. */ private void createFilteredTreeViewer(Composite parent) { PatternFilter filter = new ViewPatternFilter(); int styleBits = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER; filteredTree = new FilteredTree(parent, styleBits, filter, true); filteredTree.setQuickSelectionMode(true); filteredTree.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); TreeViewer treeViewer = filteredTree.getViewer(); Control treeControl = treeViewer.getControl(); RGB dimmedRGB = blend(treeControl.getForeground().getRGB(), treeControl.getBackground().getRGB(), 60); dimmedForeground = new Color(treeControl.getDisplay(), dimmedRGB); treeControl.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { dimmedForeground.dispose(); } }); treeViewer.setLabelProvider(new ViewLabelProvider(window, dimmedForeground)); treeViewer.setContentProvider(new ViewContentProvider()); treeViewer.setComparator(new ViewComparator((ViewRegistry) viewReg)); treeViewer.setInput(viewReg); treeViewer.addSelectionChangedListener(this); treeViewer.addDoubleClickListener(this); treeViewer.addFilter(new CapabilityFilter()); treeViewer.getControl().addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { handleTreeViewerKeyPressed(e); } }); // if the tree has only one or zero views, disable the filter text control if (hasAtMostOneView(filteredTree.getViewer())) { Text filterText = filteredTree.getFilterControl(); if (filterText != null) { filterText.setEnabled(false); } } }
From source file:org.eclipse.ui.internal.views.markers.UIUpdateJob.java
License:Open Source License
public IStatus runInUIThread(IProgressMonitor monitor) { if (monitor.isCanceled()) { return Status.CANCEL_STATUS; }/*from ww w .j a v a 2 s . c o m*/ TreeViewer viewer = view.getViewer(); if (viewer.getControl().isDisposed()) { return Status.CANCEL_STATUS; } Markers clone = view.getActiveViewerInputClone(); try { updating = true; monitor.beginTask(MarkerMessages.MarkerView_19, IProgressMonitor.UNKNOWN); if (monitor.isCanceled()) { return Status.CANCEL_STATUS; } //view.indicateUpdating(MarkerMessages.MarkerView_19, // true); // If there is only one category and the user has no saved state // show it if (view.getBuilder().isShowingHierarchy() && view.getCategoriesToExpand().isEmpty()) { MarkerCategory[] categories = clone.getCategories(); if (categories != null && categories.length == 1) view.getCategoriesToExpand().add(categories[0].getDescription()); } if (monitor.isCanceled()) return Status.CANCEL_STATUS; /* * always use a clone for Thread safety. We avoid setting the clone * as new input as we would offset the benefits of optimization in * TreeViewer. */ clone = view.createViewerInputClone(); if (clone == null) { // do not update yet,we are changing return Status.CANCEL_STATUS; } /* * we prefer not to check for cancellation beyond this since we * have to show correct marker counts on UI, not an updating message. */ IContentProvider contentProvider = viewer.getContentProvider(); contentProvider.inputChanged(viewer, view.getViewerInput(), clone); viewer.getTree().setRedraw(false); viewer.refresh(true); if (!monitor.isCanceled()) { //do not expand if canceled view.reexpandCategories(); } if (view.getBuilder().readChangeFlags()[0]) { // indicate changes } //show new counts view.updateTitle(); lastUpdateTime = System.currentTimeMillis(); } finally { viewer.getTree().setRedraw(true); view.updateStatusLine((IStructuredSelection) viewer.getSelection()); //view.updateCategoryLabels(); updating = false; } monitor.done(); return Status.OK_STATUS; }
From source file:org.eclipse.ui.tests.performance.LabelProviderTest.java
License:Open Source License
protected StructuredViewer createViewer(Shell parent) { TreeViewer viewer = new TreeViewer(parent, SWT.FULL_SELECTION); viewer.setContentProvider(new ITreeContentProvider() { public Object[] getChildren(Object parentElement) { return entries; }/* w w w . j ava 2 s. c o m*/ public Object getParent(Object element) { return null; } public boolean hasChildren(Object element) { return false; } public Object[] getElements(Object inputElement) { return entries; } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } }); GridData data = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH); viewer.getControl().setLayoutData(data); viewer.setSelection(new StructuredSelection(entries[1])); return viewer; }