use of org.eclipse.jface.viewers.ITreeContentProvider in project eclipse.platform.text by eclipse.
the class FileSearchPage method autoExpand.
/**
* Performs an auto-expansion starting at the given element in the viewer.
* As long as the object only has one unexpanded child, auto-expand will
* expand that child. It stops expanding children once there is actually a
* choice for the user to make.
*
* @param viewer
* the viewer to perform auto-expansion on
* @param toExpand
* the viewer entry at which expansion should start
*/
private void autoExpand(TreeViewer viewer, Object toExpand) {
final ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
Display.getCurrent().asyncExec(() -> {
if (viewer.getControl().isDisposed()) {
return;
}
Object current = toExpand;
while (current != null) {
Object childToExpand = null;
Object[] children = contentProvider.getChildren(current);
if (children != null && children.length == 1) {
childToExpand = children[0];
}
if (childToExpand != null) {
if (!viewer.getExpandedState(childToExpand)) {
viewer.setExpandedState(childToExpand, true);
}
}
current = childToExpand;
}
});
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project linuxtools by eclipse.
the class STDataViewersCSVExporter method export.
public void export(IProgressMonitor monitor) {
// monitoring
this.monitor = monitor;
monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", IProgressMonitor.UNKNOWN);
// save this configuration
saveState();
// init the printStream
initPrintStream(filePath);
// get the viewer's parameters
monitor.subTask("collecting viewer's parameters...");
collectViewerParameters();
// start dumping to csv file
dumpColumnHeaders();
if (input != null) {
if (contentProvider instanceof ITreeContentProvider) {
ITreeContentProvider treeContentProvider = (ITreeContentProvider) contentProvider;
Object[] topElements = treeContentProvider.getElements(input);
if (topElements != null) {
// monitoring
int work = topElements.length;
for (Object element : topElements) {
if (treeContentProvider.hasChildren(element)) {
work += treeContentProvider.getChildren(element).length;
}
}
monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", work);
monitor.subTask("exporting tree data...");
// monitoring stuff
int tempWork = 0;
int workFloor = topElements.length / 100;
if (workFloor == 0) {
workFloor = 1;
}
// exporting tree
Arrays.sort(topElements, comparator);
for (int i = 0; i < topElements.length; i++) {
dumpTreeData(treeContentProvider, topElements[i], "", i == topElements.length - 1, true);
// monitoring
tempWork++;
if (tempWork >= workFloor) {
if (monitor.isCanceled()) {
ps.close();
return;
}
monitor.worked(tempWork);
tempWork = 0;
}
}
// monitoring
monitor.worked(tempWork);
}
} else if (contentProvider instanceof IStructuredContentProvider) {
IStructuredContentProvider structContentProvider = (IStructuredContentProvider) contentProvider;
Object[] topElements = structContentProvider.getElements(input);
if (topElements != null) {
// monitoring
monitor.beginTask("Exporting to CSV (file: " + getFilePath() + ")", topElements.length);
monitor.subTask("exporting table data...");
// monitoring stuff
int tempWork = 0;
int workFloor = topElements.length / 100;
if (workFloor == 0) {
workFloor = 1;
}
// exporting table
Arrays.sort(topElements, comparator);
for (int n = 0; n < topElements.length; n++) {
if (n < topElements.length - 1) {
dumpNodeData(topElements[n], csvChildMarker);
} else {
dumpNodeData(topElements[n], csvLastChildMarker);
}
// monitoring
tempWork++;
if (tempWork >= workFloor) {
if (monitor.isCanceled()) {
ps.close();
return;
}
monitor.worked(tempWork);
tempWork = 0;
}
}
// monitoring
monitor.worked(tempWork);
}
}
}
// close the stream
ps.close();
// end monitoring
monitor.done();
IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(getFilePath()));
if (c != null) {
try {
c.refreshLocal(1, new NullProgressMonitor());
} catch (CoreException e) {
STDataViewersActivator.getDefault().getLog().log(e.getStatus());
}
}
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project linuxtools by eclipse.
the class TreeColumnViewerFilter method select.
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
ITreeContentProvider provider = (ITreeContentProvider) treeViewer.getContentProvider();
String s = field.getValue(element);
if (s.contains(matchingText)) {
return true;
}
if (provider.hasChildren(element)) {
for (Object o : provider.getChildren(element)) {
if (select(viewer, element, o)) {
return true;
}
}
}
if (keepAllChildIfParentMatch) {
while (parentElement != null) {
String ps = field.getValue(parentElement);
if (ps.contains(matchingText)) {
return true;
}
parentElement = provider.getParent(parentElement);
}
}
return false;
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project erlide_eclipse by erlang.
the class DirectorySelectUtil method chooseLocation.
public static IContainer chooseLocation(final String dialogTitle, final String labelText, final IProject project2, final String outputLocation, final Shell shell) {
final IWorkspaceRoot root = project2.getWorkspace().getRoot();
final Class<?>[] acceptedClasses = new Class[] { IProject.class, IFolder.class };
final IProject[] allProjects = root.getProjects();
final List<IProject> rejectedElements = new ArrayList<>(allProjects.length);
for (IProject allProject : allProjects) {
if (!allProject.equals(project2)) {
rejectedElements.add(allProject);
}
}
final ViewerFilter filter = new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());
final ILabelProvider lp = new WorkbenchLabelProvider();
final ITreeContentProvider cp = new WorkbenchContentProvider();
IResource initSelection = null;
if (outputLocation != null) {
initSelection = root.findMember(outputLocation);
}
final FolderSelectionDialog dialog = new FolderSelectionDialog(shell, lp, cp);
dialog.setTitle(dialogTitle);
final ISelectionStatusValidator validator = new ISelectionStatusValidator() {
ISelectionStatusValidator myValidator = new TypedElementSelectionValidator(acceptedClasses, false);
@Override
public IStatus validate(final Object[] selection) {
final IStatus typedStatus = myValidator.validate(selection);
if (!typedStatus.isOK()) {
return typedStatus;
}
if (selection[0] instanceof IFolder) {
// }
return new StatusInfo();
}
return new StatusInfo(IStatus.ERROR, "");
}
};
dialog.setValidator(validator);
dialog.setMessage(labelText);
dialog.addFilter(filter);
dialog.setInput(root);
dialog.setInitialSelection(initSelection);
dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
if (dialog.open() == Window.OK) {
return (IContainer) dialog.getFirstResult();
}
return null;
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project tmdm-studio-se by Talend.
the class MenuMainPage method createCharacteristicsContent.
@Override
protected void createCharacteristicsContent(FormToolkit toolkit, Composite mainComposite) {
try {
// description
Label descriptionLabel = toolkit.createLabel(mainComposite, Messages.MenuMainPage_Description, SWT.NULL);
descriptionLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, true, 1, 1));
// $NON-NLS-1$
descriptionText = toolkit.createText(mainComposite, "", SWT.BORDER);
descriptionText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
((GridData) descriptionText.getLayoutData()).minimumHeight = 30;
descriptionText.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
if (refreshing) {
return;
}
markDirtyWithoutCommit();
}
});
// Util.createCompDropTarget(descriptionText);
// make the Page window a DropTarget - we need to dispose it
windowTarget = new DropTarget(this.getPartControl(), DND.DROP_MOVE);
windowTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
windowTarget.addDropListener(new DCDropTargetListener());
Composite composite = toolkit.createComposite(mainComposite, SWT.BORDER);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
composite.setLayout(new GridLayout(1, false));
menuTree = new TreeViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
menuTree.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
((GridData) menuTree.getControl().getLayoutData()).heightHint = 150;
menuTree.setContentProvider(new ITreeContentProvider() {
public void dispose() {
}
public Object[] getChildren(Object parentElement) {
if (parentElement instanceof TreeEntry) {
WSMenuEntry wsEntry = ((TreeEntry) parentElement).getWSMenuEntry();
if (wsEntry.getSubMenus() != null) {
TreeEntry[] children = new TreeEntry[wsEntry.getSubMenus().size()];
for (int i = 0; i < wsEntry.getSubMenus().size(); i++) {
children[i] = new TreeEntry((TreeEntry) parentElement, wsEntry.getSubMenus().get(i));
}
return children;
}
return null;
}
if (parentElement instanceof WSMenu) {
// the root
java.util.List<WSMenuEntry> menuEntries = ((WSMenu) parentElement).getMenuEntries();
if (menuEntries != null) {
TreeEntry[] children = new TreeEntry[menuEntries.size()];
for (int i = 0; i < menuEntries.size(); i++) {
children[i] = new TreeEntry(null, menuEntries.get(i));
}
return children;
}
return null;
}
// ??!!?
return null;
}
public Object[] getElements(Object inputElement) {
return getChildren(inputElement);
}
public Object getParent(Object element) {
return null;
}
public boolean hasChildren(Object element) {
return ((getChildren(element) == null) || (getChildren(element).length > 0));
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
});
menuTree.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
WSMenuEntry wsMenuEntry = ((TreeEntry) element).getWSMenuEntry();
// $NON-NLS-1$
StringBuffer label = new StringBuffer(wsMenuEntry.getId() + " - ");
for (WSMenuMenuEntriesDescriptions description : wsMenuEntry.getDescriptions()) {
// $NON-NLS-1$//$NON-NLS-2$
label.append("[").append(description.getLanguage()).append(": ").append(description.getLabel()).append(// $NON-NLS-1$
"] ");
}
if (label.length() > 200) {
// $NON-NLS-1$
return label.substring(0, 197) + "...";
}
return label.toString();
}
@Override
public Image getImage(Object element) {
return ImageCache.getCreatedImage(EImage.MENU.getPath());
}
});
menuTreeMgr = new MenuManager();
menuTreeMgr.setRemoveAllWhenShown(true);
menuTreeMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager manager) {
IStructuredSelection selection = ((IStructuredSelection) menuTree.getSelection());
if ((selection == null) || (selection.getFirstElement() == null)) {
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
return;
}
// TreeEntry entry = (TreeEntry)selection.getFirstElement();
menuTreeMgr.add(new TreeEntryEditAction(menuTree));
menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_BEFORE));
menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_AFTER));
menuTreeMgr.add(new TreeEntryAddAction(menuTree, LOCATION_UNDER));
menuTreeMgr.add(new TreeEntryDeleteAction(menuTree));
menuTreeMgr.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
});
menuTree.addDoubleClickListener(new IDoubleClickListener() {
public void doubleClick(DoubleClickEvent event) {
(new TreeEntryEditAction(menuTree)).run();
}
});
Menu menu = menuTreeMgr.createContextMenu(menuTree.getControl());
menuTree.getControl().setMenu(menu);
getSite().registerContextMenu(menuTreeMgr, menuTree);
refreshData();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Aggregations