Emulator List View: change reloading property list function to reloading property...
authorjihye424.kim <jihye424.kim@samsung.com>
Thu, 21 May 2015 08:12:13 +0000 (17:12 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Tue, 26 May 2015 05:15:40 +0000 (14:15 +0900)
- Reloading property when click modify, create, delete, reset, export-as buttons
- Refresh view(reloading all properies) when click refresh button

Change-Id: If72f3f0886a525f46f9f69466b2b528bda682b5a
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/ui/MainDialog.java
src/org/tizen/emulator/manager/ui/MenuHandling.java
src/org/tizen/emulator/manager/ui/VMsMainView.java
src/org/tizen/emulator/manager/ui/detail/DetailViewPage.java
src/org/tizen/emulator/manager/vms/Modifier.java
src/org/tizen/emulator/manager/vms/VMProperty.java
src/org/tizen/emulator/manager/vms/VMPropertyValue.java
src/org/tizen/emulator/manager/vms/VMWorkerCommon.java

index c3ae1cf..d2df4e3 100644 (file)
@@ -59,6 +59,7 @@ import org.tizen.emulator.manager.ui.dialog.AboutDialog;
 import org.tizen.emulator.manager.ui.tabfolder.ProfileTabFolder;
 import org.tizen.emulator.manager.ui.tabfolder.ProfileTabItem;
 import org.tizen.emulator.manager.ui.widgets.ImageButton;
+import org.tizen.emulator.manager.vms.VMProperty;
 import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator;
 import org.tizen.emulator.manager.vms.helper.RefreshWorker;
 
@@ -241,10 +242,19 @@ public class MainDialog {
                if (isClear) {
                        tabFolder.getSelection().draw();
                } else {
-                       tabFolder.getSelection().redraw();
+                       redraw();
                }
        }
 
+       public static void refreshVMProperty(VMProperty prop) {
+               prop.reloadProperty();
+               redraw();
+       }
+
+       public static void redraw() {
+               tabFolder.getSelection().redraw();
+       }
+
        public void dispose() {
                ImageResources.dispose();
                ColorResources.dispose();
index 6bd0dc5..54ddeff 100644 (file)
@@ -49,34 +49,26 @@ public class MenuHandling {
                this.shell = MainDialog.getShell();
        }
 
-       public void resetVirtualMachine(VMProperty property) throws VMWorkerException {
+       public boolean resetVirtualMachine(VMProperty property) throws VMWorkerException {
                MessageDialog msg = new MessageDialog();
-/*
-               try {
-                       property.getWorker().isRunningNow();
-               } catch (VMWorkerException e) {
-                       msg.openInfoDialog("Not allowed to reset active VMs."
-                                               + StringResources.NEW_LINE
-                                               + e.getMessage());
-                       return;
-               }
-*/
+
                if (property.isRunning()) {
                        msg.openInfoDialog("Not allowed to reset active VMs."
                                        + StringResources.NEW_LINE
                                        + "[" + property.getName()
                                        + "] is running now...");
-                       return;
+                       return false;
                }
 
                int response = msg.openSelectionDialog("This VM will be formatted."
                                + StringResources.NEW_LINE + "Are you sure you want to continue?");
 
                if (response != SWT.OK) {
-                       return;
+                       return false;
                }
 
                property.getWorker().resetVM();
+               return true;
        }
 
        public boolean deleteVirtualMachine(VMProperty property) throws VMWorkerException {
@@ -85,16 +77,7 @@ public class MenuHandling {
 
        public boolean deleteVirtualMachine(VMProperty property, boolean needCheck) throws VMWorkerException {
                MessageDialog msg = new MessageDialog();
-               /*
-               try {
-                       property.getWorker().isRunningNow();
-               } catch (VMWorkerException e) {
-                       msg.openInfoDialog("Not allowed to delete active VMs."
-                                               + StringResources.NEW_LINE
-                                               + e.getMessage());
-                       return false;
-               }
-               */
+
                if (property.isRunning()) {
                        msg.openInfoDialog("Not allowed to delete active VMs."
                                        + StringResources.NEW_LINE
@@ -117,26 +100,16 @@ public class MenuHandling {
 
                return true;
        }
-       
-       public void createBaseImage(VMProperty property) throws VMWorkerException {
+
+       public boolean createBaseImage(VMProperty property) throws VMWorkerException {
                MessageDialog msg = new MessageDialog();
-               /*
-               try {
-                       property.getWorker().isRunningNow();
-               } catch (VMWorkerException e) {
-                       msg.openInfoDialog("Not allowed to 'Export as base image' active VMs."
-                                               + StringResources.NEW_LINE
-                                               + e.getMessage());
-                       return;
-               }
-               */
 
                if (property.isRunning()) {
                        msg.openInfoDialog("Not allowed to 'Exprot as base image' active VMs."
                                        + StringResources.NEW_LINE
                                        + "[" + property.getName()
                                        + "] is running now...");
-                       return;
+                       return false;
                }
 
                FileDialog fd = new FileDialog(shell, SWT.SAVE);
@@ -151,24 +124,15 @@ public class MenuHandling {
                String path = null;
                path = fd.open();
                if (path == null) {
-                       return;
+                       return false;
                }
 
                property.getWorker().createNewBaseImage(property, path);
+               return true;
        }
 
        public void cloneVirtualMachine(VMProperty property) {
                MessageDialog msg = new MessageDialog();
-               /*
-               try {
-                       property.getWorker().isRunningNow();
-               } catch (VMWorkerException e) {
-                       msg.openWarningDialog("Not allowed to 'Clone' while source VM is running."
-                                       + StringResources.NEW_LINE
-                                       + e.getMessage());
-                       return;
-               }
-               */
 
                if (property.isRunning()) {
                        msg.openInfoDialog("Not allowed to 'Clone' active VMs."
index 48a6d38..c75d2ac 100644 (file)
@@ -44,6 +44,7 @@ import org.tizen.emulator.manager.resources.ColorResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.ui.dialog.MessageDialog;
 import org.tizen.emulator.manager.vms.Creator;
+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.helper.VMLauncherException;
@@ -58,7 +59,6 @@ public class VMsMainView {
        private boolean isCreateMode    = false;
        private boolean setFocus        = false;
 
-       private boolean isNeedRefresh = false;
        private static VMsMainView view = new VMsMainView();
        public static VMsMainView getInstance() {
                return view;
@@ -375,12 +375,7 @@ public class VMsMainView {
                        }
                }
 
-               if (this.isNeedRefresh()) {
-                       refreshViewer();
-               }
-
-               // set focus vm button
-               // drawDetailVM(currentImage.getVmsList().indexOf(property));
+               reloadProperty();
                redraw();
        }
 
@@ -402,6 +397,12 @@ public class VMsMainView {
                }
 
                setCurrentProperty(prop);
+               //
+               EmulatorVMList.getInstance().addProperty(prop);
+               currentProfile.addEmulator(prop);
+               //
+
+               MainDialog.redraw();
                return true;
        }
 
@@ -422,13 +423,17 @@ public class VMsMainView {
                        return false;
                }
 
+               MainDialog.refreshVMProperty(currentProperty);
                return true;
        }
 
        private MenuHandling handling = new MenuHandling();
        public boolean createBaseImage() {
                try {
-                       handling.createBaseImage(currentProperty);
+                       if (handling.createBaseImage(currentProperty)) {
+                               reloadProperty();
+                               return true;
+                       }
                } catch (VMWorkerException e) {
                        new MessageDialog().openInfoDialog(
                                        "Filaed to export as base image ("
@@ -438,14 +443,9 @@ public class VMsMainView {
                        if (e.isNeedRefresh()) {
                                MainDialog.refreshVMPropertyList(false);
                        }
-                       return false;
                }
 
-               if (this.isNeedRefresh()) {
-                       refreshViewer();
-               }
-
-               return true;
+               return false;
        }
 
        public boolean deleteEmulator() {
@@ -455,8 +455,11 @@ public class VMsMainView {
        public boolean deleteEmulator(boolean needCheck) {
                try {
                        if (handling.deleteVirtualMachine(currentProperty, needCheck)) {
-                               currentProperty = null;
-                               MainDialog.refreshVMPropertyList(false);
+                               int index = currentProfile.getEmulatorList().indexOf(currentProperty) - 1;
+                               currentProfile.getEmulatorList().remove(currentProperty);
+                               currentProperty = (index < 0 ? null : currentProfile.getEmulatorList().get(index));
+                               MainDialog.redraw();
+                               return true;
                        }
                } catch (VMWorkerException e) {
                        new MessageDialog().openWarningDialog(
@@ -467,14 +470,17 @@ public class VMsMainView {
                        if (e.isNeedRefresh()) {
                                MainDialog.refreshVMPropertyList(false);
                        }
-                       return false;
                }
-               return true;
+
+               return false;
        }
 
        public boolean resetEmulator() {
                try {
-                       handling.resetVirtualMachine(currentProperty);
+                       if (handling.resetVirtualMachine(currentProperty)) {
+                               reloadProperty();
+                               return true;
+                       }
                } catch (VMWorkerException e) {
                        new MessageDialog().openInfoDialog(
                                        "Failed to reset Emulator ("
@@ -486,25 +492,12 @@ public class VMsMainView {
                        }
                }
 
-               if (this.isNeedRefresh()) {
-                       refreshViewer();
-               }
-
-               return true;
-       }
-
-       public boolean isNeedRefresh() {
-               return isNeedRefresh;
-       }
-
-       public void setNeedRefresh(boolean isNeedRefresh) {
-               this.isNeedRefresh = isNeedRefresh;
+               return false;
        }
 
-       public void refreshViewer() {
-               if (isNeedRefresh) {
-                       MainDialog.refreshVMPropertyList(false);
-                       isNeedRefresh = false;
+       public void reloadProperty() {
+               if (getCurrentProperty().getWorker().isModified()) {
+                       MainDialog.refreshVMProperty(currentProperty);
                        String msg = "Emulator proerty is reloaded, because emulator property had beend modified by other emulator manager.";
                        EMLogger.getLogger().info(msg);
                        MainDialog.getStatusBar().info(msg);
index 482ecfb..6915698 100644 (file)
@@ -39,7 +39,6 @@ import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
-import org.tizen.emulator.manager.platform.CustomBaseImage;
 import org.tizen.emulator.manager.platform.Platform;
 import org.tizen.emulator.manager.plugin.ExtensionItem;
 import org.tizen.emulator.manager.resources.ColorResources;
index 7719356..bbee954 100644 (file)
@@ -41,7 +41,7 @@ public class Modifier {
        static void modify(VMProperty property, VMPropertyValue newVM) throws VMWorkerException {
                VMPropertyValue oldVM = property.getPropertyValue();
                if(oldVM.equals(newVM)) {// if nothing if modified...
-                       return;
+                       throw new VMWorkerException("Value of new property is the same value of saved property.");
                }
                modifyFileShare(newVM);
                if (!newVM.resolution.equals(oldVM.resolution)) {
index 3544d63..e6b2ec4 100644 (file)
@@ -53,10 +53,6 @@ public class VMProperty {
 
        private boolean isRunning = false;
 
-       public void setPropertyValue(VMPropertyValue value) {
-               this.value = value;
-       }
-
        @Override
        public boolean equals(Object obj) {
                if (obj == null) {
@@ -70,12 +66,26 @@ public class VMProperty {
                return false;
        }
 
+       /**
+        * Create a new VMProperty instance from xml property file and xml configuration
+        * @param propertyFile property file saved in data directory
+        * @param element xml configuration of property file
+        */
        public VMProperty(File propertyFile, EmulatorConfiguration element) {
                this.propertyFile = propertyFile;
                this.lastModified = propertyFile.lastModified();
                this.configuration = element;
        }
 
+       /**
+        * Creates a new VMProperty instance from default value
+        * This is used for creating new emulator
+        * @param value default value of emulator
+        */
+       public VMProperty(VMPropertyValue value) {
+               this.value = value;
+       }
+
        public void initVMWorker() {
                ExtensionItem item = null;
                if (getPropertyValue().baseImage == null) {
@@ -98,9 +108,11 @@ public class VMProperty {
 
        }
 
-       // TODO
-       public VMProperty(VMPropertyValue value) {
-               this.value = value;
+       public void reloadProperty() {
+               this.configuration = EmulatorVMList.getInstance().parseXML(this);
+               this.lastModified = propertyFile.lastModified();
+
+               this.value.settingConfigure(this);
        }
 
        public VMPropertyValue getPropertyValue() {
@@ -108,7 +120,10 @@ public class VMProperty {
                        this.value = new VMPropertyValue(this);
                }
                return value;
-               //return new VMsPropertyValue(this); // FIXME
+       }
+
+       public void setPropertyValue(VMPropertyValue value) {
+               this.value = value;
        }
 
        public File getPropertyFile() {
@@ -127,6 +142,17 @@ public class VMProperty {
                return worker;
        }
 
+       public boolean isRunning() {
+               return isRunning;
+       }
+       public void setRunning(boolean isRunning) {
+               this.isRunning = isRunning;
+       }
+
+       public EmulatorConfiguration getConfiguration() {
+               return configuration;
+       }
+
        public String getName() {
                if(configuration == null
                                || configuration.getBaseInformation() == null) {
@@ -239,17 +265,6 @@ public class VMProperty {
                return true;
        }
 
-       public EmulatorConfiguration getConfiguration() {
-               return configuration;
-       }
-
-       public boolean isRunning() {
-               return isRunning;
-       }
-       public void setRunning(boolean isRunning) {
-               this.isRunning = isRunning;
-       }
-
        public void setCPU(int cpu, boolean isCreateElement) {
                if (configuration != null) {
                        if (isCreateElement && configuration.getDevice().getCPU() == null) {
index a938ab9..ffc0fff 100644 (file)
@@ -94,57 +94,64 @@ public class VMPropertyValue implements Cloneable {
 
        private VMPropertyValue(){} // for clone
 
+       /**
+        * Constructs a new VMPropertyValue by using base image.
+        * This is used for creating new emulator.
+        * @param image base image of emulator
+        */
        public VMPropertyValue(BaseImage image) {
                this(image, image.getDefaultProperty());
        }
 
+       /**
+        * Constructs a new VMPropertyValue by using base image and property.
+        * This is used for creating new emulator.
+        * @param image base image of emulator
+        * @param template default property of emulator
+        */
        public VMPropertyValue(BaseImage image, VMProperty template) {
-               this.baseImage    = image;
-               this.template = template;
+               assert image == null;
+
+               if (image == null) {
+                       return;
+               }
+
+               this.baseImage  = image;
+               this.template   = template;
 
                vmsName = "";
 
-               if (this.baseImage == null) {
-                       isStandard = false;
-                       settingDefault(isStandard, template);
-               } else {
-                       baseImagePath     = image.getPath();
-                       baseImagePathName = image.getPathName();
-                       archType        = image.getCpu();
-                       profile = image.getProfile();
-                       version         = image.getVersion();
-                       baseName        = image.getName();
-                       skinShape = image.getSkinShape();
-
-                       if (image instanceof CustomBaseImage) {
-                               isStandard      = false;
-                               if (template != null &&
-                                               template.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage() != null) {
-                                       if (baseImagePath == null) {
-                                               baseImagePath = template.getPropertyValue().baseImagePath;
-                                       }
-                                       if (baseImagePathName == null) {
-                                               baseImagePathName = template.getPropertyValue().baseImagePathName;
-                                       }
-                                       baseName = template.getConfiguration().getBaseInformation().getDiskImage().getBase();
-                               }
-                       } else {
-                               isStandard = true;
-                       }
+               baseImagePath     = image.getPath();
+               baseImagePathName = image.getPathName();
+               archType        = image.getCpu();
+               profile = image.getProfile();
+               version         = image.getVersion();
+               baseName        = image.getName();
+               skinShape = image.getSkinShape();
 
-                       settingConfigure(template);
+               if (image instanceof CustomBaseImage) {
+                       isStandard      = false;
+               } else {
+                       isStandard = true;
                }
+
+               settingConfigure(template);
        }
 
+       /**
+        * Constructs a new VMPropertyValue by using property.
+        * This property is saved property of emulator in data directory
+        * @param property property of emulator
+        */
        public VMPropertyValue(VMProperty property) {
                assert property == null;
 
                if (property != null) {
                        this.template = property;
 
-                       vmsName = property.getName();
-                       archType   = property.getArch().toString();
-                       // TODO
+                       vmsName         = property.getName();
+                       archType        = property.getArch().toString();
+
                        if (property.getImageProfile() != null) {
                                profile = property.getImageProfile();
                        } else {
@@ -207,7 +214,6 @@ public class VMPropertyValue implements Cloneable {
                dest.extendedOptions.addAll(this.extendedOptions);
 
                cloneAdvancedOptions(dest.advancedOptionList);
-//             dest.advancedOptionList.addAll(this.advancedOptionList);
 
                return dest;
        }
@@ -330,11 +336,11 @@ public class VMPropertyValue implements Cloneable {
                return true;
        }
 
-       private void settingConfigure(VMProperty property) {
+       void settingConfigure(VMProperty property) {
                if (property == null) {
-                       settingConfigure();
                        return;
                }
+
                Resolution re = null;
                for (RESOLUTION d : RESOLUTION.values()) {
                        re = property.getConfiguration().getDevice().getDisplay().getResolution();
@@ -431,48 +437,6 @@ public class VMPropertyValue implements Cloneable {
 
        }
 
-       private void settingConfigure() {
-               // HD(720x1280)
-               resolution = RESOLUTION.HD;
-               dpi = RESOLUTION.HD.getDPI(); // this value be related to resolution
-
-               skinPath = null;
-
-               keyType = 1;
-               //
-
-               ramSize                         = RAM_SIZE.RAM512.getSize();
-
-               cpu = 1;
-
-               isFileShareSupport      = false; 
-               fileSharePath           = "";
-               fileSharePathName   = StringResources.None;
-
-               isHWVirtualization = CheckVirtualization.getInstance().isSupportVirtualization();
-               isGLAcceleration = CheckVirtualization.getInstance().isSupportGPU();
-
-               maxTouchCount = maxTouch;
-
-               addOptions = null;
-               ociOptions = null;
-
-               isSupportSuspend = false;
-               extendedOptions = new ArrayList<ExtendedOptionType>();
-       }
-
-       private void settingDefault(boolean isStandard, VMProperty template) {
-               vmsName                         = "";
-               archType = isStandard ? template.getArch().toString() : "x86";
-
-               baseImagePath           = "";
-               baseImagePathName   = isStandard ? (archType.equals("x86") ? "( emulimg.x86 )" : "( emulimg.arm )") : StringResources.None;
-               // TODO
-               profile = PlatformStringResources.MobileProfile;
-
-               settingConfigure(template);
-       }
-
        public OptionType getAdvancedOption(String optionName) {
                for (OptionType option : advancedOptionList) {
                        if (option.getName().equals(optionName)) {
index c5e0008..75f2c40 100644 (file)
@@ -43,7 +43,6 @@ import org.tizen.emulator.manager.EmulatorManager.ManagerModeType;
 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.VMsMainView;
 import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator;
 import org.tizen.emulator.manager.vms.helper.QemuImgProc;
 import org.tizen.emulator.manager.vms.helper.VMLauncherException;
@@ -58,6 +57,7 @@ public class VMWorkerCommon {
        private String baseImagePartPath = null;
        private Object lock = new Object();
        private ILauncher launcher;
+       private boolean isModified;
 
        public void sendRemoteLog(String msg) {
 
@@ -110,16 +110,14 @@ public class VMWorkerCommon {
                                                true);
                        }
 
-                       if (isModified()) {
+                       checkPropertyModification();
+                       if (isModified) {
                                property = EmulatorVMList.getInstance().parseXML(
                                                property.getPropertyFile());
                                if (property == null) {
                                        throw new VMWorkerException(
                                                        "Failed to load modified property.", true);
                                }
-                               if (!EmulatorManager.isConsoleMode()) {
-                                       VMsMainView.getInstance().setNeedRefresh(true);
-                               }
                        }
 
                        // Do argument validation.
@@ -147,9 +145,6 @@ public class VMWorkerCommon {
                        }
 
                } catch (VMWorkerException e) {
-                       if (!EmulatorManager.isConsoleMode()) {
-                               VMsMainView.getInstance().setNeedRefresh(false);
-                       }
                        throw e;
                } finally {
                        // lock.release
@@ -169,8 +164,8 @@ public class VMWorkerCommon {
                                                true);
                        }
 
-                       // TODO
-                       if (isModified()) {
+                       checkPropertyModification();
+                       if (isModified) {
                                throw new VMWorkerException(
                                                "This VM had been modified by other emulator manager.",
                                                true);
@@ -200,13 +195,7 @@ public class VMWorkerCommon {
                                                true);
                        }
 
-                       // TODO
-                       if (isModified()) {
-                               if (!EmulatorManager.isConsoleMode()) {
-                                       VMsMainView.getInstance().setNeedRefresh(true);
-                               }
-                       }
-
+                       checkPropertyModification();
                        isRunningNow();
 
                        baseImagePath = dest;
@@ -267,15 +256,13 @@ public class VMWorkerCommon {
                                }
                        }
                } catch (VMWorkerException e) {
-                       if (!EmulatorManager.isConsoleMode()) {
-                               VMsMainView.getInstance().setNeedRefresh(false);
-                       }
                        throw e;
                } finally {
                        // lock.release
                        WorkerLock.release();
                }
 
+               // TODO: This code will be moved console source
                if (EmulatorManager.isConsoleMode()) {
                        System.out.println("Wait....while creating base image."
                                        + StringResources.NEW_LINE
@@ -401,12 +388,7 @@ public class VMWorkerCommon {
                                                true);
                        }
 
-                       if (isModified()) {
-                               if (!EmulatorManager.isConsoleMode()) {
-                                       VMsMainView.getInstance().setNeedRefresh(true);
-                               }
-                       }
-
+                       checkPropertyModification();
                        isRunningNow();
 
                        String basePath = property.getConfiguration().getBaseInformation()
@@ -451,7 +433,6 @@ public class VMWorkerCommon {
                                Creator.createSwapImage(swapBasePath, swapTargetPath);
                        }
                } catch (VMWorkerException e) {
-                       VMsMainView.getInstance().setNeedRefresh(false);
                        throw e;
                } finally {
                        // lock.relese
@@ -470,13 +451,12 @@ public class VMWorkerCommon {
                Creator.create(newValue);
        }
 
-       public boolean isModified() {
+       private void checkPropertyModification() {
                if (property.getLastModifedPropertyFile() != property.getPropertyFile()
                                .lastModified()) {
-                       return true;
+                       this.isModified = true;
                }
-
-               return false;
+               this.isModified = false;
        }
 
        // check if the emulator instance with the same name is running now.
@@ -653,8 +633,11 @@ public class VMWorkerCommon {
                }
        }
 
-       // Remove directory files recursively.
-       // Return false if one or more files fail to delete.
+       /**
+        * Remove directory files recursively.
+        * @param file vm property directory path
+        * @return Return false if one or more files fail to delete.
+        */
        public static boolean deleteFile(File file) {
                boolean result = true;
                if (!file.exists()) {
@@ -681,6 +664,15 @@ public class VMWorkerCommon {
 
                return result;
        }
+
+       /**
+        * If property had been modified by other emulator manager(cli),
+        * this method will be return true.
+        * @return return true if property had been modified
+        */
+       public boolean isModified() {
+               return isModified;
+       }
 }
 
 /*