List of usage examples for org.eclipse.jface.viewers TreeSelection TreeSelection
private TreeSelection(InitializeData data)
From source file:bndtools.jareditor.internal.JARContentTreePart.java
License:Open Source License
private void refreshSelectedPath() { if (selectedPath != null) { TreePath treePath = contentProvider.findPath(selectedPath); if (treePath != null) { viewer.setSelection(new TreeSelection(treePath), true); } else {/*from ww w.jav a 2 s. co m*/ viewer.setSelection(TreeSelection.EMPTY); } } }
From source file:com.amalto.workbench.editors.DataModelMainPage.java
License:Open Source License
private void activeMarkerItem(TreeViewer v, Element dom) { ITreeContentProvider provider = (ITreeContentProvider) v.getContentProvider(); for (Object data : provider.getElements(xsdSchema)) { Object[] foundData = findMarkerData(provider, data, dom, new Object[0]); if (foundData != null) { TreePath treePath = new TreePath(foundData); v.setSelection(new TreeSelection(treePath)); return; }/*from ww w. jav a2 s. c o m*/ } }
From source file:com.android.ddmuilib.DevicePanel.java
License:Apache License
/** * Kills the selected {@link Client} by sending its VM a halt command. *//*from www .ja v a 2s. c o m*/ public void killSelectedClient() { if (mCurrentClient != null) { Client client = mCurrentClient; // reset the selection to the device. TreePath treePath = new TreePath(new Object[] { mCurrentDevice }); TreeSelection treeSelection = new TreeSelection(treePath); mTreeViewer.setSelection(treeSelection); client.kill(); } }
From source file:com.android.ddmuilib.DevicePanel.java
License:Apache License
/** * Sent when a device data changed, or when clients are started/terminated on the device. * <p/>/*ww w. ja v a 2s.co m*/ * This is sent from a non UI thread. * @param device the device that was updated. * @param changeMask the mask indicating what changed. * * @see IDeviceChangeListener#deviceChanged(IDevice,int) */ @Override public void deviceChanged(final IDevice device, int changeMask) { boolean expand = false; synchronized (mDevicesToExpand) { int index = mDevicesToExpand.indexOf(device); if (device.hasClients() && index != -1) { mDevicesToExpand.remove(index); expand = true; } } final boolean finalExpand = expand; exec(new Runnable() { @Override public void run() { if (mTree.isDisposed() == false) { // look if the current device is selected. This is done in case the current // client of this particular device was killed. In this case, we'll need to // manually reselect the device. IDevice selectedDevice = getSelectedDevice(); // refresh the device mTreeViewer.refresh(device); // if the selected device was the changed device and the new selection is // empty, we reselect the device. if (selectedDevice == device && mTreeViewer.getSelection().isEmpty()) { mTreeViewer.setSelection(new TreeSelection(new TreePath(new Object[] { device }))); } // notify the listener of a possible selection change. notifyListeners(); if (finalExpand) { mTreeViewer.setExpandedState(device, true); } } else { // tree is disposed, we need to do something. // lets remove ourselves from the listener. AndroidDebugBridge.removeDebugBridgeChangeListener(DevicePanel.this); AndroidDebugBridge.removeDeviceChangeListener(DevicePanel.this); AndroidDebugBridge.removeClientChangeListener(DevicePanel.this); } } }); }
From source file:com.android.ddmuilib.DevicePanel.java
License:Apache License
/** * Sent when an existing client information changed. * <p/>/*w ww .jav a2 s.c o m*/ * This is sent from a non UI thread. * @param client the updated client. * @param changeMask the bit mask describing the changed properties. It can contain * any of the following values: {@link Client#CHANGE_INFO}, * {@link Client#CHANGE_DEBUGGER_STATUS}, {@link Client#CHANGE_THREAD_MODE}, * {@link Client#CHANGE_THREAD_DATA}, {@link Client#CHANGE_HEAP_MODE}, * {@link Client#CHANGE_HEAP_DATA}, {@link Client#CHANGE_NATIVE_HEAP_DATA} * * @see IClientChangeListener#clientChanged(Client, int) */ @Override public void clientChanged(final Client client, final int changeMask) { exec(new Runnable() { @Override public void run() { if (mTree.isDisposed() == false) { // refresh the client mTreeViewer.refresh(client); if ((changeMask & Client.CHANGE_DEBUGGER_STATUS) == Client.CHANGE_DEBUGGER_STATUS && client.getClientData().getDebuggerConnectionStatus() == DebuggerStatus.WAITING) { // make sure the device is expanded. Normally the setSelection below // will auto expand, but the children of device may not already exist // at this time. Forcing an expand will make the TreeViewer create them. IDevice device = client.getDevice(); if (mTreeViewer.getExpandedState(device) == false) { mTreeViewer.setExpandedState(device, true); } // create and set the selection TreePath treePath = new TreePath(new Object[] { device, client }); TreeSelection treeSelection = new TreeSelection(treePath); mTreeViewer.setSelection(treeSelection); if (mAdvancedPortSupport) { client.setAsSelectedClient(); } // notify the listener of a possible selection change. notifyListeners(device, client); } } else { // tree is disposed, we need to do something. // lets remove ourselves from the listener. AndroidDebugBridge.removeDebugBridgeChangeListener(DevicePanel.this); AndroidDebugBridge.removeDeviceChangeListener(DevicePanel.this); AndroidDebugBridge.removeClientChangeListener(DevicePanel.this); } } }); }
From source file:com.android.ide.eclipse.adt.internal.assetstudio.CreateAssetSetWizard.java
License:Open Source License
private void selectFiles(IProject project, List<? extends IResource> createdFiles) { // Attempt to select the newly created files in the Package Explorer IWorkbench workbench = AdtPlugin.getDefault().getWorkbench(); IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage(); IViewPart viewPart = page.findView(JavaUI.ID_PACKAGES); if (viewPart != null) { IWorkbenchPartSite site = viewPart.getSite(); IJavaProject javaProject = null; try {/*from ww w. ja v a2s . c o m*/ javaProject = BaseProjectHelper.getJavaProject(project); } catch (CoreException e) { AdtPlugin.log(e, null); } final ISelectionProvider provider = site.getSelectionProvider(); if (provider != null) { List<TreePath> pathList = new ArrayList<TreePath>(); for (IResource file : createdFiles) { // Create a TreePath for the given file, // which should be the JavaProject, followed by the folders down to // the final file. List<Object> segments = new ArrayList<Object>(); segments.add(file); IContainer folder = file.getParent(); if (folder != null && !(folder instanceof IProject)) { segments.add(folder); // res folder folder = folder.getParent(); if (folder != null && !(folder instanceof IProject)) { segments.add(folder); } } // project segments.add(javaProject); Collections.reverse(segments); TreePath path = new TreePath(segments.toArray()); pathList.add(path); // IDEA: Maybe normalize the files backwards (IFile objects aren't unique) // by maybe using the package explorer icons instead } TreePath[] paths = pathList.toArray(new TreePath[pathList.size()]); final TreeSelection selection = new TreeSelection(paths); provider.setSelection(selection); // Workaround: The above doesn't always work; it will frequently select // some siblings of the real files. I've tried a number of workarounds: // normalizing the IFile objects by looking up the canonical ones via // their relative paths from the project; deferring execution with // Display.asyncRun; first calling select on the parents, etc. // However, it turns out a simple workaround works best: Calling this // method TWICE. The first call seems to expand all the necessary parents, // and the second call ensures that the correct children are selected! provider.setSelection(selection); viewPart.setFocus(); } } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.configuration.ConfigManagerDialog.java
License:Open Source License
/** * Selects a device and optionally a config. Because this is meant to show newly created/edited * device/config, it'll only do so for {@link DeviceType#CUSTOM} devices. * @param device the device to select/* ww w .j a v a 2 s. co m*/ * @param configName the config to select (optional) */ private void select(LayoutDevice device, String configName) { Object[] path; if (device == null) { // select the "custom" node path = new Object[] { DeviceType.CUSTOM }; } else if (configName == null) { // this is the easy case. no config to select path = new Object[] { DeviceType.CUSTOM, device }; } else { // this is more complex. we have the configName, but the tree contains DeviceConfig // Look for the entry. DeviceConfig match = null; for (DeviceConfig config : device.getConfigs()) { if (config.getName().equals(configName)) { match = config; break; } } if (match != null) { path = new Object[] { DeviceType.CUSTOM, device, match }; } else { path = new Object[] { DeviceType.CUSTOM, device }; } } mTreeViewer.setSelection(new TreeSelection(new TreePath(path)), true /*reveal*/); }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle1.UiContentOutlinePage.java
License:Apache License
/** * Selects the corresponding edit part in the tree viewer. */// ww w. j ava2 s . com private void setViewerSelection(UiElementTreeEditPart selectedPart) { if (selectedPart != null && !(selectedPart instanceof UiDocumentTreeEditPart)) { LinkedList<UiElementTreeEditPart> segments = new LinkedList<UiElementTreeEditPart>(); for (UiElementTreeEditPart part = selectedPart; !(part instanceof UiDocumentTreeEditPart); part = (UiElementTreeEditPart) part .getParent()) { segments.add(0, part); } setSelection(new TreeSelection(new TreePath(segments.toArray()))); } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.MoveGesture.java
License:Open Source License
/** * Called on both dragEnter and dragMove. * Generates the onDropEnter/Move/Leave events depending on the currently * selected target node./*from w w w . jav a 2 s. c om*/ */ private void processDropEvent(DropTargetEvent event) { if (!mCanvas.getViewHierarchy().isValid()) { // We don't allow drop on an invalid layout, even if we have some obsolete // layout info for it. event.detail = DND.DROP_NONE; clearDropInfo(); return; } LayoutPoint p = getDropLocation(event).toLayout(); // Is the mouse currently captured by a DropFeedback.captureArea? boolean isCaptured = false; if (mFeedback != null) { Rect r = mFeedback.captureArea; isCaptured = r != null && r.contains(p.x, p.y); } // We can't switch views/nodes when the mouse is captured CanvasViewInfo vi; if (isCaptured) { vi = mCurrentView; } else { vi = mCanvas.getViewHierarchy().findViewInfoAt(p); // When dragging into the canvas, if you are not over any other view, target // the root element (since it may not "fill" the screen, e.g. if you have a linear // layout but have layout_height wrap_content, then the layout will only extend // to cover the children in the layout, not the whole visible screen area, which // may be surprising if (vi == null) { vi = mCanvas.getViewHierarchy().getRoot(); } } boolean isMove = true; boolean needRedraw = false; if (vi != mCurrentView) { // Current view has changed. Does that also change the target node? // Note that either mCurrentView or vi can be null. if (vi == null) { // vi is null but mCurrentView is not, no view is a target anymore // We don't need onDropMove in this case isMove = false; needRedraw = true; event.detail = DND.DROP_NONE; clearDropInfo(); // this will call callDropLeave. } else { // vi is a new current view. // Query GRE for onDropEnter on the ViewInfo hierarchy, starting from the child // towards its parent, till we find one that returns a non-null drop feedback. DropFeedback df = null; NodeProxy targetNode = null; for (CanvasViewInfo targetVi = vi; targetVi != null && df == null; targetVi = targetVi.getParent()) { targetNode = mCanvas.getNodeFactory().create(targetVi); df = mCanvas.getRulesEngine().callOnDropEnter(targetNode, targetVi.getViewObject(), mCurrentDragElements); if (df != null) { // We should also dispatch an onDropMove() call to the initial enter // position, such that the view is notified of the position where // we are within the node immediately (before we for example attempt // to draw feedback). This is necessary since most views perform the // guideline computations in onDropMove (since only onDropMove is handed // the -position- of the mouse), and we want this computation to happen // before we ask the view to draw its feedback. updateDropFeedback(df, event); df = mCanvas.getRulesEngine().callOnDropMove(targetNode, mCurrentDragElements, df, new Point(p.x, p.y)); } if (df != null && event.detail == DND.DROP_MOVE && mCanvas == mGlobalDragInfo.getSourceCanvas()) { // You can't move an object into itself in the same canvas. // E.g. case of moving a layout and the node under the mouse is the // layout itself: a copy would be ok but not a move operation of the // layout into himself. SelectionItem[] selection = mGlobalDragInfo.getCurrentSelection(); if (selection != null) { for (SelectionItem cs : selection) { if (cs.getViewInfo() == targetVi) { // The node that responded is one of the selection roots. // Simply invalidate the drop feedback and move on the // parent in the ViewInfo chain. updateDropFeedback(df, event); mCanvas.getRulesEngine().callOnDropLeave(targetNode, mCurrentDragElements, df); df = null; targetNode = null; } } } } } if (df == null) { // Provide visual feedback that we are refusing the drop event.detail = DND.DROP_NONE; clearDropInfo(); } else if (targetNode != mTargetNode) { // We found a new target node for the drag'n'drop. // Release the previous one, if any. callDropLeave(); // And assign the new one mTargetNode = targetNode; mFeedback = df; // We don't need onDropMove in this case isMove = false; } } mCurrentView = vi; } if (isMove && mTargetNode != null && mFeedback != null) { // this is a move inside the same view com.android.ide.common.api.Point p2 = new com.android.ide.common.api.Point(p.x, p.y); updateDropFeedback(mFeedback, event); DropFeedback df = mCanvas.getRulesEngine().callOnDropMove(mTargetNode, mCurrentDragElements, mFeedback, p2); mCanvas.getGestureManager().updateMessage(mFeedback); if (df == null) { // The target is no longer interested in the drop move. event.detail = DND.DROP_NONE; callDropLeave(); } else if (df != mFeedback) { mFeedback = df; } } if (mFeedback != null) { if (event.detail == DND.DROP_NONE && !mFeedback.invalidTarget) { // If we previously provided visual feedback that we were refusing // the drop, we now need to change it to mean we're accepting it. event.detail = DND.DROP_DEFAULT; recomputeDragType(event); } else if (mFeedback.invalidTarget) { // Provide visual feedback that we are refusing the drop event.detail = DND.DROP_NONE; } } if (needRedraw || (mFeedback != null && mFeedback.requestPaint)) { mCanvas.redraw(); } // Update outline to show the target node there OutlinePage outline = mCanvas.getOutlinePage(); TreeSelection newSelection = TreeSelection.EMPTY; if (mCurrentView != null && mTargetNode != null) { // Find the view corresponding to the target node. The current view can be a leaf // view whereas the target node is always a parent layout. if (mCurrentView.getUiViewNode() != mTargetNode.getNode()) { mCurrentView = mCurrentView.getParent(); } if (mCurrentView != null && mCurrentView.getUiViewNode() == mTargetNode.getNode()) { TreePath treePath = SelectionManager.getTreePath(mCurrentView); newSelection = new TreeSelection(treePath); } } ISelection currentSelection = outline.getSelection(); if (currentSelection == null || !currentSelection.equals(newSelection)) { outline.setSelection(newSelection); } }
From source file:com.android.ide.eclipse.adt.internal.editors.layout.gle2.SelectionManager.java
License:Open Source License
/** * Returns a {@link TreeSelection} where each {@link TreePath} item is * actually a {@link CanvasViewInfo}./*from ww w . j av a 2 s .c o m*/ */ @Override public ISelection getSelection() { if (mSelections.isEmpty()) { return TreeSelection.EMPTY; } ArrayList<TreePath> paths = new ArrayList<TreePath>(); for (SelectionItem cs : mSelections) { CanvasViewInfo vi = cs.getViewInfo(); if (vi != null) { paths.add(getTreePath(vi)); } } return new TreeSelection(paths.toArray(new TreePath[paths.size()])); }