use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.
the class GalleryTreeViewer method editElement.
public void editElement(Object element, int column) {
if (element instanceof TreePath) {
setSelection(new TreeSelection((TreePath) element));
GalleryItem[] items = gallery.getSelection();
if (items.length == 1) {
ViewerRow row = getViewerRowFromItem(items[0]);
if (row != null) {
ViewerCell cell = row.getCell(column);
if (cell != null) {
getControl().setRedraw(false);
triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent(cell));
getControl().setRedraw(true);
}
}
}
} else {
super.editElement(element, column);
}
}
use of org.eclipse.jface.viewers.TreePath in project netxms by netxms.
the class ObjectTree method enableDropSupport.
/**
* Enable drop support in object tree
*/
public // SubtreeType infrastructure
void enableDropSupport(// SubtreeType infrastructure
final ObjectBrowser obj) {
final Transfer[] transfers = new Transfer[] { LocalSelectionTransfer.getTransfer() };
objectTree.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, transfers, new ViewerDropAdapter(objectTree) {
int operation = 0;
@Override
public boolean performDrop(Object data) {
TreeSelection selection = (TreeSelection) data;
List<?> movableSelection = selection.toList();
for (int i = 0; i < movableSelection.size(); i++) {
AbstractObject movableObject = (AbstractObject) movableSelection.get(i);
TreePath path = selection.getPaths()[0];
AbstractObject parent = (AbstractObject) path.getSegment(path.getSegmentCount() - 2);
obj.performObjectMove((AbstractObject) getCurrentTarget(), parent, movableObject, operation == DND.DROP_MOVE ? true : false);
}
return true;
}
@Override
public boolean validateDrop(Object target, int operation, TransferData transferType) {
this.operation = operation;
if ((target == null) || !LocalSelectionTransfer.getTransfer().isSupportedType(transferType))
return false;
IStructuredSelection selection = (IStructuredSelection) LocalSelectionTransfer.getTransfer().getSelection();
if (selection.isEmpty())
return false;
for (final Object object : selection.toList()) {
SubtreeType subtree = null;
if ((object instanceof AbstractObject)) {
if (obj.isValidSelectionForMove(SubtreeType.INFRASTRUCTURE))
subtree = SubtreeType.INFRASTRUCTURE;
else if (obj.isValidSelectionForMove(SubtreeType.TEMPLATES))
subtree = SubtreeType.TEMPLATES;
else if (obj.isValidSelectionForMove(SubtreeType.BUSINESS_SERVICES))
subtree = SubtreeType.BUSINESS_SERVICES;
else if (obj.isValidSelectionForMove(SubtreeType.DASHBOARDS))
subtree = SubtreeType.DASHBOARDS;
else if (obj.isValidSelectionForMove(SubtreeType.MAPS))
subtree = SubtreeType.MAPS;
else if (obj.isValidSelectionForMove(SubtreeType.POLICIES))
subtree = SubtreeType.POLICIES;
}
if (subtree == null)
return false;
Set<Integer> filter;
switch(subtree) {
case INFRASTRUCTURE:
filter = ObjectSelectionDialog.createContainerSelectionFilter();
break;
case TEMPLATES:
filter = ObjectSelectionDialog.createTemplateGroupSelectionFilter();
break;
case BUSINESS_SERVICES:
filter = ObjectSelectionDialog.createBusinessServiceSelectionFilter();
break;
case DASHBOARDS:
if (object instanceof DashboardGroup)
filter = ObjectSelectionDialog.createDashboardGroupSelectionFilter();
else
filter = ObjectSelectionDialog.createDashboardSelectionFilter();
break;
case MAPS:
filter = ObjectSelectionDialog.createNetworkMapGroupsSelectionFilter();
break;
case POLICIES:
filter = ObjectSelectionDialog.createPolicyGroupSelectionFilter();
break;
default:
filter = null;
break;
}
if ((filter == null) || !filter.contains(((AbstractObject) target).getObjectClass()) || target.equals(object))
return false;
}
return true;
}
});
}
use of org.eclipse.jface.viewers.TreePath in project n4js by eclipse.
the class N4JSProjectInWorkingSetDropAdapterAssistant method handleDrop.
@Override
public IStatus handleDrop(CommonDropAdapter dropAdapter, DropTargetEvent dropTargetEvent, Object target) {
WorkingSet oldTarget = (WorkingSet) target;
WorkingSetManager manager = oldTarget.getWorkingSetManager();
List<WorkingSet> allItems = newArrayList(manager.getAllWorkingSets());
List<WorkingSet> visibleItems = newArrayList(manager.getWorkingSets());
WorkingSetDiffBuilder diffBuilder = new WorkingSetDiffBuilder(manager);
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection instanceof ITreeSelection) {
ManualAssociationWorkingSet oldSource = null;
for (TreePath path : ((ITreeSelection) selection).getPaths()) {
IProject project = ((IAdaptable) path.getLastSegment()).getAdapter(IProject.class);
if (project != null) {
if (!(target instanceof ManualAssociationWorkingSet)) {
return CANCEL_STATUS;
}
if (!ManualAssociationAwareWorkingSetManager.class.getName().equals(manager.getId())) {
return CANCEL_STATUS;
}
if (!workingSetContains(oldTarget, project) && !OTHERS_WORKING_SET_ID.equals(oldTarget.getId())) {
Collection<String> projectNames = newHashSet(((ManualAssociationWorkingSet) oldTarget).getAssociatedProjectNames());
projectNames.add(project.getName());
ManualAssociationWorkingSet newTarget = new ManualAssociationWorkingSet(projectNames, oldTarget.getId(), manager);
int allIndex = indexOfById(oldTarget, allItems);
allItems.remove(allIndex);
allItems.add(allIndex, newTarget);
int visibleIndex = indexOfById(oldTarget, visibleItems);
if (visibleIndex >= 0) {
visibleItems.remove(visibleIndex);
visibleItems.add(visibleIndex, newTarget);
}
diffBuilder.edit(oldTarget, newTarget);
oldTarget = newTarget;
}
// Check if our top-level element is a working set so that we can perform a move
if (path.getFirstSegment() instanceof ManualAssociationWorkingSet) {
if (oldSource == null) {
oldSource = ((ManualAssociationWorkingSet) path.getFirstSegment());
}
if (oldSource != null && !OTHERS_WORKING_SET_ID.equals(oldSource.getId())) {
Collection<String> projectNames = newHashSet(oldSource.getAssociatedProjectNames());
projectNames.remove(project.getName());
ManualAssociationWorkingSet newSource = new ManualAssociationWorkingSet(projectNames, oldSource.getId(), manager);
int allIndex = indexOfById(oldSource, allItems);
allItems.remove(allIndex);
allItems.add(allIndex, newSource);
int visibleIndex = indexOfById(oldSource, visibleItems);
if (visibleIndex >= 0) {
visibleItems.remove(visibleIndex);
visibleItems.add(visibleIndex, newSource);
}
diffBuilder.edit(oldSource, newSource);
oldSource = newSource;
}
}
} else if (path.getLastSegment() instanceof WorkingSet) {
WorkingSet movedWorkingSet = (WorkingSet) path.getLastSegment();
int sourceVisibleIndex = indexOfById(movedWorkingSet, visibleItems);
int sourceAllIndex = indexOfById(movedWorkingSet, allItems);
if (sourceVisibleIndex == -1 || sourceAllIndex == -1) {
return CANCEL_STATUS;
}
final Object currentTarget = getCommonDropAdapter().getCurrentTarget();
if (currentTarget instanceof WorkingSet) {
int targetVisibleIndex = indexOfById((WorkingSet) currentTarget, visibleItems);
int targetAllIndex = indexOfById((WorkingSet) currentTarget, allItems);
if (targetVisibleIndex == -1 || targetAllIndex == -1) {
return CANCEL_STATUS;
}
if (getCommonDropAdapter().getCurrentLocation() == ViewerDropAdapter.LOCATION_AFTER) {
targetVisibleIndex++;
targetAllIndex++;
}
WorkingSet visibleRemoved = visibleItems.remove(sourceVisibleIndex);
visibleItems.add(sourceVisibleIndex >= targetVisibleIndex ? targetVisibleIndex : targetVisibleIndex - 1, visibleRemoved);
WorkingSet allRemoved = allItems.remove(sourceAllIndex);
allItems.add(sourceAllIndex >= targetAllIndex ? targetAllIndex : targetAllIndex - 1, allRemoved);
} else {
return CANCEL_STATUS;
}
}
}
} else if (selection instanceof IStructuredSelection) {
for (Object item : ((IStructuredSelection) selection).toArray()) {
IProject project = ((IAdaptable) item).getAdapter(IProject.class);
if (project != null && !workingSetContains(oldTarget, project) && !OTHERS_WORKING_SET_ID.equals(oldTarget.getId())) {
Collection<String> projectNames = newHashSet(((ManualAssociationWorkingSet) oldTarget).getAssociatedProjectNames());
projectNames.add(project.getName());
ManualAssociationWorkingSet newTarget = new ManualAssociationWorkingSet(projectNames, oldTarget.getId(), manager);
allItems.remove(oldTarget);
allItems.add(newTarget);
if (visibleItems.remove(oldTarget)) {
visibleItems.add(newTarget);
}
diffBuilder.edit(oldTarget, newTarget);
oldTarget = newTarget;
}
}
}
WorkingSet[] newItems = Iterables.toArray(visibleItems, WorkingSet.class);
WorkingSet[] newAllItems = Iterables.toArray(allItems, WorkingSet.class);
Diff<WorkingSet> diff = diffBuilder.build(newItems, newAllItems);
if (!diff.isEmpty()) {
manager.updateState(diff);
manager.saveState(new NullProgressMonitor());
workingSetManagerBroker.refreshNavigator();
}
return OK_STATUS;
}
use of org.eclipse.jface.viewers.TreePath in project polymap4-core by Polymap4.
the class NavigatorContentServiceContentProvider method getParents.
public TreePath[] getParents(Object anElement) {
List paths = new ArrayList();
TreePathCompiler compiler = new TreePathCompiler(anElement);
Set compilers = findPaths(compiler);
for (Iterator iter = compilers.iterator(); iter.hasNext(); ) {
TreePathCompiler c = (TreePathCompiler) iter.next();
paths.add(c.createParentPath());
}
return (TreePath[]) paths.toArray(new TreePath[paths.size()]);
}
use of org.eclipse.jface.viewers.TreePath in project polymap4-core by Polymap4.
the class NavigatorSaveablesService method computeSaveables.
/**
* helper to compute the saveables for which elements are part of the tree.
* Must be called from a synchronized method.
*
* @return the saveables
*/
private Saveable[] computeSaveables() {
ITreeContentProvider contentProvider = (ITreeContentProvider) viewer.getContentProvider();
boolean isTreepathContentProvider = contentProvider instanceof ITreePathContentProvider;
Object viewerInput = viewer.getInput();
List result = new ArrayList();
Set roots = new HashSet(Arrays.asList(contentProvider.getElements(viewerInput)));
SaveablesProvider[] saveablesProviders = getSaveablesProviders();
for (int i = 0; i < saveablesProviders.length; i++) {
SaveablesProvider saveablesProvider = saveablesProviders[i];
Saveable[] saveables = saveablesProvider.getSaveables();
for (int j = 0; j < saveables.length; j++) {
Saveable saveable = saveables[j];
Object[] elements = saveablesProvider.getElements(saveable);
// the saveable is added to the result if at least one of the
// elements representing the saveable appears in the tree, i.e.
// if its parent chain leads to a root node.
boolean foundRoot = false;
for (int k = 0; !foundRoot && k < elements.length; k++) {
Object element = elements[k];
if (roots.contains(element)) {
result.add(saveable);
foundRoot = true;
} else if (isTreepathContentProvider) {
ITreePathContentProvider treePathContentProvider = (ITreePathContentProvider) contentProvider;
TreePath[] parentPaths = treePathContentProvider.getParents(element);
for (int l = 0; !foundRoot && l < parentPaths.length; l++) {
TreePath parentPath = parentPaths[l];
for (int m = 0; !foundRoot && m < parentPath.getSegmentCount(); m++) {
if (roots.contains(parentPath.getSegment(m))) {
result.add(saveable);
foundRoot = true;
}
}
}
} else {
while (!foundRoot && element != null) {
if (roots.contains(element)) {
// found a parent chain leading to a root. The
// saveable is part of the tree.
result.add(saveable);
foundRoot = true;
} else {
element = contentProvider.getParent(element);
}
}
}
}
}
}
return (Saveable[]) result.toArray(new Saveable[result.size()]);
}
Aggregations