use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class SearchIndexLabelProvider method getStyledText.
@Override
public StyledString getStyledText(Object element) {
if (element instanceof TreeNode) {
element = ((TreeNode<?>) element).data;
}
if (element instanceof ICustomLineElement) {
return getLineElementLabel((ICustomLineElement) element);
}
if (!(element instanceof IResource)) {
IResource resource = null;
if (element instanceof IAdaptable) {
IAdaptable iAdaptable = (IAdaptable) element;
resource = iAdaptable.getAdapter(IResource.class);
if (resource != null) {
if (element instanceof ICustomModule) {
return getColoredLabelWithCounts(resource, new StyledString(element.toString()));
}
element = resource;
}
}
if (!(element instanceof IResource)) {
return new StyledString(element.toString());
}
}
IResource resource = (IResource) element;
if (!resource.exists()) {
new StyledString("<removed resource>");
}
String name = BasicElementLabels.getResourceName(resource);
return getColoredLabelWithCounts(resource, new StyledString(name));
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class Select1Dialog method selectElement.
public TreeNode<Object> selectElement(TreeNode<Object> emptyRoot) {
Shell shell = EditorUtils.getShell();
final DialogMemento memento = new DialogMemento(shell, "org.python.pydev.ui.dialogs.Select1Dialog.shell");
TreeSelectionDialog dialog = new TreeSelectionDialog(shell, getLabelProvider(), getContentProvider()) {
@Override
public boolean close() {
memento.writeSettings(getShell());
return super.close();
}
@Override
public Control createDialogArea(Composite parent) {
memento.readSettings();
Control ret = super.createDialogArea(parent);
ret.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN) {
okPressed();
}
}
});
return ret;
}
/* (non-Javadoc)
* @see org.python.pydev.ui.dialogs.TreeSelectionDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
*/
@Override
protected Control createButtonBar(Composite parent) {
Composite buttonBar = new Composite(parent, 0);
GridLayout layout = new GridLayout();
layout.numColumns = 2;
buttonBar.setLayout(layout);
afterCreateButtonBar(parent, buttonBar);
GridData data = new GridData();
data.horizontalAlignment = SWT.FILL;
data.grabExcessHorizontalSpace = true;
buttonBar.setLayoutData(data);
return buttonBar;
}
@Override
protected Point getInitialSize() {
return memento.getInitialSize(super.getInitialSize(), getShell());
}
@Override
protected Point getInitialLocation(Point initialSize) {
return memento.getInitialLocation(initialSize, super.getInitialLocation(initialSize), getShell());
}
/*
* @see SelectionStatusDialog#computeResult()
*/
@Override
@SuppressWarnings("unchecked")
protected void computeResult() {
doFinalUpdateBeforeComputeResult();
IStructuredSelection selection = (IStructuredSelection) getTreeViewer().getSelection();
List<Object> list = selection.toList();
if (list.size() == 1) {
setResult(list);
} else {
Tree tree = getTreeViewer().getTree();
TreeItem[] items = tree.getItems();
list = new ArrayList<Object>();
// Now, if he didn't select anything, let's create tests with all that is currently filtered
// in the interface
createListWithLeafs(items, list);
if (list.size() == 1) {
setResult(list);
}
}
}
private void createListWithLeafs(TreeItem[] items, List<Object> leafObjectsList) {
for (TreeItem item : items) {
TreeItem[] children = item.getItems();
if (children.length == 0) {
leafObjectsList.add(item.getData());
} else {
createListWithLeafs(children, leafObjectsList);
}
}
}
};
dialog.setTitle("PyDev: Select entry");
dialog.setMessage("Select entry");
dialog.setInitialFilter(getInitialFilter());
dialog.setAllowMultiple(false);
dialog.setInput(emptyRoot);
int open = dialog.open();
if (open != Window.OK) {
return null;
}
Object[] result = dialog.getResult();
if (result != null && result.length == 1) {
return (TreeNode<Object>) result[0];
}
return null;
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class SelectNDialog method selectElements.
/**
* @param labelProvider: usually a TreeNodeLabelProvider
* @param title: message in shell
* @param message: message above tree
* @param checkElapsedBeforeClose: if true we'll only accept a click after some secs (to prevent an accidental click
* in the case of an unrequested dialog).
*/
public static List<TreeNode> selectElements(TreeNode root, ILabelProvider labelProvider, String title, String message, final boolean checkElapsedBeforeClose, List initialSelection) {
Shell shell = EditorUtils.getShell();
CheckedTreeSelectionDialog dialog = new CheckedTreeSelectionDialog(shell, labelProvider, new TreeNodeContentProvider()) {
private final DialogButtonEnablementHelper helper = new DialogButtonEnablementHelper(!checkElapsedBeforeClose);
@Override
public boolean close() {
if (!helper.areButtonsEnabled()) {
return false;
}
return super.close();
}
@Override
protected void cancelPressed() {
if (!helper.areButtonsEnabled()) {
return;
}
super.cancelPressed();
}
@Override
protected void okPressed() {
if (!helper.areButtonsEnabled()) {
return;
}
super.okPressed();
}
@Override
protected void constrainShellSize() {
helper.onConstrainShellSize();
super.constrainShellSize();
}
@Override
protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
Button button = super.createButton(parent, id, label, defaultButton);
helper.onCreateButton(button, id);
return button;
}
@Override
protected void createButtonsForButtonBar(Composite parent) {
// create OK and Cancel buttons by default
createButton(parent, IDialogConstants.OK_ID, "Apply selected changes (Ignore unselected)", true);
createButton(parent, IDialogConstants.CANCEL_ID, "Don't ask again (Ignore all)", false);
}
};
dialog.setTitle(title);
dialog.setMessage(message);
dialog.setInput(root);
dialog.setInitialElementSelections(initialSelection);
dialog.setExpandedElements(initialSelection.toArray());
if (dialog.open() == CheckedTreeSelectionDialog.OK) {
Object[] result = dialog.getResult();
if (result != null) {
ArrayList<TreeNode> ret = new ArrayList<TreeNode>(result.length);
for (Object o : result) {
ret.add((TreeNode) o);
}
return ret;
}
}
return null;
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class PythonBaseModelProvider method createErrorNoWorkingSetsDefined.
public TreeNode<LabelAndImage> createErrorNoWorkingSetsDefined(Object parentElement) {
IImageHandle img = SharedUiPlugin.getImageCache().get(UIConstants.WARNING);
TreeNode<LabelAndImage> root = new TreeNode<LabelAndImage>(parentElement, new LabelAndImage("Warning: Top level elements set to working sets but no working sets are defined.", img));
new TreeNode<>(root, new LabelAndImage("Access the menu (Ctrl+F10) to change to show projects or create a working set.", null));
return root;
}
use of org.python.pydev.shared_core.structure.TreeNode in project Pydev by fabioz.
the class PythonBaseModelProvider method hasChildren.
/**
* @return whether there are children for the given element. Note that there is
* an optimization in this method, so that it works correctly for elements that
* are not python files, and returns true if it is a python file with any content
* (even if that content does not actually map to a node.
*
* @see org.eclipse.ui.model.BaseWorkbenchContentProvider#hasChildren(java.lang.Object)
*/
@Override
public boolean hasChildren(Object element) {
if (element instanceof PythonFile) {
// If we're not showing nodes, return false.
INavigatorContentService contentService = viewer.getNavigatorContentService();
INavigatorFilterService filterService = contentService.getFilterService();
ViewerFilter[] visibleFilters = filterService.getVisibleFilters(true);
for (ViewerFilter viewerFilter : visibleFilters) {
if (viewerFilter instanceof PythonNodeFilter) {
return false;
}
}
PythonFile f = (PythonFile) element;
if (PythonPathHelper.isValidSourceFile(f.getActualObject())) {
try {
InputStream contents = f.getContents();
try {
if (contents.read() == -1) {
// if there is no content in the file, it has no children
return false;
} else {
// if it has any content, it has children (performance reasons)
return true;
}
} finally {
contents.close();
}
} catch (Exception e) {
Log.log("Handled error getting contents.", e);
return false;
}
}
return false;
}
if (element instanceof TreeNode<?>) {
TreeNode<?> treeNode = (TreeNode<?>) element;
return treeNode.hasChildren();
}
return getChildren(element).length > 0;
}
Aggregations