From: minkee.lee Date: Wed, 14 Oct 2015 07:55:14 +0000 (+0900) Subject: device-template: draw device template dialog using XML. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bd0a1a052ae072cdb202adce1e0238b5240dffa2;p=sdk%2Femulator%2Femulator-manager.git device-template: draw device template dialog using XML. - Now dialog use sample XML (/xsd/template-ui-mobile.xml) Change-Id: I60d2eb237873500f21d26109f66f7e4ec6811e72 Signed-off-by: minkee.lee --- diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java b/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java index 3eaee07..4656178 100644 --- a/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java +++ b/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java @@ -78,7 +78,9 @@ public class DeviceTemplateValue implements Cloneable { StringBuilder sb = new StringBuilder(); sb.append("name : " + name + StringResources.NEW_LINE); sb.append("profile : " + profile + StringResources.NEW_LINE); - sb.append("resolution : " + resolution.toString() + StringResources.NEW_LINE); + if (resolution != null) { + sb.append("resolution : " + resolution.toString() + StringResources.NEW_LINE); + } sb.append("width : " + displayWidth + StringResources.NEW_LINE); sb.append("height : " + displayHeight + StringResources.NEW_LINE); sb.append("size : " + displaySize + StringResources.NEW_LINE); @@ -429,6 +431,55 @@ public class DeviceTemplateValue implements Cloneable { return true; } + private SubDevice findSubDevice(String name) { + for (SubDevice sub : additionalDevices) { + if (sub.getName().equals(name)) { + return sub; + } + } + return null; + } + + + public void addOrUpdateSubDevices(SubDevice newSubDevice) { + SubDevice subDevice = findSubDevice(newSubDevice.getName()); + + if (subDevice == null) { + // Add if not exist. + additionalDevices.add(newSubDevice); + + } else { + updateSubDevice(subDevice, newSubDevice); + } + } + + private void updateSubDevice(SubDevice oldOne, SubDevice newOne) { + for (SubDeviceItem newItem : newOne.getItems()) { + SubDeviceItem subDeviceItem = findSubDeviceItem(oldOne, newItem.getId()); + if (subDeviceItem == null) { + // Add + oldOne.addSubDeviceItem(newItem); + + } else { + updateSubDeviceItem(subDeviceItem, newItem); + } + } + } + + private void updateSubDeviceItem(SubDeviceItem oldItem, SubDeviceItem newItem) { + oldItem.setSupport(newItem.isSupport()); + oldItem.setName(newItem.getName()); + } + + private SubDeviceItem findSubDeviceItem(SubDevice subDevice, String itemId) { + for (SubDeviceItem item : subDevice.getItems()) { + if (item.getId().equals(itemId)) { + return item; + } + } + return null; + } + public boolean isAdditionalDeviceEquals(List destList) { if (additionalDevices == null && destList == null) { return true; diff --git a/src/org/tizen/emulator/manager/devices/SubDeviceItem.java b/src/org/tizen/emulator/manager/devices/SubDeviceItem.java index 70514e8..65a0195 100644 --- a/src/org/tizen/emulator/manager/devices/SubDeviceItem.java +++ b/src/org/tizen/emulator/manager/devices/SubDeviceItem.java @@ -30,13 +30,14 @@ package org.tizen.emulator.manager.devices; +import java.util.ArrayList; import java.util.List; public class SubDeviceItem { private String id = ""; private String name = ""; private boolean isSupport = false; - private List values; + private List values = new ArrayList(); public SubDeviceItem(String id) { this.id = id; diff --git a/src/org/tizen/emulator/manager/template/TemplateLoader.java b/src/org/tizen/emulator/manager/template/TemplateLoader.java index dbaa365..6acff28 100644 --- a/src/org/tizen/emulator/manager/template/TemplateLoader.java +++ b/src/org/tizen/emulator/manager/template/TemplateLoader.java @@ -122,7 +122,7 @@ public class TemplateLoader { return context; } - private static Object loadTemplate (File f, Class type) { + public static Object loadTemplate (File f, Class type) { JAXBElement element = null; JAXBContext context = getContext(type); if (context != null) { diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialog/ItemListLoader.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/ItemListLoader.java new file mode 100644 index 0000000..5af5709 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/ItemListLoader.java @@ -0,0 +1,199 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * Minkee Lee + * JiHye Kim + * 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.util.ArrayList; +import java.util.List; + +import org.tizen.emulator.manager.logging.EMLogger; +import org.tizen.emulator.manager.ui.renewal.item.ItemName; +import org.tizen.emulator.manager.ui.renewal.item.ItemType; +import org.tizen.emulator.manager.ui.renewal.item.OptionName; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.CheckBoxItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.CheckItemData; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ConnectivityItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.DisplayItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ModifyDialogItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.NameItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ProcessorItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ProfileItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.RamSizeItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.SensorItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.template.CameraItem; +import org.tizen.emulator.manager.vms.RESOLUTION; +import org.tizen.emulator.manager.vms.xml.template2.Item; +import org.tizen.emulator.manager.vms.xml.template2.ItemGroup; +import org.tizen.emulator.manager.vms.xml.template2.ItemList2; +import org.tizen.emulator.manager.vms.xml.template2.Option; + +public class ItemListLoader { + + /** Get UI item for device-template dialog. */ + public static List getDeviceTemplateItemList(ItemList2 itemList2) { + if (itemList2 == null) { + return null; + } + + List groupList = itemList2.getItemGroup(); + List itemList = new ArrayList(); + for (ItemGroup group : groupList) { + addItemList(group, itemList); + break; // use first one item group. + } + + return itemList; + } + + private static void addItemList(ItemGroup group, List itemList) { + String name; + String title; + String type; + for (Item item : group.getItem()) { + ModifyDialogItem dialogItem = null; + name = item.getName(); + title = item.getTitle(); + type = item.getType(); + + // check item name + if (name.equals(ItemName.NAME)) { + dialogItem = new NameItem(name, title); + + } else if (name.equals(ItemName.PROFILE)) { + dialogItem = new ProfileItem(); + + } else if (name.equals(ItemName.DISPLAY)) { + dialogItem = new DisplayItem(getResolutionList(item)); + + } else if (name.equals(ItemName.PROCESSORS)) { + dialogItem = new ProcessorItem(); + + } else if (name.equals(ItemName.RAM_SIZE)) { + dialogItem = new RamSizeItem(); + + } else if (name.equals(ItemName.SENSOR)) { + dialogItem = new SensorItem(getCheckBoxDataList(item)); + + } else if (name.equals(ItemName.CONNECTIVITY)) { + dialogItem = new ConnectivityItem(getCheckBoxDataList(item)); + + } else if (name.equals(ItemName.CAMERA)) { + dialogItem = new CameraItem(getCheckBoxDataList(item)); + } + if (dialogItem != null) { + itemList.add(dialogItem); + continue; + } + + // check item type + if (type.equals(ItemType.CHECK_LABEL)) { + dialogItem = new CheckBoxItem(name, title, getCheckBoxNumColumn(item), + getCheckBoxDataList(item)); + } + if (dialogItem != null) { + itemList.add(dialogItem); + } + } + } + + private static final int DEFAULT_NUM_COLUMN = 3; + private static int getCheckBoxNumColumn(Item item) { + int numColumn = DEFAULT_NUM_COLUMN; + String str = getOption(item.getOption(), OptionName.NUM_COLUMN); + if (str != null) { + try { + numColumn = Integer.parseInt(str); + } catch (NumberFormatException e) { + EMLogger.getLogger().warning(e.getMessage()); + } + } + return numColumn; + } + + private static List getCheckBoxDataList(Item item) { + List dataList = new ArrayList(); + for (Item subItem : item.getItem()) { + dataList.add(new CheckItemData(subItem.getName(), subItem.getTitle(), true)); + } + return dataList; + + } + + private static String getOption(List