From 69cf10df5e297d390c2bb2a947e12bc9334b15b0 Mon Sep 17 00:00:00 2001 From: "jihye424.kim" Date: Thu, 3 Sep 2015 14:59:49 +0900 Subject: [PATCH] Emulator Status: add 'EmulatorStatusListener' - receive event when emulator launched or terminated. - CheckingRunningEmulator send event Change-Id: Ideba358f5fa7a4e97dc35f717cbaf86ed60940e5 Signed-off-by: jihye424.kim --- .../emulator/manager/ui/renewal/MainDialog.java | 6 +- ...fileButtonList.java => ProfileButtonMaker.java} | 2 +- .../ui/renewal/tableviewer/VMListTable.java | 79 +++++++++++++++++----- .../vms/helper/CheckingRunningEmulator.java | 77 ++++++++------------- .../manager/vms/helper/EmulatorStatusListener.java | 7 ++ 5 files changed, 101 insertions(+), 70 deletions(-) rename src/org/tizen/emulator/manager/ui/renewal/tableviewer/{ProfileButtonList.java => ProfileButtonMaker.java} (99%) create mode 100644 src/org/tizen/emulator/manager/vms/helper/EmulatorStatusListener.java diff --git a/src/org/tizen/emulator/manager/ui/renewal/MainDialog.java b/src/org/tizen/emulator/manager/ui/renewal/MainDialog.java index 67cbaa6..09a6145 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/MainDialog.java +++ b/src/org/tizen/emulator/manager/ui/renewal/MainDialog.java @@ -42,10 +42,11 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.tizen.emulator.manager.Messages; import org.tizen.emulator.manager.logging.EMLogger; -import org.tizen.emulator.manager.resources.StringResources; import org.tizen.emulator.manager.renewal.resources.ImageResources; +import org.tizen.emulator.manager.resources.StringResources; import org.tizen.emulator.manager.ui.renewal.tableviewer.AbstractTableViewer; import org.tizen.emulator.manager.ui.renewal.tableviewer.VMListTableViewer; +import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator; public class MainDialog { private static final String ICON_FILE_NAME = "res/em.ico"; //$NON-NLS-1$ @@ -106,8 +107,7 @@ public class MainDialog { } public void open() { - // TODO - //CheckingRunningEmulator.startCheckingThread(); + CheckingRunningEmulator.startCheckingThread(); shell.open(); while(!shell.isDisposed()) { diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonList.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonMaker.java similarity index 99% rename from src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonList.java rename to src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonMaker.java index 2c110ac..99f0373 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonList.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButtonMaker.java @@ -39,7 +39,7 @@ import org.tizen.emulator.manager.plugin.PluginImageResources; import org.tizen.emulator.manager.renewal.resources.ImageResources; import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton; -public class ProfileButtonList { +public class ProfileButtonMaker { private final static int WIDTH = 32; private final static int HEIGHT = 26; diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java index ce93375..f3ca153 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java @@ -39,6 +39,7 @@ import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.tizen.emulator.manager.platform.Profile; @@ -55,6 +56,7 @@ import org.tizen.emulator.manager.vms.VMProperty; import org.tizen.emulator.manager.vms.VMPropertyValue; import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator; import org.tizen.emulator.manager.vms.helper.RefreshWorker; +import org.tizen.emulator.manager.vms.helper.EmulatorStatusListener; import org.tizen.emulator.manager.vms.helper.VMWorkerException; public class VMListTable { @@ -83,7 +85,21 @@ public class VMListTable { return; } + CheckingRunningEmulator.addRunningEmulatorListener(new EmulatorStatusListener () { + @Override + public void changeEmulatorRunningStatus(final VMProperty prop) { + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + redrawProperty(prop); + } + }); + + } + }); + makeTable(); + makeCreateVMCombo(); makeProfileButton(); makeVMButton(); setLayout(); @@ -106,6 +122,7 @@ public class VMListTable { column.setText(t); column.setAlignment(SWT.CENTER); } + table.getColumn(0).setResizable(false); table.getColumn(1).setResizable(false); table.addListener(SWT.Selection, new Listener(){ @@ -119,11 +136,16 @@ public class VMListTable { }); } + private void makeCreateVMCombo() { + createVM = new CreateVMCombo(comp, SWT.None); + createVM.addSelectionListener(createVMComboSelectionListener); + } + private void makeProfileButton() { profileButtonList = new ArrayList(); - profileButtonList.add(ProfileButtonList.getProfileButton("mobile", comp)); - profileButtonList.add(ProfileButtonList.getProfileButton("tv", comp)); - profileButtonList.add(ProfileButtonList.getProfileButton("wearable", comp)); + profileButtonList.add(ProfileButtonMaker.getProfileButton("mobile", comp)); + profileButtonList.add(ProfileButtonMaker.getProfileButton("tv", comp)); + profileButtonList.add(ProfileButtonMaker.getProfileButton("wearable", comp)); for (Profile profile : ProfileList.getProfileList()) { for (ProfileButton pButton : profileButtonList) { @@ -135,19 +157,16 @@ public class VMListTable { } } } - - createVM = new CreateVMCombo(comp, SWT.None); - createVM.addSelectionListener(createVMComboSelectionListener); } - private ProfileButton findProfileButton(String profile) { - for (ProfileButton pButton : profileButtonList) { - if (pButton.getProfileName().equals(profile)) { - return pButton; - } - } - return null; - } +// private ProfileButton findProfileButton(String profile) { +// for (ProfileButton pButton : profileButtonList) { +// if (pButton.getProfileName().equals(profile)) { +// return pButton; +// } +// } +// return null; +// } private final SelectionListener createVMComboSelectionListener = new SelectionListener() { @@ -233,6 +252,7 @@ public class VMListTable { addTableItem(pButton, property); } } + private void addTableItem (ProfileButton pButton, VMProperty property) { addTableItem(pButton, property, -1); } @@ -270,6 +290,8 @@ public class VMListTable { VMPropertyValue value = property.getPropertyValue(); if (property.isRunning()) { item.setImage(0, ImageResources.ICON_RUNNING.getImage()); + } else { + item.setImage(0, null); } item.setText(2, value.vmsName); item.setText(3, "Samsung Z3"); @@ -282,6 +304,7 @@ public class VMListTable { } item.setData(property); } + private void makeVMButton() { resetButton = new ImageButton(comp, SWT.PUSH); resetButton.setBackground(null); @@ -377,7 +400,7 @@ public class VMListTable { VMProperty property = (VMProperty)table.getSelection()[0].getData(); try { if (MenuHandling.launchEmulator(property)) { - reloadProperty(); + reloadSelectedProperty(); } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { @@ -394,7 +417,7 @@ public class VMListTable { VMProperty property = (VMProperty)table.getSelection()[0].getData(); try { if (MenuHandling.createBaseImage(property)) { - reloadProperty(); + reloadSelectedProperty(); } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { @@ -428,7 +451,7 @@ public class VMListTable { try { if (MenuHandling.resetEmulator(properties)) { - reloadProperty(); + reloadSelectedProperty(); } } catch (VMWorkerException e) { if (e.isNeedRefresh()) { @@ -471,7 +494,7 @@ public class VMListTable { } } - private void reloadProperty() { + private void reloadSelectedProperty() { if (table.getSelectionCount() == 0) { return; } @@ -484,6 +507,26 @@ public class VMListTable { } } + private TableItem findTableItem(VMProperty property) { + for (TableItem item : table.getItems()) { + if (item.getData() == property) { + return item; + } + } + return null; + } + + private void redrawProperty(VMProperty property) { + TableItem item = findTableItem(property); + if (item == null) { + return; + } + + setTableItemProperty(item, property); + item.redraw(); + tableSelected(); + } + private void setLayout() { // composite is form layout FormData createButtonData; diff --git a/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java b/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java index 380fc18..8753189 100644 --- a/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java +++ b/src/org/tizen/emulator/manager/vms/helper/CheckingRunningEmulator.java @@ -44,11 +44,10 @@ import org.tizen.ecp.msg.genmsg.ecs.Ecs.DeviceAns; import org.tizen.ecp.msg.genmsg.ecs.Ecs.Master; import org.tizen.ecp.msg.genmsg.ecs.EcsIds.Master_Type; import org.tizen.emulator.manager.EmulatorManager; -import org.tizen.emulator.manager.Messages; import org.tizen.emulator.manager.EmulatorManager.ManagerModeType; +import org.tizen.emulator.manager.Messages; import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.resources.StringResources; -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; @@ -62,6 +61,7 @@ public class CheckingRunningEmulator { // Decide whether popup-message display or not. private static List LAUNCHED_VM_LIST = new ArrayList(); + private static List listenerList = new ArrayList(); public static void addLaunchedVMList(String vmName) { synchronized(LAUNCHED_VM_LIST) { @@ -75,6 +75,14 @@ public class CheckingRunningEmulator { } } + public static void addRunningEmulatorListener(EmulatorStatusListener listener) { + listenerList.add(listener); + } + + public static void removeRunnignEmulatorListener(EmulatorStatusListener listener) { + listenerList.remove(listener); + } + public static boolean needPopupMessage(VMSocket vms) { if (vms.getProperty() != null) { String vmName = vms.getProperty().getName(); @@ -131,7 +139,7 @@ public class CheckingRunningEmulator { emList.add(prop.getName()); } } - prop.setRunning(true); + setRunning(prop, true); } public static void removeEmulator(VMProperty prop, boolean isSuccess) { @@ -139,7 +147,7 @@ public class CheckingRunningEmulator { emList.remove(prop.getName()); } if (!isSuccess) { - prop.setRunning(false); + setRunning(prop, false); } else { addLaunchedVMList(prop.getName()); boolean checkFinished; @@ -180,18 +188,9 @@ public class CheckingRunningEmulator { } } else { - setRunning(prop.getName(), false); + setRunning(prop, false); EMLogger.getLogger().info("No response from VM (" + prop.getName() + ")."); //$NON-NLS-1$ //$NON-NLS-2$ - if (!EmulatorManager.isConsoleMode()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - VMsMainView.getInstance().redraw(); - } - }); - } } - } } @@ -274,7 +273,7 @@ public class CheckingRunningEmulator { } if (isVMFound) { - setRunning(vm.getName(), true); + setRunning(vm, true); CheckingRunningEmulator.removeEmulator(vm); result = VMSocket.ResultType.LAUNCHED_VM_DETECTED; // Check remote option. @@ -291,15 +290,7 @@ public class CheckingRunningEmulator { } if (!isHeartBeat){ - // this is not need for console mode - if (!EmulatorManager.isConsoleMode()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - VMsMainView.getInstance().redraw(); - } - }); - } + // TODO } return result; @@ -307,8 +298,18 @@ public class CheckingRunningEmulator { public static void setRunning(String vmName, boolean isRunning) { VMProperty prop = EmulatorVMList.getInstance().getProperty(vmName); - if (prop != null) { - prop.setRunning(isRunning); + setRunning(prop, isRunning); + } + + public static void setRunning(VMProperty prop, boolean isRunning) { + if (prop == null) { + return; + } + + prop.setRunning(isRunning); + + for (EmulatorStatusListener listener : listenerList ) { + listener.changeEmulatorRunningStatus(prop); } } @@ -522,20 +523,10 @@ public class CheckingRunningEmulator { // disconnect if (vms != null) { if (vms.getProperty() != null) { - CheckingRunningEmulator.setRunning(vms.getProperty().getName(), false); + CheckingRunningEmulator.setRunning(vms.getProperty(), false); } vms.disconnect(); } - - // this is not need for console mode - if (!EmulatorManager.isConsoleMode()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - VMsMainView.getInstance().redraw(); - } - }); - } } private void settingProperty(String path, VMSocket vms) { @@ -549,7 +540,7 @@ public class CheckingRunningEmulator { vms.setProperty(prop); RefreshWorker.addToFinishedSet(vms.getEcs_port()); } - CheckingRunningEmulator.setRunning(prop.getName(), true); + CheckingRunningEmulator.setRunning(prop, true); CheckingRunningEmulator.removeEmulator(prop); // Check remote option. @@ -558,16 +549,6 @@ public class CheckingRunningEmulator { showInfoDialog(vms); } - // this is not need for console mode - if (!EmulatorManager.isConsoleMode()) { - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - VMsMainView.getInstance().redraw(); - } - }); - } - break; } } diff --git a/src/org/tizen/emulator/manager/vms/helper/EmulatorStatusListener.java b/src/org/tizen/emulator/manager/vms/helper/EmulatorStatusListener.java new file mode 100644 index 0000000..22f9b3d --- /dev/null +++ b/src/org/tizen/emulator/manager/vms/helper/EmulatorStatusListener.java @@ -0,0 +1,7 @@ +package org.tizen.emulator.manager.vms.helper; + +import org.tizen.emulator.manager.vms.VMProperty; + +public interface EmulatorStatusListener { + void changeEmulatorRunningStatus(VMProperty prop); +} -- 2.7.4