use of org.eclipse.jface.viewers.TreePath in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method getActiveSaveablesFromTreePathProvider.
/**
* @param selection
* @param provider
* @return the active saveables
*/
private Saveable[] getActiveSaveablesFromTreePathProvider(IStructuredSelection selection, ITreePathContentProvider provider) {
Set result = new HashSet();
for (Iterator it = selection.iterator(); it.hasNext(); ) {
Object element = it.next();
Saveable saveable = getSaveable(element);
if (saveable != null) {
result.add(saveable);
} else {
TreePath[] paths = provider.getParents(element);
saveable = findSaveable(paths);
if (saveable != null) {
result.add(saveable);
}
}
}
return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.
the class ObjectBrowser method restoreSelection.
/**
* Restore selection in the tree
*/
private void restoreSelection() {
if (// $NON-NLS-1$
(initialObjectSelection == null) || initialObjectSelection.isEmpty() || !initialObjectSelection.startsWith("/"))
return;
final NXCSession session = (NXCSession) ConsoleSharedData.getSession();
// $NON-NLS-1$
final String[] parts = initialObjectSelection.split("/");
final Object[] elements = new Object[parts.length - 1];
for (int i = 1; i < parts.length; i++) {
long id;
try {
id = Long.parseLong(parts[i]);
} catch (NumberFormatException e) {
return;
}
elements[i - 1] = session.findObjectById(id);
if (elements[i - 1] == null)
// path element is missing
return;
}
objectTree.getTreeViewer().setSelection(new TreeSelection(new TreePath(elements)), true);
final Display display = getSite().getShell().getDisplay();
display.asyncExec(new Runnable() {
@Override
public void run() {
// wait for events to finish before continue
while (display.readAndDispatch()) ;
// $NON-NLS-1$
CommandBridge.getInstance().execute("TabbedObjectView/changeObject", ((AbstractObject) elements[elements.length - 1]).getObjectId());
}
});
}
use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.
the class ObjectBrowser method saveSelection.
/**
* Save tree viewer selection
*
* @param memento
*/
private void saveSelection(IMemento memento) {
ITreeSelection selection = (ITreeSelection) objectTree.getTreeViewer().getSelection();
if (selection.size() == 1) {
TreePath path = selection.getPaths()[0];
StringBuilder sb = new StringBuilder();
for (int i = 0; i < path.getSegmentCount(); i++) {
sb.append('/');
sb.append(((AbstractObject) path.getSegment(i)).getObjectId());
}
// $NON-NLS-1$
memento.putString("ObjectBrowser.selectedObject", sb.toString());
} else {
// $NON-NLS-1$ //$NON-NLS-2$
memento.putString("ObjectBrowser.selectedObject", "");
}
}
use of org.eclipse.jface.viewers.TreePath in project bndtools by bndtools.
the class RepositoriesViewRefresher method refreshRepositories.
public void refreshRepositories(final RepositoryPlugin target) {
synchronized (this) {
if (busy) {
redo = true;
return;
}
busy = true;
redo = false;
}
//
// Since this can delay, we move this to the background
//
new WorkspaceJob("Updating repositories content") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
if (monitor == null)
monitor = new NullProgressMonitor();
Set<RepositoryPlugin> repos = new HashSet<>();
if (target != null)
repos.add(target);
else {
for (RefreshModel m : viewers.values()) {
repos.addAll(m.getRepositories());
}
}
ensureLoaded(monitor, repos);
// get repositories first, then do UI thread work
final Map<Entry<TreeViewer, RefreshModel>, List<RepositoryPlugin>> entryRepos = new HashMap<>();
for (Map.Entry<TreeViewer, RefreshModel> entry : viewers.entrySet()) {
entryRepos.put(entry, entry.getValue().getRepositories());
}
//
// And now back to the UI thread
//
getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
synchronized (RepositoriesViewRefresher.this) {
redo = false;
}
for (Map.Entry<TreeViewer, RefreshModel> entry : viewers.entrySet()) {
TreePath[] expandedTreePaths = entry.getKey().getExpandedTreePaths();
entry.getKey().setInput(entryRepos.get(entry));
if (expandedTreePaths != null && expandedTreePaths.length > 0)
entry.getKey().setExpandedTreePaths(expandedTreePaths);
}
synchronized (RepositoriesViewRefresher.this) {
busy = false;
if (redo) {
refreshRepositories(null);
}
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
return Status.OK_STATUS;
}
}.schedule(1000);
}
use of org.eclipse.jface.viewers.TreePath in project tdi-studio-se by Talend.
the class MoveUpTreeNodeButton method updateStatus.
/*
* (non-Javadoc)
*
* @see org.talend.designer.fileoutputJSON.ui.footer.AbstractTreeNodeButton#updateButtonStatus()
*/
@Override
protected void updateStatus(TreeSelection selection) {
if (selection.isEmpty()) {
getButton().setEnabled(false);
return;
}
final TreePath[] paths = selection.getPaths();
boolean sameSegment = true;
for (int i = 0; i < paths.length - 1; i++) {
if (paths[i].getSegmentCount() != paths[i + 1].getSegmentCount()) {
sameSegment = false;
}
}
if (sameSegment) {
getButton().setEnabled(true);
} else {
getButton().setEnabled(false);
return;
}
// if same segment ,they have the same parent and parent must be an element
FOXTreeNode foxNode = (FOXTreeNode) selection.getFirstElement();
if (foxNode.getParent() instanceof Element) {
final Element parent = (Element) foxNode.getParent();
if (parent == null) {
getButton().setEnabled(false);
return;
}
final List<? extends FOXTreeNode> attrChildren = parent.getAttributeChildren();
final List<? extends FOXTreeNode> nameSpaceChildren = parent.getNameSpaceChildren();
final List<FOXTreeNode> elementChildren = parent.getElementChildren();
final Iterator iterator = selection.iterator();
while (iterator.hasNext()) {
final Object next = iterator.next();
if (next instanceof Attribute) {
if (attrChildren.contains(next) && attrChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof NameSpaceNode) {
if (nameSpaceChildren.contains(next) && nameSpaceChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
} else if (next instanceof Element) {
if (elementChildren.contains(next) && elementChildren.indexOf(next) == 0) {
getButton().setEnabled(false);
return;
}
}
}
}
}
Aggregations