From: jihye424.kim Date: Fri, 2 Oct 2015 05:10:25 +0000 (+0900) Subject: Device Template: make device template creator X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3e2852a2ffc396014d93de74f012e50bd413dd31;p=sdk%2Femulator%2Femulator-manager.git Device Template: make device template creator - create device template xml file from device template value Change-Id: I70a7f8cbf3acb3976062fd78ac268ace38f8c9cd Signed-off-by: jihye424.kim --- diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplateCreator.java b/src/org/tizen/emulator/manager/devices/DeviceTemplateCreator.java new file mode 100644 index 0000000..f76bdd3 --- /dev/null +++ b/src/org/tizen/emulator/manager/devices/DeviceTemplateCreator.java @@ -0,0 +1,133 @@ +/* + * 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.devices; + +import org.tizen.emulator.manager.device.xml.template.Device; +import org.tizen.emulator.manager.device.xml.template.DeviceConfiguration; +import org.tizen.emulator.manager.device.xml.template.DeviceItem; +import org.tizen.emulator.manager.device.xml.template.ObjectFactory; + + +public class DeviceTemplateCreator { + private DeviceTemplate template; + + public static DeviceTemplate create(DeviceTemplateValue value) { + return new DeviceTemplateCreator().createInternal(value); + } + + private DeviceTemplateCreator() { + } + + private DeviceTemplate createInternal(DeviceTemplateValue value) { + // lock.acquire + this.template = DeviceTemplateList.createNewDeviceTemplate(value.getName()); + if (template.getTemplateFile().exists()) { + // TODO + } + + settingConfiguration(value); + + DeviceTemplateList.saveDeviceConfiguration(template); + + // lock.release + return template; + } + + private void settingConfiguration(DeviceTemplateValue value) { + ObjectFactory factory = new ObjectFactory(); + DeviceConfiguration conf = template.getConf(); + conf.setBaseInformation(factory.createBaseInformation()); + conf.setDisplay(factory.createDisplay()); + conf.setRam(factory.createRam()); + conf.setCpu(factory.createCpu()); + + // base information + conf.getBaseInformation().setName(value.getName()); + conf.getBaseInformation().setType(value.getType()); + 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()); + if (value.getManufacturer() != null && !value.getManufacturer().isEmpty()) { + conf.getBaseInformation().setManufacturer(value.getManufacturer()); + } + + // display + conf.getDisplay().setResolution(factory.createDisplayResolution()); + conf.getDisplay().getResolution().setWidth(value.getDisplayWidth()); + conf.getDisplay().getResolution().setHeight(value.getDisplayHeight()); + + conf.getDisplay().setScreenSize(factory.createDisplayScreenSize()); + conf.getDisplay().getScreenSize().setUnit(value.getDisplaySizeUnit()); + conf.getDisplay().getScreenSize().setValue(value.getDisplaySize()); + + if (value.getSkin() != null) { + conf.getDisplay().setSkin(factory.createDisplaySkin()); + conf.getDisplay().getSkin().setName(value.getSkinName()); + conf.getDisplay().getSkin().setPath(value.getSkinPath()); + } + + // ram + conf.getRam().setSize(factory.createRamSize()); + conf.getRam().getSize().setUnit(value.getRamSizeUnit()); + conf.getRam().getSize().setValue(value.getRamSize()); + + // cpu count + conf.getCpu().setCount(value.getCpuCount()); + + // additionalDevices + if (value.getAdditionalDevices().size() > 0) { + conf.setAdditionalDevices(factory.createAdditionalDevices()); + conf.getAdditionalDevices().getDevice().clear(); + for (SubDevice device : value.getAdditionalDevices()) { + Device d = new Device(); + d.setName(device.getName()); + for (SubDeviceItem item : device.getItems()) { + DeviceItem i = new DeviceItem(); + if (item.getValues() != null && item.getValues().size() > 0) { + // TODO + } + + i.setId(item.getId()); + i.setSupport(item.isSupport()); + if (item.getName() != null && !item.getName().isEmpty()) { + i.setName(item.getName()); + } + d.getDeviceItem().add(i); + } + conf.getAdditionalDevices().getDevice().add(d); + } + } + } +} diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplateList.java b/src/org/tizen/emulator/manager/devices/DeviceTemplateList.java index 0cda77a..43ac5cd 100644 --- a/src/org/tizen/emulator/manager/devices/DeviceTemplateList.java +++ b/src/org/tizen/emulator/manager/devices/DeviceTemplateList.java @@ -46,6 +46,7 @@ import javax.xml.bind.Unmarshaller; import javax.xml.transform.stream.StreamSource; import org.tizen.emulator.manager.device.xml.template.DeviceConfiguration; +import org.tizen.emulator.manager.device.xml.template.ObjectFactory; import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.resources.FilePathResources; import org.tizen.emulator.manager.resources.StringResources; @@ -86,6 +87,15 @@ public class DeviceTemplateList { template.setConf(conf); } + public static DeviceTemplate createNewDeviceTemplate(String name) { + String templateFilePath = FilePathResources.getTizenSdkDataDevicePath() + + File.separator + name + ".xml"; + File templateFile = new File(templateFilePath); + DeviceConfiguration conf = new ObjectFactory().createDeviceConfiguration(); + + return new DeviceTemplate(templateFile, conf); + } + public static boolean saveDeviceConfiguration(DeviceTemplate template) { return saveDeviceConfiguration(template, null); } diff --git a/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java b/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java index a557171..1d7b1e6 100644 --- a/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java +++ b/src/org/tizen/emulator/manager/devices/DeviceTemplateValue.java @@ -47,11 +47,13 @@ public class DeviceTemplateValue implements Cloneable { private DeviceTemplate template; private boolean isStandard = false; private String name = ""; - private String type; - private String profile; - private String extenstion; - private int priority; - private String manufacturer; + private String type = ""; + private String profile = ""; + private String extenstion = ""; + // standard = 1, custom = 3 (1 > 3) + private int priority = 3; + private String version = "1.0.0"; + private String manufacturer = ""; private RESOLUTION resolution; @@ -95,7 +97,8 @@ public class DeviceTemplateValue implements Cloneable { } profile = conf.getBaseInformation().getProfile(); extenstion = conf.getBaseInformation().getExtension(); - priority = conf.getBaseInformation().getPriority().intValue(); + priority = conf.getBaseInformation().getPriority(); + version = conf.getBaseInformation().getVersion(); manufacturer = conf.getBaseInformation().getManufacturer(); } @@ -131,7 +134,7 @@ public class DeviceTemplateValue implements Cloneable { skinPath = conf.getDisplay().getSkin().getPath(); } - if (skinPath != null) { + if (skinPath != null && !skinPath.isEmpty()) { try { skin = new Skin(new File(skinPath)); } catch (IOException e) { @@ -232,6 +235,14 @@ public class DeviceTemplateValue implements Cloneable { this.priority = priority; } + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + public String getManufacturer() { return manufacturer; } diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java index c65d2c2..db1e30e 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/DeviceTemplateTableViewer.java @@ -63,10 +63,10 @@ import org.tizen.emulator.manager.ui.table.TableItem; import org.tizen.emulator.manager.vms.helper.VMWorkerException; public class DeviceTemplateTableViewer extends AbstractTableViewer { - private static final int BACK_BUTTON_WIDTH = 124; - private static final int BACK_BUTTON_HEIGHT = 26; - private static final int BUTTON_WIDTH = 32; - private static final int BUTTON_HEIGHT = 26; + private static final int BACK_BUTTON_WIDTH = 124; + private static final int BACK_BUTTON_HEIGHT = 26; + private static final int BUTTON_WIDTH = 32; + private static final int BUTTON_HEIGHT = 26; private Hyperlink baseImageList; private ImageButton refreshButton; @@ -102,7 +102,7 @@ public class DeviceTemplateTableViewer extends AbstractTableViewer { if (event.type == SWT.Selection) { if (event.type == SWT.Selection) { MessageBox dialog = new MessageBox(MainDialog.getShell()); - dialog.setMessage("Click BaseImages menu"); + dialog.setMessage("Click Base Images menu"); dialog.open(); } } @@ -240,7 +240,9 @@ public class DeviceTemplateTableViewer extends AbstractTableViewer { int dir = table.getSortDirection(); ItemProfilePair[] pairs = new ItemProfilePair[table.getItemCount()]; for (int i = 0; i < table.getItemCount(); i++) { - pairs[i] = new ItemProfilePair(table.getItem(i), 1, dir); + DeviceTemplate t = (DeviceTemplate)table.getItem(i).getData(); + Profile p = ProfileList.getProfile(t.getValue().getProfile()); + pairs[i] = new ItemProfilePair(table.getItem(i), 1, dir, p.getPriority()); } column.setTableItemPairs(pairs); // sort table item diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ItemProfilePair.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ItemProfilePair.java index 652317e..0466480 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ItemProfilePair.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ItemProfilePair.java @@ -30,17 +30,14 @@ package org.tizen.emulator.manager.ui.renewal.tableviewer; import org.eclipse.swt.SWT; -import org.tizen.emulator.manager.platform.Profile; import org.tizen.emulator.manager.ui.table.TableItem; import org.tizen.emulator.manager.ui.table.TableItemComparable; -import org.tizen.emulator.manager.vms.VMProperty; public class ItemProfilePair extends TableItemComparable { private int priority; - public ItemProfilePair(TableItem item, int index, int direction) { + public ItemProfilePair(TableItem item, int index, int direction, int priority) { super(item, index, direction); - Profile profile = ((VMProperty)item.getData()).getPropertyValue().baseImage.getPlatform().getProfileClass(); - priority = profile.getPriority(); + this.priority = priority; } @Override 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 351cd03..21119e9 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java @@ -150,7 +150,8 @@ public class VMListTable { int dir = table.getSortDirection(); ItemProfilePair[] pairs = new ItemProfilePair[table.getItemCount()]; for (int i = 0; i < table.getItemCount(); i++) { - pairs[i] = new ItemProfilePair(table.getItem(i), 1, dir); + Profile profile = ((VMProperty)table.getItem(i).getData()).getPropertyValue().baseImage.getPlatform().getProfileClass(); + pairs[i] = new ItemProfilePair(table.getItem(i), 1, dir, profile.getPriority()); } column.setTableItemPairs(pairs); // sort table item