use of org.eclipse.jface.viewers.ITreeContentProvider in project tdq-studio-se by Talend.
the class XmlPreviewer method createControls.
public void createControls(Composite parent, final Object data) throws ExplorerException {
Element rootElem = getXml(data);
if (rootElem == null)
return;
final Object[] root = new Object[] { rootElem };
TreeViewer tree = new TreeViewer(parent, SWT.SINGLE);
tree.setContentProvider(new ITreeContentProvider() {
public void dispose() {
}
/**
* Called to get the top level items
*/
public Object[] getChildren(Object parentElement) {
return root;
}
/**
* Called to get the item's children
*/
public Object[] getElements(Object inputElement) {
Element elem = (Element) inputElement;
return elem.elements().toArray();
}
public boolean hasChildren(Object element) {
Element elem = (Element) element;
List<Element> list = elem.elements();
return list != null && list.size() > 0;
}
public Object getParent(Object element) {
Element elem = (Element) element;
return elem.getParent();
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
// Nothing
}
});
tree.setLabelProvider(new LabelProvider() {
public String getText(Object obj) {
Element elem = (Element) obj;
StringBuffer result = new StringBuffer();
result.append('<');
result.append(elem.getName());
for (Attribute attr : elem.attributes()) {
result.append(' ').append(attr.getName()).append('=').append('\"').append(attr.getValue()).append('\"');
}
if (!elem.hasContent())
result.append('/');
result.append('>');
return result.toString();
}
});
tree.expandToLevel(1);
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project whole by wholeplatform.
the class MergeResourcesAction method performWorkspaceResourceSelection.
protected IEntity performWorkspaceResourceSelection(Shell shell, IEntity entity) {
IResource input;
if (Matcher.matchImpl(ArtifactsEntityDescriptorEnum.Workspace, entity.wGetParent()))
input = ResourcesPlugin.getWorkspace().getRoot();
else {
IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
ArtifactsWorkspaceUtils.bindPath(entity.wGetParent(), bm, false);
input = (IResource) (bm.wIsSet("folder") ? bm.wGetValue("folder") : bm.wGetValue("project"));
}
IJavaElement javaInput = JavaCore.create(input);
LabelProvider labelProvider = javaInput != null ? new JavaElementLabelProvider() : new WorkbenchLabelProvider();
ITreeContentProvider contentProvider = javaInput != null ? new StandardJavaElementContentProvider() : new WorkbenchContentProvider();
ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, labelProvider, contentProvider);
dialog.setInput(javaInput != null ? javaInput : input);
dialog.setTitle(SELECT_RESOURCE_MSG);
dialog.setMessage("Choose a resource");
if (javaInput != null)
dialog.addFilter(new ViewerFilter() {
public boolean select(Viewer viewer, Object parentElement, Object element) {
try {
return !(element instanceof IPackageFragmentRoot) || ((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_SOURCE;
} catch (Exception e) {
return false;
}
}
});
if (dialog.open() != IDialogConstants.OK_ID)
return NullEntity.instance;
IEntity result = null;
for (Object resource : dialog.getResult()) {
IEntity artifactsPath;
if (resource instanceof IJavaElement) {
IJavaElement toJavaElement = (IJavaElement) resource;
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(javaInput, toJavaElement);
} else {
IResource toResource = (IResource) resource;
IJavaElement parentJavaElement = JavaCore.create(toResource.getParent());
if (javaInput == null || parentJavaElement == null)
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(input, toResource);
else
artifactsPath = ArtifactsWorkspaceUtils.toArtifactsPath(javaInput, toResource);
}
result = result == null ? artifactsPath : EntityUtils.merge(result, artifactsPath, createEntityComparator(), false);
}
int index = Matcher.match(ArtifactsEntityDescriptorEnum.Workspace, result) ? result.wIndexOf(ArtifactsFeatureDescriptorEnum.projects) : result.wIndexOf(ArtifactsFeatureDescriptorEnum.artifacts);
IEntity tree = result.wGet(index);
result.wRemove(index);
return tree;
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project portfolio by buchen.
the class TreeViewerCSVExporter method writeToFile.
@Override
protected void writeToFile(File file) throws IOException {
try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8)) {
CSVPrinter printer = new CSVPrinter(writer);
printer.setStrategy(STRATEGY);
ITreeContentProvider provider = (ITreeContentProvider) viewer.getContentProvider();
int depth = depth(provider);
int columnCount = viewer.getTree().getColumnCount();
ILabelProvider[] labels = new ILabelProvider[columnCount];
extractLabelProvider(labels);
// write header
String label = viewer.getTree().getColumn(0).getText();
for (int ii = 0; ii < depth; ii++) // $NON-NLS-1$
printer.print(label + " " + (ii + 1));
for (int ii = 1; ii < columnCount; ii++) printer.print(viewer.getTree().getColumn(ii).getText());
printer.println();
// write body
LinkedList<String> path = new LinkedList<>();
for (Object element : provider.getElements(null)) {
writeLine(printer, provider, labels, depth, path, element);
}
}
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.
the class LinkRequirementsCheckStateListener method checkAndGrayAllParents.
/**
* Checks and grays all the parents in {@code checkboxTreeViewer} of
* {@code element}.
*
* @param checkboxTreeViewer
* @param element
*/
private static void checkAndGrayAllParents(CheckboxTreeViewer checkboxTreeViewer, Object element) {
ITreeContentProvider contentProvider = getTreeContentProvider(checkboxTreeViewer);
Object parent = contentProvider.getParent(element);
do {
checkboxTreeViewer.setGrayChecked(parent, true);
parent = contentProvider.getParent(parent);
} while (parent != null);
}
use of org.eclipse.jface.viewers.ITreeContentProvider in project InformationSystem by ObeoNetwork.
the class LinkRequirementsCheckStateListener method unCheckAndUnGrayAllAppropriateParents.
/**
* Unchecks and ungrays all parents which have no more children that's
* checked.
*
* @param checkboxTreeViewer
* @param element
*/
private static void unCheckAndUnGrayAllAppropriateParents(CheckboxTreeViewer checkboxTreeViewer, Object element) {
ITreeContentProvider contentProvider = getTreeContentProvider(checkboxTreeViewer);
Object parent = contentProvider.getParent(element);
while (parent != null && !anyCheckedInViewer(Arrays.asList(contentProvider.getChildren(parent)), checkboxTreeViewer)) {
checkboxTreeViewer.setGrayChecked(parent, false);
parent = contentProvider.getParent(parent);
}
}
Aggregations