DeviceTemplate: add priority and type class
authorjihye424.kim <jihye424.kim@samsung.com>
Fri, 16 Oct 2015 10:33:39 +0000 (19:33 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Fri, 16 Oct 2015 10:33:39 +0000 (19:33 +0900)
- priority: default, standard, custom
- type: standard, custom

Change-Id: I1867cfec8a4c3abc70b0e492dcbbb2479a1601fb
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/devices/DeviceTemplate.java
src/org/tizen/emulator/manager/devices/DeviceTemplatePriority.java [new file with mode: 0644]
src/org/tizen/emulator/manager/devices/DeviceTemplateType.java [new file with mode: 0644]
src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java
src/org/tizen/emulator/manager/platform/Profile.java
src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java

index a9e20a9..f228d49 100644 (file)
@@ -191,14 +191,14 @@ public class DeviceTemplate {
 
                // base information
                conf.getBaseInformation().setName(value.getName());
-               conf.getBaseInformation().setType(value.getType());
+               conf.getBaseInformation().setType(value.getType().toString());
                conf.getBaseInformation().setProfile(value.getProfile());
                if (value.getExtenstion() != null && !value.getExtenstion().isEmpty()) {
                        conf.getBaseInformation().setExtension(value.getExtenstion());
                }
 
                conf.getBaseInformation().setVersion(value.getVersion());
-               conf.getBaseInformation().setPriority(value.getPriority());
+               conf.getBaseInformation().setPriority(value.getPriority().getValue());
                if (value.getManufacturer() != null && !value.getManufacturer().isEmpty()) {
                        conf.getBaseInformation().setManufacturer(value.getManufacturer());
                }
diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplatePriority.java b/src/org/tizen/emulator/manager/devices/DeviceTemplatePriority.java
new file mode 100644 (file)
index 0000000..4a734f9
--- /dev/null
@@ -0,0 +1,94 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho.p@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.emulator.manager.devices;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DeviceTemplatePriority implements Comparable<Object> {
+       public static DeviceTemplatePriority DEFAULT =
+                       new DeviceTemplatePriority(0);
+       public static DeviceTemplatePriority STANDARD =
+                       new DeviceTemplatePriority(1);
+       public static DeviceTemplatePriority CUSTOM =
+                       new DeviceTemplatePriority(3);
+
+       private static List<DeviceTemplatePriority> priorityList =
+                       new ArrayList<DeviceTemplatePriority>();
+       static {
+               priorityList.add(DEFAULT);
+               priorityList.add(STANDARD);
+               priorityList.add(CUSTOM);
+       }
+
+       public static void addPriority(DeviceTemplatePriority priority) {
+               if (priority == null) {
+                       return;
+               }
+
+               for (DeviceTemplatePriority p : priorityList) {
+                       if (p.getValue() == priority.getValue()) {
+                               return;
+                       }
+               }
+
+               priorityList.add(priority);
+       }
+
+       public static DeviceTemplatePriority findPriority(int priority) {
+               for (DeviceTemplatePriority p : priorityList) {
+                       if (p.getValue() == priority) {
+                               return p;
+                       }
+               }
+               return null;
+       }
+
+       private int priority = 0;
+       public DeviceTemplatePriority(int priority) {
+               this.priority = priority;
+       }
+
+       public int getValue() {
+               return priority;
+       }
+
+       public void setValue(int priority) {
+               this.priority = priority;
+       }
+
+       @Override
+       public int compareTo(Object o) {
+               int targetPriority = ((DeviceTemplatePriority)o).priority;
+
+               return priority > targetPriority ? -1 : 1;
+       }
+
+}
diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplateType.java b/src/org/tizen/emulator/manager/devices/DeviceTemplateType.java
new file mode 100644 (file)
index 0000000..e5aa550
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho.p@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.emulator.manager.devices;
+
+public class DeviceTemplateType {
+       public static DeviceTemplateType STANDARD =
+                       new DeviceTemplateType("standard");
+       public static DeviceTemplateType CUSTOM =
+                       new DeviceTemplateType("custom");
+
+       private String type = "";
+
+       public DeviceTemplateType(String type) {
+               this.setType(type);
+       }
+
+       public String getType() {
+               return type;
+       }
+
+       public void setType(String type) {
+               this.type = type;
+       }
+
+       @Override
+       public String toString() {
+               return type;
+       }
+}
index 0fd1b01..011326c 100644 (file)
@@ -49,11 +49,12 @@ public class DeviceTemplateValue implements Cloneable {
        private DeviceTemplate template;
        private boolean isStandard = false;
        private String name = "";
-       private String type = "custom";
+       private DeviceTemplateType type = DeviceTemplateType.CUSTOM;
        private String profile = "";
        private String extenstion = "";
        // standard = 1, custom = 3 (1 > 3)
-       private int priority = 3;
+       //private int priority = 3;
+       private DeviceTemplatePriority priority = DeviceTemplatePriority.CUSTOM;
        private double version = 1.0;
        private String manufacturer = "";
 
@@ -119,13 +120,17 @@ public class DeviceTemplateValue implements Cloneable {
 
                if (conf.getBaseInformation() != null) {
                        name = conf.getBaseInformation().getName();
-                       type = conf.getBaseInformation().getType();
-                       if (type.equals("standard")) {
-                               isStandard = true;
-                       }
+                       String type = conf.getBaseInformation().getType();
+                       setType(type);
+
                        profile = conf.getBaseInformation().getProfile();
                        extenstion = conf.getBaseInformation().getExtension();
-                       priority = conf.getBaseInformation().getPriority();
+                       int p = conf.getBaseInformation().getPriority();
+                       priority = DeviceTemplatePriority.findPriority(p);
+                       if (priority == null) {
+                               priority = DeviceTemplatePriority.CUSTOM;
+                       }
+
                        version = conf.getBaseInformation().getVersion();
                        manufacturer = conf.getBaseInformation().getManufacturer();
                }
@@ -238,13 +243,23 @@ public class DeviceTemplateValue implements Cloneable {
                this.name = name;
        }
 
-       public String getType() {
+       public DeviceTemplateType getType() {
                return type;
        }
 
        public void setType(String type) {
+               if (type.equals(DeviceTemplateType.STANDARD.getType())) {
+                       this.type = DeviceTemplateType.STANDARD;
+                       isStandard = true;
+               } else {
+                       this.type = DeviceTemplateType.CUSTOM;
+                       isStandard = false;
+               }
+       }
+
+       public void setType(DeviceTemplateType type) {
                this.type = type;
-               if (type.equals("standard")) {
+               if (type == DeviceTemplateType.STANDARD) {
                        isStandard = true;
                } else {
                        isStandard = false;
@@ -267,11 +282,11 @@ public class DeviceTemplateValue implements Cloneable {
                this.profile = profile;
        }
 
-       public int getPriority() {
+       public DeviceTemplatePriority getPriority() {
                return priority;
        }
 
-       public void setPriority(int priority) {
+       public void setPriority(DeviceTemplatePriority priority) {
                this.priority = priority;
        }
 
index a88895c..62e823c 100644 (file)
@@ -37,6 +37,7 @@ import java.util.List;
 
 import org.tizen.emulator.manager.devices.DeviceTemplate;
 import org.tizen.emulator.manager.devices.DeviceTemplateList;
+import org.tizen.emulator.manager.devices.DeviceTemplatePriority;
 import org.tizen.emulator.manager.resources.FilePathResources;
 import org.tizen.emulator.manager.resources.StringResources;
 import org.tizen.emulator.manager.vms.EmulatorVMList;
@@ -282,7 +283,8 @@ public class Profile {
                for (int i = 0; i < templateList.size(); i++) {
                        pairs[i] = new TemplatePair(templateList.get(i));
                        // setting default template
-                       if (templateList.get(i).getValue().getPriority() == 0) {
+                       if (templateList.get(i).getValue().getPriority() ==
+                                       DeviceTemplatePriority.DEFAULT) {
                                defaultTemplate = templateList.get(i);
                        }
                }
index 3ad7004..ea85814 100644 (file)
@@ -49,6 +49,8 @@ import org.eclipse.swt.widgets.MenuItem;
 import org.eclipse.swt.widgets.Shell;
 import org.tizen.emulator.manager.EmulatorManager;
 import org.tizen.emulator.manager.devices.DeviceTemplate;
+import org.tizen.emulator.manager.devices.DeviceTemplatePriority;
+import org.tizen.emulator.manager.devices.DeviceTemplateType;
 import org.tizen.emulator.manager.devices.DeviceTemplateValue;
 import org.tizen.emulator.manager.devices.DeviceWorkerException;
 import org.tizen.emulator.manager.logging.EMLogger;
@@ -649,7 +651,8 @@ public class DeviceTemplateTableViewer extends AbstractTableViewer {
                if (newValue == null) {
                        return;
                } else {
-                       newValue.setType("custom");
+                       newValue.setType(DeviceTemplateType.CUSTOM);
+                       newValue.setPriority(DeviceTemplatePriority.CUSTOM);
                }
 
                ProfileButton pButton = null;