1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ide.eclipse.ddms.views; 18 19 import com.android.ddmlib.Client; 20 import com.android.ddmlib.IDevice; 21 import com.android.ddmuilib.ImageLoader; 22 import com.android.ddmuilib.explorer.DeviceExplorer; 23 import com.android.ide.eclipse.ddms.CommonAction; 24 import com.android.ide.eclipse.ddms.DdmsPlugin; 25 import com.android.ide.eclipse.ddms.DdmsPlugin.ISelectionListener; 26 import com.android.ide.eclipse.ddms.i18n.Messages; 27 28 import org.eclipse.jface.action.IMenuManager; 29 import org.eclipse.jface.action.IToolBarManager; 30 import org.eclipse.jface.action.Separator; 31 import org.eclipse.swt.graphics.Device; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.ui.IActionBars; 34 import org.eclipse.ui.ISharedImages; 35 import org.eclipse.ui.PlatformUI; 36 import org.eclipse.ui.part.ViewPart; 37 38 public class FileExplorerView extends ViewPart implements ISelectionListener { 39 40 public static final String ID = "com.android.ide.eclipse.ddms.views.FileExplorerView"; //$NON-NLS-1$ 41 42 private final static String COLUMN_NAME = 43 DdmsPlugin.PLUGIN_ID + ".explorer.name"; //$NON-NLS-1S 44 private final static String COLUMN_SIZE = 45 DdmsPlugin.PLUGIN_ID + ".explorer.size"; //$NON-NLS-1S 46 private final static String COLUMN_DATE = 47 DdmsPlugin.PLUGIN_ID + ".explorer.data"; //$NON-NLS-1S 48 private final static String COLUMN_TIME = 49 DdmsPlugin.PLUGIN_ID + ".explorer.time"; //$NON-NLS-1S 50 private final static String COLUMN_PERMISSIONS = 51 DdmsPlugin.PLUGIN_ID + ".explorer.permissions"; //$NON-NLS-1S 52 private final static String COLUMN_INFO = 53 DdmsPlugin.PLUGIN_ID + ".explorer.info"; //$NON-NLS-1$ 54 55 private DeviceExplorer mExplorer; 56 57 public FileExplorerView() { 58 } 59 60 @Override 61 public void createPartControl(Composite parent) { 62 ImageLoader loader = ImageLoader.getDdmUiLibLoader(); 63 64 DeviceExplorer.COLUMN_NAME = COLUMN_NAME; 65 DeviceExplorer.COLUMN_SIZE = COLUMN_SIZE; 66 DeviceExplorer.COLUMN_DATE = COLUMN_DATE; 67 DeviceExplorer.COLUMN_TIME = COLUMN_TIME; 68 DeviceExplorer.COLUMN_PERMISSIONS = COLUMN_PERMISSIONS; 69 DeviceExplorer.COLUMN_INFO = COLUMN_INFO; 70 71 // device explorer 72 mExplorer = new DeviceExplorer(); 73 74 mExplorer.setCustomImages( 75 PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE), 76 PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER), 77 null /* apk image */, 78 PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT) 79 ); 80 81 // creates the actions 82 CommonAction pushAction = new CommonAction(Messages.FileExplorerView_Push_File) { 83 @Override 84 public void run() { 85 mExplorer.pushIntoSelection(); 86 } 87 }; 88 pushAction.setToolTipText(Messages.FileExplorerView_Push_File_Onto_Device); 89 pushAction.setImageDescriptor(loader.loadDescriptor("push.png")); //$NON-NLS-1$ 90 pushAction.setEnabled(false); 91 92 CommonAction pullAction = new CommonAction(Messages.FileExplorerView_Pull_File) { 93 @Override 94 public void run() { 95 mExplorer.pullSelection(); 96 } 97 }; 98 pullAction.setToolTipText(Messages.FileExplorerView_Pull_File_From_File); 99 pullAction.setImageDescriptor(loader.loadDescriptor("pull.png")); //$NON-NLS-1$ 100 pullAction.setEnabled(false); 101 102 CommonAction deleteAction = new CommonAction(Messages.FileExplorerView_Delete) { 103 @Override 104 public void run() { 105 mExplorer.deleteSelection(); 106 } 107 }; 108 deleteAction.setToolTipText(Messages.FileExplorerView_Delete_The_Selection); 109 deleteAction.setImageDescriptor(loader.loadDescriptor("delete.png")); //$NON-NLS-1$ 110 deleteAction.setEnabled(false); 111 112 CommonAction createNewFolderAction = new CommonAction("New Folder") { 113 @Override 114 public void run() { 115 mExplorer.createNewFolderInSelection(); 116 } 117 }; 118 createNewFolderAction.setToolTipText("New Folder"); 119 createNewFolderAction.setImageDescriptor(loader.loadDescriptor("add.png")); //$NON-NLS-1$ 120 createNewFolderAction.setEnabled(false); 121 122 // set up the actions in the explorer 123 mExplorer.setActions(pushAction, pullAction, deleteAction, createNewFolderAction); 124 125 // and in the ui 126 IActionBars actionBars = getViewSite().getActionBars(); 127 IMenuManager menuManager = actionBars.getMenuManager(); 128 IToolBarManager toolBarManager = actionBars.getToolBarManager(); 129 130 menuManager.add(pullAction); 131 menuManager.add(pushAction); 132 menuManager.add(new Separator()); 133 menuManager.add(deleteAction); 134 menuManager.add(new Separator()); 135 menuManager.add(createNewFolderAction); 136 137 toolBarManager.add(pullAction); 138 toolBarManager.add(pushAction); 139 toolBarManager.add(new Separator()); 140 toolBarManager.add(deleteAction); 141 toolBarManager.add(new Separator()); 142 toolBarManager.add(createNewFolderAction); 143 144 mExplorer.createPanel(parent); 145 146 DdmsPlugin.getDefault().addSelectionListener(this); 147 } 148 149 @Override 150 public void setFocus() { 151 mExplorer.setFocus(); 152 } 153 154 /** 155 * Sent when a new {@link Client} is selected. 156 * 157 * @param selectedClient The selected client. 158 */ 159 public void selectionChanged(Client selectedClient) { 160 // pass 161 } 162 163 /** 164 * Sent when a new {@link Device} is selected. 165 * 166 * @param selectedDevice the selected device. 167 */ 168 public void selectionChanged(IDevice selectedDevice) { 169 mExplorer.switchDevice(selectedDevice); 170 } 171 172 /** 173 * Sent when there is no current selection. 174 */ 175 public void selectionRemoved() { 176 177 } 178 179 } 180