From: jihye424.kim Date: Wed, 13 May 2015 04:20:28 +0000 (+0900) Subject: Custom Emulator: enable to launch and modify custom vm X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3cf1b3b1f6de9e83550c2510e144d87bf1b491c4;p=sdk%2Femulator%2Femulator-manager.git Custom Emulator: enable to launch and modify custom vm - add template, item list, option list to platform for custom base image - use template, item list of platform drawing custom emulator on detail view - use option list of platform launching custom emulator Change-Id: Ib0c2c3e1ec3cd7eb1fbd8109752156ff3baaecd2 Signed-off-by: jihye424.kim --- diff --git a/common-project/src/org/tizen/emulator/manager/platform/CustomBaseImage.java b/common-project/src/org/tizen/emulator/manager/platform/CustomBaseImage.java index f6a2f65..533d54f 100644 --- a/common-project/src/org/tizen/emulator/manager/platform/CustomBaseImage.java +++ b/common-project/src/org/tizen/emulator/manager/platform/CustomBaseImage.java @@ -31,27 +31,17 @@ package org.tizen.emulator.manager.platform; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import org.tizen.emulator.manager.resources.FilePathResources; import org.tizen.emulator.manager.resources.StringResources; -import org.tizen.emulator.manager.ui.detail.item.OptionType; -import org.tizen.emulator.manager.vms.EmulatorVMList; import org.tizen.emulator.manager.vms.SKIN_SHAPE; -import org.tizen.emulator.manager.vms.xml.template.DeviceList; -import org.tizen.emulator.manager.vms.xml.template.Item; +import org.tizen.emulator.manager.vms.VMProperty; +import org.tizen.emulator.manager.vms.option.IOption; import org.tizen.emulator.manager.vms.xml.template.ItemList; -import org.tizen.emulator.manager.vms.xml.template.ObjectFactory; -import org.tizen.emulator.manager.vms.xml.template.Option; -import org.tizen.emulator.manager.vms.xml.template.PropertyList; public class CustomBaseImage extends BaseImage { - public static ObjectFactory factory = new ObjectFactory(); - public CustomBaseImage(Platform platform, String path) throws IOException { if (platform == null) { throw new IOException("Failed to create custom base image " @@ -69,8 +59,6 @@ public class CustomBaseImage extends BaseImage { // TODO initLastCreatedPropertyPath(); - //loadProperty(); - //createTemplate(); } private void settingProperty(Platform platform) { @@ -82,6 +70,7 @@ public class CustomBaseImage extends BaseImage { binaryVersion = ""; } + @Override protected void initLastCreatedPropertyPath() { StringBuilder sb = new StringBuilder(); sb.append(FilePathResources.getTizenVmsPath()).append(File.separator) @@ -91,268 +80,18 @@ public class CustomBaseImage extends BaseImage { lastCreatedPropertyPath = sb.toString(); } - // Create template from standard platform's template. - private void createTemplate() { - if (PlatformList.getPlatformList() != null) { - for (Platform p : PlatformList.getPlatformList()) { - if (p.getProfile().equals(profile)) { - List templateList = new ArrayList(); - for(BaseImage i : p.getImageList()) { - if (i.getItemList() != null) { - templateList.add(i.getItemList()); - } - } - itemList = createCustomTemplate(templateList); - } - } - } + @Override + public List getOptionList() { + return platform.getCustomOptionList(); } - - - private void loadProperty() { - // load default - File propertyFile = new File(platform.platformPath + File.separator - + FilePathResources.getPlatformTemplatePath() - + File.separator - + imageName + "." + PlatformStringResources.CONFIG_EXTENSION); - if (propertyFile.exists()) { - EmulatorVMList vmList = EmulatorVMList.getInstance(); - defaultProperty = vmList.parseXML(propertyFile); - - } else { - // If custom default property not exist, load standard property - if (PlatformList.getPlatformList() != null) { - Platform latest = null; - for (Platform p : PlatformList.getPlatformList()) { - if (p.getProfile().equals(profile)) { - if (latest == null) { - latest = p; - } else { - if (p.getVersion().compareTo(latest.getVersion()) > 0) { - latest = p; - } - } - } - } - - if (latest != null) { - for (BaseImage image : latest.getImageList()) { - if (image.getType() != null && image.getType().equals("default")) { - defaultProperty = image.getDefaultProperty(); - } - } - if (defaultProperty == null) { - if (latest.getImageList().size() > 0) { - defaultProperty = latest.getImageList().get(0).getDefaultProperty(); - } - } - } - // TODO if defaultProperty == null ??? - } - } + @Override + public VMProperty getDefaultProperty() { + return platform.getCustomDefaultProperty(); } - private ItemList createCustomTemplate(List templateList) { - - if (templateList.size() == 0) { - return null; - - } else if (templateList.size() == 1) { - ItemList template = cloneTemplate(templateList.get(0)); - template.setImage(null); - return template; - - } else { // Make union set - ItemList base = cloneTemplate(templateList.get(0)); - for (int i=1 ; i < templateList.size() ; i++) { - addToBase(base,templateList.get(i)); - } - return base; - } - } - - private void addToBase(ItemList base, ItemList newOne) { - // Property list add - PropertyList newPropertyList = newOne.getPropertyList(); - PropertyList basePropertyList = base.getPropertyList(); - if (newPropertyList != null) { - if (basePropertyList == null) { - basePropertyList = factory.createPropertyList(); - base.setPropertyList(basePropertyList); - } - for (Item newItem : newPropertyList.getItem()) { - boolean itemExistInBase = false; - for (Item baseItem : basePropertyList.getItem()) { - if (baseItem.getName().equals(newItem.getName())) { - itemExistInBase = true; - joinItem(baseItem, newItem); - } - } - if (!itemExistInBase) { - basePropertyList.getItem().add(cloneItem(newItem)); - } - } - } - - // Device list add - DeviceList newDeviceList = newOne.getDeviceList(); - DeviceList baseDeviceList = base.getDeviceList(); - if (newDeviceList != null) { - if (baseDeviceList == null) { - baseDeviceList = factory.createDeviceList(); - base.setDeviceList(baseDeviceList); - } - for (Item newItem : newDeviceList.getItem()) { - boolean itemExistInBase = false; - for (Item baseItem : baseDeviceList.getItem()) { - if (baseItem.getName().equals(newItem.getName())) { - itemExistInBase = true; - joinItem(baseItem, newItem); - } - } - if (!itemExistInBase) { - baseDeviceList.getItem().add(cloneItem(newItem)); - } - } - } - } - - - private void joinItem(Item baseItem, Item newItem) { - // join sub items - for (Item newSub : newItem.getItem()) { - boolean itemExistInBase = false; - for (Item baseSub : baseItem.getItem()) { - if (baseSub.getName().equals(newSub.getName())) { - itemExistInBase = true; - joinItem(baseSub, newSub); - } - } - if (!itemExistInBase) { - baseItem.getItem().add(cloneItem(newSub)); - } - } - // join options - for (Option newOption : newItem.getOption()) { - boolean optionExistInBase = false; - for (Option baseOption : baseItem.getOption()) { - if (baseOption.getName().equals(newOption.getName())) { - optionExistInBase = true; - if (isListOption(baseOption, newOption)) { - joinOption(baseOption, newOption); - } - } - } - - if (!optionExistInBase) { - baseItem.getOption().add(cloneOption(newOption)); - } - } - - } - - private void joinOption(Option baseOption, Option newOption) { - baseOption.setValue(joinCommaString(baseOption.getValue(), newOption.getValue())); - } - - - private String joinCommaString(String base, String newOne) { - List optionList = new ArrayList(); - if (base != null) { - String[] split = base.split(","); - for (String str : split) { - optionList.add(str.trim()); - } - } - if (newOne != null) { - String[] split = newOne.split(","); - for (String str : split) { - optionList.add(str.trim()); - } - } - - if (optionList.size() > 0) { - Set optionSet = new HashSet(); - optionSet.addAll(optionList); - optionList.clear(); - optionList.addAll(optionSet); -// Collections.sort(optionList); - StringBuilder sb = new StringBuilder(); - - for (int i=0 ; iskinList = new ArrayList(); - // TODO : for template - //private ArrayList templateList = new ArrayList(); - protected VMProperty template; protected EMPlugin plugin; + // for custom base image + private ItemList customItemList; + private VMProperty customDefaultProperty; + private List customOptionList; + protected ArrayList imageList = new ArrayList(); protected int currentImageIndex = -1; protected Platform() { @@ -82,7 +90,6 @@ public class Platform { loadProperties(); if (!imageList.isEmpty()) { loadSkins(); - loadTemplate(); loadPlugin(); } } @@ -134,6 +141,20 @@ public class Platform { return null; } + // Load option list for each image. + public List getCustomOptionList() { + if (customOptionList == null) { + if (plugin != null) { + ExtensionItem exItem = getPlugin().getExtensionItem(PluginStringResources.OptionFactory); + IOptionFactory f = (IOptionFactory)(exItem.createClass()); + if (f != null) { + customOptionList = f.makeOptionList(getCustomItemList()); + } + } + } + return customOptionList; + } + private void loadProperties() { if (platformPath == null) { return; @@ -266,6 +287,56 @@ public class Platform { } } + + private void createCustomDefaultProperty() { + // If custom default property not exist, load standard property + for (BaseImage image : getProfileClass().getImageList()) { + if (image.getPlatform() == this) { + if (image.getType() != null && image.getType().equals("default")) { + customDefaultProperty = image.getDefaultProperty(); + } + } + } + + if (customDefaultProperty == null) { + for (BaseImage image : getProfileClass().getImageList()) { + if (image.getPlatform() == this) { + customDefaultProperty = image.getDefaultProperty(); + } + } + } + // TODO: if customDefaultProperty is still null ??? + } + + private void createCustomItemList() { + List templateList = new ArrayList(); + for (BaseImage image : getProfileClass().getImageList()) { + if (image.getPlatform() == this) { + templateList.add(image.getItemList()); + } + } + customItemList = createCustomTemplate(templateList); + } + + private ItemList createCustomTemplate(List templateList) { + + if (templateList.size() == 0) { + return null; + + } else if (templateList.size() == 1) { + ItemList template = cloneTemplate(templateList.get(0)); + template.setImage(null); + return template; + + } else { // Make union set + ItemList base = cloneTemplate(templateList.get(0)); + for (int i=1 ; i < templateList.size() ; i++) { + addToBase(base,templateList.get(i)); + } + return base; + } + } + private void loadPlugin() { File pluginJar = new File(platformPath + File.separator + FilePathResources.getPlatformPluginsPath() @@ -280,18 +351,6 @@ public class Platform { } } - private void loadTemplate() { - File templateFile = new File(platformPath + File.separator - + FilePathResources.getPlatformTemplatePath() - + File.separator - + PlatformStringResources.TemplateFile); - if (templateFile.exists()) { - EmulatorVMList vmList = EmulatorVMList.getInstance(); - VMProperty property = vmList.parseXML(templateFile); - template = property; - } - } - private void loadSkins() { File dir = new File(platformPath + File.separator + FilePathResources.getPlatformSkinsPath()); @@ -350,19 +409,6 @@ public class Platform { return SkinList.getInstance().findGeneralSkinList(skinList); } -/* - public ArrayList getTemplates() { - return templateList; - } -*/ - public VMProperty getTemplate() { - return template; - } - - public void setTemplate(VMProperty template) { - this.template = template; - } - public EMPlugin getPlugin() { return plugin; } @@ -378,4 +424,204 @@ public class Platform { public void setProfileClass(Profile profileClass) { this.profileClass = profileClass; } + + public ItemList getCustomItemList() { + if (customItemList == null) { + createCustomItemList(); + } + + return customItemList; + } + + public VMProperty getCustomDefaultProperty() { + if (customDefaultProperty == null) { + createCustomDefaultProperty(); + } + return customDefaultProperty; + } + + public static ObjectFactory factory = new ObjectFactory(); + private void addToBase(ItemList base, ItemList newOne) { + // Property list add + PropertyList newPropertyList = newOne.getPropertyList(); + PropertyList basePropertyList = base.getPropertyList(); + if (newPropertyList != null) { + if (basePropertyList == null) { + basePropertyList = factory.createPropertyList(); + base.setPropertyList(basePropertyList); + } + for (Item newItem : newPropertyList.getItem()) { + boolean itemExistInBase = false; + for (Item baseItem : basePropertyList.getItem()) { + if (baseItem.getName().equals(newItem.getName())) { + itemExistInBase = true; + joinItem(baseItem, newItem); + } + } + if (!itemExistInBase) { + basePropertyList.getItem().add(cloneItem(newItem)); + } + } + } + + // Device list add + DeviceList newDeviceList = newOne.getDeviceList(); + DeviceList baseDeviceList = base.getDeviceList(); + if (newDeviceList != null) { + if (baseDeviceList == null) { + baseDeviceList = factory.createDeviceList(); + base.setDeviceList(baseDeviceList); + } + for (Item newItem : newDeviceList.getItem()) { + boolean itemExistInBase = false; + for (Item baseItem : baseDeviceList.getItem()) { + if (baseItem.getName().equals(newItem.getName())) { + itemExistInBase = true; + joinItem(baseItem, newItem); + } + } + if (!itemExistInBase) { + baseDeviceList.getItem().add(cloneItem(newItem)); + } + } + } + } + + + private void joinItem(Item baseItem, Item newItem) { + // join sub items + for (Item newSub : newItem.getItem()) { + boolean itemExistInBase = false; + for (Item baseSub : baseItem.getItem()) { + if (baseSub.getName().equals(newSub.getName())) { + itemExistInBase = true; + joinItem(baseSub, newSub); + } + } + if (!itemExistInBase) { + baseItem.getItem().add(cloneItem(newSub)); + } + } + // join options + for (Option newOption : newItem.getOption()) { + boolean optionExistInBase = false; + for (Option baseOption : baseItem.getOption()) { + if (baseOption.getName().equals(newOption.getName())) { + optionExistInBase = true; + if (isListOption(baseOption, newOption)) { + joinOption(baseOption, newOption); + } + } + } + + if (!optionExistInBase) { + baseItem.getOption().add(cloneOption(newOption)); + } + } + + } + + private void joinOption(Option baseOption, Option newOption) { + baseOption.setValue(joinCommaString(baseOption.getValue(), newOption.getValue())); + } + + + private String joinCommaString(String base, String newOne) { + List optionList = new ArrayList(); + if (base != null) { + String[] split = base.split(","); + for (String str : split) { + optionList.add(str.trim()); + } + } + if (newOne != null) { + String[] split = newOne.split(","); + for (String str : split) { + optionList.add(str.trim()); + } + } + + if (optionList.size() > 0) { + Set optionSet = new HashSet(); + optionSet.addAll(optionList); + optionList.clear(); + optionList.addAll(optionSet); +// Collections.sort(optionList); + StringBuilder sb = new StringBuilder(); + + for (int i=0 ; i itemList; // ArrayList itemList; // ArrayList itemList; - String profile; + Platform platform; String imageName; boolean isCustom; - public ViewItemList(ExtensionItem exItem, String profile, String imageName, boolean isCustom) { + public ViewItemList(ExtensionItem exItem, Platform platform, String imageName, boolean isCustom) { this.exItem = exItem; - this.profile = profile; + this.platform = platform; this.imageName = imageName; this.isCustom = isCustom; } public boolean matchesWith(VMPropertyValue propertyValue) { - if (!profile.equals(propertyValue.profile)) { + if (platform != propertyValue.baseImage.getPlatform()) { return false; } else { if (imageName != null && !imageName.equals(propertyValue.baseImage.getName())) { diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/PInfoViewPage.java b/common-project/src/org/tizen/emulator/manager/ui/detail/PInfoViewPage.java index 14bdbcf..7a0f105 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/detail/PInfoViewPage.java +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/PInfoViewPage.java @@ -205,20 +205,12 @@ public class PInfoViewPage extends DetailViewPage { if (template != null) { templateList.add(template); infoItemList.add(new InfoViewItemList(item, this.getItemListComposite(), - template, platform.getProfile(), image.getName(), false)); + template, platform, image.getName(), false)); } } - - // TODO - // add itemlist for custom. - /* - for (Platform custom : PlatformList.getCustomPlatform()) { - if (custom.getProfile().equals(platform.getProfile())) { - infoItemList.add(new InfoViewItemList(item, this.getItemListComposite(), - custom.getImageList().get(0).getItemList(), custom.getProfile(), null, true)); - } - } - */ + // add item list for custom. + infoItemList.add(new InfoViewItemList(item, this.getItemListComposite(), + platform.getCustomItemList(), platform, null, true)); } } } @@ -340,19 +332,12 @@ class InfoViewItemList extends ViewItemList{ ArrayList itemList; InfoViewItemList(ExtensionItem item, Composite parent, ItemList template, - String profile, String imageName, boolean isCustom) { - super(item, profile, imageName, isCustom); + Platform platform, String imageName, boolean isCustom) { + super(item, platform, imageName, isCustom); makeItemList(parent, template, isCustom); initItemList(parent); } - InfoViewItemList(ExtensionItem item, Composite parent, List list, String profile) { - super(item, profile, null, true); - makeCustomItemList(parent, list); - initItemList(parent); - } - - private void makeItemList(Composite parent, ItemList templateList, boolean isCustom) { IItemListFactory f = (IItemListFactory)(exItem.createClass()); itemList = new ArrayList(); @@ -362,12 +347,6 @@ class InfoViewItemList extends ViewItemList{ // itemList = f.getInfoItemList(deviceItemList); } - private void makeCustomItemList(Composite parent, List list) { - IItemListFactory f = (IItemListFactory)(exItem.createClass()); - itemList = new ArrayList(); - f.makeCustomItemList(itemList, list); - } - private void initItemList(Composite parent){ comp = new Composite(parent, SWT.NONE); comp.setLayout(new FormLayout()); diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/PModifyViewPage.java b/common-project/src/org/tizen/emulator/manager/ui/detail/PModifyViewPage.java index a4760cf..224cf42 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/detail/PModifyViewPage.java +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/PModifyViewPage.java @@ -43,7 +43,6 @@ import org.eclipse.swt.widgets.Composite; import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.platform.BaseImage; import org.tizen.emulator.manager.platform.Platform; -import org.tizen.emulator.manager.platform.PlatformList; import org.tizen.emulator.manager.platform.Profile; import org.tizen.emulator.manager.platform.ProfileList; import org.tizen.emulator.manager.plugin.ExtensionItem; @@ -184,20 +183,12 @@ public class PModifyViewPage extends DetailViewPage if (template != null) { templateList.add(template); modifyItemList.add(new ModifyViewItemList(item, this, - template, platform.getProfile(), image.getName(), false)); + template, platform, image.getName(), false)); } } - - // TODO - // add itemlist for custom. - /* - for (Platform custom : PlatformList.getCustomPlatform()) { - if (custom.getProfile().equals(platform.getProfile())) { - modifyItemList.add(new ModifyViewItemList(item, this, - custom.getImageList().get(0).getItemList(), custom.getProfile(), null, true)); - } - } - */ + // add item list for custom. + modifyItemList.add(new ModifyViewItemList(item, this, + platform.getCustomItemList(), platform, null, true)); } } } @@ -446,18 +437,12 @@ class ModifyViewItemList extends ViewItemList{ ArrayList itemList; ModifyViewItemList(ExtensionItem item, PModifyViewPage page, ItemList template - ,String profile, String imageName, boolean isCustom) { - super(item, profile, imageName, isCustom); + ,Platform platform, String imageName, boolean isCustom) { + super(item, platform, imageName, isCustom); makeItemList(page, template, isCustom); initItemList(page); } - ModifyViewItemList(ExtensionItem item, PModifyViewPage page, List list, String profile) { - super(item, profile, null, true); - makeCustomItemList(page, list); - initItemList(page); - } - private void makeItemList(PModifyViewPage page, ItemList deviceItemList, boolean isCustom) { IItemListFactory f = (IItemListFactory)(exItem.createClass()); itemList = new ArrayList(); @@ -467,12 +452,6 @@ class ModifyViewItemList extends ViewItemList{ } } - private void makeCustomItemList(PModifyViewPage page, List list) { - IItemListFactory f = (IItemListFactory)(exItem.createClass()); - itemList = new ArrayList(); - f.makeCustomItemList(itemList, list); - } - private void initItemList(PModifyViewPage page) { comp = new Composite(page.getItemListComposite(), SWT.NONE); comp.setLayout(new FormLayout());