aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSiva Velusamy <vsiva@google.com>2012-03-29 11:23:59 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-03-29 11:23:59 -0700
commit7d94f2e3da01698e7dde3daea1ab13afbd6419cf (patch)
treed9e00b9a124fabac2520097abb8e30271975cca4
parent94bab8acc98af8708c2e0e73b3a6dbd43880cadc (diff)
parentb64164c24a187aaf9633152a8c72b0ea9a43810b (diff)
downloadsdk-7d94f2e3da01698e7dde3daea1ab13afbd6419cf.zip
sdk-7d94f2e3da01698e7dde3daea1ab13afbd6419cf.tar.gz
sdk-7d94f2e3da01698e7dde3daea1ab13afbd6419cf.tar.bz2
Merge "rcp: Add missing preferences and menu items."
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.monitor/.classpath2
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.monitor/plugin.xml37
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/AndroidPreferencePage.java43
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/MonitorActionBarAdvisor.java34
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/DebugPortProvider.java165
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/StaticPortConfigDialog.java396
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/StaticPortEditDialog.java334
-rw-r--r--eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/handlers/StaticPortConfigHandler.java33
-rw-r--r--eclipse/scripts/rcp/build.properties21
9 files changed, 1056 insertions, 9 deletions
diff --git a/eclipse/plugins/com.android.ide.eclipse.monitor/.classpath b/eclipse/plugins/com.android.ide.eclipse.monitor/.classpath
index 2e5a9ea..09137cb 100644
--- a/eclipse/plugins/com.android.ide.eclipse.monitor/.classpath
+++ b/eclipse/plugins/com.android.ide.eclipse.monitor/.classpath
@@ -6,5 +6,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/ddmlib"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/ddmuilib"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/eclipse/plugins/com.android.ide.eclipse.monitor/plugin.xml b/eclipse/plugins/com.android.ide.eclipse.monitor/plugin.xml
index c428868..3a58d84 100644
--- a/eclipse/plugins/com.android.ide.eclipse.monitor/plugin.xml
+++ b/eclipse/plugins/com.android.ide.eclipse.monitor/plugin.xml
@@ -48,4 +48,41 @@
class="com.android.ide.eclipse.monitor.ToolsLocator">
</locator>
</extension>
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ defaultHandler="com.android.ide.eclipse.monitor.handlers.StaticPortConfigHandler"
+ id="com.android.monitor.commands.StaticPortConfiguration"
+ name="Static Port Configuration">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="menu:file?after=additions">
+ <command
+ commandId="com.android.monitor.commands.StaticPortConfiguration"
+ label="Static Port Configuration"
+ style="push"
+ tooltip="Configure static debug ports">
+ </command>
+ </menuContribution>
+ <menuContribution
+ allPopups="false"
+ locationURI="menu:window?after=additions">
+ <command
+ commandId="org.eclipse.ui.views.showView"
+ style="push">
+ </command>
+ </menuContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.preferencePages">
+ <page
+ class="com.android.ide.eclipse.monitor.AndroidPreferencePage"
+ id="com.android.ide.eclipse.preferences.main"
+ name="Android">
+ </page>
+ </extension>
</plugin>
diff --git a/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/AndroidPreferencePage.java b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/AndroidPreferencePage.java
new file mode 100644
index 0000000..b85f016
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/AndroidPreferencePage.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.ide.eclipse.monitor;
+
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+public class AndroidPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
+ public AndroidPreferencePage() {
+ super(""); //$NON-NLS-1$
+ setPreferenceStore(MonitorPlugin.getDefault().getPreferenceStore());
+ }
+
+ @Override
+ public void init(IWorkbench workbench) {
+ }
+
+ @Override
+ protected Control createContents(Composite parent) {
+ // TODO: This page is empty currently. It is only used as the top level
+ // to which DDMS & logcat attach their preference pages.
+ // ADT's root page contains the path to the Android SDK, and we should recreate
+ // that here once we figure out how to share this across plugins.
+ return null;
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/MonitorActionBarAdvisor.java b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/MonitorActionBarAdvisor.java
index c606c60..4cf7a94 100644
--- a/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/MonitorActionBarAdvisor.java
+++ b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/MonitorActionBarAdvisor.java
@@ -28,6 +28,11 @@ import org.eclipse.ui.application.IActionBarConfigurer;
public class MonitorActionBarAdvisor extends ActionBarAdvisor {
private IWorkbenchAction mQuitAction;
+ private IWorkbenchAction mCopyAction;
+ private IWorkbenchAction mSelectAllAction;
+ private IWorkbenchAction mOpenPerspectiveAction;
+ private IWorkbenchAction mResetPerspectiveAction;
+ private IWorkbenchAction mPreferencesAction;
private IWorkbenchAction mAboutAction;
public MonitorActionBarAdvisor(IActionBarConfigurer configurer) {
@@ -39,6 +44,21 @@ public class MonitorActionBarAdvisor extends ActionBarAdvisor {
mQuitAction = ActionFactory.QUIT.create(window);
register(mQuitAction);
+ mCopyAction = ActionFactory.COPY.create(window);
+ register(mCopyAction);
+
+ mSelectAllAction = ActionFactory.SELECT_ALL.create(window);
+ register(mSelectAllAction);
+
+ mOpenPerspectiveAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG.create(window);
+ register(mOpenPerspectiveAction);
+
+ mResetPerspectiveAction = ActionFactory.RESET_PERSPECTIVE.create(window);
+ register(mResetPerspectiveAction);
+
+ mPreferencesAction = ActionFactory.PREFERENCES.create(window);
+ register(mPreferencesAction);
+
mAboutAction = ActionFactory.ABOUT.create(window);
register(mAboutAction);
}
@@ -46,16 +66,30 @@ public class MonitorActionBarAdvisor extends ActionBarAdvisor {
@Override
protected void fillMenuBar(IMenuManager menuBar) {
MenuManager fileMenu = new MenuManager("&File", IWorkbenchActionConstants.M_FILE);
+ MenuManager editMenu = new MenuManager("&Edit", IWorkbenchActionConstants.M_EDIT);
MenuManager helpMenu = new MenuManager("&Help", IWorkbenchActionConstants.M_HELP);
+ MenuManager windowMenu = new MenuManager("&Window", IWorkbenchActionConstants.M_WINDOW);
menuBar.add(fileMenu);
+ menuBar.add(editMenu);
menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ menuBar.add(windowMenu);
menuBar.add(helpMenu);
// contents of File menu
fileMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
fileMenu.add(mQuitAction);
+ // contents of Edit menu
+ editMenu.add(mCopyAction);
+ editMenu.add(mSelectAllAction);
+
+ // contents of Window menu
+ windowMenu.add(mOpenPerspectiveAction);
+ windowMenu.add(mResetPerspectiveAction);
+ windowMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
+ windowMenu.add(mPreferencesAction);
+
// contents of Help menu
helpMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
helpMenu.add(mAboutAction);
diff --git a/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/DebugPortProvider.java b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/DebugPortProvider.java
new file mode 100644
index 0000000..a2ffa04
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/DebugPortProvider.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.ide.eclipse.monitor.ddms;
+
+import com.android.ddmlib.DebugPortManager.IDebugPortProvider;
+import com.android.ddmlib.IDevice;
+import com.android.ide.eclipse.ddms.DdmsPlugin;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * DDMS implementation of the IDebugPortProvider interface.
+ * This class handles saving/loading the list of static debug port from
+ * the preference store and provides the port number to the Device Monitor.
+ */
+public class DebugPortProvider implements IDebugPortProvider {
+
+ private static DebugPortProvider sThis = new DebugPortProvider();
+
+ /** Preference name for the static port list. */
+ public static final String PREFS_STATIC_PORT_LIST = "android.staticPortList"; //$NON-NLS-1$
+
+ /**
+ * Mapping device serial numbers to maps. The embedded maps are mapping application names to
+ * debugger ports.
+ */
+ private Map<String, Map<String, Integer>> mMap;
+
+ public static DebugPortProvider getInstance() {
+ return sThis;
+ }
+
+ private DebugPortProvider() {
+ computePortList();
+ }
+
+ /**
+ * Returns a static debug port for the specified application running on the
+ * specified {@link IDevice}.
+ * @param device The device the application is running on.
+ * @param appName The application name, as defined in the
+ * AndroidManifest.xml package attribute.
+ * @return The static debug port or {@link #NO_STATIC_PORT} if there is none setup.
+ *
+ * @see IDebugPortProvider#getPort(IDevice, String)
+ */
+ @Override
+ public int getPort(IDevice device, String appName) {
+ if (mMap != null) {
+ Map<String, Integer> deviceMap = mMap.get(device.getSerialNumber());
+ if (deviceMap != null) {
+ Integer i = deviceMap.get(appName);
+ if (i != null) {
+ return i.intValue();
+ }
+ }
+ }
+ return IDebugPortProvider.NO_STATIC_PORT;
+ }
+
+ /**
+ * Returns the map of Static debugger ports. The map links device serial numbers to
+ * a map linking application name to debugger ports.
+ */
+ public Map<String, Map<String, Integer>> getPortList() {
+ return mMap;
+ }
+
+ /**
+ * Create the map member from the values contained in the Preference Store.
+ */
+ private void computePortList() {
+ mMap = new HashMap<String, Map<String, Integer>>();
+
+ // get the prefs store
+ IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
+ String value = store.getString(PREFS_STATIC_PORT_LIST);
+
+ if (value != null && value.length() > 0) {
+ // format is
+ // port1|port2|port3|...
+ // where port# is
+ // appPackageName:appPortNumber:device-serial-number
+ String[] portSegments = value.split("\\|"); //$NON-NLS-1$
+ for (String seg : portSegments) {
+ String[] entry = seg.split(":"); //$NON-NLS-1$
+
+ // backward compatibility support. if we have only 2 entry, we default
+ // to the first emulator.
+ String deviceName = null;
+ if (entry.length == 3) {
+ deviceName = entry[2];
+ } else {
+ deviceName = IDevice.FIRST_EMULATOR_SN;
+ }
+
+ // get the device map
+ Map<String, Integer> deviceMap = mMap.get(deviceName);
+ if (deviceMap == null) {
+ deviceMap = new HashMap<String, Integer>();
+ mMap.put(deviceName, deviceMap);
+ }
+
+ deviceMap.put(entry[0], Integer.valueOf(entry[1]));
+ }
+ }
+ }
+
+ /**
+ * Sets new [device, app, port] values.
+ * The values are also sync'ed in the preference store.
+ * @param map The map containing the new values.
+ */
+ public void setPortList(Map<String, Map<String,Integer>> map) {
+ // update the member map.
+ mMap.clear();
+ mMap.putAll(map);
+
+ // create the value to store in the preference store.
+ // see format definition in getPortList
+ StringBuilder sb = new StringBuilder();
+
+ Set<String> deviceKeys = map.keySet();
+ for (String deviceKey : deviceKeys) {
+ Map<String, Integer> deviceMap = map.get(deviceKey);
+ if (deviceMap != null) {
+ Set<String> appKeys = deviceMap.keySet();
+
+ for (String appKey : appKeys) {
+ Integer port = deviceMap.get(appKey);
+ if (port != null) {
+ sb.append(appKey).append(':').append(port.intValue()).append(':').
+ append(deviceKey).append('|');
+ }
+ }
+ }
+ }
+
+ String value = sb.toString();
+
+ // get the prefs store.
+ IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
+
+ // and give it the new value.
+ store.setValue(PREFS_STATIC_PORT_LIST, value);
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/StaticPortConfigDialog.java b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/StaticPortConfigDialog.java
new file mode 100644
index 0000000..456cdcf
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/StaticPortConfigDialog.java
@@ -0,0 +1,396 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.ide.eclipse.monitor.ddms;
+
+import com.android.ddmuilib.TableHelper;
+import com.android.ide.eclipse.ddms.DdmsPlugin;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableItem;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Dialog to configure the static debug ports.
+ *
+ */
+public class StaticPortConfigDialog extends Dialog {
+
+ /** Preference name for the 0th column width */
+ private static final String PREFS_DEVICE_COL = "spcd.deviceColumn"; //$NON-NLS-1$
+
+ /** Preference name for the 1st column width */
+ private static final String PREFS_APP_COL = "spcd.AppColumn"; //$NON-NLS-1$
+
+ /** Preference name for the 2nd column width */
+ private static final String PREFS_PORT_COL = "spcd.PortColumn"; //$NON-NLS-1$
+
+ private static final int COL_DEVICE = 0;
+ private static final int COL_APPLICATION = 1;
+ private static final int COL_PORT = 2;
+
+
+ private static final int DLG_WIDTH = 500;
+ private static final int DLG_HEIGHT = 300;
+
+ private Shell mShell;
+ private Shell mParent;
+
+ private Table mPortTable;
+
+ /**
+ * Array containing the list of already used static port to avoid
+ * duplication.
+ */
+ private ArrayList<Integer> mPorts = new ArrayList<Integer>();
+
+ /**
+ * Basic constructor.
+ * @param parent
+ */
+ public StaticPortConfigDialog(Shell parent) {
+ super(parent, SWT.DIALOG_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL);
+ }
+
+ /**
+ * Open and display the dialog. This method returns only when the
+ * user closes the dialog somehow.
+ *
+ */
+ public void open() {
+ createUI();
+
+ if (mParent == null || mShell == null) {
+ return;
+ }
+
+ updateFromStore();
+
+ // Set the dialog size.
+ mShell.setMinimumSize(DLG_WIDTH, DLG_HEIGHT);
+ Rectangle r = mParent.getBounds();
+ // get the center new top left.
+ int cx = r.x + r.width/2;
+ int x = cx - DLG_WIDTH / 2;
+ int cy = r.y + r.height/2;
+ int y = cy - DLG_HEIGHT / 2;
+ mShell.setBounds(x, y, DLG_WIDTH, DLG_HEIGHT);
+
+ mShell.pack();
+
+ // actually open the dialog
+ mShell.open();
+
+ // event loop until the dialog is closed.
+ Display display = mParent.getDisplay();
+ while (!mShell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ }
+
+ /**
+ * Creates the dialog ui.
+ */
+ private void createUI() {
+ mParent = getParent();
+ mShell = new Shell(mParent, getStyle());
+ mShell.setText("Static Port Configuration");
+
+ mShell.setLayout(new GridLayout(1, true));
+
+ mShell.addListener(SWT.Close, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ event.doit = true;
+ }
+ });
+
+ // center part with the list on the left and the buttons
+ // on the right.
+ Composite main = new Composite(mShell, SWT.NONE);
+ main.setLayoutData(new GridData(GridData.FILL_BOTH));
+ main.setLayout(new GridLayout(2, false));
+
+ // left part: list view
+ mPortTable = new Table(main, SWT.SINGLE | SWT.FULL_SELECTION);
+ mPortTable.setLayoutData(new GridData(GridData.FILL_BOTH));
+ mPortTable.setHeaderVisible(true);
+ mPortTable.setLinesVisible(true);
+
+ TableHelper.createTableColumn(mPortTable, "Device Serial Number",
+ SWT.LEFT, "emulator-5554", //$NON-NLS-1$
+ PREFS_DEVICE_COL, DdmsPlugin.getDefault().getPreferenceStore());
+
+ TableHelper.createTableColumn(mPortTable, "Application Package",
+ SWT.LEFT, "com.android.samples.phone", //$NON-NLS-1$
+ PREFS_APP_COL, DdmsPlugin.getDefault().getPreferenceStore());
+
+ TableHelper.createTableColumn(mPortTable, "Debug Port",
+ SWT.RIGHT, "Debug Port", //$NON-NLS-1$
+ PREFS_PORT_COL, DdmsPlugin.getDefault().getPreferenceStore());
+
+ // right part: buttons
+ Composite buttons = new Composite(main, SWT.NONE);
+ buttons.setLayoutData(new GridData(GridData.FILL_VERTICAL));
+ buttons.setLayout(new GridLayout(1, true));
+
+ Button newButton = new Button(buttons, SWT.NONE);
+ newButton.setText("New...");
+ newButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ StaticPortEditDialog dlg = new StaticPortEditDialog(mShell,
+ mPorts);
+ if (dlg.open()) {
+ // get the text
+ String device = dlg.getDeviceSN();
+ String app = dlg.getAppName();
+ int port = dlg.getPortNumber();
+
+ // add it to the list
+ addEntry(device, app, port);
+ }
+ }
+ });
+
+ final Button editButton = new Button(buttons, SWT.NONE);
+ editButton.setText("Edit...");
+ editButton.setEnabled(false);
+ editButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int index = mPortTable.getSelectionIndex();
+ String oldDeviceName = getDeviceName(index);
+ String oldAppName = getAppName(index);
+ String oldPortNumber = getPortNumber(index);
+ StaticPortEditDialog dlg = new StaticPortEditDialog(mShell,
+ mPorts, oldDeviceName, oldAppName, oldPortNumber);
+ if (dlg.open()) {
+ // get the text
+ String deviceName = dlg.getDeviceSN();
+ String app = dlg.getAppName();
+ int port = dlg.getPortNumber();
+
+ // add it to the list
+ replaceEntry(index, deviceName, app, port);
+ }
+ }
+ });
+
+ final Button deleteButton = new Button(buttons, SWT.NONE);
+ deleteButton.setText("Delete");
+ deleteButton.setEnabled(false);
+ deleteButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int index = mPortTable.getSelectionIndex();
+ removeEntry(index);
+ }
+ });
+
+ // bottom part with the ok/cancel
+ Composite bottomComp = new Composite(mShell, SWT.NONE);
+ bottomComp.setLayoutData(new GridData(
+ GridData.HORIZONTAL_ALIGN_CENTER));
+ bottomComp.setLayout(new GridLayout(2, true));
+
+ Button okButton = new Button(bottomComp, SWT.NONE);
+ okButton.setText("OK");
+ okButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateStore();
+ mShell.close();
+ }
+ });
+
+ Button cancelButton = new Button(bottomComp, SWT.NONE);
+ cancelButton.setText("Cancel");
+ cancelButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ mShell.close();
+ }
+ });
+
+ mPortTable.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ // get the selection index
+ int index = mPortTable.getSelectionIndex();
+
+ boolean enabled = index != -1;
+ editButton.setEnabled(enabled);
+ deleteButton.setEnabled(enabled);
+ }
+ });
+
+ mShell.pack();
+
+ }
+
+ /**
+ * Add a new entry in the list.
+ * @param deviceName the serial number of the device
+ * @param appName java package for the application
+ * @param portNumber port number
+ */
+ private void addEntry(String deviceName, String appName, int portNumber) {
+ // create a new item for the table
+ TableItem item = new TableItem(mPortTable, SWT.NONE);
+
+ item.setText(COL_DEVICE, deviceName);
+ item.setText(COL_APPLICATION, appName);
+ item.setText(COL_PORT, Integer.toString(portNumber));
+
+ // add the port to the list of port number used.
+ mPorts.add(portNumber);
+ }
+
+ /**
+ * Remove an entry from the list.
+ * @param index The index of the entry to be removed
+ */
+ private void removeEntry(int index) {
+ // remove from the ui
+ mPortTable.remove(index);
+
+ // and from the port list.
+ mPorts.remove(index);
+ }
+
+ /**
+ * Replace an entry in the list with new values.
+ * @param index The index of the item to be replaced
+ * @param deviceName the serial number of the device
+ * @param appName The new java package for the application
+ * @param portNumber The new port number.
+ */
+ private void replaceEntry(int index, String deviceName, String appName, int portNumber) {
+ // get the table item by index
+ TableItem item = mPortTable.getItem(index);
+
+ // set its new value
+ item.setText(COL_DEVICE, deviceName);
+ item.setText(COL_APPLICATION, appName);
+ item.setText(COL_PORT, Integer.toString(portNumber));
+
+ // and replace the port number in the port list.
+ mPorts.set(index, portNumber);
+ }
+
+
+ /**
+ * Returns the device name for a specific index
+ * @param index The index
+ * @return the java package name of the application
+ */
+ private String getDeviceName(int index) {
+ TableItem item = mPortTable.getItem(index);
+ return item.getText(COL_DEVICE);
+ }
+
+ /**
+ * Returns the application name for a specific index
+ * @param index The index
+ * @return the java package name of the application
+ */
+ private String getAppName(int index) {
+ TableItem item = mPortTable.getItem(index);
+ return item.getText(COL_APPLICATION);
+ }
+
+ /**
+ * Returns the port number for a specific index
+ * @param index The index
+ * @return the port number
+ */
+ private String getPortNumber(int index) {
+ TableItem item = mPortTable.getItem(index);
+ return item.getText(COL_PORT);
+ }
+
+ /**
+ * Updates the ui from the value in the preference store.
+ */
+ private void updateFromStore() {
+ // get the map from the debug port manager
+ DebugPortProvider provider = DebugPortProvider.getInstance();
+ Map<String, Map<String, Integer>> map = provider.getPortList();
+
+ // we're going to loop on the keys and fill the table.
+ Set<String> deviceKeys = map.keySet();
+
+ for (String deviceKey : deviceKeys) {
+ Map<String, Integer> deviceMap = map.get(deviceKey);
+ if (deviceMap != null) {
+ Set<String> appKeys = deviceMap.keySet();
+
+ for (String appKey : appKeys) {
+ Integer port = deviceMap.get(appKey);
+ if (port != null) {
+ addEntry(deviceKey, appKey, port);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Update the store from the content of the ui.
+ */
+ private void updateStore() {
+ // create a new Map object and fill it.
+ HashMap<String, Map<String, Integer>> map = new HashMap<String, Map<String, Integer>>();
+
+ int count = mPortTable.getItemCount();
+
+ for (int i = 0 ; i < count ; i++) {
+ TableItem item = mPortTable.getItem(i);
+ String deviceName = item.getText(COL_DEVICE);
+
+ Map<String, Integer> deviceMap = map.get(deviceName);
+ if (deviceMap == null) {
+ deviceMap = new HashMap<String, Integer>();
+ map.put(deviceName, deviceMap);
+ }
+
+ deviceMap.put(item.getText(COL_APPLICATION), Integer.valueOf(item.getText(COL_PORT)));
+ }
+
+ // set it in the store through the debug port manager.
+ DebugPortProvider provider = DebugPortProvider.getInstance();
+ provider.setPortList(map);
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/StaticPortEditDialog.java b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/StaticPortEditDialog.java
new file mode 100644
index 0000000..a9b0cd4
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/ddms/StaticPortEditDialog.java
@@ -0,0 +1,334 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.ide.eclipse.monitor.ddms;
+
+import com.android.ddmlib.IDevice;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Dialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+import java.util.ArrayList;
+
+/**
+ * Small dialog box to edit a static port number.
+ */
+public class StaticPortEditDialog extends Dialog {
+
+ private static final int DLG_WIDTH = 400;
+ private static final int DLG_HEIGHT = 200;
+
+ private Shell mParent;
+
+ private Shell mShell;
+
+ private boolean mOk = false;
+
+ private String mAppName;
+
+ private String mPortNumber;
+
+ private Button mOkButton;
+
+ private Label mWarning;
+
+ /** List of ports already in use */
+ private ArrayList<Integer> mPorts;
+
+ /** This is the port being edited. */
+ private int mEditPort = -1;
+ private String mDeviceSn;
+
+ /**
+ * Creates a dialog with empty fields.
+ * @param parent The parent Shell
+ * @param ports The list of already used port numbers.
+ */
+ public StaticPortEditDialog(Shell parent, ArrayList<Integer> ports) {
+ super(parent, SWT.DIALOG_TRIM | SWT.BORDER | SWT.APPLICATION_MODAL);
+ mPorts = ports;
+ mDeviceSn = IDevice.FIRST_EMULATOR_SN;
+ }
+
+ /**
+ * Creates a dialog with predefined values.
+ * @param shell The parent shell
+ * @param ports The list of already used port numbers.
+ * @param oldDeviceSN the device serial number to display
+ * @param oldAppName The application name to display
+ * @param oldPortNumber The port number to display
+ */
+ public StaticPortEditDialog(Shell shell, ArrayList<Integer> ports,
+ String oldDeviceSN, String oldAppName, String oldPortNumber) {
+ this(shell, ports);
+
+ mDeviceSn = oldDeviceSN;
+ mAppName = oldAppName;
+ mPortNumber = oldPortNumber;
+ mEditPort = Integer.valueOf(mPortNumber);
+ }
+
+ /**
+ * Opens the dialog. The method will return when the user closes the dialog
+ * somehow.
+ *
+ * @return true if ok was pressed, false if cancelled.
+ */
+ public boolean open() {
+ createUI();
+
+ if (mParent == null || mShell == null) {
+ return false;
+ }
+
+ mShell.setMinimumSize(DLG_WIDTH, DLG_HEIGHT);
+ Rectangle r = mParent.getBounds();
+ // get the center new top left.
+ int cx = r.x + r.width/2;
+ int x = cx - DLG_WIDTH / 2;
+ int cy = r.y + r.height/2;
+ int y = cy - DLG_HEIGHT / 2;
+ mShell.setBounds(x, y, DLG_WIDTH, DLG_HEIGHT);
+
+ mShell.open();
+
+ Display display = mParent.getDisplay();
+ while (!mShell.isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+
+ return mOk;
+ }
+
+ public String getDeviceSN() {
+ return mDeviceSn;
+ }
+
+ public String getAppName() {
+ return mAppName;
+ }
+
+ public int getPortNumber() {
+ return Integer.valueOf(mPortNumber);
+ }
+
+ private void createUI() {
+ mParent = getParent();
+ mShell = new Shell(mParent, getStyle());
+ mShell.setText("Static Port");
+
+ mShell.setLayout(new GridLayout(1, false));
+
+ mShell.addListener(SWT.Close, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ }
+ });
+
+ // center part with the edit field
+ Composite main = new Composite(mShell, SWT.NONE);
+ main.setLayoutData(new GridData(GridData.FILL_BOTH));
+ main.setLayout(new GridLayout(2, false));
+
+ Label l0 = new Label(main, SWT.NONE);
+ l0.setText("Device Name:");
+
+ final Text deviceSNText = new Text(main, SWT.SINGLE | SWT.BORDER);
+ deviceSNText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ if (mDeviceSn != null) {
+ deviceSNText.setText(mDeviceSn);
+ }
+ deviceSNText.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ mDeviceSn = deviceSNText.getText().trim();
+ validate();
+ }
+ });
+
+ Label l = new Label(main, SWT.NONE);
+ l.setText("Application Name:");
+
+ final Text appNameText = new Text(main, SWT.SINGLE | SWT.BORDER);
+ if (mAppName != null) {
+ appNameText.setText(mAppName);
+ }
+ appNameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ appNameText.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ mAppName = appNameText.getText().trim();
+ validate();
+ }
+ });
+
+ Label l2 = new Label(main, SWT.NONE);
+ l2.setText("Debug Port:");
+
+ final Text debugPortText = new Text(main, SWT.SINGLE | SWT.BORDER);
+ if (mPortNumber != null) {
+ debugPortText.setText(mPortNumber);
+ }
+ debugPortText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ debugPortText.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ mPortNumber = debugPortText.getText().trim();
+ validate();
+ }
+ });
+
+ // warning label
+ Composite warningComp = new Composite(mShell, SWT.NONE);
+ warningComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ warningComp.setLayout(new GridLayout(1, true));
+
+ mWarning = new Label(warningComp, SWT.NONE);
+ mWarning.setText("");
+ mWarning.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+
+ // bottom part with the ok/cancel
+ Composite bottomComp = new Composite(mShell, SWT.NONE);
+ bottomComp
+ .setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
+ bottomComp.setLayout(new GridLayout(2, true));
+
+ mOkButton = new Button(bottomComp, SWT.NONE);
+ mOkButton.setText("OK");
+ mOkButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ mOk = true;
+ mShell.close();
+ }
+ });
+ mOkButton.setEnabled(false);
+ mShell.setDefaultButton(mOkButton);
+
+ Button cancelButton = new Button(bottomComp, SWT.NONE);
+ cancelButton.setText("Cancel");
+ cancelButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ mShell.close();
+ }
+ });
+
+ validate();
+ }
+
+ /**
+ * Validates the content of the 2 text fields and enable/disable "ok", while
+ * setting up the warning/error message.
+ */
+ private void validate() {
+ // first we reset the warning dialog. This allows us to latter
+ // display warnings.
+ mWarning.setText(""); //$NON-NLS-1$
+
+ // check the device name field is not empty
+ if (mDeviceSn == null || mDeviceSn.length() == 0) {
+ mWarning.setText("Device name missing.");
+ mOkButton.setEnabled(false);
+ return;
+ }
+
+ // check the application name field is not empty
+ if (mAppName == null || mAppName.length() == 0) {
+ mWarning.setText("Application name missing.");
+ mOkButton.setEnabled(false);
+ return;
+ }
+
+ String packageError = "Application name must be a valid Java package name.";
+
+ // validate the package name as well. It must be a fully qualified
+ // java package.
+ String[] packageSegments = mAppName.split("\\."); //$NON-NLS-1$
+ for (String p : packageSegments) {
+ if (p.matches("^[a-zA-Z][a-zA-Z0-9]*") == false) { //$NON-NLS-1$
+ mWarning.setText(packageError);
+ mOkButton.setEnabled(false);
+ return;
+ }
+
+ // lets also display a warning if the package contains upper case
+ // letters.
+ if (p.matches("^[a-z][a-z0-9]*") == false) { //$NON-NLS-1$
+ mWarning.setText("Lower case is recommended for Java packages.");
+ }
+ }
+
+ // the split will not detect the last char being a '.'
+ // so we test it manually
+ if (mAppName.charAt(mAppName.length()-1) == '.') {
+ mWarning.setText(packageError);
+ mOkButton.setEnabled(false);
+ return;
+ }
+
+ // now we test the package name field is not empty.
+ if (mPortNumber == null || mPortNumber.length() == 0) {
+ mWarning.setText("Port Number missing.");
+ mOkButton.setEnabled(false);
+ return;
+ }
+
+ // then we check it only contains digits.
+ if (mPortNumber.matches("[0-9]*") == false) { //$NON-NLS-1$
+ mWarning.setText("Port Number invalid.");
+ mOkButton.setEnabled(false);
+ return;
+ }
+
+ // get the int from the port number to validate
+ long port = Long.valueOf(mPortNumber);
+ if (port >= 32767) {
+ mOkButton.setEnabled(false);
+ return;
+ }
+
+ // check if its in the list of already used ports
+ if (port != mEditPort) {
+ for (Integer i : mPorts) {
+ if (port == i.intValue()) {
+ mWarning.setText("Port already in use.");
+ mOkButton.setEnabled(false);
+ return;
+ }
+ }
+ }
+
+ // at this point there's not error, so we enable the ok button.
+ mOkButton.setEnabled(true);
+ }
+}
diff --git a/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/handlers/StaticPortConfigHandler.java b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/handlers/StaticPortConfigHandler.java
new file mode 100644
index 0000000..ff63aca
--- /dev/null
+++ b/eclipse/plugins/com.android.ide.eclipse.monitor/src/com/android/ide/eclipse/monitor/handlers/StaticPortConfigHandler.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+package com.android.ide.eclipse.monitor.handlers;
+
+import com.android.ide.eclipse.monitor.ddms.StaticPortConfigDialog;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class StaticPortConfigHandler extends AbstractHandler {
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ StaticPortConfigDialog dlg = new StaticPortConfigDialog(HandlerUtil.getActiveShell(event));
+ dlg.open();
+ return null;
+ }
+}
diff --git a/eclipse/scripts/rcp/build.properties b/eclipse/scripts/rcp/build.properties
index 421a5ae..b104b77 100644
--- a/eclipse/scripts/rcp/build.properties
+++ b/eclipse/scripts/rcp/build.properties
@@ -1,13 +1,16 @@
-###############################################################################
-# Copyright (c) 2003, 2009 IBM Corporation and others.
-# All rights reserved. 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
+# Copyright (C) 2012 The Android Open Source Project
#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
+# 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.
############# PRODUCT/PACKAGING CONTROL #############
product=/com.android.ide.eclipse.monitor/monitor.product