From 0102602a95c24eefc710415edda11ae3c085151a Mon Sep 17 00:00:00 2001 From: YoonKi Park Date: Sat, 3 Sep 2011 17:48:37 +0900 Subject: [PATCH] [Title] support drag and drop between targets and project explorer --- .../META-INF/MANIFEST.MF | 3 +- com.samsung.slp.common.connection/plugin.xml | 12 +- .../sdblib/dnd/FileEntryDropAdapter.java | 146 +++++ .../connection/sdblib/dnd/FileEntryTransfer.java | 100 +++ .../connection/ui/ConnectionExplorerPanel.java | 63 +- .../slp/common/connection/ui/ConnectionsPanel.java | 712 --------------------- .../samsung/slp/common/connection/ui/Messages.java | 126 ++++ .../slp/common/connection/ui/messages.properties | 3 + 8 files changed, 445 insertions(+), 720 deletions(-) create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryDropAdapter.java create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryTransfer.java delete mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionsPanel.java create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/Messages.java create mode 100644 com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/messages.properties diff --git a/com.samsung.slp.common.connection/META-INF/MANIFEST.MF b/com.samsung.slp.common.connection/META-INF/MANIFEST.MF index e657bef..48f47c4 100644 --- a/com.samsung.slp.common.connection/META-INF/MANIFEST.MF +++ b/com.samsung.slp.common.connection/META-INF/MANIFEST.MF @@ -6,7 +6,8 @@ Bundle-Version: 1.0.0.qualifier Bundle-Activator: com.samsung.slp.common.connection.ConnectionActivator Bundle-Vendor: SAMSUNG Require-Bundle: org.eclipse.ui, - org.eclipse.core.runtime + org.eclipse.core.runtime, + org.eclipse.core.resources;bundle-version="3.6.1" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Import-Package: com.samsung.slp.common.conn.device, diff --git a/com.samsung.slp.common.connection/plugin.xml b/com.samsung.slp.common.connection/plugin.xml index c20ed31..018333b 100644 --- a/com.samsung.slp.common.connection/plugin.xml +++ b/com.samsung.slp.common.connection/plugin.xml @@ -34,6 +34,16 @@ + + + + + - \ No newline at end of file + diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryDropAdapter.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryDropAdapter.java new file mode 100644 index 0000000..7b1fa15 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryDropAdapter.java @@ -0,0 +1,146 @@ +package com.samsung.slp.common.connection.sdblib.dnd; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.osgi.util.NLS; +import org.eclipse.swt.SWT; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.part.IDropActionDelegate; + +import com.samsung.slp.common.connection.ddmlib.AdbCommandRejectedException; +import com.samsung.slp.common.connection.ddmlib.AndroidDebugBridge; +import com.samsung.slp.common.connection.ddmlib.IDevice; +import com.samsung.slp.common.connection.ddmlib.SyncService; +import com.samsung.slp.common.connection.ddmlib.SyncService.ISyncProgressMonitor; +import com.samsung.slp.common.connection.ddmlib.SyncService.SyncResult; +import com.samsung.slp.common.connection.ddmlib.TimeoutException; +import com.samsung.slp.common.connection.ddmuilib.console.DdmConsole; +import com.samsung.slp.common.connection.ui.Messages; + +public class FileEntryDropAdapter implements IDropActionDelegate { + + @Override + public boolean run(Object source, Object target) { + + if (target instanceof IContainer) { + + String[] entries = FileEntryTransfer.getInstance().fromByteArray( + (byte[]) source); + + if (entries.length < 1) + return false; + + IContainer parent = (IContainer) target; + + if (parent.getType() == IResource.FILE) + return false; + + // FIXME : how to know the current selected device?? + IDevice[] device = AndroidDebugBridge.getBridge().getDevices(); + SyncService sync = null; + try { + sync = device[0].getSyncService(); + } catch (TimeoutException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (AdbCommandRejectedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if (sync != null) { + ISyncProgressMonitor monitor = SyncService.getNullProgressMonitor(); + boolean isAlwayCopy = false; + + IWorkspaceRoot root = parent.getWorkspace().getRoot(); + + for (int i = 0; i < entries.length; i++) { + File f = new File(entries[i]); + IPath destPath = parent.getFullPath().append(f.getName()); + IResource newRes = root.findMember(destPath); + String localFilePath = parent.getLocation().append(f.getName()).toOSString(); + if (newRes != null) { + if (isAlwayCopy == false) { + int ret = checkOverwrite(f.getName()); + switch (ret) { + case IDialogConstants.CANCEL_ID : + return false; + case IDialogConstants.YES_TO_ALL_ID : + isAlwayCopy = true; + break; + case IDialogConstants.NO_ID : + continue; + } + } + } + + SyncResult result = sync.pullFile(entries[i],localFilePath , monitor); + + if (result.getCode() != SyncService.RESULT_OK) { + DdmConsole.printErrorToConsole(String.format( + "Failed to pull %1$s: %2$s", + localFilePath, result.getMessage())); + continue; + } else { + if (ResourcesPlugin.getWorkspace().isTreeLocked() == false) { + try { + parent.getProject().refreshLocal(IResource.DEPTH_INFINITE, null); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + } + } + + } + return false; + } + private int checkOverwrite(final String filename) { + final int[] result = new int[1]; // using array since you can't change a final int + + Runnable query = new Runnable() { + public void run() { + int resultId[] = { + IDialogConstants.YES_ID, + IDialogConstants.YES_TO_ALL_ID, + IDialogConstants.NO_ID, + IDialogConstants.CANCEL_ID }; + + String labels[] = new String[] { + IDialogConstants.YES_LABEL, + IDialogConstants.YES_TO_ALL_LABEL, + IDialogConstants.NO_LABEL, + IDialogConstants.CANCEL_LABEL }; + + String msg = NLS.bind(Messages.getString("FileEntryDropAdapter.overrite.message"), filename); + MessageDialog dialog = new MessageDialog( + PlatformUI.getWorkbench().getDisplay().getActiveShell(), + Messages.getString("FileEntryDropAdapter.overrite.title"), + null,msg , MessageDialog.QUESTION, labels, 0); + dialog.open(); + if (dialog.getReturnCode() == SWT.DEFAULT) { + // A window close returns SWT.DEFAULT - mapped to a cancel + result[0] = IDialogConstants.CANCEL_ID; + } else { + result[0] = resultId[dialog.getReturnCode()]; + } + } + }; + + PlatformUI.getWorkbench().getDisplay().syncExec(query); + return result[0]; + } +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryTransfer.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryTransfer.java new file mode 100644 index 0000000..f20564f --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/sdblib/dnd/FileEntryTransfer.java @@ -0,0 +1,100 @@ +/* + * {common-plugins} + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Yoonki Park + * Hoon Kang + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package com.samsung.slp.common.connection.sdblib.dnd; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + +import org.eclipse.swt.dnd.ByteArrayTransfer; + +import com.samsung.slp.common.connection.ddmlib.FileListingService.FileEntry; +//Reference: http://www.eclipse.org/articles/Article-SWT-DND/DND-in-SWT.html + +public class FileEntryTransfer extends ByteArrayTransfer { + + private static FileEntryTransfer instance = new FileEntryTransfer(); + private static final String TYPE_NAME = "sdb-transfer-format"; + private static final int TYPE_ID = registerType(TYPE_NAME); + + private FileEntryTransfer() {} + + public static FileEntryTransfer getInstance() { + return instance; + } + @Override + protected int[] getTypeIds() { + // TODO Auto-generated method stub + return new int[] { TYPE_ID }; + } + @Override + protected String[] getTypeNames() { + // TODO Auto-generated method stub + return new String[] { TYPE_NAME }; + } + + public byte[] toByteArray(FileEntry[] entries) { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(byteOut); + + byte[] bytes = null; + + try { + out.writeInt(entries.length); + + for (int i = 0; i < entries.length; i++) { + FileEntry data = entries[i]; + if (data instanceof FileEntry) { + try { + out.writeUTF(((FileEntry) data).getFullPath()); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + + out.close(); + bytes = byteOut.toByteArray(); + } catch (IOException e) { + // when in doubt send nothing + } + return bytes; + } + + public String[] fromByteArray(byte[] bytes) { + DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes)); + try { + int n = in.readInt(); + + String[] paths = new String[n]; + for (int i = 0; i < n; i++) { + String path = in.readUTF(); + paths[i] = path; + } + return paths; + } catch (IOException e) { + return null; + } + } + + +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerPanel.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerPanel.java index 676dfa7..8ebea08 100644 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerPanel.java +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionExplorerPanel.java @@ -22,22 +22,22 @@ import org.eclipse.jface.viewers.ViewerDropAdapter; import org.eclipse.swt.SWT; import org.eclipse.swt.SWTException; import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DragSourceEvent; +import org.eclipse.swt.dnd.DragSourceListener; import org.eclipse.swt.dnd.FileTransfer; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.dnd.TransferData; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.DirectoryDialog; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.part.PluginTransfer; +import org.eclipse.ui.part.PluginTransferData; import com.samsung.slp.common.connection.ddmlib.AndroidDebugBridge; import com.samsung.slp.common.connection.ddmlib.AndroidDebugBridge.IDebugBridgeChangeListener; @@ -54,9 +54,8 @@ import com.samsung.slp.common.connection.ddmuilib.ImageLoader; import com.samsung.slp.common.connection.ddmuilib.Panel; import com.samsung.slp.common.connection.ddmuilib.SyncProgressMonitor; import com.samsung.slp.common.connection.ddmuilib.TableHelper; -import com.samsung.slp.common.connection.ddmuilib.actions.ICommonAction; -import com.samsung.slp.common.connection.ddmuilib.actions.ToolItemAction; import com.samsung.slp.common.connection.ddmuilib.console.DdmConsole; +import com.samsung.slp.common.connection.sdblib.dnd.FileEntryTransfer; public class ConnectionExplorerPanel extends Panel implements IDeviceChangeListener, IDebugBridgeChangeListener{ @@ -271,7 +270,59 @@ public class ConnectionExplorerPanel extends Panel implements IDeviceChangeListe } } }); + // setup drag listener Transfer[] transfers = new Transfer[] { GadgetTransfer.getInstance(), PluginTransfer.getInstance()}; + mTreeViewer.addDragSupport(DND.DROP_MOVE | DND.DROP_COPY, + new Transfer[] {PluginTransfer.getInstance(),FileEntryTransfer.getInstance() }, + new DragSourceListener() { + + @Override + public void dragStart(DragSourceEvent e) { + + TreeItem[] items = mTree.getSelection(); + + for (int i = 0; i < items.length; i++) { + Object data = items[i].getData(); + if (data instanceof FileEntry) { + if ( ((FileEntry)data).isDirectory() == true || ((FileEntry)data).isRoot() == true) { + e.doit = false; + return; + } + } + } + e.doit = true; + } + @Override + public void dragFinished(DragSourceEvent arg0) { + + } + + @Override + public void dragSetData(DragSourceEvent e) { + // get the selection + TreeItem[] items = mTree.getSelection(); + FileEntry[] entries = new FileEntry[items.length]; + + for (int i = 0; i < items.length; i++) { + Object data = items[i].getData(); + if (data instanceof FileEntry) { + entries[i] = ((FileEntry) data); + } + } + if (FileEntryTransfer.getInstance().isSupportedType( + e.dataType)) { + e.data = entries; + } else if (PluginTransfer.getInstance() + .isSupportedType(e.dataType)) { + byte[] data = FileEntryTransfer.getInstance() + .toByteArray(entries); + e.data = new PluginTransferData( + "com.samsung.slp.common.connection.filedrop", + data); + } + + } + }); // setup drop listener mTreeViewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { FileTransfer.getInstance() }, diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionsPanel.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionsPanel.java deleted file mode 100644 index 39689bb..0000000 --- a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/ConnectionsPanel.java +++ /dev/null @@ -1,712 +0,0 @@ -//package com.samsung.slp.common.connection.ui; -///* -// * Copyright (C) 2007 The Android Open Source Project -// * -// * Licensed under the Apache License, Version 2.0 (the "License"); -// * you may not use this file except in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, software -// * distributed under the License is distributed on an "AS IS" BASIS, -// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// * See the License for the specific language governing permissions and -// * limitations under the License. -// */ -//import java.io.File; -//import org.eclipse.jface.preference.IPreferenceStore; -//import org.eclipse.jface.viewers.ILabelProviderListener; -//import org.eclipse.jface.viewers.ITableLabelProvider; -//import org.eclipse.jface.viewers.ITreeContentProvider; -//import org.eclipse.jface.viewers.TreePath; -//import org.eclipse.jface.viewers.TreeSelection; -//import org.eclipse.jface.viewers.TreeViewer; -//import org.eclipse.jface.viewers.Viewer; -//import org.eclipse.swt.SWT; -//import org.eclipse.swt.SWTException; -//import org.eclipse.swt.events.SelectionAdapter; -//import org.eclipse.swt.events.SelectionEvent; -//import org.eclipse.swt.graphics.Image; -//import org.eclipse.swt.layout.FillLayout; -//import org.eclipse.swt.widgets.Composite; -//import org.eclipse.swt.widgets.Control; -//import org.eclipse.swt.widgets.Display; -//import org.eclipse.swt.widgets.Tree; -//import org.eclipse.swt.widgets.TreeColumn; -//import org.eclipse.swt.widgets.TreeItem; -// -// -//import com.samsung.slp.common.connection.device.IDevice; -// -//import java.awt.Panel; -//import java.util.ArrayList; -// -//public class ConnectionsPanel extends Panel { -// -// -// -// -// /** -// * A display of both the devices and their clients. -// */ -// public final class DevicePanel extends Panel implements IDebugBridgeChangeListener, -// IDeviceChangeListener, IClientChangeListener { -// -// private final static String PREFS_COL_NAME_SERIAL = "devicePanel.Col0"; //$NON-NLS-1$ -// private final static String PREFS_COL_PID_STATE = "devicePanel.Col1"; //$NON-NLS-1$ -// private final static String PREFS_COL_PORT_BUILD = "devicePanel.Col4"; //$NON-NLS-1$ -// -// private final static int DEVICE_COL_SERIAL = 0; -// private final static int DEVICE_COL_STATE = 1; -// // col 2, 3 not used. -// private final static int DEVICE_COL_BUILD = 4; -// -// private final static int CLIENT_COL_NAME = 0; -// private final static int CLIENT_COL_PID = 1; -// private final static int CLIENT_COL_THREAD = 2; -// private final static int CLIENT_COL_HEAP = 3; -// private final static int CLIENT_COL_PORT = 4; -// -// public final static int ICON_WIDTH = 16; -// public final static String ICON_THREAD = "thread.png"; //$NON-NLS-1$ -// public final static String ICON_HEAP = "heap.png"; //$NON-NLS-1$ -// public final static String ICON_HALT = "halt.png"; //$NON-NLS-1$ -// public final static String ICON_GC = "gc.png"; //$NON-NLS-1$ -// public final static String ICON_HPROF = "hprof.png"; //$NON-NLS-1$ -// public final static String ICON_TRACING_START = "tracing_start.png"; //$NON-NLS-1$ -// public final static String ICON_TRACING_STOP = "tracing_stop.png"; //$NON-NLS-1$ -// -// private IDevice mCurrentDevice; -// -// private Tree mTree; -// private TreeViewer mTreeViewer; -// -// private Image mDeviceImage; -// private Image mEmulatorImage; -// -// private Image mThreadImage; -// private Image mHeapImage; -// private Image mWaitingImage; -// private Image mDebuggerImage; -// private Image mDebugErrorImage; -// -//// private final ArrayList mListeners = new ArrayList(); -// -// private final ArrayList mDevicesToExpand = new ArrayList(); -// -// private boolean mAdvancedPortSupport; -// -// /** -// * A Content provider for the {@link TreeViewer}. -// *

-// * The input is a {@link AndroidDebugBridge}. First level elements are {@link IDevice} objects, -// * and second level elements are {@link Client} object. -// */ -// private class FileTreeContentProvider implements ITreeContentProvider { -// public Object[] getChildren(Object parentElement) { -// return ((File) parentElement).listFiles(); -// } -// -// public Object getParent(Object element) { -// return ((File) element).getParentFile(); -// } -// -// public boolean hasChildren(Object element) { -// // Get the children -// Object[] obj = getChildren(element); -// -// // Return whether the parent has children -// return obj == null ? false : obj.length > 0; -// -// } -// -// public Object[] getElements(Object inputElement) { -// // These are the root elements of the tree -// // We don't care what arg0 is, because we just want all -// // the root nodes in the file system -// return File.listRoots(); -// } -// -// public void dispose() { -// // pass -// } -// -// public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { -// // pass -// } -// } -// -// /** -// * A Label Provider for the {@link TreeViewer} in {@link DevicePanel}. It provides -// * labels and images for {@link IDevice} and {@link Client} objects. -// */ -// private class FileTreeLabelProvider implements ITableLabelProvider { -// -// public Image getColumnImage(Object element, int columnIndex) { -// } -// -// public String getColumnText(Object element, int columnIndex) { -// if (element instanceof IDevice) { -// IDevice device = (IDevice)element; -// switch (columnIndex) { -// case DEVICE_COL_SERIAL: -// return device.getSerialNumber(); -// case DEVICE_COL_STATE: -// return getStateString(device); -// case DEVICE_COL_BUILD: { -// String version = device.getProperty(IDevice.PROP_BUILD_VERSION); -// if (version != null) { -// String debuggable = device.getProperty(IDevice.PROP_DEBUGGABLE); -// if (device.isEmulator()) { -// String avdName = device.getAvdName(); -// if (avdName == null) { -// avdName = "?"; // the device is probably not online yet, so -// // we don't know its AVD name just yet. -// } -// if (debuggable != null && debuggable.equals("1")) { //$NON-NLS-1$ -// return String.format("%1$s [%2$s, debug]", avdName, -// version); -// } else { -// return String.format("%1$s [%2$s]", avdName, version); //$NON-NLS-1$ -// } -// } else { -// if (debuggable != null && debuggable.equals("1")) { //$NON-NLS-1$ -// return String.format("%1$s, debug", version); -// } else { -// return String.format("%1$s", version); //$NON-NLS-1$ -// } -// } -// } else { -// return "unknown"; -// } -// } -// } -// } else if (element instanceof Client) { -// Client client = (Client)element; -// ClientData cd = client.getClientData(); -// -// switch (columnIndex) { -// case CLIENT_COL_NAME: -// String name = cd.getClientDescription(); -// if (name != null) { -// return name; -// } -// return "?"; -// case CLIENT_COL_PID: -// return Integer.toString(cd.getPid()); -// case CLIENT_COL_PORT: -// if (mAdvancedPortSupport) { -// int port = client.getDebuggerListenPort(); -// String portString = "?"; -// if (port != 0) { -// portString = Integer.toString(port); -// } -// if (client.isSelectedClient()) { -// return String.format("%1$s / %2$d", portString, //$NON-NLS-1$ -// DdmPreferences.getSelectedDebugPort()); -// } -// -// return portString; -// } -// } -// } -// return null; -// } -// -// public void addListener(ILabelProviderListener listener) { -// // pass -// } -// -// public void dispose() { -// // pass -// } -// -// public boolean isLabelProperty(Object element, String property) { -// // pass -// return false; -// } -// -// public void removeListener(ILabelProviderListener listener) { -// // pass -// } -// } -// -// /** -// * Classes which implement this interface provide methods that deals -// * with {@link IDevice} and {@link Client} selection changes coming from the ui. -// */ -// public interface IUiSelectionListener { -// /** -// * Sent when a new {@link IDevice} and {@link Client} are selected. -// * @param selectedDevice the selected device. If null, no devices are selected. -// * @param selectedClient The selected client. If null, no clients are selected. -// */ -// public void selectionChanged(IDevice selectedDevice, Client selectedClient); -// } -// -// /** -// * Creates the {@link DevicePanel} object. -// * @param loader -// * @param advancedPortSupport if true the device panel will add support for selected client port -// * and display the ports in the ui. -// */ -// public DevicePanel(boolean advancedPortSupport) { -// mAdvancedPortSupport = advancedPortSupport; -// } -// -// public void addSelectionListener(IUiSelectionListener listener) { -// mListeners.add(listener); -// } -// -// public void removeSelectionListener(IUiSelectionListener listener) { -// mListeners.remove(listener); -// } -// -// @Override -// protected Control createControl(Composite parent) { -// loadImages(parent.getDisplay()); -// -// parent.setLayout(new FillLayout()); -// -// // create the tree and its column -// mTree = new Tree(parent, SWT.SINGLE | SWT.FULL_SELECTION); -// mTree.setHeaderVisible(true); -// mTree.setLinesVisible(true); -// -// IPreferenceStore store = DdmUiPreferences.getStore(); -// -// TableHelper.createTreeColumn(mTree, "Name", SWT.LEFT, -// "com.android.home", //$NON-NLS-1$ -// PREFS_COL_NAME_SERIAL, store); -// TableHelper.createTreeColumn(mTree, "", SWT.LEFT, //$NON-NLS-1$ -// "Offline", //$NON-NLS-1$ -// PREFS_COL_PID_STATE, store); -// -// TreeColumn col = new TreeColumn(mTree, SWT.NONE); -// col.setWidth(ICON_WIDTH + 8); -// col.setResizable(false); -// col = new TreeColumn(mTree, SWT.NONE); -// col.setWidth(ICON_WIDTH + 8); -// col.setResizable(false); -// -// TableHelper.createTreeColumn(mTree, "", SWT.LEFT, //$NON-NLS-1$ -// "9999-9999", //$NON-NLS-1$ -// PREFS_COL_PORT_BUILD, store); -// -// // create the tree viewer -// mTreeViewer = new TreeViewer(mTree); -// -// // make the device auto expanded. -// mTreeViewer.setAutoExpandLevel(TreeViewer.ALL_LEVELS); -// -// // set up the content and label providers. -// mTreeViewer.setContentProvider(new ContentProvider()); -// mTreeViewer.setLabelProvider(new LabelProvider()); -// -// mTree.addSelectionListener(new SelectionAdapter() { -// @Override -// public void widgetSelected(SelectionEvent e) { -// notifyListeners(); -// } -// }); -// -// return mTree; -// } -// -// /** -// * Sets the focus to the proper control inside the panel. -// */ -// @Override -// public void setFocus() { -// mTree.setFocus(); -// } -// -// @Override -// protected void postCreation() { -// // ask for notification of changes in AndroidDebugBridge (a new one is created when -// // adb is restarted from a different location), IDevice and Client objects. -// AndroidDebugBridge.addDebugBridgeChangeListener(this); -// AndroidDebugBridge.addDeviceChangeListener(this); -// AndroidDebugBridge.addClientChangeListener(this); -// } -// -// public void dispose() { -// AndroidDebugBridge.removeDebugBridgeChangeListener(this); -// AndroidDebugBridge.removeDeviceChangeListener(this); -// AndroidDebugBridge.removeClientChangeListener(this); -// } -// -// /** -// * Returns the selected {@link Client}. May be null. -// */ -// public Client getSelectedClient() { -// return mCurrentClient; -// } -// -// /** -// * Returns the selected {@link IDevice}. If a {@link Client} is selected, it returns the -// * IDevice object containing the client. -// */ -// public IDevice getSelectedDevice() { -// return mCurrentDevice; -// } -// -// /** -// * Kills the selected {@link Client} by sending its VM a halt command. -// */ -// 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(); -// } -// } -// -// /** -// * Forces a GC on the selected {@link Client}. -// */ -// public void forceGcOnSelectedClient() { -// if (mCurrentClient != null) { -// mCurrentClient.executeGarbageCollector(); -// } -// } -// -// public void dumpHprof() { -// if (mCurrentClient != null) { -// mCurrentClient.dumpHprof(); -// } -// } -// -// public void toggleMethodProfiling() { -// if (mCurrentClient != null) { -// mCurrentClient.toggleMethodProfiling(); -// } -// } -// -// public void setEnabledHeapOnSelectedClient(boolean enable) { -// if (mCurrentClient != null) { -// mCurrentClient.setHeapUpdateEnabled(enable); -// } -// } -// -// public void setEnabledThreadOnSelectedClient(boolean enable) { -// if (mCurrentClient != null) { -// mCurrentClient.setThreadUpdateEnabled(enable); -// } -// } -// -// /** -// * Sent when a new {@link AndroidDebugBridge} is started. -// *

-// * This is sent from a non UI thread. -// * @param bridge the new {@link AndroidDebugBridge} object. -// * -// * @see IDebugBridgeChangeListener#serverChanged(AndroidDebugBridge) -// */ -// public void bridgeChanged(final AndroidDebugBridge bridge) { -// if (mTree.isDisposed() == false) { -// exec(new Runnable() { -// public void run() { -// if (mTree.isDisposed() == false) { -// // set up the data source. -// mTreeViewer.setInput(bridge); -// -// // notify the listener of a possible selection change. -// notifyListeners(); -// } 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); -// } -// } -// }); -// } -// -// // all current devices are obsolete -// synchronized (mDevicesToExpand) { -// mDevicesToExpand.clear(); -// } -// } -// -// /** -// * Sent when the a device is connected to the {@link AndroidDebugBridge}. -// *

-// * This is sent from a non UI thread. -// * @param device the new device. -// * -// * @see IDeviceChangeListener#deviceConnected(IDevice) -// */ -// public void deviceConnected(IDevice device) { -// exec(new Runnable() { -// public void run() { -// if (mTree.isDisposed() == false) { -// // refresh all -// mTreeViewer.refresh(); -// -// // notify the listener of a possible selection change. -// notifyListeners(); -// } 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); -// } -// } -// }); -// -// // if it doesn't have clients yet, it'll need to be manually expanded when it gets them. -// if (device.hasClients() == false) { -// synchronized (mDevicesToExpand) { -// mDevicesToExpand.add(device); -// } -// } -// } -// -// /** -// * Sent when the a device is connected to the {@link AndroidDebugBridge}. -// *

-// * This is sent from a non UI thread. -// * @param device the new device. -// * -// * @see IDeviceChangeListener#deviceDisconnected(IDevice) -// */ -// public void deviceDisconnected(IDevice device) { -// deviceConnected(device); -// -// // just in case, we remove it from the list of devices to expand. -// synchronized (mDevicesToExpand) { -// mDevicesToExpand.remove(device); -// } -// } -// -// /** -// * Sent when a device data changed, or when clients are started/terminated on the device. -// *

-// * 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) -// */ -// 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() { -// 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); -// } -// } -// }); -// } -// -// /** -// * Sent when an existing client information changed. -// *

-// * 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) -// */ -// public void clientChanged(final Client client, final int changeMask) { -// exec(new Runnable() { -// 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); -// } -// } -// }); -// } -// -// private void loadImages(Display display) { -// ImageLoader loader = ImageLoader.getDdmUiLibLoader(); -// -// if (mDeviceImage == null) { -// mDeviceImage = loader.loadImage(display, "device.png", //$NON-NLS-1$ -// ICON_WIDTH, ICON_WIDTH, -// display.getSystemColor(SWT.COLOR_RED)); -// } -// if (mEmulatorImage == null) { -// mEmulatorImage = loader.loadImage(display, -// "emulator.png", ICON_WIDTH, ICON_WIDTH, //$NON-NLS-1$ -// display.getSystemColor(SWT.COLOR_BLUE)); -// } -// if (mThreadImage == null) { -// mThreadImage = loader.loadImage(display, ICON_THREAD, -// ICON_WIDTH, ICON_WIDTH, -// display.getSystemColor(SWT.COLOR_YELLOW)); -// } -// if (mHeapImage == null) { -// mHeapImage = loader.loadImage(display, ICON_HEAP, -// ICON_WIDTH, ICON_WIDTH, -// display.getSystemColor(SWT.COLOR_BLUE)); -// } -// if (mWaitingImage == null) { -// mWaitingImage = loader.loadImage(display, -// "debug-wait.png", ICON_WIDTH, ICON_WIDTH, //$NON-NLS-1$ -// display.getSystemColor(SWT.COLOR_RED)); -// } -// if (mDebuggerImage == null) { -// mDebuggerImage = loader.loadImage(display, -// "debug-attach.png", ICON_WIDTH, ICON_WIDTH, //$NON-NLS-1$ -// display.getSystemColor(SWT.COLOR_GREEN)); -// } -// if (mDebugErrorImage == null) { -// mDebugErrorImage = loader.loadImage(display, -// "debug-error.png", ICON_WIDTH, ICON_WIDTH, //$NON-NLS-1$ -// display.getSystemColor(SWT.COLOR_RED)); -// } -// } -// -// /** -// * Returns a display string representing the state of the device. -// * @param d the device -// */ -// private static String getStateString(IDevice d) { -// DeviceState deviceState = d.getState(); -// if (deviceState == DeviceState.ONLINE) { -// return "Online"; -// } else if (deviceState == DeviceState.OFFLINE) { -// return "Offline"; -// } else if (deviceState == DeviceState.BOOTLOADER) { -// return "Bootloader"; -// } -// -// return "??"; -// } -// -// /** -// * Executes the {@link Runnable} in the UI thread. -// * @param runnable the runnable to execute. -// */ -// private void exec(Runnable runnable) { -// try { -// Display display = mTree.getDisplay(); -// display.asyncExec(runnable); -// } catch (SWTException e) { -// // tree is disposed, we need to do something. lets remove ourselves from the listener. -// AndroidDebugBridge.removeDebugBridgeChangeListener(this); -// AndroidDebugBridge.removeDeviceChangeListener(this); -// AndroidDebugBridge.removeClientChangeListener(this); -// } -// } -// -// private void notifyListeners() { -// // get the selection -// TreeItem[] items = mTree.getSelection(); -// -// Client client = null; -// IDevice device = null; -// -// if (items.length == 1) { -// Object object = items[0].getData(); -// if (object instanceof Client) { -// client = (Client)object; -// device = client.getDevice(); -// } else if (object instanceof IDevice) { -// device = (IDevice)object; -// } -// } -// -// notifyListeners(device, client); -// } -// -// private void notifyListeners(IDevice selectedDevice, Client selectedClient) { -// if (selectedDevice != mCurrentDevice || selectedClient != mCurrentClient) { -// mCurrentDevice = selectedDevice; -// mCurrentClient = selectedClient; -// -// for (IUiSelectionListener listener : mListeners) { -// // notify the listener with a try/catch-all to make sure this thread won't die -// // because of an uncaught exception before all the listeners were notified. -// try { -// listener.selectionChanged(selectedDevice, selectedClient); -// } catch (Exception e) { -// } -// } -// } -// } -// -// } diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/Messages.java b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/Messages.java new file mode 100644 index 0000000..256d8c8 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/Messages.java @@ -0,0 +1,126 @@ +/* + * Messages.java + * + * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * YoonKi Park + * Hoon Kang + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * - S-Core Co., Ltd + * + */ +package com.samsung.slp.common.connection.ui; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Messages { + private static final String BUNDLE_NAME = "com.samsung.slp.common.connection.ui.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle + .getBundle(BUNDLE_NAME); + + private Messages() { + } + + public static String getString(String key) { + // TODO Auto-generated method stub + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + + public static String getString(String key, Object binding) { + // TODO Auto-generated method stub + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } + private static String messageBind(String message, Object[] args, String argZero, String argOne) { + int length = message.length(); + //estimate correct size of string buffer to avoid growth + int bufLen = length + (args.length * 5); + if (argZero != null) + bufLen += argZero.length() - 3; + if (argOne != null) + bufLen += argOne.length() - 3; + StringBuffer buffer = new StringBuffer(bufLen < 0 ? 0 : bufLen); + for (int i = 0; i < length; i++) { + char c = message.charAt(i); + switch (c) { + case '{' : + int index = message.indexOf('}', i); + // if we don't have a matching closing brace then... + if (index == -1) { + buffer.append(c); + break; + } + i++; + if (i >= length) { + buffer.append(c); + break; + } + // look for a substitution + int number = -1; + try { + number = Integer.parseInt(message.substring(i, index)); + } catch (NumberFormatException e) { + throw (IllegalArgumentException) new IllegalArgumentException().initCause(e); + } + if (number == 0 && argZero != null) + buffer.append(argZero); + else if (number == 1 && argOne != null) + buffer.append(argOne); + else { + if (number >= args.length || number < 0) { + buffer.append(""); //$NON-NLS-1$ + i = index; + break; + } + buffer.append(args[number]); + } + i = index; + break; + case '\'' : + // if a single quote is the last char on the line then skip it + int nextIndex = i + 1; + if (nextIndex >= length) { + buffer.append(c); + break; + } + char next = message.charAt(nextIndex); + // if the next char is another single quote then write out one + if (next == '\'') { + i++; + buffer.append(c); + break; + } + // otherwise we want to read until we get to the next single quote + index = message.indexOf('\'', nextIndex); + // if there are no more in the string, then skip it + if (index == -1) { + buffer.append(c); + break; + } + // otherwise write out the chars inside the quotes + buffer.append(message.substring(nextIndex, index)); + i = index; + break; + default : + buffer.append(c); + } + } + return buffer.toString(); + } +} diff --git a/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/messages.properties b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/messages.properties new file mode 100644 index 0000000..61c0c35 --- /dev/null +++ b/com.samsung.slp.common.connection/src/com/samsung/slp/common/connection/ui/messages.properties @@ -0,0 +1,3 @@ + +FileEntryDropAdapter.overrite.title=File Exists +FileEntryDropAdapter.overrite.message=The file {0} already exists. Are you going to overwrite it? \ No newline at end of file -- 2.7.4