- Tun/tap, proxy.
Change-Id: Ic71960d2aca261d958d1986250aadf5ca9849241
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
<property name="swt.file" value="swt.jar" />
<property name="jsch.file" value="jsch-0.1.50.jar" />
<property name="jna.file" value="jna-4.1.0.jar" />
+ <property name="jna-platform.file" value="jna-platform-4.1.0.jar" />
<property name="common.dir" value="common-project" />
<fileset dir="${common.dir}/lib" includes="${jsch.file}" />
<fileset dir="${common.dir}/lib" includes="${proto.file}" />
<fileset dir="${common.dir}/lib" includes="${jna.file}" />
+ <fileset dir="${common.dir}/lib" includes="${jna-platform.file}" />
</path>
<target name="clean">
<fileset file="about.properties" />
<manifest>
<attribute name="Main-Class" value="${mainclass}" />
- <attribute name="Class-path" value="${swt.file} ${jsch.file} ${proto.file} ${jna.file}" />
+ <attribute name="Class-path" value="${swt.file} ${jsch.file} ${proto.file} ${jna.file} ${jna-platform.file}" />
</manifest>
</jar>
</target>
<fileset dir="${classpath.dibs}" includes="${jsch.file}" />
<fileset dir="${classpath.dibs}" includes="${proto.file}" />
<fileset dir="${classpath.dibs}" includes="${jna.file}" />
+ <fileset dir="${classpath.dibs}" includes="${jna-platform.file}" />
</path>
<target name="common-compile-dibs" depends="make-properties">
--- /dev/null
+/* Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.tool;
+
+import java.io.IOException;
+import java.net.Inet4Address;
+import java.net.InterfaceAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Display;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+import org.tizen.emulator.manager.ui.dialog.TapGuideDialogForWin;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.helper.ProcessOutputReader;
+import org.tizen.emulator.manager.vms.helper.ProcessResult;
+import org.tizen.emulator.manager.vms.helper.VMWorkerException;
+
+import com.sun.jna.platform.win32.Advapi32Util;
+import com.sun.jna.platform.win32.Win32Exception;
+import com.sun.jna.platform.win32.WinNT;
+import com.sun.jna.platform.win32.WinReg;
+import com.sun.jna.platform.win32.WinReg.HKEY;
+import com.sun.jna.platform.win32.WinReg.HKEYByReference;
+
+public class TapUtil {
+
+ public static String getBridgeFromDevice(String device)
+ throws VMWorkerException {
+
+ String result = null;
+ if (EmulatorManager.isLinux()) {
+ List<String> cmd = Arrays.asList("brctl", "show");
+ ProcessResult res = HelperClass.runProcess(cmd);
+
+ if (res.isSuccess() == false) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ String parsedBridge = null;
+ String parsedDevice = null;
+ for (String line : res.getStdOutMsg()) {
+ String[] arr = line.split("\\s+");
+ if (arr.length == 4) {
+ parsedBridge = arr[0].trim();
+ parsedDevice = arr[3].trim();
+
+ } else if (arr.length == 2 && arr[0].isEmpty()) {
+ parsedDevice = arr[1].trim();
+
+ } else {
+ continue;
+ }
+ if (device.equals(parsedDevice)) {
+ result = parsedBridge;
+ }
+
+ }
+ }
+
+ return result;
+ }
+
+ public static List<String> getDefaultGateway(String ifName)
+ throws VMWorkerException {
+ List<String> result = new ArrayList<String>();
+
+ if (EmulatorManager.isLinux()) {
+ // If ifName == null, return all default gw.
+ List<String> cmd = Arrays.asList("ip", "route");
+ ProcessResult res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == true) {
+ for (String str : res.getStdOutMsg()) {
+ String[] arr = str.split("\\s+");
+ if (ifName == null) {
+ if (arr.length >= 3) {
+ if (arr[0].equals("default")) {
+ result.add(arr[2]);
+ }
+ }
+
+ } else {
+ if (arr.length >= 5) {
+ if (arr[0].equals("default")
+ && arr[4].equals(ifName)) {
+ result.add(arr[2]);
+ }
+ }
+ }
+ }
+
+ } else {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+ }
+ return result;
+ }
+
+ public static List<String> getBridgeList() throws VMWorkerException {
+ List<String> result = new ArrayList<String>();
+ if (EmulatorManager.isLinux()) {
+ List<String> cmd = Arrays.asList("brctl", "show");
+ ProcessResult res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == true) {
+ for (String str : res.getStdOutMsg()) {
+ String[] arr = str.split("\\s+");
+ if (arr.length > 4)
+ continue; // Skip header line
+ if (!arr[0].isEmpty()) {
+ result.add(arr[0]);
+ }
+ }
+
+ } else {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+ }
+ return result;
+
+ }
+
+ public static List<String> getTapList() {
+ List<String> list = new ArrayList<String>();
+
+ // Get tap device list from Host OS.
+ if (EmulatorManager.isLinux()) {
+ for (String tap : getTapListForLinux()) {
+ try {
+ // Except not-bridged tap.
+ if (getBridgeFromDevice(tap) != null) {
+ list.add(tap);
+ }
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ }
+
+ } else if (EmulatorManager.isWin()) {
+ list = getTapListForWin2();
+
+ } else if (EmulatorManager.isMac()) {
+ // TODO
+ }
+ return list;
+ }
+
+ // Use "ip tuntap" command.
+ // Result is like below.
+ // "tap1: tap one_queue vnet_hdr"
+ // We need "tap1" in result.
+ private static List<String> getTapListForLinux() {
+ List<String> result = new ArrayList<String>();
+ List<String> cmd = Arrays.asList("ip", "tuntap");
+ ProcessResult res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ EMLogger.getLogger().warning(
+ "Get tap list fail. Command returns fail:" + "cmd : "
+ + cmd.toString() + ", return : "
+ + res.getExitValue());
+ } else {
+ for (String line : res.getStdOutMsg()) {
+ String arr[] = line.split(":");
+ if (arr.length > 0) {
+ result.add(arr[0].trim());
+ }
+ }
+ }
+ return result;
+ }
+
+ // Use "openvpn --show-adapters" command.
+ // Result is like below.
+ // "'Local Area Connection 2' {9BDB05CA-...}"
+ // We need "Local Area Connection 2" in result.
+ @Deprecated
+ private static List<String> getTapListForWin() {
+ List<String> result = new ArrayList<String>();
+ List<String> cmd = new ArrayList<String>();
+ ProcessBuilder pb = new ProcessBuilder(new String[] { "openvpn",
+ "--show-adapters" });
+ int exitValue = 0;
+ Process process;
+ try {
+ process = pb.start();
+ List<String> stdOut = ProcessOutputReader.readStdOut(process,
+ cmd.toString());
+ exitValue = process.waitFor();
+
+ if (exitValue != 0) {
+ EMLogger.getLogger().warning(
+ "Get tap list fail. Command returns fail:" + "cmd : "
+ + cmd.toString() + ", return : " + exitValue);
+ } else {
+ for (String line : stdOut) {
+ if (line.contains("'")) {
+ String arr[] = line.split("'");
+ if (arr.length >= 2) {
+ result.add(arr[1].trim());
+ }
+ }
+ }
+ }
+
+ } catch (IOException e) {
+ EMLogger.getLogger()
+ .warning("Get tap list fail. " + e.getMessage());
+ e.printStackTrace();
+
+ } catch (InterruptedException e) {
+ EMLogger.getLogger()
+ .warning("Get tap list fail. " + e.getMessage());
+ e.printStackTrace();
+ }
+
+ return result;
+ }
+
+ private static List<String> getTapListForWin2() {
+ List<String> tapNameList = new ArrayList<String>();
+ List<String> tapIdList = getTapIdList();
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
+ String key = "Connection";
+ String value = "Name";
+ HKEYByReference regKey = null;
+ try {
+ regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
+ String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
+ for (String subKey : subKeys) {
+ for (String tapId : tapIdList) {
+ if (subKey.equals(tapId)) {
+ String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + "\\" + subKey);
+ for (String subKey2 : subKeys2) {
+ if (subKey2.equals(key)) {
+ String tapName = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey + "\\" + key, value);
+ if (tapName != null) {
+ tapNameList.add(tapName);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ } catch (Win32Exception e) {
+
+ } finally {
+ if (regKey != null) {
+ Advapi32Util.registryCloseKey(regKey.getValue());
+ }
+ }
+
+ return tapNameList;
+ }
+
+ private static List<String> getTapIdList() {
+
+ List<String> tapIdList = new ArrayList<String>();
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey= "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
+
+ String value1 = "ComponentId";
+ String value2 = "NetCfgInstanceId";
+ HKEYByReference regKey = null;
+ try {
+ regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
+ String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
+ for (String subKey : subKeys) {
+ String compId = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey, value1);
+ String tapId = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey, value2);
+ if (compId != null && tapId != null) {
+ if (compId.startsWith("tap")) {
+ tapIdList.add(tapId);
+ }
+ }
+ }
+
+ } catch (Win32Exception e) {
+
+ } finally {
+ if (regKey != null) {
+ Advapi32Util.registryCloseKey(regKey.getValue());
+ }
+ }
+
+ return tapIdList;
+ }
+
+ public static boolean isTapInBridge(String tapName) {
+ boolean result = false;
+ if (EmulatorManager.isWin()) {
+ String foundTapId = null;
+ List<String> tapIdList = getTapIdList();
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey = "SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}";
+ String key = "Connection";
+ String value = "Name";
+ HKEYByReference regKey = null;
+ try {
+ regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
+ String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
+ for (String subKey : subKeys) {
+ for (String tapId : tapIdList) {
+ if (subKey.equals(tapId)) {
+ String[] subKeys2 = Advapi32Util.registryGetKeys(root, topKey + "\\" + subKey);
+ for (String subKey2 : subKeys2) {
+ if (subKey2.equals(key)) {
+ String name = Advapi32Util.registryGetStringValue(root, topKey + "\\" + subKey + "\\" + key, value);
+ if (name != null) {
+ if (name.equals(tapName)) {
+ foundTapId = tapId;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ topKey = "SYSTEM\\CurrentControlSet\\services\\Bridge\\Linkage";
+ value = "Route";
+ String valueArr[] = Advapi32Util.registryGetStringArray(root, topKey, value);
+ for (String str : valueArr) {
+ if (str.replace("\"", "").equals(foundTapId)) {
+ result = true;
+ break;
+ }
+ }
+
+ } catch (Win32Exception e) {
+
+ } finally {
+ if (regKey != null) {
+ Advapi32Util.registryCloseKey(regKey.getValue());
+ }
+ }
+
+ } else if (EmulatorManager.isLinux())
+ try {
+ if (getBridgeFromDevice(tapName) != null)
+ result = true;
+ } catch (VMWorkerException e) {
+ (new MessageDialog()).openWarningDialog(e.getMessage());
+ }
+ return result;
+ }
+
+ public static String getNetmaskFromTap(String tapName) {
+ String netMask = "";
+ if (EmulatorManager.isLinux())
+ try {
+ String bridge = getBridgeFromDevice(tapName);
+ InterfaceAddress addr = getInterfaceIpInfo(bridge);
+ if (addr != null)
+ netMask = getNetMask(addr.getNetworkPrefixLength());
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
+ HKEY key = getBridgeTcpipKey();
+ if (key != null) {
+ try {
+ String data[] = Advapi32Util.registryGetStringArray(key, "SubnetMask");
+ if (data.length > 0) {
+ netMask = data[0];
+ }
+
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(key);
+ }
+ }
+
+ if (netMask.isEmpty()) {
+ key = getInterfaceTcpipKey(getBridgeId());
+ if (key != null) {
+ try {
+ String data[] = Advapi32Util.registryGetStringArray(key, "SubnetMask");
+ if (data.length > 0) {
+ netMask = data[0];
+ }
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(key);
+ }
+ }
+ }
+ }
+ return netMask;
+ }
+
+ private static HKEY getBridgeTcpipKey() {
+ HKEY resultKey = null;
+ String bridgeId = getBridgeId();
+ if (bridgeId == null) {
+ return resultKey;
+ }
+
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey = "SYSTEM\\CurrentControlSet\\services";
+ HKEYByReference regKey = null;
+ try {
+ regKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ);
+ String[] subKeys = Advapi32Util.registryGetKeys(regKey.getValue());
+ for (String subKey : subKeys) {
+ if (subKey.equals(bridgeId)) {
+ resultKey = Advapi32Util.registryGetKey(root,
+ topKey + "\\" + subKey + "\\Parameters\\Tcpip", WinNT.KEY_READ).getValue();
+ break;
+ }
+ }
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ if (regKey != null) {
+ Advapi32Util.registryCloseKey(regKey.getValue());
+ }
+ }
+ return resultKey;
+ }
+
+ private static HKEY getInterfaceTcpipKey(String ifId) {
+ if (ifId == null) {
+ return null;
+ }
+ HKEY resultKey = null;
+
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey = "SYSTEM\\CurrentControlSet\\services\\Tcpip\\Parameters\\Interfaces"
+ + "\\" + ifId;
+
+ try {
+ resultKey = Advapi32Util.registryGetKey(root, topKey, WinNT.KEY_READ).getValue();
+
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ return resultKey;
+ }
+
+ private static String getBridgeId() {
+ String bridgeId = null;
+ if (EmulatorManager.isWin()) {
+ HKEY root = WinReg.HKEY_LOCAL_MACHINE;
+ String topKey = "SYSTEM\\CurrentControlSet\\services\\BridgeMP";
+ String value = "Device";
+ try {
+ String data = Advapi32Util.registryGetStringValue(root, topKey, value);
+ if (data != null) {
+ String arr[] = data.split("\\\\");
+ bridgeId = arr[arr.length - 1];
+ }
+ } catch (Win32Exception e) {
+
+ }
+ }
+ return bridgeId;
+ }
+
+ public static String getGatewayFromTap(String tapName) {
+ String gateway = "";
+ if (EmulatorManager.isLinux())
+ try {
+ List gwList = getDefaultGateway(getBridgeFromDevice(tapName));
+ if (gwList.size() == 1)
+ gateway = (String) gwList.get(0);
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
+ HKEY key = getBridgeTcpipKey();
+ if (key != null) {
+ try {
+ String data[] = Advapi32Util.registryGetStringArray(key, "DefaultGateway");
+ if (data.length > 0) {
+ gateway = data[0];
+ }
+
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(key);
+ }
+ }
+
+ if (gateway.isEmpty()) {
+ key = getInterfaceTcpipKey(getBridgeId());
+ if (key != null) {
+ try {
+ String data[] = Advapi32Util.registryGetStringArray(key, "DefaultGateway");
+ if (data.length > 0) {
+ gateway = data[0];
+ }
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(key);
+ }
+ }
+ }
+ }
+ return gateway;
+ }
+
+ public static String getDnsFromTap(String tapName) {
+ String dns="";
+ if (EmulatorManager.isLinux()) {
+ dns = getDnsForLinux(tapName);
+
+ } else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
+ dns = getDnsForWin(tapName);
+ }
+ return dns;
+ }
+
+ private static String getDnsForLinux(String tapName) {
+ String brName = null;
+ try {
+ brName = getBridgeFromDevice(tapName);
+
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning("Get dns failed. " + e.getMessage());
+ return "";
+ }
+
+ if (brName == null) {
+ return "";
+ }
+
+ List<String> cmd = Arrays.asList("nm-tool", brName);
+ ProcessResult res = HelperClass.runProcess(cmd);
+ if (!res.isSuccess()) {
+ EMLogger.getLogger().warning("Get dns failed. " + res.getResultMessage());
+ return "";
+ }
+
+ for (String line : res.getStdOutMsg()) {
+ String[] arr = line.split("\\s+");
+ if (arr.length >= 3) {
+ if (arr[1].trim().startsWith("DNS")) {
+ return arr[2].trim();
+ }
+ }
+ }
+
+ return "";
+ }
+
+ private static String getDnsForWin(String tapName) {
+ String dns = "";
+ HKEY key = getInterfaceTcpipKey(getBridgeId());
+ if (key != null) {
+ try {
+ String val = Advapi32Util.registryGetStringValue(key, "NameServer");
+ String[] arr = val.split(",");
+ if (arr.length > 0) {
+ dns = arr[0];
+ }
+
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(key);
+ }
+ }
+
+ return dns;
+ }
+
+
+ // return ip, broadcast, mask-length
+ public static InterfaceAddress getInterfaceIpInfo(String ifName) {
+ Enumeration<NetworkInterface> interfaces;
+ try {
+ interfaces = NetworkInterface.getNetworkInterfaces();
+ if (interfaces != null) {
+ while (interfaces.hasMoreElements()) {
+ NetworkInterface current = interfaces.nextElement();
+ if (current.getName().equals(ifName)) {
+ for (InterfaceAddress addr : current
+ .getInterfaceAddresses()) {
+ if (addr.getAddress() instanceof Inet4Address) {
+ return addr;
+ }
+ }
+ }
+ }
+ }
+ } catch (SocketException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ return null;
+ }
+
+ public static String getNetMask(int maskLength) {
+ StringBuilder netMaskAddr = new StringBuilder();
+ int val = maskLength / 8;
+ int mod = maskLength % 8;
+ int count = 0;
+
+ for (int i = 0; i < val; i++) {
+ if (i > 0) {
+ netMaskAddr.append(".");
+ }
+ netMaskAddr.append("255");
+ count++;
+ }
+
+ if (mod != 0) {
+ int modMask = 0;
+ for (int i = 7; i > 7 - mod; i--) {
+ modMask += Math.pow(2, i);
+ }
+ netMaskAddr.append(".").append(String.valueOf(modMask));
+ count++;
+ }
+
+ for (; count < 4; count++) {
+ netMaskAddr.append(".0");
+ }
+
+ return netMaskAddr.toString();
+ }
+
+ static private final String IPV4_REGEX = "(([0-1]?[0-9]{1,2}\\.)|(2[0-4][0-9]\\.)|(25[0-5]\\.)){3}(([0-1]?[0-9]{1,2})|(2[0-4][0-9])|(25[0-5]))";
+ static private Pattern IPV4_PATTERN = Pattern.compile(IPV4_REGEX);
+
+ public static boolean checkIPString(boolean widgetEnable, String ip,
+ String title) {
+ boolean result = true;
+ String errMsg = "";
+ if (widgetEnable == true) {
+ if (ip == null || ip.isEmpty()) {
+ errMsg = title + " cannot be empty!";
+ result = false;
+
+ } else {
+ result = IPV4_PATTERN.matcher(ip).matches();
+ if (result == false) {
+ errMsg = title + " is invalid!";
+ }
+ }
+ }
+
+ HelperClass.setStatusBar(errMsg);
+ return result;
+ }
+
+ public static boolean checkIP(String ip) {
+ return IPV4_PATTERN.matcher(ip).matches();
+ }
+
+ public static boolean nameNotExist(String tapName) {
+ boolean isNotExist = true;
+ List<String> tapList = null;
+
+ if (EmulatorManager.isWin()) {
+ tapList = getTapListForWin2();
+
+ } else if (EmulatorManager.isLinux()) {
+ tapList = getTapListForLinux();
+ }
+
+ if (tapList != null) {
+ for (String str : tapList) {
+ if (str.equals(tapName)) {
+ isNotExist = false;
+ break;
+ }
+ }
+ }
+ return isNotExist;
+ }
+
+ public static void createTapDevice(String tapName,
+ ComboViewItem comboViewItem) {
+ if (EmulatorManager.isWin()) {
+ MessageDialog msgDialog = new MessageDialog();
+ msgDialog
+ .openNoButtonInfoDialog("Creating tap device.\nThis will take few seconds..");
+ TapCreateWorker worker = new TapCreateWorker(tapName, msgDialog,
+ comboViewItem);
+ worker.start();
+ }
+
+ }
+
+ public static String getBridgeIpAddr(String tapName) {
+ String ipAddr = null;
+ if (EmulatorManager.isLinux())
+ try {
+ InterfaceAddress ifAddr = getInterfaceIpInfo(getBridgeFromDevice(tapName));
+ if (ifAddr != null)
+ ipAddr = ifAddr.getAddress().getHostAddress();
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning(
+ (new StringBuilder())
+ .append("Failed to get bridge ip address. ")
+ .append(e.getMessage()).toString());
+ }
+ else if (EmulatorManager.isWin() && isTapInBridge(tapName)) {
+ HKEY key = getBridgeTcpipKey();
+ if (key != null) {
+ try {
+ String data[] = Advapi32Util.registryGetStringArray(key, "IPAddress");
+ if (data.length > 0) {
+ ipAddr = data[0];
+ }
+
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(key);
+ }
+ }
+
+ if (ipAddr == null) {
+ key = getInterfaceTcpipKey(getBridgeId());
+ if (key != null) {
+ try {
+ String data[] = Advapi32Util.registryGetStringArray(key, "IPAddress");
+ if (data.length > 0) {
+ ipAddr = data[0];
+ }
+ } catch (Win32Exception e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ } finally {
+ Advapi32Util.registryCloseKey(key);
+ }
+ }
+ }
+ }
+ return ipAddr;
+ }
+
+ public static boolean isValidTap(String tapName) throws VMWorkerException {
+ if (getGatewayFromTap(tapName).isEmpty()) {
+ return false;
+ }
+ if (getNetmaskFromTap(tapName).isEmpty()) {
+ return false;
+ }
+ return getBridgeIpAddr(tapName) != null;
+ }
+
+ public static String getAvailableTapName() {
+ List<String> list = null;
+ if (EmulatorManager.isLinux()) {
+ list = getTapListForLinux();
+
+ } else if (EmulatorManager.isWin()) {
+ list = getTapListForWin2();
+ }
+
+ String newName = "";
+ if (list != null) {
+ for (int i = 1;; i++) {
+ newName = "tap" + String.valueOf(i);
+ boolean nameIsSame = false;
+ for (String tap : list) {
+ if (newName.equals(tap)) {
+ nameIsSame = true;
+ break;
+ }
+ }
+ if (!nameIsSame) {
+ break;
+ }
+ }
+ }
+
+ return newName;
+ }
+}
+
+class TapCreateWorker extends Thread {
+
+ final MessageDialog dialog;
+ final String tapName;
+ final ComboViewItem comboViewItem; // for refresh combo-list
+
+ public TapCreateWorker(String tapName, MessageDialog dialog,
+ ComboViewItem comboViewItem) {
+ this.dialog = dialog;
+ this.tapName = tapName;
+ this.comboViewItem = comboViewItem;
+ }
+
+ @Override
+ public void run() {
+ // Create tap device
+ // - Create tap device and rename(user input name) because
+ // windows OS generate device name automatically.
+ // - For rename, inquire tap list before and after create and
+ // compare both to find what is new one.
+ try {
+ // 1. Get tap list before create new tap.
+ List<String> before = TapUtil.getTapList();
+ try { // TODO for test
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ // 2. Create tap
+ List<String> cmd = Arrays.asList("tapinstall", "install",
+ "OemVista.inf", "Tap0901");
+ ProcessResult res = HelperClass.runProcess(cmd);
+
+ if (!res.isSuccess()) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ // 3. Get tap list and find new one.
+ List<String> after = TapUtil.getTapList();
+ String newOne = null;
+ for (String str : after) {
+ if (!before.contains(str)) {
+ newOne = str;
+ break;
+ }
+ }
+
+ if (newOne == null) {
+ throw new VMWorkerException(
+ "Tap create fail. Cannot find new tap device.");
+ }
+
+ // 4. Rename
+ cmd = Arrays.asList("netsh", "interface", "set", "interface",
+ "name=" + newOne, "newname=" + tapName);
+ res = HelperClass.runProcess(cmd);
+ if (!res.isSuccess()) {
+ throw new VMWorkerException(res.getResultMessage());
+ }
+
+ // 5. Check tap create in success.
+ boolean isTapExist = false;
+ for (String str : TapUtil.getTapList()) {
+ if (str.equals(tapName)) {
+ isTapExist = true;
+ }
+ }
+
+ final MessageDialog resultDialog = new MessageDialog();
+ if (isTapExist) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ int res = resultDialog
+ .openSelectionDialog("Tap device created : "
+ + tapName
+ + "\nDo you want to see the guide for bridge network ?");
+ if (res == SWT.OK) {
+ // Show bridge guide dialog
+ TapGuideDialogForWin.open();
+ }
+ }
+ });
+
+ } else {
+ throw new VMWorkerException("Tap is not exist : " + tapName);
+ }
+
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning("Failed to create tap device.");
+ EMLogger.getLogger().warning(e.getMessage());
+ final String msg = e.getMessage();
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ new MessageDialog()
+ .openWarningDialog("\nFailed to create tap device.\n\n"
+ + msg);
+ }
+ });
+
+ } finally {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ dialog.close();
+ comboViewItem.resetCombo();
+ }
+ });
+ }
+
+ }
+}
public static String ITEM_FILE_SHARE = "fileShare";
public static String ITEM_HW_SUPPORT = "hwSupport";
public static String ITEM_PROCESSORS = "processors";
+ public static String ITEM_NET_CONFIG = "netConfig";
+ public static String ITEM_NET_PROXY = "proxy";
+ public static String ITEM_NET_CONNECT_TYPE = "netConnectType";
+ public static String ITEM_NET_TAP_DEVICE = "netTapDevice";
+ public static String ITEM_NET_IP_INFO = "netIpInfo";
+ public static String ITEM_NET_DNS = "netDns";
+ public static String ITEM_NET_MAC = "netMac";
public static ObjectFactory factory = new ObjectFactory();
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import org.eclipse.swt.events.SelectionEvent;
+
+import org.eclipse.swt.events.SelectionListener;
+import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+
+public class NetConnectTypeViewItem extends ComboViewItem {
+
+ public static final String VALUE_NAT = "NAT";
+ public static final String VALUE_BRIDGE = "Bridge";
+
+ public NetConnectTypeViewItem(Item template,
+ LineLabelViewItem lineLabelViewItem) {
+ super(template, lineLabelViewItem);
+ lineLabelViewItem.addItem(name, this);
+ }
+
+ @Override
+ protected void addWidgetListener() {
+ combo.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ newValue = combo.getText();
+
+ // Disable / enable following item - bridge name, ip info, dns
+ AdvancedViewItem item = lineLabelViewItem
+ .getItem(CommonItemListFactory.ITEM_NET_IP_INFO);
+ if (item != null && item instanceof NetIPInfoViewItem) {
+ ((NetIPInfoViewItem) item).resetSubItems(newValue);
+ }
+
+ item = lineLabelViewItem
+ .getItem(CommonItemListFactory.ITEM_NET_TAP_DEVICE);
+ if (item != null && item instanceof NetTapDeviceViewItem) {
+ ((NetTapDeviceViewItem) item).resetCombo(newValue);
+ }
+
+ item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_DNS);
+ if (item != null && item instanceof NetDnsViewItem) {
+ ((NetDnsViewItem) item).resetText(newValue);
+ }
+
+ item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_MAC);
+ if (item != null && item instanceof NetMacViewItem) {
+ ((NetMacViewItem) item).resetText(newValue);
+ }
+
+ if (isCreateMode()) {
+ getListener().changeConfirmButton();
+
+ } else {
+ getListener().changeConfirmButton(getThis());
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+ }
+ });
+ }
+
+ public String getValue() {
+ return newValue;
+ }
+
+ @Override
+ public boolean settingModifyItem(VMPropertyValue value) {
+
+ if (isCreateMode()) {
+ newValue = VALUE_NAT; // TODO use template option
+ // (defaultOnCreate)..
+ } else {
+ newValue = getItemValue(value);
+ }
+
+ // makeComboBox
+ if (comboOptions != null) {
+ if (combo != null) {
+ combo.removeAll();
+ }
+ for (String option : comboOptions) {
+ combo.add(option);
+ }
+ }
+
+ // Select combo-box item.
+ int index = -1;
+ for (int i = 0; i < comboOptions.size(); i++) {
+ if (comboOptions.get(i).equals(newValue)) {
+ index = i;
+ break;
+ }
+ }
+ if (comboOptions.size() > 0) {
+ if (index == -1) {
+ // if value not matches..
+ combo.select(0);
+ newValue = combo.getItem(0);
+ } else {
+ combo.select(index);
+ }
+ }
+ return true;
+ }
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.ItemChangeState;
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.TextViewItem;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+
+public class NetDnsViewItem extends TextViewItem {
+
+ public NetDnsViewItem(Item template, LineLabelViewItem lineLabelViewItem) {
+ super(template, lineLabelViewItem);
+ lineLabelViewItem.addItem(name, this);
+ }
+
+ public void setDns(String dns) {
+ newValue = oldValue = dns;
+ text.setText(dns);
+ }
+
+ public String getDns() {
+ return newValue;
+ }
+
+ public void resetText(String connectType) {
+ if (connectType.equals(NetConnectTypeViewItem.VALUE_NAT)) {
+ // disable text input
+ text.setEnabled(false);
+ oldValue = newValue; // save
+ newValue = "";
+
+ } else if (connectType.equals(NetConnectTypeViewItem.VALUE_BRIDGE)) {
+ // enable text input
+ text.setEnabled(true);
+ newValue = oldValue; // restore
+ }
+
+ text.setText(newValue);
+ }
+
+ @Override
+ public boolean settingModifyItem(VMPropertyValue value) {
+
+ if (isCreateMode()) {
+ oldValue = newValue = "";
+ } else {
+ oldValue = newValue = value.getAdvancedOptionValue(name);
+ }
+ text.setText(newValue);
+
+ AdvancedViewItem item = lineLabelViewItem
+ .getItem(CommonItemListFactory.ITEM_NET_CONNECT_TYPE);
+ if (item != null && item instanceof NetConnectTypeViewItem) {
+ String connectType = ((NetConnectTypeViewItem) item).getValue();
+ resetText(connectType);
+ }
+
+ // If use DHCP, set disabled.
+ item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_IP_INFO);
+ if (item != null && item instanceof NetIPInfoViewItem) {
+ if (((NetIPInfoViewItem)item).useDHCP()) {
+ setEnabled(false);
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void addListener() {
+ text.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ newValue = text.getText();
+
+ if (isCreateMode()) {
+ getListener().changeConfirmButton();
+ } else {
+ getListener().changeConfirmButton(getThis());
+ }
+ }
+ });
+
+ text.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent event) {
+ switch (event.keyCode) {
+ case SWT.CR:
+ case SWT.KEYPAD_CR:
+ // TODO
+ getListener().ChangeState(ItemChangeState.CREATE);
+ break;
+ case SWT.ESC:
+ getListener().ChangeState(ItemChangeState.CANCEL);
+ break;
+ default:
+ // TODO
+ break;
+ }
+ }
+ });
+ }
+
+ @Override
+ public boolean checkValue() {
+ return TapUtil.checkIPString(text.isEnabled(), newValue, title);
+ }
+
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Composite;
+import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.template.CheckSubViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.ISubViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.LabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.TextSubViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.TextViewItem;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+
+public class NetIPInfoDHCPSubViewItem extends CheckSubViewItem {
+
+ public NetIPInfoDHCPSubViewItem(LabelViewItem parentItem, Composite comp,
+ Item template, boolean isOdd) {
+ super(parentItem, comp, template, isOdd);
+ defaultIfEmpty = false;
+ }
+
+ public void resetCheckbox(String connectType) {
+ if (modifyEnable == true) { // config from template.
+ if (connectType.equals(NetConnectTypeViewItem.VALUE_NAT)) {
+ setCheckBox(false);
+ setEnabled(false);
+
+ } else if (connectType.equals(NetConnectTypeViewItem.VALUE_BRIDGE)) {
+// setCheckBox(newValue ? true : false);
+ setEnabled(true);
+ }
+ }
+ }
+
+ @Override
+ public boolean settingModifyItem(VMPropertyValue value) {
+
+ // Set value.
+ String val = getModifyValue(value);
+ newValue = oldValue = checkOnOff(val);
+
+ // Set enable/disable
+ if (parentItem.isCreateMode() && disableOnCreate) {
+ setEnabled(false);
+ } else {
+ setEnabled(true);
+ }
+
+ setItemState();
+
+ AdvancedViewItem item = parentItem.getLineLabelViewItem().getItem(
+ CommonItemListFactory.ITEM_NET_CONNECT_TYPE);
+ if (item != null && item instanceof NetConnectTypeViewItem) {
+ String connectType = ((NetConnectTypeViewItem) item).getValue();
+ resetCheckbox(connectType);
+ }
+
+ // Set checkbox state.
+ if (modifyEnable) {
+ modifyCheckBox.setChecked(newValue);
+ }
+ setIPInfoEnabled(newValue ? false : true); // Disabled if "checked".
+
+ return false;
+ }
+
+ @Override
+ protected void addCheckboxListener() {
+ modifyCheckBox.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (modifyCheckBox.isSelection()) {
+ newValue = true;
+ setIPInfoEnabled(false);
+
+ } else { // ON
+ newValue = false;
+ setIPInfoEnabled(true);
+ }
+
+ if (parentItem.isCreateMode()) {
+ parentItem.getListener().changeConfirmButton();
+ } else {
+ parentItem.getListener().changeConfirmButton(
+ parentItem.getThis());
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ // TODO Auto-generated method stub
+ }
+ });
+ }
+
+ public void setIPInfoEnabled(boolean enabled) {
+ // Enable/Disable ip setting
+ if (parentItem instanceof NetIPInfoViewItem) {
+ NetIPInfoViewItem item = (NetIPInfoViewItem)parentItem;
+ for (ISubViewItem subItem : item.getSubItemList()) {
+ if (subItem instanceof TextSubViewItem) {
+ ((TextSubViewItem) subItem).resetText(enabled);
+ }
+ }
+ }
+ // Enable/Disable DNS setting
+ AdvancedViewItem dnsItem = parentItem.getLineLabelViewItem().getItem(CommonItemListFactory.ITEM_NET_DNS);
+ if (dnsItem != null && dnsItem instanceof TextViewItem) {
+ ((TextViewItem) dnsItem).resetText(enabled);
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.widgets.Composite;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.ItemChangeState;
+import org.tizen.emulator.manager.ui.detail.item.template.LabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.TextSubViewItem;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+
+public class NetIPInfoTextSubViewItem extends TextSubViewItem {
+
+ private boolean alreadyChanged;
+
+ public void setAlreadyChanged(boolean changed) {
+ alreadyChanged = changed;
+ }
+
+ public NetIPInfoTextSubViewItem(LabelViewItem parentItem, Composite comp,
+ Item template) {
+ super(parentItem, comp, template);
+ }
+
+ public void setText(String value) {
+ oldValue = newValue = value;
+ text.setText(value);
+ }
+
+ public void resetText(String connectType) {
+ if (connectType.equals(NetConnectTypeViewItem.VALUE_NAT)) {
+ resetText(false);
+
+ } else if (connectType.equals(NetConnectTypeViewItem.VALUE_BRIDGE)) {
+ resetText(true);
+ }
+ }
+
+ @Override
+ public boolean settingModifyItem(VMPropertyValue value) {
+
+ if (parentItem.isCreateMode()) {
+ oldValue = newValue = "";
+ } else {
+ if (!alreadyChanged) {
+ oldValue = newValue = value.getAdvancedOptionSubValue(
+ parentItem.getName(), name);
+ }
+ }
+ text.setText(newValue);
+
+ AdvancedViewItem item = parentItem.getLineLabelViewItem().getItem(
+ CommonItemListFactory.ITEM_NET_CONNECT_TYPE);
+ if (item != null && item instanceof NetConnectTypeViewItem) {
+ String connectType = ((NetConnectTypeViewItem) item).getValue();
+ resetText(connectType);
+ }
+
+ // If use DHCP, set disabled.
+ if (parentItem instanceof NetIPInfoViewItem) {
+ NetIPInfoViewItem netItem = (NetIPInfoViewItem)parentItem;
+ if (netItem.useDHCP()) {
+ setEnabled(false);
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void addListener() {
+
+ text.addFocusListener(new FocusListener() {
+
+ @Override
+ public void focusGained(FocusEvent arg0) {
+ if (name.equals(NetIPInfoViewItem.ITEM_IP)) {
+ String tapName = null;
+ AdvancedViewItem item = parentItem.getLineLabelViewItem()
+ .getItem(CommonItemListFactory.ITEM_NET_TAP_DEVICE);
+ if (item instanceof NetTapDeviceViewItem)
+ tapName = ((NetTapDeviceViewItem) item).getValue();
+
+ // Set subnet, gateway if empty.
+ if (tapName != null || tapName.isEmpty()) {
+ item = parentItem.getLineLabelViewItem().getItem(
+ CommonItemListFactory.ITEM_NET_IP_INFO);
+ if (item instanceof NetIPInfoViewItem) {
+ NetIPInfoViewItem netIPItem = (NetIPInfoViewItem) item;
+ String subnet = TapUtil.getNetmaskFromTap(tapName);
+ if (subnet == null || subnet.isEmpty()) {
+ netIPItem.setSubnet("");
+
+ } else if (netIPItem.getSubnet() == null
+ || netIPItem.getSubnet().isEmpty()) {
+ netIPItem.setSubnet(subnet);
+ }
+
+ String gateway = TapUtil.getGatewayFromTap(tapName);
+ if (gateway == null || gateway.isEmpty()) {
+ netIPItem.setGateway("");
+
+ } else if (netIPItem.getGateway() == null
+ || netIPItem.getGateway().isEmpty()) {
+ netIPItem.setGateway(gateway);
+ }
+ }
+
+ // Set DNS if empty.
+ item = parentItem.getLineLabelViewItem().getItem(
+ CommonItemListFactory.ITEM_NET_DNS);
+ if (item instanceof NetDnsViewItem) {
+ NetDnsViewItem netDnsItem = (NetDnsViewItem)item;
+ String dns = TapUtil.getDnsFromTap(tapName);
+ if (dns == null || dns.isEmpty()) {
+ netDnsItem.setDns("");
+
+ } else if (netDnsItem.getDns() == null || netDnsItem.getDns().isEmpty()) {
+ netDnsItem.setDns(dns);
+ }
+ }
+ }
+ }
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void focusLost(FocusEvent arg0) {
+ // TODO Auto-generated method stub
+
+ }
+ });
+
+ text.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ newValue = text.getText();
+ if (parentItem.isCreateMode()) {
+ parentItem.getListener().changeConfirmButton();
+ } else {
+ parentItem.getListener().changeConfirmButton(
+ parentItem.getThis());
+ }
+ }
+ });
+
+ text.addKeyListener(new KeyAdapter() {
+ public void keyPressed(KeyEvent event) {
+ switch (event.keyCode) {
+ case SWT.CR:
+ case SWT.KEYPAD_CR:
+ // TODO
+ parentItem.getListener()
+ .ChangeState(ItemChangeState.CREATE);
+ break;
+ case SWT.ESC:
+ parentItem.getListener()
+ .ChangeState(ItemChangeState.CANCEL);
+ break;
+ default:
+ // TODO
+ break;
+ }
+ }
+ });
+ }
+
+ public String getValue() {
+ return newValue;
+ }
+
+ public boolean checkValue() {
+ return TapUtil.checkIPString(text.isEnabled(), newValue, title);
+ }
+
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.CheckSubViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.ISubViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.LabelViewItem;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+
+public class NetIPInfoViewItem extends LabelViewItem {
+
+ public static final String ITEM_IP = "ipAddr";
+ public static final String ITEM_SUBNET = "subnet";
+ public static final String ITEM_GATEWAY = "gateway";
+ public static final String ITEM_USE_DHCP = "useDHCP";
+
+ public boolean useDHCP() {
+ boolean useDHCP = false;
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem.getName().equals(ITEM_USE_DHCP)) {
+ useDHCP = ((NetIPInfoDHCPSubViewItem) subItem).getValue();
+ }
+ }
+ return useDHCP;
+ }
+
+ public void setIPAddress(String ipAddress) {
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem.getName().equals(ITEM_IP)) {
+ ((NetIPInfoTextSubViewItem) subItem).setText(ipAddress);
+ }
+ }
+ }
+
+ public void setSubnet(String subnet) {
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem.getName().equals(ITEM_SUBNET)) {
+ ((NetIPInfoTextSubViewItem) subItem).setText(subnet);
+ }
+ }
+ }
+
+ public void setGateway(String gateway) {
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem.getName().equals(ITEM_GATEWAY)) {
+ ((NetIPInfoTextSubViewItem) subItem).setText(gateway);
+ }
+ }
+ }
+
+ public String getIpAddress() {
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem.getName().equals(ITEM_IP)) {
+ return ((NetIPInfoTextSubViewItem) subItem).getValue();
+ }
+ }
+ return null;
+ }
+
+ public String getSubnet() {
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem.getName().equals(ITEM_SUBNET)) {
+ return ((NetIPInfoTextSubViewItem) subItem).getValue();
+ }
+ }
+ return null;
+ }
+
+ public String getGateway() {
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem.getName().equals(ITEM_GATEWAY)) {
+ return ((NetIPInfoTextSubViewItem) subItem).getValue();
+ }
+ }
+ return null;
+ }
+
+ public NetIPInfoViewItem(Item template, LineLabelViewItem lineLabelViewItem) {
+ super(template, lineLabelViewItem);
+ lineLabelViewItem.addItem(name, this);
+ }
+
+ public void resetSubItems(String connectType) {
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem instanceof NetIPInfoTextSubViewItem) {
+ ((NetIPInfoTextSubViewItem) subItem).resetText(connectType);
+
+ } else if (subItem instanceof NetIPInfoDHCPSubViewItem) {
+ ((NetIPInfoDHCPSubViewItem) subItem).resetCheckbox(connectType);
+ }
+ }
+ if (connectType.equals(NetConnectTypeViewItem.VALUE_NAT)) {
+ // TODO hide
+ // hideItem();
+ } else {
+ // TODO show
+ // showItem();
+ }
+ }
+
+ @Override
+ protected List<ISubViewItem> getSubItemList() {
+ if (subItemList == null) {
+ subItemList = new ArrayList<ISubViewItem>();
+
+ List<Item> itemList = template.getItem();
+ int i = 0;
+ for (Item item : itemList) {
+ String itemName = item.getName();
+ if (itemName.equals(ITEM_USE_DHCP)) {
+ subItemList.add(new NetIPInfoDHCPSubViewItem(this, compList
+ .get(i++), item, true));
+
+ } else if (itemName.equals(ITEM_IP)) {
+ subItemList.add(new NetIPInfoTextSubViewItem(this, compList
+ .get(i++), item));
+
+ } else if (itemName.equals(ITEM_SUBNET)) {
+ subItemList.add(new NetIPInfoTextSubViewItem(this, compList
+ .get(i++), item));
+
+ } else if (itemName.equals(ITEM_GATEWAY)) {
+ subItemList.add(new NetIPInfoTextSubViewItem(this, compList
+ .get(i++), item));
+ }
+ }
+ }
+ return subItemList;
+ }
+
+ @Override
+ protected int getSubItemCount(Item template) {
+ List<Item> itemList = template.getItem();
+ int count = 0;
+ for (Item item : itemList) {
+ String itemName = item.getName();
+ if (itemName.equals(ITEM_USE_DHCP)) {
+ count++;
+ } else if (itemName.equals(ITEM_IP)) {
+ count++;
+ } else if (itemName.equals(ITEM_SUBNET)) {
+ count++;
+ } else if (itemName.equals(ITEM_GATEWAY)) {
+ count++;
+ }
+ }
+ return count;
+ }
+
+ @Override
+ public boolean checkValue() {
+ boolean isValid = true;
+
+ for (ISubViewItem subItem : getSubItemList()) {
+ if (subItem instanceof NetIPInfoTextSubViewItem) {
+ isValid = ((NetIPInfoTextSubViewItem) subItem).checkValue();
+ if (!isValid) {
+ break;
+ }
+ }
+ }
+
+ return isValid;
+
+ }
+
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import java.util.Random;
+import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.TextViewItem;
+import org.tizen.emulator.manager.vms.EmulatorVMList;
+import org.tizen.emulator.manager.vms.VMProperty;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+
+public class NetMacViewItem extends TextViewItem {
+
+ public NetMacViewItem(Item template, LineLabelViewItem lineLabelViewItem) {
+ super(template, lineLabelViewItem);
+ lineLabelViewItem.addItem(name, this);
+ }
+
+ public void resetText(String connectType) {
+
+ if (connectType.equals(NetConnectTypeViewItem.VALUE_NAT)) {
+ oldValue = newValue;
+ newValue = "";
+
+ } else if (connectType.equals(NetConnectTypeViewItem.VALUE_BRIDGE)) {
+ if (isCreateMode()) {
+ oldValue = newValue = getMacAddress();
+
+ } else {
+ if (oldValue.isEmpty()) {
+ oldValue = newValue = getMacAddress();
+
+ } else {
+ newValue = oldValue;
+ }
+ }
+ }
+ text.setText(newValue);
+ }
+
+ @Override
+ public boolean settingModifyItem(VMPropertyValue value) {
+
+ text.setEnabled(false);
+ if (isCreateMode()) {
+ oldValue = newValue = "";
+ } else {
+ oldValue = newValue = value.getAdvancedOptionValue(name);
+ }
+ text.setText(newValue);
+
+ AdvancedViewItem item = lineLabelViewItem
+ .getItem(CommonItemListFactory.ITEM_NET_CONNECT_TYPE);
+ if (item != null && item instanceof NetConnectTypeViewItem) {
+ String connectType = ((NetConnectTypeViewItem) item).getValue();
+ resetText(connectType);
+ }
+
+ return false;
+ }
+
+ // Return random mac address. (Not duplicated with another VM)
+ public static String getMacAddress() {
+
+ String newMacAddr;
+ boolean isDuplicated = false;
+
+ do {
+ newMacAddr = genetateRandomMacAddr();
+ for (VMProperty prop : (VMProperty[]) EmulatorVMList.getInstance()
+ .getProperties()) {
+ if (newMacAddr.equals(prop.getPropertyValue()
+ .getAdvancedOptionValue(CommonItemListFactory.ITEM_NET_MAC))) {
+ isDuplicated = true;
+ break;
+ }
+ }
+ } while (isDuplicated);
+
+ return newMacAddr;
+ }
+
+ private static String genetateRandomMacAddr() {
+ String[] MAC_CHAR = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
+ "A", "B", "C", "D", "E", "F" };
+ Random rd = new Random();
+ rd.nextInt(15);
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 12; i++) {
+ sb.append(MAC_CHAR[rd.nextInt(15)]);
+ if (i == 1) { // First 2 byte must be EVEN.
+ if ((Integer.parseInt(sb.toString(), 16) % 2) == 1) {
+ sb.delete(0, sb.length());
+ i = -1;
+ continue;
+ }
+ }
+ if (i > 0 && i < 11 && (i % 2 == 1)) {
+ sb.append(":");
+ }
+ }
+ return sb.toString();
+ }
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.ImageResources;
+import org.tizen.emulator.manager.resources.PatchImageResources;
+import org.tizen.emulator.manager.ui.MainDialog;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.ui.widgets.ImageCombo;
+import org.tizen.emulator.manager.ui.widgets.WSTATE;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+import org.tizen.emulator.manager.vms.xml.template.Option;
+import org.tizen.emulator.manager.ui.dialog.ProxyDialog;
+
+public class NetProxyViewItem extends ComboViewItem {
+
+ private String httpProxy = "";
+ private String httpsProxy = "";
+ private String ftpProxy = "";
+ private String socksProxy = "";
+
+ public final String ITEM_PROXY = CommonItemListFactory.ITEM_NET_PROXY;
+ public static final String ITEM_PROXY_MODE = "proxyMode";
+ public static final String ITEM_HTTP_PROXY = "httpProxy";
+ public static final String ITEM_HTTPS_PROXY = "httpsProxy";
+ public static final String ITEM_FTP_PROXY = "ftpProxy";
+ public static final String ITEM_SOCKS_PROXY = "socksProxy";
+ public static final String MODE_NONE = "none";
+ public static final String MODE_AUTO = "auto";
+ public static final String MODE_MANUAL = "manual";
+
+ private Map<String, String> optionMap;
+
+ Button button;
+ protected static int BUTTON_WIDTH = 49;
+ protected static int BUTTON_HEIGHT = 21;
+ protected static int COMBOBOX_WIDTH_MODIFY = 123;
+
+ public String getProxyMode() {
+ return newValue;
+ }
+
+ public void setProxyMode(String proxyMode) {
+ oldValue = newValue = proxyMode;
+ }
+
+ public String getHttpProxy() {
+ return httpProxy;
+ }
+
+ public void setHttpProxy(String httpProxy) {
+ this.httpProxy = httpProxy;
+ }
+
+ public String getHttpsProxy() {
+ return httpsProxy;
+ }
+
+ public void setHttpsProxy(String httpsProxy) {
+ this.httpsProxy = httpsProxy;
+ }
+
+ public String getFtpProxy() {
+ return ftpProxy;
+ }
+
+ public void setFtpProxy(String ftpProxy) {
+ this.ftpProxy = ftpProxy;
+ }
+
+ public String getSocksProxy() {
+ return socksProxy;
+ }
+
+ public void setSocksProxy(String socksProxy) {
+ this.socksProxy = socksProxy;
+ }
+
+ public NetProxyViewItem(Item template, LineLabelViewItem lineLabelViewItem) {
+ super(template, lineLabelViewItem);
+
+ }
+
+ @Override
+ protected void parseOption(List<Option> optionList) {
+ super.parseOption(optionList);
+
+ optionMap = new HashMap<String, String>();
+ for (Option option : optionList) {
+ if (option.getName().equals(MODE_NONE)
+ || option.getName().equals(MODE_AUTO)
+ || option.getName().equals(MODE_MANUAL)) {
+ optionMap.put(option.getName(), option.getValue());
+ comboOptions.add(option.getName());
+ }
+ }
+
+ }
+
+ public boolean settingDetailItem(VMPropertyValue value) {
+ getProxyValues(value);
+ valueLabel.setText(optionMap.get(newValue));
+ if (newValue.equals(MODE_MANUAL)) {
+ valueLabel.setToolTipText("HTTP proxy : " + httpProxy
+ + "\nHTTPS proxy : " + httpsProxy
+ + "\nFTP proxy : " + ftpProxy
+ + "\nSOCKS proxy : " + socksProxy);
+
+ } else {
+ valueLabel.setToolTipText("");
+ }
+ return false;
+ }
+
+ public void setValue(VMPropertyValue value) {
+ value.setAdvancedOptionSub(ITEM_PROXY, ITEM_PROXY_MODE, newValue);
+
+ value.setAdvancedOptionSub(ITEM_PROXY, ITEM_HTTP_PROXY, httpProxy);
+ value.setAdvancedOptionSub(ITEM_PROXY, ITEM_HTTPS_PROXY, httpsProxy);
+ value.setAdvancedOptionSub(ITEM_PROXY, ITEM_FTP_PROXY, ftpProxy);
+ value.setAdvancedOptionSub(ITEM_PROXY, ITEM_SOCKS_PROXY, socksProxy);
+
+ }
+
+ @Override
+ public void drawModify() {
+ if (INPUTBOX_ON_IMAGE == null) {
+ INPUTBOX_ON_IMAGE = PatchImageResources
+ .getInputBoxON(COMBOBOX_WIDTH_MODIFY);
+ }
+
+ if (INPUTBOX_OFF_IMAGE == null) {
+ INPUTBOX_OFF_IMAGE = PatchImageResources
+ .getInputBoxOff(COMBOBOX_WIDTH_MODIFY);
+ }
+
+ combo = new ImageCombo(compList.get(0), SWT.NONE);
+ combo.setImage(WSTATE.NORMAL, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.PUSH, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.HOVER, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.DISABLE_ON, INPUTBOX_ON_IMAGE);
+
+ combo.setArrowButtonImage(ImageResources.ARROW_DROPDOWN.getImage());
+ combo.setEnabled(true);
+ combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height);
+ combo.setLayout(new FormLayout());
+
+ button = new Button(compList.get(0), SWT.NORMAL);
+ button.setText("setting");
+ button.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, INPUTBOX_OFFSET);
+ data.top = new FormAttachment(0, INPUTBOX_TOP_GAP);
+ data.width = INPUTBOX_ON_IMAGE.getImageData().width;
+ data.height = INPUTBOX_ON_IMAGE.getImageData().height;
+ combo.setLayoutData(data);
+
+ data = new FormData();
+ data.left = new FormAttachment(combo, 5);
+ data.top = new FormAttachment(0, 3);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ button.setLayoutData(data);
+
+ addWidgetListener();
+
+ }
+
+ @Override
+ public void addWidgetListener() {
+
+ combo.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ newValue = getValueFromText(combo.getText());
+ changeButtonState();
+ resetAddress();
+
+ if (isCreateMode()) {
+ getListener().changeConfirmButton();
+
+ } else {
+ getListener().changeConfirmButton(getThis());
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ button.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+ // TODO Open proxy configuration dialog
+ // TODO set user input value to
+ // - httpProxy, httpsProxy, ftpProxy, sockProxy
+ settingAddress(ProxyDialog.open(makeDialogValue()));
+
+ if (isCreateMode()) {
+ getListener().changeConfirmButton();
+
+ } else {
+ getListener().changeConfirmButton(getThis());
+ }
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+
+ }
+ });
+
+ }
+
+ public boolean settingModifyItem(VMPropertyValue value) {
+ getProxyValues(value);
+
+ if (isCreateMode() && useDefaultOnCreate) {
+ newValue = defaultOnCreate;
+ }
+
+ // makeComboBox
+ combo.removeAll();
+ for (String option : comboOptions) {
+ combo.add(optionMap.get(option));
+ }
+
+ // Select combo-box item.
+ int index = -1;
+ for (int i = 0; i < comboOptions.size(); i++) {
+ if (comboOptions.get(i).equals(newValue)) {
+ index = i;
+ break;
+ }
+ }
+ if (comboOptions.size() > 0) {
+ if (index == -1) {
+ // if value not matches..
+ combo.select(0);
+ newValue = getValueFromText(combo.getItem(0));
+ } else {
+ combo.select(index);
+ }
+ }
+ changeButtonState();
+ resetAddress();
+ return true;
+ }
+
+ public boolean checkValue() {
+ String errMsg = null;
+ if (newValue != null && newValue.equals(MODE_MANUAL)) {
+ if (httpProxy.isEmpty() && httpsProxy.isEmpty()
+ && ftpProxy.isEmpty() && socksProxy.isEmpty()) {
+ errMsg = "Please set manual proxy address.";
+ }
+ }
+ HelperClass.setStatusBar(errMsg);
+ return errMsg == null ? true : false;
+ }
+
+ private void getProxyValues(VMPropertyValue value) {
+ oldValue = newValue = value.getAdvancedOptionSubValue(ITEM_PROXY,
+ ITEM_PROXY_MODE);
+ if (newValue.equals(MODE_MANUAL)) {
+ httpProxy = value.getAdvancedOptionSubValue(ITEM_PROXY,
+ ITEM_HTTP_PROXY);
+ httpsProxy = value.getAdvancedOptionSubValue(ITEM_PROXY,
+ ITEM_HTTPS_PROXY);
+ ftpProxy = value.getAdvancedOptionSubValue(ITEM_PROXY,
+ ITEM_FTP_PROXY);
+ socksProxy = value.getAdvancedOptionSubValue(ITEM_PROXY,
+ ITEM_SOCKS_PROXY);
+ }
+ }
+
+ private void changeButtonState() {
+ button.setEnabled(newValue.equals(MODE_MANUAL));
+ }
+
+ private String getValueFromText(String text) {
+ for (String str : optionMap.keySet()) {
+ if (optionMap.get(str).equals(text)) {
+ return str;
+ }
+ }
+ return "";
+ }
+
+ private void resetAddress() {
+ if (!newValue.equals(MODE_MANUAL)) {
+ httpProxy = "";
+ httpsProxy = "";
+ ftpProxy = "";
+ socksProxy = "";
+ }
+ }
+
+ private void settingAddress(String dialogResult) {
+ if (dialogResult == null) {
+ return;
+ }
+
+ // Get address from dialog result
+ // ex : http_proxy=1.1.1.1:1 https_proxy= ftp_proxy= socks_proxy=
+ String[] arr = dialogResult.split("socks_proxy");
+ String tmp = null;
+ if (arr.length > 1) {
+ socksProxy = arr[1].substring(1);
+ tmp = arr[0];
+ }
+
+ if (tmp != null) {
+ arr = tmp.split("ftp_proxy");
+ if (arr.length > 1) {
+ ftpProxy = arr[1].substring(1, arr[1].length()-1);
+ tmp = arr[0];
+ }
+ }
+
+ if (tmp != null) {
+ arr = tmp.split("https_proxy");
+ if (arr.length > 1) {
+ httpsProxy = arr[1].substring(1, arr[1].length()-1);
+ tmp = arr[0];
+ }
+ }
+
+ if (tmp != null) {
+ arr = tmp.split("http_proxy");
+ if (arr.length > 1) {
+ httpProxy = arr[1].substring(1, arr[1].length()-1);
+ }
+ }
+ }
+
+ // Send existing values to dialog.
+ // Return : Return has forms of "{http},{https},{ftp},{socks}"
+ // ex : "192.168.1.1:8181, 192.168.1.1:8181, 192.168.1.1:8181, 192.168.1.1:8181"
+ private String makeDialogValue() {
+ return httpProxy + "," + httpsProxy + ","
+ + ftpProxy + "," + socksProxy;
+ }
+
+}
--- /dev/null
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye1128.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.detail.item.property;
+
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.widgets.Button;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.ImageResources;
+import org.tizen.emulator.manager.resources.PatchImageResources;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.detail.item.AdvancedViewItem;
+import org.tizen.emulator.manager.ui.detail.item.CommonItemListFactory;
+import org.tizen.emulator.manager.ui.detail.item.LineLabelViewItem;
+import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.ui.dialog.MessageDialog;
+import org.tizen.emulator.manager.ui.dialog.TapDeviceDialogForLinux;
+import org.tizen.emulator.manager.ui.dialog.TapDeviceDialogForWin;
+import org.tizen.emulator.manager.ui.widgets.ImageCombo;
+import org.tizen.emulator.manager.ui.widgets.WSTATE;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.xml.template.Item;
+import org.tizen.emulator.manager.vms.xml.template.Option;
+
+public class NetTapDeviceViewItem extends ComboViewItem {
+
+ Button createButton;
+ protected static int BUTTON_WIDTH = 48;
+ protected static int BUTTON_HEIGHT = 20;
+ protected static int COMBOBOX_WIDTH_MODIFY = 123;
+
+ boolean isBridge = false;
+ NetTapDeviceViewItem thisItem;
+
+ public NetTapDeviceViewItem(Item template,
+ LineLabelViewItem lineLabelViewItem) {
+ super(template, lineLabelViewItem);
+ lineLabelViewItem.addItem(name, this);
+ }
+
+ @Override
+ protected void parseOption(List<Option> optionList) {
+ comboOptions = TapUtil.getTapList();
+ }
+
+ @Override
+ public void drawModify() {
+ if (INPUTBOX_ON_IMAGE == null) {
+ INPUTBOX_ON_IMAGE = PatchImageResources
+ .getInputBoxON(COMBOBOX_WIDTH_MODIFY);
+ }
+
+ if (INPUTBOX_OFF_IMAGE == null) {
+ INPUTBOX_OFF_IMAGE = PatchImageResources
+ .getInputBoxOff(COMBOBOX_WIDTH_MODIFY);
+ }
+
+ combo = new ImageCombo(compList.get(0), SWT.NONE);
+ combo.setImage(WSTATE.NORMAL, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.PUSH, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.HOVER, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.DISABLE_ON, INPUTBOX_ON_IMAGE);
+
+ combo.setArrowButtonImage(ImageResources.ARROW_DROPDOWN.getImage());
+ combo.setEnabled(true);
+ combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height);
+ combo.setLayout(new FormLayout());
+
+ createButton = new Button(compList.get(0), SWT.NORMAL);
+ createButton.setText("create");
+ createButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, INPUTBOX_OFFSET);
+ data.top = new FormAttachment(0, INPUTBOX_TOP_GAP);
+ data.width = INPUTBOX_ON_IMAGE.getImageData().width;
+ data.height = INPUTBOX_ON_IMAGE.getImageData().height;
+ combo.setLayoutData(data);
+
+ data = new FormData();
+ data.left = new FormAttachment(combo, 5);
+ data.top = new FormAttachment(0, 3);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ createButton.setLayoutData(data);
+
+ // make combobox list
+ addWidgetListener();
+
+ thisItem = this;
+ }
+
+ @Override
+ protected void addWidgetListener() {
+ combo.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ newValue = combo.getText();
+
+ // Set netmask, gateway
+ resetAddress();
+
+ if (!isCreateMode()) {
+ // getListener().ChangeValue(getThis());
+ getListener().changeConfirmButton(getThis());
+ }
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+
+ createButton.addSelectionListener(new SelectionListener() {
+
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ if (EmulatorManager.isLinux()) {
+ TapDeviceDialogForLinux.open();
+
+ } else if (EmulatorManager.isWin()) {
+ TapDeviceDialogForWin.open(thisItem);
+ }
+ resetCombo(NetConnectTypeViewItem.VALUE_BRIDGE);
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+
+ });
+ }
+
+ @Override
+ public boolean settingModifyItem(VMPropertyValue value) {
+
+ oldValue = newValue = value.getAdvancedOptionValue(name);
+ // text.setText(newValue);
+
+ AdvancedViewItem item = lineLabelViewItem
+ .getItem(CommonItemListFactory.ITEM_NET_CONNECT_TYPE);
+ if (item != null && item instanceof NetConnectTypeViewItem) {
+ String connectType = ((NetConnectTypeViewItem) item).getValue();
+ resetCombo(connectType);
+ if (connectType.equals("Bridge") && !oldValue.equals(newValue)) {
+ resetAddress();
+ (new MessageDialog()).openWarningDialog((new StringBuilder())
+ .append("Tap device (").append(oldValue)
+ .append(") is removed or unavailable.")
+ .append("\nCheck tap configuration.").toString());
+ }
+ }
+
+ getListener().changeConfirmButton(getThis());
+
+ return true;
+ }
+
+ @Override
+ public void resetCombo() {
+ String connectType = isBridge ? NetConnectTypeViewItem.VALUE_BRIDGE
+ : NetConnectTypeViewItem.VALUE_NAT;
+ resetCombo(connectType);
+ }
+
+ // called when NAT/Bridge changed.
+ public void resetCombo(String connectType) {
+ // Reset combo when connect type(NAT/Bridge) is changed.
+ if (combo != null) {
+ combo.removeAll();
+ }
+
+ // Enable if "Bridge"
+ if (connectType.equals(NetConnectTypeViewItem.VALUE_BRIDGE)) {
+ isBridge = true;
+ comboOptions = TapUtil.getTapList();
+ newValue = oldValue; // restore
+
+ // make combo box list
+ if (comboOptions != null) {
+ for (String option : comboOptions) {
+ combo.add(option);
+ }
+ }
+
+ // Select combo-box item.
+ int index = -1;
+ for (int i = 0; i < comboOptions.size(); i++) {
+ if (comboOptions.get(i).equals(newValue)) {
+ index = i;
+ break;
+ }
+ }
+ if (comboOptions.size() > 0) {
+ if (index == -1) {
+ // if value not matches..
+ combo.select(0);
+ newValue = combo.getItem(0);
+ } else {
+ combo.select(index);
+ }
+ resetAddress();
+ }
+ newValue = combo.getText();
+ combo.setEnabled(true);
+ createButton.setEnabled(true);
+
+ // Disable if "NAT"
+ } else {
+ isBridge = false;
+ oldValue = newValue; // save
+ newValue = "";
+ combo.setText(newValue);
+ combo.setEnabled(false);
+ createButton.setEnabled(false);
+ }
+ }
+
+ @Override
+ public boolean checkValue() {
+ if (!combo.isEnabled()) {
+ return true;
+ }
+
+ if (newValue == null || !newValue.isEmpty()) {
+ return true;
+ }
+
+ HelperClass.setStatusBar("At least one Tap device should be created.");
+ return false;
+ }
+
+ private void resetAddress() {
+ AdvancedViewItem item = lineLabelViewItem
+ .getItem(CommonItemListFactory.ITEM_NET_IP_INFO);
+ if (item != null && item instanceof NetIPInfoViewItem) {
+ NetIPInfoViewItem netIPInfoItem = (NetIPInfoViewItem) item;
+ netIPInfoItem.setSubnet(TapUtil.getNetmaskFromTap(newValue));
+ netIPInfoItem.setGateway(TapUtil.getGatewayFromTap(newValue));
+ }
+
+ item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_DNS);
+ if (item != null && item instanceof NetDnsViewItem) {
+ ((NetDnsViewItem)item).setDns(TapUtil.getDnsFromTap(newValue));
+ }
+
+ item = lineLabelViewItem.getItem(CommonItemListFactory.ITEM_NET_MAC);
+ if (item != null && item instanceof NetMacViewItem) {
+ ((NetMacViewItem) item).resetText(newValue);
+ }
+
+ }
+
+}
--- /dev/null
+/* Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+
+package org.tizen.emulator.manager.ui.dialog;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.graphics.Point;
+import org.tizen.emulator.manager.resources.ColorResources;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.PatchImageResources;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.MainDialog;
+import org.tizen.emulator.manager.ui.widgets.ImageLabel;
+
+public class IPAddressInputDialog {
+ private static Shell dialog = null;
+ private static int width = 300;
+ private static int height = 130;
+ private static Image image;
+ private static int COMP_WIDTH = 270;
+ private static int UPPER_HEIGHT = 27;
+ private static int ITEM_COUNT = 1;
+
+ private static Text gwText;
+ private static String gatewayAddr;
+
+ private static Button okButton;
+ private static Button cancelButton;
+
+ static {
+ image = PatchImageResources.getDetailListView2(ITEM_COUNT);
+ }
+
+ public static String open(String title) {
+ gatewayAddr = null;
+ makeDialog(title);
+ dialog.open();
+ while (!dialog.isDisposed()) {
+ if (!Display.getCurrent().readAndDispatch()) {
+ Display.getCurrent().sleep();
+ }
+ }
+ return gatewayAddr;
+ }
+
+ private static void makeDialog(String content) {
+ dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
+ | SWT.APPLICATION_MODAL);
+ dialog.setText(content);
+ dialog.setSize(width, height);
+ dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ RowLayout rowLayout = new RowLayout();
+ rowLayout.type = SWT.VERTICAL;
+ rowLayout.marginTop = 15;
+ rowLayout.marginLeft = 10;
+ rowLayout.spacing = 15;
+
+ dialog.setLayout(rowLayout);
+
+ if (MainDialog.getShell() != null) {
+ Point p = MainDialog.getShell().getLocation();
+ Point s = MainDialog.getShell().getSize();
+ dialog.setLocation(p.x + (s.x>>2), p.y + (s.y>>2));
+ }
+
+ makeUpperComposite();
+ makeLowerComposite();
+ addListener();
+
+ }
+
+ private static void makeUpperComposite() {
+ Composite upperComp = new Composite(dialog, SWT.BORDER);
+ upperComp.setLayoutData(new RowData(COMP_WIDTH, UPPER_HEIGHT));
+ upperComp.addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ Rectangle rect = ((Composite) e.widget).getClientArea();
+ e.gc.drawImage(image, rect.x - 2, rect.y);
+
+ }
+ });
+ upperComp.setLayout(new FormLayout());
+
+ // tap name (text input)
+ Label nameLabel = new Label(upperComp, SWT.NONE);
+ nameLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ nameLabel.setText("Address");
+ nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 15);
+ data.top = new FormAttachment(0, 4);
+ data.width = 85;
+ data.height = 20;
+ nameLabel.setLayoutData(data);
+
+ Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(150);
+ ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE);
+ valueLabel.setEnableImage(INPUTBOX_ON_IMAGE);
+ valueLabel.setLayout(new FormLayout());
+ data = new FormData();
+ data.left = new FormAttachment(0, 100);
+ data.top = new FormAttachment(0, 4);
+ data.width = 150;
+ data.height = 19;
+ valueLabel.setLayoutData(data);
+
+ gwText = new Text(valueLabel, SWT.NONE);
+ gwText.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
+ gwText.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
+ gwText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR.getColor());
+ gwText.setTextLimit(20);
+
+ data = new FormData();
+ data.left = new FormAttachment(0, 5);
+ data.top = new FormAttachment(0, 2);
+ data.right = new FormAttachment(100, -5);
+ data.bottom = new FormAttachment(100, -2);
+ gwText.setLayoutData(data);
+
+ }
+
+ private static void makeLowerComposite() {
+ Composite lowerComp = new Composite(dialog, SWT.NONE);
+ lowerComp.setLayoutData(new RowData(COMP_WIDTH + 1, 30));
+ lowerComp
+ .setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ lowerComp.setLayout(new FormLayout());
+
+ int BUTTON_WIDTH = 128;
+ int BUTTON_HEIGHT = 26;
+
+ okButton = new Button(lowerComp, SWT.PUSH);
+ okButton.setText("OK");
+ okButton.setEnabled(true);
+ okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 0);
+ data.top = new FormAttachment(0, 0);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ okButton.setLayoutData(data);
+ okButton.setEnabled(false);
+
+ cancelButton = new Button(lowerComp, SWT.PUSH);
+ cancelButton.setText("CANCEL");
+ cancelButton.setEnabled(true);
+ cancelButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ data = new FormData();
+ data.left = new FormAttachment(okButton, 16);
+ data.top = new FormAttachment(0, 0);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ cancelButton.setLayoutData(data);
+
+ }
+
+ private static void addListener() {
+
+ gwText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent arg0) {
+ // Check ip address
+ okButton.setEnabled(TapUtil.checkIP(gwText.getText()));
+ }
+ });
+
+ okButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+ gatewayAddr = gwText.getText();
+ dialog.close();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+
+ }
+ });
+
+ cancelButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+ dialog.close();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+
+ }
+ });
+
+ }
+}
--- /dev/null
+/* Emulator Manager
+ *
+ * Copyright (C) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Munkyu Im <munkyu.im@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.dialog;
+
+import java.util.ArrayList;
+
+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.events.VerifyEvent;
+import org.eclipse.swt.events.VerifyListener;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.resources.ColorResources;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.ImageResources;
+import org.tizen.emulator.manager.resources.PatchImageResources;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.MainDialog;
+import org.tizen.emulator.manager.ui.widgets.ImageButton;
+import org.tizen.emulator.manager.ui.widgets.ImageLabel;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+
+public class ProxyDialog {
+ private static int SHELL_WIDTH = 370;
+ private static int SHELL_HEIGHT = 230;
+ private static int MAX_PORT = 65535;
+ private static Shell shell;
+ private static int MAX_TEXTARRARY_SIZE = 4;
+ private static int LABEL_HEIGHT_POS = 4;
+ private static int TEXT_HEIGHT_POS = 2;
+ private static int ROW_HEIGHT = 27;
+ private static Button okButton;
+ private static Button cancelButton;
+ private static ArrayList<Text> textArrayAddr;
+ private static ArrayList<Text> textArrayPort;
+ private static ArrayList<Label> labelArrayAddr;
+ private static ArrayList<Label> labelArrayPort;
+ private static ImageButton applyAllProtocol;
+ private static int BUTTON_WIDTH = 90;
+ private static int BUTTON_HEIGHT = 26;
+ private static int MAX_INPUT_COUNT = 8;
+ private static String returnValue;
+
+ public static String open(String value) {
+ shell = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
+ | SWT.APPLICATION_MODAL);
+ shell.setSize(SHELL_WIDTH, SHELL_HEIGHT);
+ shell.setText("Proxy Setting");
+ shell.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ RowLayout rowLayout = new RowLayout();
+ rowLayout.type = SWT.VERTICAL;
+ rowLayout.marginTop = 15;
+ rowLayout.marginLeft = 10;
+ rowLayout.marginRight = 10;
+ rowLayout.spacing = 15;
+
+ shell.setLayout(rowLayout);
+
+ createWidgets(shell);
+ setValues(value);
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!Display.getCurrent().readAndDispatch()) {
+ Display.getCurrent().sleep();
+ }
+ }
+ EMLogger.getLogger().info("return: " + returnValue);
+ return returnValue;
+ }
+
+ private static void createWidgets(Shell shell) {
+ Composite mainComposite = new Composite(shell, SWT.BORDER);
+ mainComposite.setLayoutData(new RowData(SHELL_WIDTH - 30, 140));
+ // TODO: need background image
+ // final Image image =
+ // mainComposite.addPaintListener(new PaintListener() {
+ // public void paintControl(PaintEvent e) {
+ // Rectangle rect = ((Composite) e.widget).getClientArea();
+ // e.gc.drawImage(image, rect.x - 2, rect.y);
+ //
+ // }
+ // });
+ mainComposite.setLayout(new FormLayout());
+ textArrayAddr = new ArrayList<Text>();
+ textArrayPort = new ArrayList<Text>();
+ labelArrayAddr = new ArrayList<Label>();
+ labelArrayPort = new ArrayList<Label>();
+
+ createProxyContents(mainComposite, "HTTP", 0);
+ createCheckBox(mainComposite);
+ LABEL_HEIGHT_POS += ROW_HEIGHT;
+ createProxyContents(mainComposite, "HTTPS", 1);
+ createProxyContents(mainComposite, "FTP", 2);
+ createProxyContents(mainComposite, "SOCKS", 3);
+ createConfirmButtons();
+ addListeners();
+ LABEL_HEIGHT_POS = 4;
+ }
+
+ private static void createConfirmButtons() {
+ Composite lowerComp = new Composite(shell, 0);
+ lowerComp
+ .setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ lowerComp.setLayout(new FormLayout());
+
+ okButton = new Button(lowerComp, SWT.PUSH);
+ okButton.setText("OK");
+ okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 160);
+ data.top = new FormAttachment(0, 0);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ okButton.setLayoutData(data);
+ okButton.setEnabled(true);
+
+ cancelButton = new Button(lowerComp, SWT.PUSH);
+ cancelButton.setText("CANCEL");
+ cancelButton.setEnabled(true);
+ cancelButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ data = new FormData();
+ data.left = new FormAttachment(okButton, 10);
+ data.top = new FormAttachment(0, 0);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ cancelButton.setLayoutData(data);
+
+ okButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ if (applyAllProtocol.isSelection()) {
+ String httpProxyAddr = textArrayAddr.get(0).getText();
+ String httpProxyPort = textArrayPort.get(0).getText();
+ String httpsProxyAddr = textArrayAddr.get(1).getText();
+ String httpsProxyPort = textArrayPort.get(1).getText();
+ String ftpProxyAddr = textArrayAddr.get(2).getText();
+ String ftpProxyPort = textArrayPort.get(2).getText();
+ String socksProxyAddr = textArrayAddr.get(3).getText();
+ String socksProxyPort = textArrayPort.get(3).getText();
+ String httpProxy;
+ String httpsProxy;
+ String ftpProxy;
+ String socksProxy;
+
+ if (httpProxyAddr.isEmpty() && httpProxyPort.isEmpty()) {
+ httpProxy = "http_proxy=";
+ } else {
+ httpProxy = "http_proxy=" + httpProxyAddr + ":"
+ + httpProxyPort;
+ }
+
+ if (httpsProxyAddr.isEmpty() && httpsProxyPort.isEmpty()) {
+ httpsProxy = "https_proxy=";
+ } else {
+ httpsProxy = "https_proxy=" + httpsProxyAddr + ":"
+ + httpsProxyPort;
+ }
+
+ if (ftpProxyAddr.isEmpty() && ftpProxyPort.isEmpty()) {
+ ftpProxy = "ftp_proxy=";
+ } else {
+ ftpProxy = "ftp_proxy=" + ftpProxyAddr + ":"
+ + ftpProxyPort;
+ }
+
+ if (socksProxyAddr.isEmpty() && socksProxyPort.isEmpty()) {
+ socksProxy = "socks_proxy=";
+ } else {
+ socksProxy = "socks_proxy=" + socksProxyAddr + ":"
+ + socksProxyPort;
+ }
+ returnValue = httpProxy + " " + httpsProxy + " " + ftpProxy
+ + " " + socksProxy;
+
+ } else {
+ if (textArrayAddr.get(0).getText().isEmpty()
+ && textArrayPort.get(0).getText().isEmpty()) {
+ returnValue = null;
+ }
+ returnValue = "http_proxy="
+ + textArrayAddr.get(0).getText() + ":"
+ + textArrayPort.get(0).getText() + " https_proxy="
+ + textArrayAddr.get(0).getText() + ":"
+ + textArrayPort.get(0).getText() + " ftp_proxy="
+ + textArrayAddr.get(0).getText() + ":"
+ + textArrayPort.get(0).getText() + " socks_proxy="
+ + textArrayAddr.get(0).getText() + ":"
+ + textArrayPort.get(0).getText();
+ }
+ shell.close();
+ }
+ });
+
+ cancelButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent event) {
+ returnValue = null;
+ shell.close();
+ }
+ });
+
+ shell.setDefaultButton(okButton);
+ }
+
+ private static void createCheckBox(Composite mainComposite) {
+ applyAllProtocol = new ImageButton(mainComposite, SWT.TOGGLE);
+ applyAllProtocol.setImages(
+ ImageResources.CHECKBOX_ON.getImage(), // on normal
+ ImageResources.CHECKBOX_ON.getImage(),
+ ImageResources.CHECKBOX_ON.getImage(),
+ ImageResources.CHECKBOX_OFF.getImage(), // off normal
+ ImageResources.CHECKBOX_OFF.getImage(),
+ ImageResources.CHECKBOX_OFF.getImage(),
+ // ImageResources.CHECKBOX_OFF_DIS.getImage(), // disable
+ ImageResources.CHECKBOX_ON_DIS.getImage()); // disable
+
+ FormData data = new FormData();
+ data = new FormData();
+ data.left = new FormAttachment(0, 65);
+ data.top = new FormAttachment(0, LABEL_HEIGHT_POS);
+ data.width = 19;
+ data.height = 19;
+ applyAllProtocol.setLayoutData(data);
+ applyAllProtocol.setSelection(true);
+
+ // text label
+ Label titleLabel = new Label(mainComposite, SWT.NONE);
+ titleLabel.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
+ titleLabel.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR
+ .getColor());
+ // titleLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+
+ data = new FormData();
+ data.left = new FormAttachment(applyAllProtocol, 4);
+ data.top = new FormAttachment(0, LABEL_HEIGHT_POS + 3);
+ data.height = 18;
+ titleLabel.setLayoutData(data);
+ titleLabel.setText("Use this proxy for all protocols");
+ }
+
+ private static void createProxyContents(Composite mainComposite,
+ String proxy, int index) {
+ Label labelAddr = new Label(mainComposite, SWT.NONE);
+ labelAddr.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ labelAddr.setText(proxy + ":");
+ // labelAddr.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 15);
+ data.top = new FormAttachment(0, LABEL_HEIGHT_POS);
+ data.width = 50;
+ data.height = 20;
+ labelAddr.setLayoutData(data);
+ labelArrayAddr.add(index, labelAddr);
+
+ ImageLabel imageLabelAddr = new ImageLabel(mainComposite, SWT.NONE);
+ imageLabelAddr.setEnableImage(PatchImageResources.getInputBoxON(150));
+ imageLabelAddr.setLayout(new FormLayout());
+ data = new FormData();
+ data.left = new FormAttachment(0, 65);
+ data.top = new FormAttachment(0, LABEL_HEIGHT_POS);
+ data.width = 150;
+ data.height = 19;
+ imageLabelAddr.setLayoutData(data);
+
+ Text textAddr = new Text(imageLabelAddr, SWT.NONE);
+ textAddr.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
+ textAddr.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
+ textAddr.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR
+ .getColor());
+ textAddr.setTextLimit(40);
+ data = new FormData();
+ data.left = new FormAttachment(0, 5);
+ data.top = new FormAttachment(0, TEXT_HEIGHT_POS);
+ data.right = new FormAttachment(100, -5);
+ data.bottom = new FormAttachment(100, -2);
+ textAddr.setLayoutData(data);
+ textAddr.setEnabled(true);
+ textArrayAddr.add(index, textAddr);
+
+ Label labelPort = new Label(mainComposite, SWT.NONE);
+ labelPort.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ labelPort.setText("Port:");
+ // labelPort.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ FormData data2 = new FormData();
+ data2.left = new FormAttachment(0, 230);
+ data2.top = new FormAttachment(0, LABEL_HEIGHT_POS);
+ data2.width = 40;
+ data2.height = 20;
+ labelPort.setLayoutData(data2);
+ labelArrayPort.add(index, labelPort);
+
+ ImageLabel imagelabelPort = new ImageLabel(mainComposite, SWT.NONE);
+ imagelabelPort.setEnableImage(PatchImageResources.getInputBoxON(60));
+ imagelabelPort.setLayout(new FormLayout());
+ data = new FormData();
+ data.left = new FormAttachment(0, 270);
+ data.top = new FormAttachment(0, LABEL_HEIGHT_POS);
+ data.width = 60;
+ data.height = 19;
+ imagelabelPort.setLayoutData(data);
+ Text textPort = new Text(imagelabelPort, SWT.NONE);
+ textPort.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
+ textPort.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
+ textPort.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR
+ .getColor());
+ textPort.setTextLimit(6);
+
+ data = new FormData();
+ data.left = new FormAttachment(0, 5);
+ data.top = new FormAttachment(0, TEXT_HEIGHT_POS);
+ data.right = new FormAttachment(100, -5);
+ data.bottom = new FormAttachment(100, -2);
+ textPort.setLayoutData(data);
+ textPort.setEnabled(true);
+ textArrayPort.add(index, textPort);
+ LABEL_HEIGHT_POS += ROW_HEIGHT;
+ }
+
+ private static void addListeners() {
+ applyAllProtocol.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ if (applyAllProtocol.isSelection()) {
+ for (int i = 1; i < MAX_TEXTARRARY_SIZE; i++) {
+ textArrayAddr.get(i).setEnabled(true);
+ textArrayPort.get(i).setEnabled(true);
+ labelArrayAddr.get(i).setEnabled(true);
+ labelArrayPort.get(i).setEnabled(true);
+ }
+
+ } else { // SUPPORT
+ for (int i = 1; i < MAX_TEXTARRARY_SIZE; i++) {
+ textArrayAddr.get(i).setEnabled(false);
+ textArrayAddr.get(i).setText("");
+ textArrayPort.get(i).setEnabled(false);
+ textArrayPort.get(i).setText("");
+ labelArrayAddr.get(i).setEnabled(false);
+ labelArrayPort.get(i).setEnabled(false);
+
+ if (!textArrayAddr.get(0).getText().isEmpty()
+ && !textArrayPort.get(0).getText().isEmpty()
+ && !textArrayPort.get(0).getText().equals("0")) {
+ okButton.setEnabled(true);
+ }
+ }
+ }
+ }
+ });
+ for (Text textPort : textArrayPort) {
+ textPort.addVerifyListener(new VerifyListener() {
+
+ @Override
+ public void verifyText(VerifyEvent e) {
+ Text text = (Text) e.getSource();
+ int newValue;
+ int oldValue;
+ // get old text and create new text by using the
+ // VerifyEvent.text
+ final String oldS = text.getText();
+ String newS = oldS.substring(0, e.start) + e.text
+ + oldS.substring(e.end);
+
+ boolean isInteger = true;
+ if (newS.isEmpty()) {
+ e.doit = true;
+ return;
+ }
+
+ try {
+ newValue = Integer.parseInt(newS);
+ if (newValue > MAX_PORT) {
+ e.doit = false;
+ return;
+ }
+
+ if (!oldS.isEmpty()) {
+ oldValue = Integer.parseInt(oldS);
+ if (newValue == oldValue) {
+ e.doit = false;
+ return;
+ }
+ }
+ } catch (NumberFormatException ex) {
+ isInteger = false;
+ }
+
+ if (!isInteger)
+ e.doit = false;
+ }
+ });
+
+ textPort.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent arg0) {
+ if (checkTextPort() && checkTextAddr()) {
+ okButton.setEnabled(true);
+
+ } else {
+ okButton.setEnabled(false);
+ }
+ }
+ });
+ }
+
+ for (Text textAddr : textArrayAddr) {
+ textAddr.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent arg0) {
+ if (checkTextPort() && checkTextAddr()) {
+ okButton.setEnabled(true);
+
+ } else {
+ okButton.setEnabled(false);
+ }
+ }
+ });
+ }
+ }
+
+ private static boolean checkTextPort() {
+ int i;
+ boolean isSet[] = { false, false, false, false };
+ for (i = 0; i < textArrayAddr.size(); i++) {
+ if (!textArrayAddr.get(i).getText().isEmpty()) {
+ if (!textArrayPort.get(i).getText().isEmpty()
+ && !textArrayPort.get(i).getText()
+ .equals("0")) {
+ isSet[i] = true;
+ } else {
+ isSet[i] = false;
+ }
+ } else {
+ if (textArrayPort.get(i).getText().isEmpty()) {
+ isSet[i] = true;
+ }
+ }
+ }
+
+ if (isSet[0] && isSet[1] && isSet[2] && isSet[3]) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ private static boolean checkTextAddr() {
+ int i;
+ boolean isSet[] = { false, false, false, false };
+ for (i = 0; i < textArrayAddr.size(); i++) {
+ if (!textArrayAddr.get(i).getText().isEmpty()) {
+ if (!textArrayPort.get(i).getText().isEmpty()
+ && !textArrayPort.get(i).getText()
+ .equals("0")) {
+ isSet[i] = true;
+ } else {
+ isSet[i] = false;
+ }
+
+// isSet[i] = TapUtil.checkIP(textArrayAddr.get(i).getText());
+ } else {
+ if (textArrayPort.get(i).getText().isEmpty()) {
+ isSet[i] = true;
+ }
+ }
+ }
+
+ if (isSet[0] && isSet[1] && isSet[2] && isSet[3]) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ // Set existing address value to text box.
+ // Value have forms of "{http}, {https}, {ftp}, {socks}.
+ // ex : "192.168.1.1:8181, 192.168.1.1:8181, 192.168.1.1:8181, 192.168.1.1:8181"
+ private static void setValues(String value) {
+ if (value == null) {
+ return;
+ }
+
+ int i=0;
+ String ipPortArr[] = value.split(",");
+ for (i=0 ; i < ipPortArr.length ; i++) {
+ int idx = ipPortArr[i].lastIndexOf(":");
+ if (idx > 0) {
+ textArrayAddr.get(i).setText(ipPortArr[i].substring(0,idx));
+ textArrayPort.get(i).setText(ipPortArr[i].substring(idx+1, ipPortArr[i].length()));
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/* Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+package org.tizen.emulator.manager.ui.dialog;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.net.InterfaceAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.resources.ColorResources;
+import org.tizen.emulator.manager.resources.FilePathResources;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.ImageResources;
+import org.tizen.emulator.manager.resources.PatchImageResources;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.MainDialog;
+import org.tizen.emulator.manager.ui.widgets.ImageCombo;
+import org.tizen.emulator.manager.ui.widgets.ImageLabel;
+import org.tizen.emulator.manager.ui.widgets.WSTATE;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+import org.tizen.emulator.manager.vms.helper.ProcessResult;
+import org.tizen.emulator.manager.vms.helper.VMWorkerException;
+
+public class TapDeviceDialogForLinux {
+ private static Shell dialog = null;
+ private static int width = 300;
+ private static int height = 155;
+ private static Image image;
+ private static int COMP_WIDTH = 270;
+ private static int UPPER_HEIGHT = 54;
+ private static int ITEM_COUNT = 2;
+
+ private static Text nameText;
+ private static ImageCombo combo;
+
+ private static Button okButton;
+ private static Button cancelButton;
+
+ private static String tapName;
+ private static String ifName;
+
+ static {
+ image = PatchImageResources.getDetailListView2(ITEM_COUNT);
+ }
+
+ public static void open() {
+ makeDialog();
+ dialog.open();
+ while (!dialog.isDisposed()) {
+ if (!Display.getCurrent().readAndDispatch()) {
+ Display.getCurrent().sleep();
+ }
+ }
+ }
+
+ private static void makeDialog() {
+ dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
+ | SWT.APPLICATION_MODAL);
+ dialog.setText("Creating tap device.");
+ dialog.setSize(width, height);
+ dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ RowLayout rowLayout = new RowLayout();
+ rowLayout.type = SWT.VERTICAL;
+ rowLayout.marginTop = 15;
+ rowLayout.marginLeft = 10;
+ rowLayout.spacing = 15;
+
+ dialog.setLayout(rowLayout);
+
+ makeUpperComposite();
+ makeLowerComposite();
+ addListener();
+
+ }
+
+ private static void makeUpperComposite() {
+ Composite upperComp = new Composite(dialog, SWT.BORDER);
+ upperComp.setLayoutData(new RowData(COMP_WIDTH, UPPER_HEIGHT));
+ upperComp.addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ Rectangle rect = ((Composite) e.widget).getClientArea();
+ e.gc.drawImage(image, rect.x - 2, rect.y);
+
+ }
+ });
+ upperComp.setLayout(new FormLayout());
+
+ // tap name (text input)
+ Label nameLabel = new Label(upperComp, SWT.NONE);
+ nameLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ nameLabel.setText("Tap name");
+ nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 15);
+ data.top = new FormAttachment(0, 4);
+ data.width = 85;
+ data.height = 20;
+ nameLabel.setLayoutData(data);
+
+ Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(150);
+ ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE);
+ valueLabel.setEnableImage(INPUTBOX_ON_IMAGE);
+ valueLabel.setLayout(new FormLayout());
+ data = new FormData();
+ data.left = new FormAttachment(0, 100);
+ data.top = new FormAttachment(0, 4);
+ data.width = 150;
+ data.height = 19;
+ valueLabel.setLayoutData(data);
+
+ nameText = new Text(valueLabel, SWT.NONE);
+ nameText.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
+ nameText.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
+ nameText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR
+ .getColor());
+ nameText.setTextLimit(20);
+
+ data = new FormData();
+ data.left = new FormAttachment(0, 5);
+ data.top = new FormAttachment(0, 2);
+ data.right = new FormAttachment(100, -5);
+ data.bottom = new FormAttachment(100, -2);
+ nameText.setLayoutData(data);
+ nameText.setEnabled(false);
+ nameText.setText(TapUtil.getAvailableTapName());
+
+ // interface (combo select)
+ Label ifLabel = new Label(upperComp, SWT.NONE);
+ ifLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ ifLabel.setText("Interface");
+ ifLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ data = new FormData();
+ data.left = new FormAttachment(0, 15);
+ data.top = new FormAttachment(0, 31);
+ data.width = 85;
+ data.height = 20;
+ ifLabel.setLayoutData(data);
+
+ combo = new ImageCombo(upperComp, SWT.NONE);
+ combo.setImage(WSTATE.NORMAL, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.PUSH, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.HOVER, INPUTBOX_ON_IMAGE);
+ combo.setImage(WSTATE.DISABLE_ON, INPUTBOX_ON_IMAGE);
+
+ combo.setArrowButtonImage(ImageResources.ARROW_DROPDOWN.getImage());
+ combo.setEnabled(true);
+ combo.setItemHeight(INPUTBOX_ON_IMAGE.getImageData().height);
+ combo.setLayout(new FormLayout());
+
+ data = new FormData();
+ data.left = new FormAttachment(0, 100);
+ data.top = new FormAttachment(0, 31);
+ data.width = INPUTBOX_ON_IMAGE.getImageData().width;
+ data.height = INPUTBOX_ON_IMAGE.getImageData().height;
+ combo.setLayoutData(data);
+
+ try {
+ for (String str : getInterfaceList()) {
+ if (str.equals("eth0")) {
+ combo.add(str, 0);
+ continue;
+ }
+ combo.add(str);
+ }
+ combo.select(0);
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger().warning("Failed to get interface list.");
+ EMLogger.getLogger().warning(e.getMessage());
+ new MessageDialog()
+ .openWarningDialog("Failed to get interface list.\n"
+ + e.getMessage());
+ }
+
+ }
+
+ private static void makeLowerComposite() {
+ Composite lowerComp = new Composite(dialog, 0);
+ lowerComp.setLayoutData(new RowData(COMP_WIDTH + 1, 30));
+ lowerComp
+ .setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ lowerComp.setLayout(new FormLayout());
+
+ int BUTTON_WIDTH = 128;
+ int BUTTON_HEIGHT = 26;
+
+ okButton = new Button(lowerComp, SWT.PUSH);
+ okButton.setText("OK");
+ okButton.setEnabled(true);
+ okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 0);
+ data.top = new FormAttachment(0, 0);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ okButton.setLayoutData(data);
+
+ cancelButton = new Button(lowerComp, SWT.PUSH);
+ cancelButton.setText("CANCEL");
+ cancelButton.setEnabled(true);
+ cancelButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ data = new FormData();
+ data.left = new FormAttachment(okButton, 16);
+ data.top = new FormAttachment(0, 0);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ cancelButton.setLayoutData(data);
+
+ }
+
+ private static void addListener() {
+ cancelButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+ dialog.close();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+
+ }
+ });
+
+ okButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+
+ tapName = nameText.getText();
+ ifName = combo.getText();
+ dialog.close();
+ try {
+ createTapDevice();
+
+ } catch (VMWorkerException e) {
+ EMLogger.getLogger()
+ .warning("Failed to create tap device.");
+ EMLogger.getLogger().warning(e.getMessage());
+ new MessageDialog()
+ .openWarningDialog("\nFailed to create tap device.\n"
+ + e.getMessage());
+ }
+
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ // TODO Auto-generated method stub
+ }
+ });
+
+ }
+
+ private static List<String> getInterfaceList() throws VMWorkerException {
+ List<String> result = new ArrayList<String>();
+
+ // Get intereface list
+ List<String> ifList = new ArrayList<String>();
+ Enumeration<NetworkInterface> interfaces;
+ try {
+ interfaces = NetworkInterface.getNetworkInterfaces();
+ if (interfaces != null) {
+ while (interfaces.hasMoreElements()) {
+ NetworkInterface current = interfaces.nextElement();
+
+ if (!current.isUp() || current.isLoopback()
+ || current.isVirtual())
+ continue;
+ ifList.add(current.getName());
+ }
+ }
+ } catch (SocketException e) {
+ EMLogger.getLogger().warning(e.getMessage());
+ throw new VMWorkerException(e.getMessage());
+ }
+
+ // Except bridges in list
+ List<String> brList = TapUtil.getBridgeList();
+ for (String str : ifList) {
+ if (!brList.contains(str)) {
+ result.add(str);
+ }
+ }
+
+ return result;
+ }
+
+ // Generate script file and run as admin(sudo)
+ private static boolean createTapDevice() throws VMWorkerException {
+ boolean result = true;
+
+ String script = generateScript();
+
+ File tempFile = null;
+ FileWriter writer = null;
+ List<String> cmd = null;
+ ProcessResult res = null;
+ try {
+ // create temp file and write script
+ File dir = new File(FilePathResources.getBinPath());
+ tempFile = File.createTempFile("tap_script~", ".sh", dir);
+ writer = new FileWriter(tempFile);
+ writer.append(script);
+ writer.flush();
+ writer.close();
+
+ // Add executable attribute.
+ cmd = Arrays.asList("chmod", "+x", tempFile.getAbsolutePath());
+ res = HelperClass.runProcess(cmd);
+ if (res.isSuccess() == false) {
+ EMLogger.getLogger().warning(
+ "Fail to run process. " + cmd + " failed");
+ result = false;
+
+ } else {
+ // Run script. TODO if gksudo not exist ?
+ if (isCommandExist("gksudo"))
+ cmd = Arrays
+ .asList(new String[] {
+ "gksudo",
+ "-m",
+ "\nEnter your password to create tap device and change bridge configuration.",
+ tempFile.getAbsolutePath() });
+ else {
+ cmd = Arrays.asList(new String[] { "pkexec",
+ tempFile.getAbsolutePath() });
+ }
+ res = HelperClass.runProcess(cmd);
+
+ if (res.isSuccess() == true && isTapCreated(tapName, ifName)) {
+ EMLogger.getLogger()
+ .info("Tap device created : " + tapName);
+ result = true;
+ new MessageDialog().openInfoDialog("Tap device created : "
+ + tapName);
+
+ } else {
+ EMLogger.getLogger().warning(
+ "Fail to run script with sudo. " + cmd + " failed");
+ for (String str : res.getStdOutMsg()) {
+ EMLogger.getLogger().warning(str);
+ }
+ for (String str : res.getStdErrMsg()) {
+ EMLogger.getLogger().warning(str);
+ }
+ result = false;
+ new VMWorkerException(res.getResultMessage());
+ }
+ }
+
+ } catch (IOException e) {
+ EMLogger.getLogger().warning(
+ "Failed to create tap device. " + e.getMessage());
+
+ } finally {
+ // close writer
+ if (writer != null) {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ // delete temp file
+ if (tempFile != null) {
+ tempFile.delete();
+ }
+ }
+
+ return result;
+ }
+
+ private static boolean isCommandExist(String command)
+ throws VMWorkerException {
+ List<String> cmd = Arrays.asList(new String[] { "which", command });
+ ProcessResult res = HelperClass.runProcess(cmd);
+ return res.isSuccess() && res.getResultMessage().contains(command);
+ }
+
+ private static String generateScript() throws VMWorkerException {
+ // Script.
+ // - Create tap.
+ // - Add tap and interface to bridge.
+ // - If interface is already a member of another bridge,
+ // - add tap to that bridge. And set bridge ip information as
+ // interface's ip.
+ // - If interface is not a member of other bridge,
+ // - create new bridge and add tap and interface to new bridge.
+
+ // Create tap device.
+ StringBuilder script = new StringBuilder();
+ script.append("#!/bin/bash +x\n\n");
+
+ script.append("# Create the tap device.\n");
+ script.append("openvpn --mktun --dev ").append(tapName).append("\n");
+ script.append("ifconfig ").append(tapName)
+ .append(" 0.0.0.0 promisc up\n\n");
+
+ // Create the bridge if need.
+ String bridgeName;
+ String bridge = TapUtil.getBridgeFromDevice(ifName);
+ if (bridge == null) {
+ bridgeName = getNewBridgeName();
+ script.append("# Create the bridge.\n");
+ script.append("brctl addbr ").append(bridgeName).append("\n\n");
+
+ InterfaceAddress addr = TapUtil.getInterfaceIpInfo(ifName);
+ if (addr == null) {
+ throw new VMWorkerException(
+ "Cannot get the ip address information of interface : "
+ + ifName);
+ }
+ String ipAddr = addr.getAddress().getHostAddress();
+ String broadCastAddr = addr.getBroadcast().getHostAddress();
+ String netMask = TapUtil.getNetMask(addr.getNetworkPrefixLength());
+ script.append("# Bring up the bridge.\n");
+ script.append("ifconfig ").append(bridgeName).append(" ")
+ .append(ipAddr).append(" netmask ").append(netMask)
+ .append(" broadcast ").append(broadCastAddr).append("\n\n");
+
+ } else {
+ bridgeName = bridge;
+ // TODO Popup message about change.. (bridge ip info may be
+ // changed..)
+ }
+
+ // Add tap to bridge
+ script.append("# Take interface down.\n");
+ script.append("ifdown ").append(ifName).append("\n");
+ script.append("ifconfig ").append(ifName)
+ .append(" 0.0.0.0 promisc up\n\n");
+
+ script.append("# Add tap device and interface to bridge.\n");
+ if (bridge == null) {
+ script.append("brctl addif ").append(bridgeName).append(" ")
+ .append(ifName).append("\n");
+ }
+ script.append("brctl addif ").append(bridgeName).append(" ")
+ .append(tapName).append("\n\n");
+
+ // Add default gateway
+ List<String> gatewayList = TapUtil.getDefaultGateway(null);
+ if (gatewayList.size() == 0) {
+ // user input gateway address
+ String gw = IPAddressInputDialog.open("Input gateway address");
+ if (gw != null) {
+ gatewayList.add(gw);
+
+ } else {
+ throw new VMWorkerException("User canceled.");
+ }
+ }
+ script.append("# Add the default route.\n");
+ for (String gateway : gatewayList) {
+ script.append("route add default gw ").append(gateway)
+ .append("\n\n");
+ }
+
+ script.append("exit 0\n");
+ return script.toString();
+ }
+
+ private static boolean isTapCreated(String tapName, String ifName) {
+ for (String str : TapUtil.getTapList()) {
+ if (str.equals(tapName)) {
+ return true;
+ }
+ }
+ // TODO Check tap, interface is bridged correctly.
+ return false;
+ }
+
+ private static String getNewBridgeName() throws VMWorkerException {
+ final String prefix = "br-tizen-vm-";
+ int index = 1;
+
+ String bridgeName;
+ List<String> bridgeList = TapUtil.getBridgeList();
+
+ boolean isExist;
+ do {
+ isExist = false;
+ bridgeName = prefix + String.valueOf(index++);
+ for (String str : bridgeList) {
+ if (bridgeName.equals(str)) {
+ isExist = true;
+ break;
+ }
+ }
+ } while (isExist);
+
+ return bridgeName;
+ }
+
+}
+
+// Gateway Input dialog.
+class GatewayInputDialog {
+ private static Shell dialog = null;
+ private static int width = 300;
+ private static int height = 130;
+ private static Image image;
+ private static int COMP_WIDTH = 270;
+ private static int UPPER_HEIGHT = 27;
+ private static int ITEM_COUNT = 1;
+
+ private static Text gwText;
+ private static String gatewayAddr;
+
+ private static Button okButton;
+ private static Button cancelButton;
+
+ static {
+ image = PatchImageResources.getDetailListView2(ITEM_COUNT);
+ }
+
+ public static String open(String content) {
+ gatewayAddr = null;
+ makeDialog(content);
+ dialog.open();
+ while (!dialog.isDisposed()) {
+ if (!Display.getCurrent().readAndDispatch()) {
+ Display.getCurrent().sleep();
+ }
+ }
+ return gatewayAddr;
+ }
+
+ private static void makeDialog(String content) {
+ dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
+ | SWT.APPLICATION_MODAL);
+ dialog.setText(content);
+ dialog.setSize(width, height);
+ dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ RowLayout rowLayout = new RowLayout();
+ rowLayout.type = SWT.VERTICAL;
+ rowLayout.marginTop = 15;
+ rowLayout.marginLeft = 10;
+ rowLayout.spacing = 15;
+
+ dialog.setLayout(rowLayout);
+
+ makeUpperComposite();
+ makeLowerComposite();
+ addListener();
+
+ }
+
+ private static void makeUpperComposite() {
+ Composite upperComp = new Composite(dialog, SWT.BORDER);
+ upperComp.setLayoutData(new RowData(COMP_WIDTH, UPPER_HEIGHT));
+ upperComp.addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ Rectangle rect = ((Composite) e.widget).getClientArea();
+ e.gc.drawImage(image, rect.x - 2, rect.y);
+
+ }
+ });
+ upperComp.setLayout(new FormLayout());
+
+ // tap name (text input)
+ Label nameLabel = new Label(upperComp, SWT.NONE);
+ nameLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ nameLabel.setText("Gateway");
+ nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 15);
+ data.top = new FormAttachment(0, 4);
+ data.width = 85;
+ data.height = 20;
+ nameLabel.setLayoutData(data);
+
+ Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(150);
+ ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE);
+ valueLabel.setEnableImage(INPUTBOX_ON_IMAGE);
+ valueLabel.setLayout(new FormLayout());
+ data = new FormData();
+ data.left = new FormAttachment(0, 100);
+ data.top = new FormAttachment(0, 4);
+ data.width = 150;
+ data.height = 19;
+ valueLabel.setLayoutData(data);
+
+ gwText = new Text(valueLabel, SWT.NONE);
+ gwText.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
+ gwText.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
+ gwText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR.getColor());
+ gwText.setTextLimit(20);
+
+ data = new FormData();
+ data.left = new FormAttachment(0, 5);
+ data.top = new FormAttachment(0, 2);
+ data.right = new FormAttachment(100, -5);
+ data.bottom = new FormAttachment(100, -2);
+ gwText.setLayoutData(data);
+
+ }
+
+ private static void makeLowerComposite() {
+ Composite lowerComp = new Composite(dialog, SWT.NONE);
+ lowerComp.setLayoutData(new RowData(COMP_WIDTH + 1, 30));
+ lowerComp
+ .setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ lowerComp.setLayout(new FormLayout());
+
+ int BUTTON_WIDTH = 128;
+ int BUTTON_HEIGHT = 26;
+
+ okButton = new Button(lowerComp, SWT.PUSH);
+ okButton.setText("OK");
+ okButton.setEnabled(true);
+ okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 0);
+ data.top = new FormAttachment(0, 0);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ okButton.setLayoutData(data);
+ okButton.setEnabled(false);
+
+ cancelButton = new Button(lowerComp, SWT.PUSH);
+ cancelButton.setText("CANCEL");
+ cancelButton.setEnabled(true);
+ cancelButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ data = new FormData();
+ data.left = new FormAttachment(okButton, 16);
+ data.top = new FormAttachment(0, 0);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ cancelButton.setLayoutData(data);
+
+ }
+
+ private static void addListener() {
+
+ gwText.addModifyListener(new ModifyListener() {
+ public void modifyText(ModifyEvent arg0) {
+ // Check ip address
+ okButton.setEnabled(TapUtil.checkIP(gwText.getText()));
+ }
+ });
+
+ okButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+ gatewayAddr = gwText.getText();
+ dialog.close();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+
+ }
+ });
+
+ cancelButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+ dialog.close();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+
+ }
+ });
+
+ }
+}
--- /dev/null
+/* Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+
+package org.tizen.emulator.manager.ui.dialog;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.PaintEvent;
+import org.eclipse.swt.events.PaintListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.tizen.emulator.manager.resources.ColorResources;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.resources.PatchImageResources;
+import org.tizen.emulator.manager.tool.TapUtil;
+import org.tizen.emulator.manager.ui.MainDialog;
+import org.tizen.emulator.manager.ui.detail.item.template.ComboViewItem;
+import org.tizen.emulator.manager.ui.widgets.ImageLabel;
+import org.tizen.emulator.manager.vms.helper.HelperClass;
+
+public class TapDeviceDialogForWin {
+ private static Shell dialog = null;
+ private static int width = 300;
+ private static int height = 130;
+ private static Image image;
+ private static int COMP_WIDTH = 270;
+ private static int UPPER_HEIGHT = 27;
+ private static int ITEM_COUNT = 1;
+
+ private static Text nameText;
+
+ private static Button okButton;
+ private static Button cancelButton;
+
+ private static String tapName;
+
+ private static ComboViewItem comboViewItem;
+
+
+ static {
+ image = PatchImageResources.getDetailListView2(ITEM_COUNT);
+ }
+
+ public static void open(ComboViewItem comboViewItem) {
+ TapDeviceDialogForWin.comboViewItem = comboViewItem;
+ makeDialog();
+ dialog.open();
+ while (!dialog.isDisposed()) {
+ if (!Display.getCurrent().readAndDispatch()) {
+ Display.getCurrent().sleep();
+ }
+ }
+ }
+
+
+ private static void makeDialog() {
+ dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM
+ | SWT.APPLICATION_MODAL);
+ dialog.setText("Creating tap device.");
+ dialog.setSize(width, height);
+ dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ RowLayout rowLayout = new RowLayout();
+ rowLayout.type = SWT.VERTICAL;
+ rowLayout.marginTop = 15;
+ rowLayout.marginLeft = 10;
+ rowLayout.spacing = 3;
+
+ dialog.setLayout(rowLayout);
+
+ makeUpperComposite();
+ makeLowerComposite();
+ addListener();
+
+ }
+
+ private static void makeUpperComposite() {
+ Composite upperComp = new Composite(dialog, SWT.BORDER);
+ upperComp.setLayoutData(new RowData(COMP_WIDTH, UPPER_HEIGHT));
+ upperComp.addPaintListener(new PaintListener() {
+ public void paintControl(PaintEvent e) {
+ Rectangle rect = ((Composite) e.widget).getClientArea();
+ e.gc.drawImage(image, rect.x - 2, rect.y);
+
+ }
+ });
+ upperComp.setLayout(new FormLayout());
+
+ // tap name (text input)
+ Label nameLabel = new Label(upperComp, SWT.NONE);
+ nameLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ nameLabel.setText("Tap name");
+ nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, 15);
+ data.top = new FormAttachment(0, 4);
+ data.width = 85;
+ data.height = 20;
+ nameLabel.setLayoutData(data);
+
+ Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(150);
+ ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE);
+ valueLabel.setEnableImage(INPUTBOX_ON_IMAGE);
+ valueLabel.setLayout(new FormLayout());
+ data = new FormData();
+ data.left = new FormAttachment(0, 100);
+ data.top = new FormAttachment(0, 4);
+ data.width = 150;
+ data.height = 19;
+ valueLabel.setLayoutData(data);
+
+ nameText = new Text(valueLabel, SWT.NONE);
+ nameText.setBackground(ColorResources.DETAIL_INPUT_BOX_COLOR.getColor());
+ nameText.setFont(FontResources.DETAIL_LABEL_FONT.getFont());
+ nameText.setForeground(ColorResources.DETAIL_ENABLE_FONT_COLOR.getColor());
+ nameText.setTextLimit(20);
+
+ data = new FormData();
+ data.left = new FormAttachment(0, 5);
+ data.top = new FormAttachment(0, 2);
+ data.right = new FormAttachment(100, -5);
+ data.bottom = new FormAttachment(100, -2);
+ nameText.setLayoutData(data);
+ nameText.setEnabled(false);
+ nameText.setText(TapUtil.getAvailableTapName());
+
+ }
+
+ private static void makeLowerComposite() {
+ Composite lowerComp = new Composite(dialog, 0);
+ lowerComp.setLayoutData(new RowData(COMP_WIDTH + 1, 40));
+ lowerComp.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ lowerComp.setLayout(new FormLayout());
+
+ FormData data = new FormData();
+// Label infoLabel = new Label(lowerComp, SWT.NONE);
+// data.left = new FormAttachment(5, 0);
+// data.top = new FormAttachment(0, 0);
+// data.right = new FormAttachment(100,-1);
+// data.height = 13;
+// infoLabel.setLayoutData(data);
+// infoLabel.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+// infoLabel.setForeground(ColorResources.TEAL.getColor());
+// infoLabel.setFont(FontResources.TOOLTIP.getFont());
+// infoLabel.setText("- Input tap device name.(alphanumeric)"); // TODO
+
+ int BUTTON_WIDTH = 128;
+ int BUTTON_HEIGHT = 26;
+
+ okButton = new Button(lowerComp, SWT.PUSH);
+ okButton.setText("OK");
+ okButton.setEnabled(true);
+ okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ data = new FormData();
+ data.left = new FormAttachment(0, 0);
+ data.top = new FormAttachment(0, 15);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ okButton.setLayoutData(data);
+
+ cancelButton = new Button(lowerComp, SWT.PUSH);
+ cancelButton.setText("CANCEL");
+ cancelButton.setEnabled(true);
+ cancelButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont());
+ data = new FormData();
+ data.left = new FormAttachment(okButton, 16);
+ data.top = new FormAttachment(0, 15);
+ data.width = BUTTON_WIDTH;
+ data.height = BUTTON_HEIGHT;
+ cancelButton.setLayoutData(data);
+
+ }
+
+ private static void addListener() {
+
+// nameText.addModifyListener(new ModifyListener() {
+// public void modifyText(ModifyEvent arg0) {
+// // name invalidation
+// if (!nameText.getText().isEmpty() &&
+// HelperClass.checkString(nameText.getText())) {
+// okButton.setEnabled(true);
+// } else {
+// okButton.setEnabled(false);
+// }
+// }
+// });
+
+ okButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+
+ // Check Tap duplication
+// if (TapUtil.nameNotExist(nameText.getText())) {
+ tapName = nameText.getText();
+ dialog.close();
+
+ TapUtil.createTapDevice(tapName, comboViewItem);
+
+// } else {
+// new MessageDialog().openWarningDialog("Name already exist.");
+// }
+
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+ });
+
+ cancelButton.addSelectionListener(new SelectionListener() {
+ public void widgetSelected(SelectionEvent arg0) {
+ dialog.close();
+ }
+
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+
+ }
+ });
+
+ }
+
+
+}
+
--- /dev/null
+/* Emulator Manager
+ *
+ * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
+
+
+package org.tizen.emulator.manager.ui.dialog;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.tizen.emulator.manager.resources.ColorResources;
+import org.tizen.emulator.manager.resources.FontResources;
+import org.tizen.emulator.manager.ui.MainDialog;
+
+public class TapGuideDialogForWin {
+
+ private static Shell dialog = null;
+ private static int WIDTH = 520;
+ private static int HEIGHT = 590;
+
+ private static int TITLE_INDENT = 7;
+ private static int CONTENT_INDENT = 15;
+
+ public static void open() {
+ makeDialog();
+ dialog.open();
+ while (!dialog.isDisposed()) {
+ if (!Display.getCurrent().readAndDispatch()) {
+ Display.getCurrent().sleep();
+ }
+ }
+ }
+
+ private static void makeDialog() {
+ dialog = new Shell(MainDialog.getShell(), SWT.DIALOG_TRIM | SWT.NONE);
+ dialog.setText("Using bridge network");
+ dialog.setSize(WIDTH, HEIGHT);
+ dialog.setBackground(ColorResources.TAB_CONTENTS_BG_COLOR.getColor());
+ RowLayout rowLayout = new RowLayout();
+ rowLayout.type = 512;
+ rowLayout.marginTop = 15;
+ rowLayout.marginLeft = 10;
+ rowLayout.spacing = 3;
+ dialog.setLayout(rowLayout);
+ makeContent();
+
+ }
+
+ private static void makeContent() {
+
+ Composite comp = new Composite(dialog, SWT.BORDER);
+ comp.setLayoutData(new RowData(WIDTH - 30, HEIGHT - 60));
+ comp.setLayout(new FormLayout());
+
+ Label objective = new Label(comp, SWT.NONE);
+ objective.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ objective
+ .setText("To use bridge network in Tizen emulator, bridge connection should be"
+ + "\ncreated with proper TCP/IP setting.");
+ FormData data = new FormData();
+ data.left = new FormAttachment(0, TITLE_INDENT);
+ data.top = new FormAttachment(0, 5);
+ data.width = WIDTH - 50;
+ data.height = 40;
+ objective.setLayoutData(data);
+
+ Label title1 = new Label(comp, SWT.NONE);
+ title1.setFont(FontResources.DETAIL_TOP_FONT.getFont());
+ title1.setForeground(ColorResources.TEAL.getColor());
+ title1.setText("Create a network bridge");
+ data = new FormData();
+ data.left = new FormAttachment(0, TITLE_INDENT);
+ data.top = new FormAttachment(objective, 3);
+ data.width = WIDTH - 50;
+ data.height = 20;
+ title1.setLayoutData(data);
+
+ Label content1 = new Label(comp, SWT.NONE);
+ String msg = "1. Open Network Connections by clicking the Start button, and then"
+ + "\nclicking Control Panel. In the search box, type adapter, and then,"
+ + "\nclick Network and Sharing Center click View network connections."
+
+ + "\n\n2. Hold down the Ctrl key and select each network connection that"
+ + "\nyou want to add to the bridge."
+ + "\nFor example, Tap + Local area connection."
+
+ + "\n\n3. Right-click one of the selected network connections, and then"
+ + "\nclick Bridge Connections.";
+
+ content1.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ content1.setText(msg);
+ // nameLabel.set
+ // nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ data = new FormData();
+ data.left = new FormAttachment(0, CONTENT_INDENT);
+ data.top = new FormAttachment(title1, 5);
+ data.width = WIDTH - 50;
+ data.height = 150;
+ content1.setLayoutData(data);
+
+ Label title2 = new Label(comp, SWT.NONE);
+ title2.setFont(FontResources.DETAIL_TOP_FONT.getFont());
+ title2.setForeground(ColorResources.TEAL.getColor());
+ title2.setText("TCP/IP setting for bridge connection.");
+ data = new FormData();
+ data.left = new FormAttachment(0, TITLE_INDENT);
+ data.top = new FormAttachment(content1, 20);
+ data.width = WIDTH - 50;
+ data.height = 20;
+ title2.setLayoutData(data);
+
+ Label content2 = new Label(comp, SWT.NONE);
+ String msg2 = "Set TCP/IP configuration for bridge. -Use Local area connection's"
+ + "\nconfiguration : IP, subnet, gateway and DNS."
+ + "\n(Bridge with DHCP is not supported by Tizen emulator.)"
+
+ + "\n\n1. Open the network connections.(Follow above step1.)"
+
+ + "\n\n2. Right click on network bridge and from drop-down choose Properties."
+ + "\nUnder the Networking tab, choose Internet Protocol Version 4(TCP/IPv4)"
+ + "\nand then click Properties."
+
+ + "\n\n3. Click Use the following IP address, and set IP address, Subnet mask,"
+ + "\nDefault gateway. And set DNS server.";
+
+ content2.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ content2.setText(msg2);
+ // nameLabel.set
+ // nameLabel.setBackground(ColorResources.DETAIL_MIDDLE_COLOR.getColor());
+ data = new FormData();
+ data.left = new FormAttachment(0, CONTENT_INDENT);
+ data.top = new FormAttachment(title2, 5);
+ data.width = WIDTH - 50;
+ data.height = 200;
+ content2.setLayoutData(data);
+
+ Label end = new Label(comp, SWT.NONE);
+ String endMsg = "Finally, check if your host network works and continue launching VM."
+ + "\nIf host network doesn't work like before, there may be some problems in"
+ + "\nbridge configuration.";
+ end.setFont(FontResources.DETAIL_TITLE_FONT.getFont());
+ end.setText(endMsg);
+ data = new FormData();
+ data.left = new FormAttachment(0, TITLE_INDENT);
+ data.top = new FormAttachment(content2, 0);
+ data.width = WIDTH - 50;
+ data.height = 50;
+ end.setLayoutData(data);
+
+ }
+
+}