From: jihye424.kim Date: Tue, 22 Dec 2015 06:35:17 +0000 (+0900) Subject: Merge branch 'develop' into features/new_ui X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf1a22f333a3cfc61e5b241b6c7bd2099adca737;p=sdk%2Femulator%2Femulator-manager.git Merge branch 'develop' into features/new_ui Conflicts: src/org/tizen/emulator/manager/ui/widgets/CommonVMButtonPainter.java src/org/tizen/emulator/manager/ui/widgets/VMButton.java src/org/tizen/emulator/manager/vms/VMWorkerCommon.java src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java Change-Id: Ie263280cb0e57decadc20bf8fdcd1795505ec342 Signed-off-by: jihye424.kim --- cf1a22f333a3cfc61e5b241b6c7bd2099adca737 diff --cc src/org/tizen/emulator/manager/tool/TapUtil.java index a63a7e2,c1691ec..727cda7 --- a/src/org/tizen/emulator/manager/tool/TapUtil.java +++ b/src/org/tizen/emulator/manager/tool/TapUtil.java @@@ -555,12 -608,11 +608,11 @@@ public class TapUtil return resultKey; } - private static void setWinbridgeNetwork(String interfaceClassID) + public static void setWinbridgeNetwork(String interfaceClassID) throws VMWorkerException { HKEY interfaceKey = getInterfaceTcpipKey(interfaceClassID); - // HKEY bridgeKey = getInterfaceTcpipKey(getBridgeId()); - System.out.println("interfaceKey: " + interfaceClassID); //$NON-NLS-1$ - System.out.println("bridgeKey: " + getBridgeId()); //$NON-NLS-1$ + EMLogger.getLogger().info("interfaceID: " + interfaceClassID); //$NON-NLS-1$ + EMLogger.getLogger().info("bridgeID: " + getBridgeId()); //$NON-NLS-1$ String dns = null; String ip = null; String gateway = null; diff --cc src/org/tizen/emulator/manager/ui/renewal/dialog/TapDeviceDialogForWin.java index 941c9c4,0000000..afdd608 mode 100644,000000..100644 --- a/src/org/tizen/emulator/manager/ui/renewal/dialog/TapDeviceDialogForWin.java +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/TapDeviceDialogForWin.java @@@ -1,572 -1,0 +1,572 @@@ +/* Emulator Manager + * + * Copyright (C) 2011 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * 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.renewal.dialog; + +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +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.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.tizen.emulator.manager.EmulatorManager; +import org.tizen.emulator.manager.Messages; +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.resources.StringResources; +import org.tizen.emulator.manager.tool.TapUtil; +import org.tizen.emulator.manager.ui.MainDialog; +import org.tizen.emulator.manager.ui.dialog.MessageDialog; +import org.tizen.emulator.manager.ui.dialog.TapGuideDialogForWin; +import org.tizen.emulator.manager.ui.renewal.item.modify.vm.NetTapDeviceItemForWin; +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 TapDeviceDialogForWin { + private static Shell dialog = null; + private static int width = 395; + private static int height = 155; + private static int labelWidth = 95; + private static int comboWidth = 250; + private static int COMP_WIDTH = width - 30; + + private static Text nameText; + private static ImageCombo combo; + + private static Button okButton; + private static Button cancelButton; + + private static String tapName; + private static String ifName; + + private static NetTapDeviceItemForWin viewItem; + private static String platformVersion; + + public static ArrayList getInterfaceList() { + // Get intereface list + ProcessResult res; + ArrayList ifList = new ArrayList(); + List cmd = Arrays.asList(FilePathResources.getPlatformEmulatorBinPath(platformVersion) + + File.separator + "devcon.exe", "find", "=net", "@pci*"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + res = HelperClass.runProcess(cmd); + boolean isCommandSuccess = false; + if (res.isSuccess()) { + for (String str : res.getStdOutMsg()) { + if (str.contains(": ")) { //$NON-NLS-1$ + isCommandSuccess = true; + String pciNet = str.split(": ")[1].trim(); //$NON-NLS-1$ + EMLogger.getLogger().info( + "PCI network interface: " + pciNet); //$NON-NLS-1$ + ifList.add(pciNet); + } + } + + } else if (!res.isSuccess() || !isCommandSuccess) { + EMLogger.getLogger().warning(res.getResultMessage()); + } + + return ifList; + } + + public static void open(NetTapDeviceItemForWin viewItem, String platformVersion) { + TapDeviceDialogForWin.viewItem = viewItem; + TapDeviceDialogForWin.platformVersion = platformVersion; + 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("Setting tap device."); //$NON-NLS-1$ + 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.marginRight = 10; + rowLayout.spacing = 3; + + dialog.setLayout(rowLayout); + + makeUpperComposite(); + makeLowerComposite(); + addListener(); + + } + + private static void makeUpperComposite() { + Composite upperComp = new Composite(dialog, SWT.BORDER); + 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"); //$NON-NLS-1$ + FormData data = new FormData(); + data.left = new FormAttachment(0, 15); + data.top = new FormAttachment(0, 4); + data.width = labelWidth; + data.height = 20; + nameLabel.setLayoutData(data); + + Image INPUTBOX_ON_IMAGE = PatchImageResources.getInputBoxON(comboWidth); + ImageLabel valueLabel = new ImageLabel(upperComp, SWT.NONE); + valueLabel.setEnableImage(INPUTBOX_ON_IMAGE); + valueLabel.setLayout(new FormLayout()); + data = new FormData(); + data.left = new FormAttachment(nameLabel, 0); + data.top = new FormAttachment(0, 4); + data.width = comboWidth; + 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()); - if (!EmulatorManager.isWin8()) { ++ if (!EmulatorManager.isWin8AndAbove()) { + // interface (combo select) + Label ifLabel = new Label(upperComp, SWT.NONE); + ifLabel.setFont(FontResources.DETAIL_TITLE_FONT.getFont()); + ifLabel.setText("Host Network"); //$NON-NLS-1$ + data = new FormData(); + data.left = new FormAttachment(0, 15); + data.top = new FormAttachment(0, 31); + data.width = labelWidth; + 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(ifLabel, 0); + data.right = new FormAttachment(100, -5); + data.top = new FormAttachment(0, 31); + data.width = INPUTBOX_ON_IMAGE.getImageData().width; + data.height = INPUTBOX_ON_IMAGE.getImageData().height; + combo.setLayoutData(data); + + for (String str : getInterfaceList()) { + combo.add(str); + } + combo.select(0); + } + } + + 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"); //$NON-NLS-1$ + okButton.setEnabled(true); + okButton.setFont(FontResources.COMBO_BUTTON_FONT.getFont()); + data = new FormData(); + data.left = new FormAttachment(0, 45); + 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"); //$NON-NLS-1$ + 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() { + @Override + public void widgetSelected(SelectionEvent arg0) { + + // Check Tap duplication + // if (TapUtil.nameNotExist(nameText.getText())) { + tapName = nameText.getText(); - if (!EmulatorManager.isWin8()) { ++ if (!EmulatorManager.isWin8AndAbove()) { + ifName = combo.getText(); + } + dialog.close(); + + createTapDevice(tapName, ifName, viewItem, platformVersion); + + // } else { + // new MessageDialog().openWarningDialog("Name already exist."); + // } + + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + } + }); + + cancelButton.addSelectionListener(new SelectionListener() { + @Override + public void widgetSelected(SelectionEvent arg0) { + dialog.close(); + } + + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + + } + }); + + } + + public static void createTapDevice(String tapName, String ifName, + NetTapDeviceItemForWin viewItem, String platformVersion) { + if (EmulatorManager.isWin()) { + MessageDialog msgDialog = new MessageDialog(); + msgDialog + .openNoButtonInfoDialog(Messages.getString("TapUtil.CreateTapDevice.0")); //$NON-NLS-1$ + TapCreateWorker worker = new TapCreateWorker(tapName, ifName, + msgDialog, viewItem, platformVersion); + worker.start(); + } + + } + + static class TapCreateWorker extends Thread { + + final MessageDialog dialog; + final String tapName; + final String ifName; + final NetTapDeviceItemForWin viewItem; // for refresh combo-list + final String platformVersion; + + public TapCreateWorker(String tapName, String ifName, + MessageDialog dialog, NetTapDeviceItemForWin viewItem, String platformVersion) { + this.dialog = dialog; + this.tapName = tapName; + this.ifName = ifName; + this.viewItem = viewItem; + this.platformVersion = platformVersion; + } + + @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. + List cmd; + ProcessResult res; + try { - if (!EmulatorManager.isWin8()) { ++ if (!EmulatorManager.isWin8AndAbove()) { + EMLogger.getLogger().info( + "get CompatibleIDs from pci network device"); //$NON-NLS-1$ + cmd = Arrays.asList(TapUtil.getDevconPath(platformVersion), "find", "=net", //$NON-NLS-1$ //$NON-NLS-2$ + "@pci*"); //$NON-NLS-1$ + res = HelperClass.runProcess(cmd); + boolean isCommandSuccess = false; + String CompatibleIDs = null; + if (res.isSuccess()) { + for (String str : res.getStdOutMsg()) { + if (str.endsWith(ifName)) { + isCommandSuccess = true; + CompatibleIDs = str.split(":")[0].trim(); //$NON-NLS-1$ + EMLogger.getLogger().info( + "CompatibleIDs: " + CompatibleIDs); //$NON-NLS-1$ + break; + } + } + } else if (!res.isSuccess() || !isCommandSuccess) { + EMLogger.getLogger().warning(res.getResultMessage()); + } + + if (TapUtil.isWinBridgeExist() == false) { + // Create Bridge device and set IP + EMLogger.getLogger().info("create bridge"); //$NON-NLS-1$ + cmd = Arrays + .asList(TapUtil.getDevconPath(platformVersion), + "install", //$NON-NLS-1$ + "c:\\windows\\inf\\netbrdgm.inf", //$NON-NLS-1$ + "ms_bridgemp"); //$NON-NLS-1$ + res = HelperClass.runProcess(cmd); + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); + } + + EMLogger.getLogger().info("bind interface to bridge"); //$NON-NLS-1$ + cmd = Arrays.asList(FilePathResources.getPlatformEmulatorBinPath(platformVersion) + + File.separator + "bindbridge.exe", //$NON-NLS-1$ + "ms_bridge", CompatibleIDs, "bind"); //$NON-NLS-1$ //$NON-NLS-2$ + res = HelperClass.runProcess(cmd); + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); + } + EMLogger.getLogger().info("set bridge's IP"); //$NON-NLS-1$ + TapUtil.setWinbridgeNetwork(TapUtil.getClassIDFromPnpInstanceID(CompatibleIDs)); + } + } + + // Get tap list before create new tap. + EMLogger.getLogger() + .info("Get tap list before create new tap."); //$NON-NLS-1$ + List before = TapUtil.getTapList(); + + // Create new tap + EMLogger.getLogger().info("Create new tap."); //$NON-NLS-1$ + cmd = Arrays.asList(TapUtil.getDevconPath(platformVersion), "install", //$NON-NLS-1$ + FilePathResources.getPlatformEmulatorBinPath(platformVersion) + File.separator + + "OemWin2k.inf", "Tap0901"); //$NON-NLS-1$ //$NON-NLS-2$ + res = HelperClass.runProcess(cmd); + + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); + } + + // Get tap list and find new one. + EMLogger.getLogger().info("Get tap list and find new one."); //$NON-NLS-1$ + List 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."); //$NON-NLS-1$ + } + + // Rename new tap to tapX + EMLogger.getLogger().info("Rename new tap to tapX."); //$NON-NLS-1$ + cmd = Arrays.asList("netsh", "interface", "set", "interface", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + "name=" + newOne, "newname=" + tapName); //$NON-NLS-1$ //$NON-NLS-2$ + res = HelperClass.runProcess(cmd); + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); + } + + // Check tap create in success. + EMLogger.getLogger().info("Check tap create in success."); //$NON-NLS-1$ + boolean isTapExist = false; + for (String str : TapUtil.getTapList()) { + if (str.equals(tapName)) { + isTapExist = true; + } + } + - if (!EmulatorManager.isWin8()) { ++ if (!EmulatorManager.isWin8AndAbove()) { + EMLogger.getLogger().info("bind host network to bridge"); //$NON-NLS-1$ + String tapPnpInstanceID = TapUtil.getPnpInstanceIDFromName(tapName); + + cmd = Arrays.asList(FilePathResources.getPlatformEmulatorBinPath(platformVersion) + + File.separator + "bindbridge.exe", "ms_bridge", //$NON-NLS-1$ //$NON-NLS-2$ + tapPnpInstanceID, "bind"); //$NON-NLS-1$ + res = HelperClass.runProcess(cmd); + if (!res.isSuccess()) { + throw new VMWorkerException(res.getResultMessage()); + } + + EMLogger.getLogger().info( + "wait while finishing bridged network setting"); //$NON-NLS-1$ + String proxyCommand = "check-net.exe"; //$NON-NLS-1$ + cmd = Arrays.asList(FilePathResources.getEmulatorCheckToolPath() + + File.separator + proxyCommand, "--bridge"); //$NON-NLS-1$ + res = HelperClass.runProcess(cmd); + while (!res.getStdOutMsg().isEmpty()) { + boolean isCommandSuccess = false; + String ipAddr = null; + if (res.isSuccess()) { + for (String str : res.getStdOutMsg()) { + if (str.startsWith("IP Address:")) { //$NON-NLS-1$ + isCommandSuccess = true; + ipAddr = str.split("IP Address: ")[1] //$NON-NLS-1$ + .trim(); + EMLogger.getLogger().info( + "bridge IP address: " + ipAddr); //$NON-NLS-1$ + break; + } + } + } else if (!res.isSuccess() || !isCommandSuccess) { + EMLogger.getLogger() + .warning(res.getResultMessage()); + } + if (ipAddr != null) { + break; + } + res = HelperClass.runProcess(cmd); + } + + // shows success message + final MessageDialog messageDialog = new MessageDialog(); + if (isTapExist) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + messageDialog + .openInfoDialog(Messages.getString("TapUtil.CreatedTapDevice.0") //$NON-NLS-1$ + + tapName); + } + }); + } + } else { + final MessageDialog resultDialog = new MessageDialog(); + if (isTapExist) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + int res = resultDialog + .openSelectionDialog(Messages.getString("TapUtil.CreatedTapDevice.0") //$NON-NLS-1$ + + StringResources.NEW_LINE + + Messages.getString("TapUtil.CreatedTapDevice.1") //$NON-NLS-1$ + + tapName + StringResources.NEW_LINE + + Messages.getString("TapUtil.CreatedTapDevice.1")); //$NON-NLS-1$ + if (res == SWT.OK) { + // Show bridge guide dialog + TapGuideDialogForWin.open(); + } + } + }); + + } else { + throw new VMWorkerException("Tap is not exist : " //$NON-NLS-1$ + + tapName); + } + } + } catch (VMWorkerException e) { + EMLogger.getLogger().warning("Failed to create tap device."); //$NON-NLS-1$ + EMLogger.getLogger().warning(e.getMessage()); + final String msg = e.getMessage(); + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + new MessageDialog() + .openWarningDialog(StringResources.NEW_LINE + + Messages.getString("TapUtil.FailedCreateTapDevice.0") //$NON-NLS-1$ + + StringResources.NEW_LINE + StringResources.NEW_LINE + + msg); + } + }); + + } finally { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + dialog.close(); + viewItem.resetCombo(true); + } + }); + } + } + } + +} diff --cc src/org/tizen/emulator/manager/ui/renewal/tableviewer/MenuHandling.java index 66b173d,0000000..f81116c mode 100644,000000..100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MenuHandling.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/MenuHandling.java @@@ -1,339 -1,0 +1,339 @@@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JiHye Kim + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * 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.renewal.tableviewer; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; +import org.tizen.emulator.manager.logging.EMLogger; +import org.tizen.emulator.manager.resources.FilePathResources; +import org.tizen.emulator.manager.resources.StringResources; +import org.tizen.emulator.manager.ui.renewal.MainDialog; +import org.tizen.emulator.manager.ui.renewal.dialog.MessageBox; +import org.tizen.emulator.manager.vms.VMProperty; +import org.tizen.emulator.manager.vms.helper.VMLauncherException; +import org.tizen.emulator.manager.vms.helper.VMWorkerException; + +public class MenuHandling { + private static final Shell shell; + static { + shell = MainDialog.getShell(); + } + + private static int openMessageBox(String message) { + return openMessageBox(message, SWT.OK, true); + } + +// private static int openMessageBox(String message, int style) { +// return openMessageBox(message, style, true); +// } +// +// private static int openMessageBox(String message, boolean printLog) { +// return openMessageBox(message, SWT.OK, printLog); +// } + + private static int openMessageBox(String message, int style, boolean printLog) { + MessageBox msgBox = new MessageBox(shell, style); + msgBox.setMessage(message); + if (printLog) { + EMLogger.getLogger().warning(message); + } + return msgBox.open(); + } + + public static boolean launchEmulator(VMProperty property) throws VMWorkerException { + try { + property.getWorker().launchVM(); + } catch (VMLauncherException le) { + String msg = "Failed to launch [ " + + property.getPropertyValue().vmsName + " ] virtual machine." + + StringResources.NEW_LINE + + le.getMessage(); + + if (le.isCritical()) { + EMLogger.getLogger().warning(msg); + msg += StringResources.NEW_LINE + StringResources.NEW_LINE + + "This virtual machine has problem." + StringResources.NEW_LINE + + "Do you want to delete this virtual machine?"; + + int response = openMessageBox(msg, SWT.YES | SWT.NO, false); + if (response == SWT.YES) { + // TODO: does not delete emulator + // TODO: need to refresh vm property list + deleteEmulator(property, false); + throw new VMWorkerException(le.getMessage(), true); + } + } else { + openMessageBox(msg); + } + return false; + } catch (VMWorkerException e) { + String msg = "Failed to launch [ " + + property.getPropertyValue().vmsName + " ] virtual machine." + + StringResources.NEW_LINE + + e.getMessage(); + + openMessageBox(msg); + throw e; + } + return true; + } + + public static boolean resetEmulator(VMProperty property) throws VMWorkerException { + if (property == null) { + return false; + } + + String msg = "This virtual machine will be formatted." + + StringResources.NEW_LINE + + "Do you want to be continue?"; + int response = openMessageBox(msg, SWT.OK | SWT.CANCEL, false); + + if (response != SWT.OK) { + return false; + } + + try { + property.getWorker().resetVM(); + } catch(VMWorkerException e) { + String errorMsg = "[Failure]" + + StringResources.NEW_LINE + + "Failed to reset [ " + + property.getName() + " ] virtual machine." + + StringResources.NEW_LINE + + e.getMessage(); + openMessageBox(errorMsg); + throw e; + } + return true; + } + + public static boolean resetEmulator(VMProperty[] properties) throws VMWorkerException { + if (properties == null || properties.length == 0) { + return false; // TODO + } + + if (properties.length == 1) { + return resetEmulator(properties[0]); + } + + String message = "This virtual machine will be formatted."; + + String isRunning = ""; + for (VMProperty prop : properties) { + if (prop.isRunning()) { + isRunning += " [" + prop.getName() + "] "; + } + } + if (!isRunning.isEmpty()) { + message = message + StringResources.NEW_LINE + + isRunning + StringResources.NEW_LINE + + "virtual machines are already running. So, these will be not reset." + + StringResources.NEW_LINE; + } + message += StringResources.NEW_LINE + + "Do you want to be continue?"; + + int response = openMessageBox(message, SWT.OK | SWT.CANCEL, false); + + if (response != SWT.OK) { + return false; + } + + return reset(properties); + } + + private static boolean reset(VMProperty[] properties) throws VMWorkerException { + MessageBox dialog = new MessageBox(shell, SWT.OK, false); + if (properties.length < 6) { + dialog.setSize(490, 50 * properties.length); + } else { + dialog.setSize(490, 300); + } + + dialog.open(); + + boolean isNeedRefresh = false; + String errorMessage = ""; + for (VMProperty prop : properties) { + try { + prop.getWorker().resetVM(); + + dialog.addMessage("[Success]" + + StringResources.NEW_LINE + + "'" + prop.getName() + "' virtual machine has been reset." + + StringResources.NEW_LINE + StringResources.NEW_LINE); + + } catch(VMWorkerException e) { + dialog.addMessage("[Failure]" + StringResources.NEW_LINE + + "'" + prop.getName() + "' virtual machine has been failed to reset." + + StringResources.NEW_LINE); + dialog.addMessage(e.getMessage() + StringResources.NEW_LINE + StringResources.NEW_LINE); + + errorMessage += e.getMessage() + StringResources.NEW_LINE; + if (!isNeedRefresh) { + isNeedRefresh = e.isNeedRefresh(); + } + } + } + + if (!errorMessage.isEmpty()) { + EMLogger.getLogger().warning(errorMessage); + throw new VMWorkerException(errorMessage, isNeedRefresh); + } + + return true; + } + + public static boolean deleteEmulator(VMProperty property, boolean needCheck) throws VMWorkerException { + if (property == null) { + return false; + } + + if (needCheck) { + String msg = "Do you want to delete selected virtual machine?"; + int response = openMessageBox(msg, SWT.OK | SWT.CANCEL, false); + + if (response != SWT.OK) { + return false; + } + } + + try { + property.getWorker().deleteVM(); + } catch(VMWorkerException e) { + String errorMsg = "[Failure]" + + StringResources.NEW_LINE + + "Failed to delete [ " + + property.getName() + " ] virtual machine." + + StringResources.NEW_LINE + + e.getMessage(); + openMessageBox(errorMsg); + throw e; + } + return true; + } + + public static boolean deleteEmulator(VMProperty[] properties) throws VMWorkerException { + if (properties == null || properties.length == 0) { + return false; // TODO + } + + if (properties.length == 1) { + return deleteEmulator(properties[0], true); + } + + String message = "Do you want to delete selected virtual machines?"; + String isRunning = ""; + for (VMProperty prop : properties) { + if (prop.isRunning()) { + isRunning += " [" + prop.getName() + "] "; + } + } + if (!isRunning.isEmpty()) { + message = message + StringResources.NEW_LINE + + isRunning + StringResources.NEW_LINE + + "virtual machines are already running. So, these will be not deleted." + + StringResources.NEW_LINE + StringResources.NEW_LINE + + "Do you want to be continue?"; + } + + int response = openMessageBox(message, SWT.OK | SWT.CANCEL, false); + + if (response != SWT.OK) { + return false; + } + + boolean isNeedRefresh = false; + MessageBox dialog = new MessageBox(shell, SWT.OK, false); + if (properties.length < 6) { + dialog.setSize(490, 50 * properties.length); + } else { + dialog.setSize(490, 300); + } + + dialog.open(); + String errorMessage = ""; + for (VMProperty prop : properties) { + try { + prop.getWorker().deleteVM(); + dialog.addMessage("[Success]" + StringResources.NEW_LINE + + "'" + prop.getName() + "' vm image has been deleted." + + StringResources.NEW_LINE + StringResources.NEW_LINE); + } catch(VMWorkerException e) { + dialog.addMessage("[Failure]" + StringResources.NEW_LINE + + "'" + prop.getName() + "' vm image has been failed to delete." + + StringResources.NEW_LINE); + dialog.addMessage(e.getMessage() + StringResources.NEW_LINE + StringResources.NEW_LINE); + + errorMessage += e.getMessage() + StringResources.NEW_LINE; + if (!isNeedRefresh) { + isNeedRefresh = e.isNeedRefresh(); + } + } + } + + if (!errorMessage.isEmpty()) { + EMLogger.getLogger().warning(errorMessage); + throw new VMWorkerException(errorMessage, isNeedRefresh); + } + + return true; + } + + public static boolean createBaseImage(VMProperty property) throws VMWorkerException { + FileDialog fd = new FileDialog(shell, SWT.SAVE); + fd.setText("Export 'Base Image' as"); + String[] filter = {"*."+ property.getArchInternal().toString()}; + String[] filterName = {"Image Files(*." + property.getArchInternal().toString() + ")"}; + fd.setFilterExtensions(filter); + fd.setFilterNames(filterName); + fd.setFileName("emulimg-" + property.getName()); //$NON-NLS-1$ + fd.setFilterPath(FilePathResources.getTizenSdkDataEmulatorPath()); + + String path = null; + path = fd.open(); + if (path == null) { + return false; + } + try { - property.getWorker().createNewBaseImage(property, path); ++ property.getWorker().createNewBaseImage(property, path, false); + } catch (VMWorkerException e) { + String error = "Faile to export as [ " + + property.getName() + " ] base image." + + StringResources.NEW_LINE + + e.getMessage(); + openMessageBox(error); + throw e; + } + return true; + } +} diff --cc src/org/tizen/emulator/manager/ui/widgets/CommonVMButtonPainter.java index a61fd22,461f62c..54daff5 --- a/src/org/tizen/emulator/manager/ui/widgets/CommonVMButtonPainter.java +++ b/src/org/tizen/emulator/manager/ui/widgets/CommonVMButtonPainter.java @@@ -56,92 -53,54 +56,83 @@@ public abstract class CommonVMButtonPai protected int TITLE_X_OFFSET = 9; @Override - public void paintControl(PaintEvent e) { - VMButton button = (VMButton) e.widget; - WSTATE state = button.currentState(); - Image image = button.getImage(state); + public PaintListener getPaintListener() { + return paintListener; + } - if (image == null) { - return; - } + private PaintListener paintListener = new PaintListener() { + @Override + public void paintControl(PaintEvent e) { + VMButton button = (VMButton) e.widget; + WSTATE state = button.currentState(); + Image image = button.getImage(state); - SKIN_SHAPE skinShape = null; - if (button.getProperty() != null) { - Skin skin = button.getProperty().getPropertyValue().skin; - if (skin != null) { - skinShape = skin.getSkinShape(); + if (image == null) { + return; } - } - if (button.getProperty() != null) { - // If VM is custom, - if (!button.getProperty().getPropertyValue().baseImage.isStandard()) { - if (state == WSTATE.HOVER || state == WSTATE.SELECTED_HOVER) { - image = PluginImageResources.VM_IMAGE_CUSTOM_HOVER - .getImage(button.getPlatformName(), skinShape); - } else { - image = PluginImageResources.VM_IMAGE_CUSTOM_NORMAL - .getImage(button.getPlatformName(), skinShape); + SKIN_SHAPE skinShape = null; + if (button.getProperty() != null) { + Skin skin = button.getProperty().getPropertyValue().skin; + if (skin != null) { + skinShape = skin.getSkinShape(); + } - } - - if (button.getProperty() != null) { - if (button.getProperty().isRunning() - || !button.getProperty().isAvailable()) { - button.getLaunchButton().setEnabled(false); - } else { - button.getLaunchButton().setEnabled(true); - } + + // If VM is custom, + if (!button.getProperty().getPropertyValue().baseImage.isStandard()) { + if (state == WSTATE.HOVER || state == WSTATE.SELECTED_HOVER) { + image = PluginImageResources.VM_IMAGE_CUSTOM_HOVER + .getImage(button.getPlatformName(), skinShape); + } else { + image = PluginImageResources.VM_IMAGE_CUSTOM_NORMAL + .getImage(button.getPlatformName(), skinShape); + } + } + if (image == null) { + return; } } - if (image == null) { - return; + + Rectangle rect = ((Canvas) e.widget).getClientArea(); + GC gc = e.gc; + + gc.setBackground(button.getBackgroundColor(button.currentState())); + gc.fillRectangle(rect); + gc.drawImage(image, rect.x + BUTTON_X_OFFSET, rect.y + BUTTON_Y_OFFSET); + if (button.isSelection()) { + Image selectionImage = PluginImageResources.VM_IMAGE_SELECTED + .getImage(button.getPlatformName(), skinShape); + if (selectionImage == null) { + return; + } + gc.drawImage(selectionImage, rect.x, rect.y); } + + drawButtonText(gc, rect, button); + } - Rectangle rect = ((Canvas) e.widget).getClientArea(); - GC gc = e.gc; + }; + + @Override + public void drawButtonText(GC gc, Rectangle rect, VMButton button) { + // drawing Title + gc.setForeground(button.getFontColor(button.currentState())); + gc.setFont(FontResources.VM_BUTTON_TITLE_FONT.getFont()); gc.setBackground(button.getBackgroundColor(button.currentState())); - gc.fillRectangle(rect); - gc.drawImage(image, rect.x + BUTTON_X_OFFSET, rect.y + BUTTON_Y_OFFSET); - if (button.isSelection()) { - Image selectionImage = PluginImageResources.VM_IMAGE_SELECTED - .getImage(button.getPlatformName(), skinShape); - if (selectionImage == null) { - return; - } - gc.drawImage(selectionImage, rect.x, rect.y); - } - drawButtonText(gc, rect, button); + gc.drawString(button.getTitle(), button.getTitle_x(), TITLE_Y_OFFSET, true); + + gc.setForeground(button.getFontColor(WSTATE.NORMAL)); + + // drawing information + drawButtonText(new PaintGC(gc), button.getProperty()); + } + + @Override + public void drawButtonText(PaintGC gc, VMProperty property) { + // not to use + // override for compatibility (prevent build break) } @Override diff --cc src/org/tizen/emulator/manager/vms/VMWorkerCommon.java index 46016ae,fb0e23e..5ce9bd2 --- a/src/org/tizen/emulator/manager/vms/VMWorkerCommon.java +++ b/src/org/tizen/emulator/manager/vms/VMWorkerCommon.java @@@ -188,11 -192,13 +194,10 @@@ public class VMWorkerCommon implements checkPropertyModification(); isRunningNow(); - String baseImagePath = dest; - String baseImagePartPath = dest + ".part"; //$NON-NLS-1$ - + // check base image file - File childImage = new File(property.getConfiguration() - .getBaseInformation().getDiskImage().getCurrentDiskImage() - .getValue()); - File baseImage = new File(property.getConfiguration() - .getBaseInformation().getDiskImage().getBaseDiskImage() - .getValue()); + File childImage = new File(property.getChildImagePath()); + File baseImage = new File(property.getBaseImagePath()); ++ if (!childImage.exists()) { throw new VMWorkerException(Messages.getString("VMWorkerCommon.Error.0") //$NON-NLS-1$ + childImage.getAbsolutePath()); diff --cc src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java index 4eb7e85,343f7e1..0c38749 --- a/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java +++ b/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java @@@ -141,7 -141,7 +141,8 @@@ public class CheckingRunningEmulator emList.add(prop.getName()); } } - setRunning(prop, true); ++ + setRunning(prop.getName(), true); } public static void removeEmulator(VMProperty prop, boolean isSuccess) {