From c6ff674e349ca88d81a893e74447f7a94c234ad9 Mon Sep 17 00:00:00 2001 From: "minkee.lee" Date: Thu, 11 Sep 2014 20:08:58 +0900 Subject: [PATCH] Remote: Added web-viewer type VM handling . - Added pop-up after VM is launched as web-viewer type. (spice mode) - Added tool-tip information to VM list. Change-Id: Ia515beb66a7f0409d85c571fcf9db65afb8be2cf Signed-off-by: minkee.lee --- .../manager/resources/FilePathResources.java | 4 + .../ui/detail/item/template/ComboSubViewItem.java | 14 ++- .../ui/detail/item/template/ComboViewItem.java | 14 ++- .../emulator/manager/ui/widgets/ImageButton.java | 2 +- .../emulator/manager/ui/widgets/VMButton.java | 78 +++++++++++++++ .../vms/helper/CheckingRunningEmulator.java | 107 +++++++++++++++++++++ .../emulator/manager/vms/helper/HelperClass.java | 41 ++++++++ 7 files changed, 257 insertions(+), 3 deletions(-) diff --git a/common-project/src/org/tizen/emulator/manager/resources/FilePathResources.java b/common-project/src/org/tizen/emulator/manager/resources/FilePathResources.java index 80bac11..3c26429 100644 --- a/common-project/src/org/tizen/emulator/manager/resources/FilePathResources.java +++ b/common-project/src/org/tizen/emulator/manager/resources/FilePathResources.java @@ -478,4 +478,8 @@ public class FilePathResources { public static String getOldSdkDataVmsPath() { return oldSdkDataVmsPath; } + + public static String getEmulatorPath() { + return emulatorPath; + } } diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/ComboSubViewItem.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/ComboSubViewItem.java index b0e01c3..de7be47 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/ComboSubViewItem.java +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/ComboSubViewItem.java @@ -62,6 +62,9 @@ public class ComboSubViewItem extends SubViewItem { protected Image INPUTBOX_ON_IMAGE = null; protected static int COMBO_WIDTH = 105; + private boolean useDefaultOnCreate = false; + private String defaultOnCreate = null; + public ComboSubViewItem(LabelViewItem parentItem, Composite comp, Item template) { super(parentItem, comp, template); parseOption(template.getOption()); @@ -75,6 +78,11 @@ public class ComboSubViewItem extends SubViewItem { comboOptions.add(s.trim()); } } + + if (option.getName().equals(OptionType.DEFAULT_ON_CREATE.getName())) { + useDefaultOnCreate = true; + defaultOnCreate = option.getValue(); + } } } @@ -140,7 +148,11 @@ public class ComboSubViewItem extends SubViewItem { @Override public boolean settingModifyItem(VMPropertyValue value) { - newValue = value.getAdvancedOptionSubValue(parentItem.getName(), name); + if (parentItem.isCreateMode() && useDefaultOnCreate) { + newValue = defaultOnCreate; + } else { + newValue = value.getAdvancedOptionSubValue(parentItem.getName(), name); + } // make combo box list combo.removeAll(); diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/ComboViewItem.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/ComboViewItem.java index 3882387..e5f46ea 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/ComboViewItem.java +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/item/template/ComboViewItem.java @@ -73,6 +73,9 @@ public class ComboViewItem extends AdvancedViewItem{ protected Image INPUTBOX_OFF_IMAGE = null; protected int COMBOBOX_WIDTH = 175; + private boolean useDefaultOnCreate = false; + private String defaultOnCreate = null; + public ComboViewItem(Item template, LineLabelViewItem lineLabelViewItem) { super(lineLabelViewItem); if (lineLabelViewItem == null) { @@ -94,6 +97,11 @@ public class ComboViewItem extends AdvancedViewItem{ comboOptions.add(s.trim()); } } + + if (option.getName().equals(OptionType.DEFAULT_ON_CREATE.getName())) { + useDefaultOnCreate = true; + defaultOnCreate = option.getValue(); + } } } @@ -189,8 +197,12 @@ public class ComboViewItem extends AdvancedViewItem{ @Override public boolean settingModifyItem(VMPropertyValue value) { + if (isCreateMode() && useDefaultOnCreate) { + newValue = defaultOnCreate; + } else { + newValue = getItemValue(value); + } - newValue = getItemValue(value); // makeComboBox combo.removeAll(); diff --git a/common-project/src/org/tizen/emulator/manager/ui/widgets/ImageButton.java b/common-project/src/org/tizen/emulator/manager/ui/widgets/ImageButton.java index da20232..06e886d 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/widgets/ImageButton.java +++ b/common-project/src/org/tizen/emulator/manager/ui/widgets/ImageButton.java @@ -66,7 +66,7 @@ public class ImageButton extends Canvas { protected ArrayList fonts = null; private String text = ""; - private boolean selected = false; + protected boolean selected = false; private boolean defaultPush = true; private int RADIO_IMAGE_SIZE = 16; diff --git a/common-project/src/org/tizen/emulator/manager/ui/widgets/VMButton.java b/common-project/src/org/tizen/emulator/manager/ui/widgets/VMButton.java index 66fe212..c5b0eae 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/widgets/VMButton.java +++ b/common-project/src/org/tizen/emulator/manager/ui/widgets/VMButton.java @@ -47,6 +47,10 @@ import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.MenuItem; import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.platform.BaseImage; import org.tizen.emulator.manager.plugin.ExtensionItem; @@ -58,6 +62,9 @@ import org.tizen.emulator.manager.ui.MainDialog; import org.tizen.emulator.manager.ui.VMsMainView; import org.tizen.emulator.manager.ui.list.VMButtonFactory; import org.tizen.emulator.manager.vms.VMProperty; +import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator; +import org.tizen.emulator.manager.vms.helper.HelperClass; +import org.tizen.emulator.manager.vms.helper.VMSocket; public class VMButton extends ImageButton { private VMButton button = null; @@ -90,6 +97,8 @@ public class VMButton extends ImageButton { settingImage(); settingLaunchButton(); + addListener(SWT.MouseEnter, mouseListener); + } private void settingImage() { @@ -159,6 +168,7 @@ public class VMButton extends ImageButton { // TODO Auto-generated method stub } }); + } public void clickLaunchButton() { @@ -309,4 +319,72 @@ public class VMButton extends ImageButton { } }; + + + private Listener mouseListener = new Listener() { + + @Override + public void handleEvent(Event event) { + if (state == WSTATE.DISABLE) { + return; + } + + VMButton button = (VMButton) event.widget; + if (event.type == SWT.MouseDown) { + button.setFocus(); + if (state != WSTATE.PUSH) { + if (state == WSTATE.SELECTED + || state == WSTATE.SELECTED_HOVER ) { + state = WSTATE.SELECTED_PUSH; + } else { + state = WSTATE.PUSH; + } + } + redraw(); + } else if (event.type == SWT.MouseUp) { + Rectangle rect = button.getClientArea(); + if (rect.contains(event.x, event.y)) { + notifyListeners(SWT.Selection, new Event()); + //notifyListeners(SWT.DefaultSelection, new Event()); + } + } else if (event.type == SWT.MouseEnter) { + if ((state != WSTATE.HOVER) && (state != WSTATE.SELECTED_HOVER)) { + if (selected) { + state = WSTATE.SELECTED_HOVER; + } else { + state = WSTATE.HOVER; + } + } + // Check tooltip text. + checkToolTipText(button); + redraw(); + } else if (event.type == SWT.MouseExit) { + button.setSelection(selected); + } + } + }; + + private void checkToolTipText(VMButton button) { + VMProperty prop = button.getProperty(); + if (prop != null) { + if (CheckingRunningEmulator.isRemote(prop) && prop.isRunning()) { + int webVMPort = 0; + synchronized (VMSocket.list) { + for (VMSocket s : VMSocket.list) { + if (s.getProperty() != null && s.getProperty().getName().equals(prop.getName())) { + webVMPort = s.getEcs_port() + 3; + } + } + } + if (webVMPort > 0) { + String ip = HelperClass.getLocalIPAddress(webVMPort-3); + button.setToolTipText(prop.getName() + "(web client)" + "\n" + + "url : " + ip + ":8080\n" + + "vm port : " + webVMPort); + } + } else { + button.setToolTipText(prop.getName()); + } + } + } } \ No newline at end of file diff --git a/common-project/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java b/common-project/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java index 48fd515..1806b62 100644 --- a/common-project/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java +++ b/common-project/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java @@ -37,6 +37,7 @@ import java.nio.channels.Selector; import java.nio.channels.SocketChannel; import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import org.eclipse.swt.widgets.Display; import org.tizen.ecp.msg.genmsg.ecs.Ecs.DeviceAns; @@ -45,6 +46,7 @@ import org.tizen.ecp.msg.genmsg.ecs.EcsIds.Master_Type; import org.tizen.emulator.manager.EmulatorManager; import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.ui.VMsMainView; +import org.tizen.emulator.manager.ui.dialog.MessageDialog; import org.tizen.emulator.manager.vms.EmulatorVMList; import org.tizen.emulator.manager.vms.VMProperty; import org.tizen.emulator.manager.vms.helper.VMSocketQueue.QueueObject; @@ -54,6 +56,41 @@ public class CheckingRunningEmulator { private static CheckingThread thread = null; + // Decide whether popup-message display or not. + private static List LAUNCHED_VM_LIST = new ArrayList(); + + public static void addLaunchedVMList(String vmName) { + synchronized(LAUNCHED_VM_LIST) { + LAUNCHED_VM_LIST.add(vmName); + } + } + + private static void removeLaunchedVMList(String vmName) { + synchronized(LAUNCHED_VM_LIST) { + LAUNCHED_VM_LIST.remove(vmName); + } + } + + public static boolean needPopupMessage(VMSocket vms) { + if (vms.getProperty() != null) { + String vmName = vms.getProperty().getName(); + String launched = null; + synchronized(LAUNCHED_VM_LIST) { + for (String s : LAUNCHED_VM_LIST) { + if (s.equals(vmName)) { + launched = s; + } + } + if (launched != null) { + removeLaunchedVMList(launched); + return true; + } + } + } + return false; + + } + public static synchronized void startCheckingThread() { if (EmulatorManager.isConsoleMode()) { return; @@ -100,6 +137,7 @@ public class CheckingRunningEmulator { if (!isSuccess) { prop.setRunning(false); } else { + addLaunchedVMList(prop.getName()); connectToECS(prop); if (prop.getWorker() != null) { prop.getWorker().getLauncher().sendRemoteLog("start"); @@ -133,6 +171,7 @@ public class CheckingRunningEmulator { } boolean isHeartBeat = false; boolean isImagePathSame = false; + VMSocket currentVms = null; synchronized (VMSocket.list) { for (VMSocket s : VMSocket.list) { @@ -145,6 +184,7 @@ public class CheckingRunningEmulator { switch(type){ case PATH_SAME: isImagePathSame = true; + currentVms = s; break; case SOCK_CLOSED: @@ -165,6 +205,11 @@ public class CheckingRunningEmulator { if (isImagePathSame) { vm.setRunning(true); CheckingRunningEmulator.removeEmulator(vm); + // Check remote option. + if (isRemote(vm)) { +// runServer(currentVms); + showInfoDialog(currentVms); + } } else { vm.setRunning(false); } @@ -372,6 +417,10 @@ public class CheckingRunningEmulator { if (vms.getProperty() != null && vms.getProperty().getWorker() != null) { vms.getProperty().getWorker().getLauncher().sendRemoteLog("stop"); } + // Check remote. +// if (isRemote(vms.getProperty())) { +// killServer(vms); +// } } disconnect(vms); } @@ -406,6 +455,12 @@ public class CheckingRunningEmulator { prop.setRunning(true); CheckingRunningEmulator.removeEmulator(prop); + // Check remote option. + if (isRemote(prop)) { +// runServer(vms); + showInfoDialog(vms); + } + // this is not need for console mode Display.getDefault().asyncExec(new Runnable() { public void run() { @@ -419,4 +474,56 @@ public class CheckingRunningEmulator { } } + + public static String OPTION_VIEWER = "viewer"; + public static String OPTION_TYPE = "type"; + public static String VAL_WEB = "Web"; + + public static boolean isRemote(VMProperty prop) { + if (EmulatorManager.isLinux() && prop.getPropertyValue().getAdvancedOptionSubValue( + OPTION_VIEWER, OPTION_TYPE).equals(VAL_WEB)) { + return true; + } + return false; + } + + /* + public static void runServer(VMSocket vms) { + // Run web(Node) server (if not running) + boolean nodeResult = WebEmulator.runWebServer(); + + // Run emulator(spice) server (if not running) + boolean spiceResult = WebEmulator.runEmulatorServer(vms); + + showInfoDialog(nodeResult, spiceResult, vms); + } + */ + + public static void showInfoDialog(VMSocket vms) { + if(needPopupMessage(vms)) { + final int clientPort = vms.getEcs_port() + 3; + final String vmName = (vms.getProperty() != null) ? vms.getProperty().getName() : ""; + final String ip = HelperClass.getLocalIPAddress(vms.getEcs_port()); + Display.getDefault().asyncExec(new Runnable() { + public void run() { + MessageDialog msgDialog = new MessageDialog(); + String title = "Web viewer Information (" + vmName + ")"; + String msg = "\nURL : http://" + ip + ":8080\n" + + "VM Port : " + clientPort + "\n\n" + + "You can connect to emulator via web-browser."; + msgDialog.openInfoDialog(title, msg); + } + }); + } + } + + /* + public static void killServer(VMSocket vms) { + WebEmulator.killEmulatorServer(vms); + + // Kill web server if no remote VM runs. + WebEmulator.killWebServer(); + } + */ + } diff --git a/common-project/src/org/tizen/emulator/manager/vms/helper/HelperClass.java b/common-project/src/org/tizen/emulator/manager/vms/helper/HelperClass.java index 9120657..51270b5 100644 --- a/common-project/src/org/tizen/emulator/manager/vms/helper/HelperClass.java +++ b/common-project/src/org/tizen/emulator/manager/vms/helper/HelperClass.java @@ -31,6 +31,18 @@ package org.tizen.emulator.manager.vms.helper; import java.io.File; +import java.io.IOException; +import java.net.ConnectException; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.NetworkInterface; +import java.net.ServerSocket; +import java.net.SocketAddress; +import java.net.SocketException; +import java.nio.channels.SocketChannel; +import java.nio.channels.UnresolvedAddressException; +import java.util.Enumeration; import org.tizen.emulator.manager.EmulatorManager; import org.tizen.emulator.manager.logging.EMLogger; @@ -201,4 +213,33 @@ public class HelperClass { return layout; } */ + +// public static String loaclIPAddress = null; + public static String loaclIPAddress = "(your IP)"; // TODO + public static String getLocalIPAddress(int ecsPort) { + if (loaclIPAddress == null) { + Enumeration interfaces; + try { + interfaces = NetworkInterface.getNetworkInterfaces(); + while (interfaces.hasMoreElements()){ + NetworkInterface current = interfaces.nextElement(); + + if (!current.isUp() || current.isLoopback() || current.isVirtual()) continue; + Enumeration addresses = current.getInetAddresses(); + while (addresses.hasMoreElements()){ + InetAddress current_addr = addresses.nextElement(); + if (current_addr.isLoopbackAddress()) continue; + if (current_addr instanceof Inet6Address) continue; + + loaclIPAddress = current_addr.getHostAddress(); + } + } + } catch (SocketException e) { + EMLogger.getLogger().warning(e.getMessage()); + } + } + return loaclIPAddress; + } + } + -- 2.7.4