List of usage examples for org.eclipse.jface.viewers TreePath TreePath
public TreePath(Object[] segments)
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 w w w. j av a 2s . c o m } }
From source file:com.amazonaws.eclipse.codedeploy.explorer.editor.table.DeploymentsTableView.java
License:Apache License
private void loadAllTopLevelElements() { Object[] topLevelElements = contentCache.getChildren(new TreePath(new Object[0])); int progressPerElement = 100 / (topLevelElements.length + 1); int loadedElements = 1; updateRefreshProgress(loadedElements++ * progressPerElement, true); for (Object topLevelElement : topLevelElements) { contentCache.getChildren(new TreePath(new Object[] { topLevelElement })); updateRefreshProgress(loadedElements++ * progressPerElement, true); }//from w ww. ja v a 2 s . co m Display.getDefault().syncExec(new Runnable() { public void run() { tableTitleLabel.setText("Deployments"); tableTitleLabel.pack(); } }); }
From source file:com.android.ddmuilib.DevicePanel.java
License:Apache License
/** * Kills the selected {@link Client} by sending its VM a halt command. */// w w w. j a v a 2 s .c om 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/>/*from w ww. ja v a2 s . c o 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/>//from ww w .j a va 2 s .com * 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 w ww . j a v a2s . co 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/*from w w w. j a v a 2 s. com*/ * @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. *//*from w w w . j a v a2 s . c om*/ 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.SelectionManager.java
License:Open Source License
/** * Create a {@link TreePath} from the given view info * * @param viewInfo the view info to look up a tree path for * @return a {@link TreePath} for the given view info *//*from www . j a va 2s .co m*/ public static TreePath getTreePath(CanvasViewInfo viewInfo) { ArrayList<Object> segments = new ArrayList<Object>(); while (viewInfo != null) { segments.add(0, viewInfo); viewInfo = viewInfo.getParent(); } return new TreePath(segments.toArray()); }
From source file:com.android.ide.eclipse.adt.internal.ui.ReferenceChooserDialog.java
License:Open Source License
/** * Sets up the initial selection based on a {@link ResourceType} and a resource name. * @param resourceType the resource type. * @param resourceName the resource name. *//*from w w w .ja v a 2 s . c o m*/ private void setupInitialSelection(ResourceType resourceType, String resourceName) { // get all the resources of this type Collection<ResourceItem> resourceItems = mProjectResources.getResourceItemsOfType(resourceType); for (ResourceItem resourceItem : resourceItems) { if (resourceName.equals(resourceItem.getName())) { // name of the resource match, we select it, TreePath treePath = new TreePath(new Object[] { resourceType, resourceItem }); mFilteredTree.getViewer().setSelection(new TreeSelection(treePath), true /*reveal*/); // and we're done. return; } } // if we get here, the resource type is valid, but the resource is missing. // we select and expand the resource type element. TreePath treePath = new TreePath(new Object[] { resourceType }); mFilteredTree.getViewer().setSelection(new TreeSelection(treePath), true /*reveal*/); mFilteredTree.getViewer().setExpandedState(resourceType, true /* expanded */); }