@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { // System.out.println("select change\n"); // if(!getSite().getPage().isPartVisible(this)) //if i am not visible ,i will not change // return; if (!banner.isVisible()) return; if (selection != null) { treeObj = (TreeModel.TreeObject) ((IStructuredSelection) selection).getFirstElement(); if (treeObj != null && !(treeObj instanceof TreeModel.TreeParent)) if (treeObj.getModel() != null) { // update content Control[] children = left.getChildren(); for (Control child : children) child.dispose(); BasicModel bm = treeObj.getModel(); // update screen shot thread's device if (bm instanceof MobileModel) { System.out.println("change model start"); if (mMobileModel != null) mMobileModel.stopShot(this); mMobileModel = (MobileModel) bm; showInfo(left, mMobileModel); left.layout(true, true); mMobileModel.startShot(this); System.out.println("change model stop"); } } } }
// information layout public void showInfo(final Composite parent, final MobileModel mm) { Font boldFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT); final IDevice device = mm.getDevice(); Composite view = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 2; view.setLayout(layout); Label l = new Label(view, SWT.WRAP); l.setText("Name: "); l.setFont(boldFont); l = new Label(view, SWT.WRAP); l.setText(mm.getName()); l = new Label(view, SWT.WRAP); l.setText("SerialNumber: "); l.setFont(boldFont); l = new Label(view, SWT.WRAP); l.setText(mm.getSerialNumber()); l = new Label(view, SWT.WRAP); l.setText("Model: "); l.setFont(boldFont); l = new Label(view, SWT.WRAP); l.setText(mm.getModel()); l = new Label(view, SWT.WRAP); l.setText("Manufacturer: "); l.setFont(boldFont); l = new Label(view, SWT.WRAP); l.setText(mm.getManufacturer()); try { l = new Label(view, SWT.WRAP); l.setText("ApiLevel: "); l.setFont(boldFont); l = new Label(view, SWT.WRAP); l.setText(device.getPropertyCacheOrSync(IDevice.PROP_BUILD_API_LEVEL)); l = new Label(view, SWT.WRAP); l.setText("AndroidBuidVersion: "); l.setFont(boldFont); l = new Label(view, SWT.WRAP); l.setText(device.getPropertyCacheOrSync(IDevice.PROP_BUILD_VERSION)); l = new Label(view, SWT.WRAP); l.setText("CpuAbi: "); l.setFont(boldFont); l = new Label(view, SWT.WRAP); l.setText(device.getPropertyCacheOrSync(IDevice.PROP_DEVICE_CPU_ABI)); l = new Label(view, SWT.WRAP); l.setText("isOnline: "); l.setFont(boldFont); l = new Label(view, SWT.WRAP); l.setText(device.isOnline() ? "yes" : "no"); } catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException e1) { // TODO Auto-generated catch block // e1.printStackTrace(); System.out.println("adb get info wrong!"); } Button getClientsButton = new Button(parent, SWT.PUSH); // Text infoText = new Text(parent, SWT.WRAP | SWT.MULTI); // get all clients button getClientsButton.setText("Clients"); getClientsButton.addMouseListener( new MouseListener() { @Override public void mouseDoubleClick(MouseEvent e) {} @Override public void mouseDown(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseUp(MouseEvent e) { Client[] clients = device.getClients(); // Display cDisplay=new Display(); Shell cShell = new Shell(); cShell.setBounds(300, 100, 500, 500); cShell.setText("Clients"); // cShell.setLayout(layout); TreeModel cTreeModel = new TreeModel(); for (Client client : clients) { // System.out.println(client.getClientData().getClientDescription()); ClientModel clientModel = new ClientModel(client); cTreeModel.addModel(clientModel); } TreeViewer viewer = new TreeViewer(cShell, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER); viewer.setContentProvider(cTreeModel.getVcProvider()); viewer.setLabelProvider(cTreeModel.getVlProvider()); viewer.setInput(cTreeModel.getRoot()); cShell.open(); cShell.setLayout(new FillLayout()); cShell.layout(); } }); // reboot button Button rebootButton = new Button(parent, SWT.PUSH); rebootButton.setText("Reboot"); rebootButton.addMouseListener( new MouseListener() { @Override public void mouseUp(MouseEvent e) { // TODO Auto-generated method stub try { device.reboot(mm.getSerialNumber()); } catch (TimeoutException | AdbCommandRejectedException | IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } @Override public void mouseDown(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseDoubleClick(MouseEvent e) {} }); // install apk dialog Button installApkButton = new Button(parent, SWT.PUSH); installApkButton.setText("Install Apk"); installApkButton.addMouseListener( new MouseListener() { @Override public void mouseUp(MouseEvent e) { FileDialog fileDialog = new FileDialog(parent.getShell(), SWT.TITLE | SWT.MULTI); fileDialog.setText("Upload Apk"); fileDialog.open(); String[] fileNames = fileDialog.getFileNames(); for (String fileName : fileNames) { System.out.println(fileNames[0]); try { String ir = device.installPackage(fileName, true); if (ir == null) System.out.println("install successfully!"); } catch (InstallException e1) { // TODO Auto-generated catch block e1.printStackTrace(); System.out.println("install unsuccessfully.."); } } } @Override public void mouseDown(MouseEvent e) { // TODO Auto-generated method stub } @Override public void mouseDoubleClick(MouseEvent e) {} }); }