- Each profile has last-created VM property.
Change-Id: I66d5214a18bb980fc6d3b47380d10cbbf196f226
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
protected boolean isStandard;
private String information;
- protected String lastCreatedPropertyPath;
protected VMProperty defaultProperty;
protected ItemList itemList;
loadProperty(path);
settingImagePath(path);
- initLastCreatedPropertyPath();
loadTemplate();
}
return defaultProperty;
}
- public ItemList getItemList() {
- return itemList;
+ public void setDefaultProperty(VMProperty property) {
+ this.defaultProperty = property;
}
- public String getLastCreatedPropertyPath() {
- return lastCreatedPropertyPath;
+ public ItemList getItemList() {
+ return itemList;
}
public SKIN_SHAPE getSkinShape() {
return skinShape;
}
- protected void initLastCreatedPropertyPath() {
- StringBuilder sb = new StringBuilder();
- sb.append(FilePathResources.getTizenVmsPath()).append(File.separator)
- .append(StringResources.LAST_CREATED_XML_PREFIX).append("_")
- .append(profile).append("-").append(version).append("_")
- .append(imageName).append(".xml");
- lastCreatedPropertyPath = sb.toString();
- }
-
private void checkBaseImageName() throws IOException {
if (imageName == null) {
throw new IOException("Image name is null. This image can not add.");
inputStream = new FileInputStream(f);
Properties prop = new Properties();
prop.load(inputStream);
- imageName = prop.getProperty(StringResources.IMAGE_NAME);
+ imageName = prop.getProperty(StringResources.IMAGE_NAME, "");
checkBaseImageName();
version = prop.getProperty(StringResources.IMAGE_VERSION, "2.4");
profile = prop.getProperty(StringResources.PRODUCT_PROFILE, PlatformStringResources.MobileProfile).toLowerCase();
return binaryVersion;
}
- // For usability : return last-created property.
- public VMProperty getCreateProperty() {
- File lastCreated = new File(lastCreatedPropertyPath);
-
- // Use last-created_xxx.xml
- if(lastCreated.exists()) {
- return EmulatorVMList.getInstance().parseXML(lastCreated);
- }
-
- // Use standard.xml
- return defaultProperty;
- }
-
private void loadTemplate() {
// load template
File templateFile = new File(platform.platformPath + File.separator
import java.io.IOException;
import java.util.List;
-import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.StringResources;
import org.tizen.emulator.manager.vms.SKIN_SHAPE;
import org.tizen.emulator.manager.vms.VMProperty;
this.path = path;
if (path != null && !path.isEmpty()) {
- imageName = pathName = path.substring(path.lastIndexOf(File.separator));
+ imageName = pathName = path.substring(path.lastIndexOf(File.separator) + 1);
}
settingProperty(platform);
-
- // TODO
- initLastCreatedPropertyPath();
}
private void settingProperty(Platform platform) {
}
@Override
- protected void initLastCreatedPropertyPath() {
- StringBuilder sb = new StringBuilder();
- sb.append(FilePathResources.getTizenVmsPath()).append(File.separator)
- .append(StringResources.LAST_CREATED_XML_PREFIX).append("_")
- .append(profile).append("-").append("custom").append("_")
- .append(imageName).append(".xml");
- lastCreatedPropertyPath = sb.toString();
- }
-
- @Override
public List<IOption> getOptionList() {
return platform.getCustomOptionList();
}
package org.tizen.emulator.manager.platform;
+import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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.vms.EmulatorVMList;
import org.tizen.emulator.manager.vms.VMProperty;
import org.tizen.emulator.manager.vms.VMProperty.FSImageType;
private List<BaseImage> imageList = new ArrayList<BaseImage>();
private List<VMProperty> vmList = new ArrayList<VMProperty>();
+ protected String lastCreatedPropertyPath;
+
// for sort VM list
private SortBy sortType = SortBy.DateDes;
private boolean isSort = false;
public Profile(String name) {
this.name = name;
+ initLastCreatedPropertyPath();
}
public String getName() {
return platformList;
}
+ public String getLastCreatedPropertyPath() {
+ return lastCreatedPropertyPath;
+ }
+
+ protected void initLastCreatedPropertyPath() {
+ StringBuilder sb = new StringBuilder();
+ sb.append(FilePathResources.getTizenVmsPath()).append(File.separator)
+ .append(StringResources.LAST_CREATED_XML_PREFIX).append("_")
+ .append(name).append(".xml");
+ lastCreatedPropertyPath = sb.toString();
+ }
+
+ public BaseImage findBaseImage(VMProperty createProperty) {
+ // return base image
+ for(BaseImage image : imageList) {
+ if (createProperty.compareImage(image)) {
+ return image;
+ }
+ }
+ // return custom base image
+ Platform platform = ProfileList.getProfile(createProperty.getImageProfile()).
+ getPlatformByVersion(createProperty.getImageVersion());
+ try {
+ return new CustomBaseImage(platform, createProperty.getBaseImagePath());
+ } catch (IOException e) {
+ EMLogger.getLogger().warning("Failed to find baseimage. No platform");
+ return null;
+ }
+ }
+
+ public VMProperty getLastCreatedProperty() {
+ File lastCreated = new File(lastCreatedPropertyPath);
+ // Use last-created_xxx.xml
+ if(lastCreated.exists()) {
+ return EmulatorVMList.getInstance().parseXML(lastCreated);
+ }
+
+ return null;
+ }
+
/**
*
* @param name profile + "-" + version
// Get current last-created property file path.
List<String> currentPathList = new ArrayList<String>();
for (Profile p : profileList) {
- for (BaseImage image : p.getImageList()) {
- currentPathList.add(image.getLastCreatedPropertyPath());
- }
+ currentPathList.add(p.getLastCreatedPropertyPath());
}
- // Remove old last-created property.
+ // Remove legacy last-created property.
File vms = new File(FilePathResources.getTizenVmsPath());
File[] files = vms.listFiles();
if (files != null) {
public static final String EM_INFO_FILE = ".tizen-em-info";
public static final String MAC_ADDRESS="MAC_ADDRESS";
public static final String LAST_TAB_INDEX="LAST_TAB_INDEX";
- public static final String LAST_IMAGE_INDEX="LAST_IMAGE_INDEX";
//ArchitectureGroup
public static final String GROUP_TITLE = "Emulator Architecture";
return index;
}
- // For image index reuse.
- public static void setLastImageIndex(int index) {
- setProperty(StringResources.LAST_IMAGE_INDEX, String.valueOf(index));
- }
- public static int getLastImageIndex() {
- int index = 0;
- String value = getProperty(StringResources.LAST_IMAGE_INDEX);
- try {
- index = Integer.parseInt(value);
- } catch (Exception e) {
- EMLogger.addStaticLog("Failed to read last-image-index from property file. " +e.getMessage());
- index = 0;
- }
-
- return index;
- }
-
public static boolean setProperty(String name, String value) {
String infoFilePath = null;
infoFilePath = FilePathResources.getTizenVmsPath()
}
// TODO
- drawCreateVM(currentProfile.getImageList().get(0), setFocus);
+ drawCreateVM(currentProfile, setFocus);
}
- public void drawCreateVM(BaseImage image, boolean setFocus) {
+ public void drawCreateVM(Profile profile, boolean setFocus) {
setSetFocus(setFocus);
if (!isCreateMode) {
isCreateMode = true;
- VMProperty createProperty = image.getCreateProperty();
- detailView.drawCreateVM(
- new VMPropertyValue(image, createProperty));
+ VMProperty lastCreatedProperty = profile.getLastCreatedProperty();
+ BaseImage findImage = null;
+ if (lastCreatedProperty != null) {
+ findImage = profile.findBaseImage(lastCreatedProperty);
+ }
+
+ if (findImage == null) {
+ detailView.drawCreateVM(
+ new VMPropertyValue(profile.getImageList().get(0)));
+ } else {
+ detailView.drawCreateVM(
+ new VMPropertyValue(findImage, lastCreatedProperty));
+ }
}
}
import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.EmulatorManager.ManagerModeType;
import org.tizen.emulator.manager.platform.BaseImage;
-import org.tizen.emulator.manager.platform.Platform;
import org.tizen.emulator.manager.platform.Profile;
import org.tizen.emulator.manager.platform.ProfileList;
import org.tizen.emulator.manager.resources.FontResources;
// Select image.
int index = combo.getSelectionIndex();
- setCurrentBaseImage(index);
+ changePropertyView(baseImageItemList.get(index));
+ if(isCreateMode()) {
+ getListener().changeCreateConfirmButton();
+ }
}
@Override
EmulatorVMList.getInstance().CustomArch = !isArm ? "x86"
: "arm";
- addCustomImageItem(new BaseImageItem(newPathName,
- newPathName, newPath, profile, "", false, SKIN_SHAPE.NONE));
+ BaseImageItem newItem = new BaseImageItem(newPathName,
+ newPathName, newPath, profile, "", false, SKIN_SHAPE.NONE);
+ addToBaseImageItemList(newItem);
+ storeCustomImage(newItem);
+ resetComboList();
+ changePropertyView(newItem);
- // filePathLabel.setText(newPathName);
- // filePathLabel.redraw();
isSelected = true;
getListener().changeCreateConfirmButton();
this.value = value;
this.profile = value.profile;
- currentBaseImageItem.setFileName(value.baseImagePathName);
- currentBaseImageItem.setFilePath(value.baseImagePath);
- currentBaseImageItem.setStandard(value.isStandard);
- currentBaseImageItem.setImageName(value.baseName);
- currentBaseImageItem.setProfile(value.profile);
- currentBaseImageItem.setSkinShape(value.skinShape);
+ currentBaseImageItem.setValue(value);
+ if (!value.isStandard) {
+ storeCustomImage(currentBaseImageItem);
+ }
+
isSelected = false;
if (isCreateMode()) {
return "";
}
+ private void changePropertyView(BaseImageItem item) {
+ currentBaseImageItem = item;
+ setValue(value);
+ getListener().changePropertyView(value, isCreateMode());
+ }
+
private void loadBaseImageItemList(String profileName) {
baseImageItemList.clear();
Profile profile = ProfileList.getProfile(profileName);
if (profile != null) {
for (BaseImage img : profile.getImageList()) {
- baseImageItemList.add(new BaseImageItem(img.getName(), img
+ addToBaseImageItemList(new BaseImageItem(img.getName(), img
.getPathName(), img.getPath(), img.getProfile(), img.getVersion(),
true, img.getSkinShape()));
}
private void loadCustomImageItemList(String profile) {
for (BaseImageItem customImageItem : customImageItemList) {
if (customImageItem.getProfile().equals(profile)) {
- baseImageItemList.add(new BaseImageItem(customImageItem));
+ addToBaseImageItemList(new BaseImageItem(customImageItem));
}
}
}
- private void addCustomImageItem(BaseImageItem customImageItem) {
+ private void addToBaseImageItemList(BaseImageItem baseImageItem) {
// Check duplicated custom image.
int index = -1;
for (int i = 0; i < baseImageItemList.size(); i++) {
BaseImageItem item = baseImageItemList.get(i);
- if (item.equals(customImageItem)) {
+ if (item.equals(baseImageItem)) {
index = i;
break;
}
if (index == -1) {
// Add to image list
- baseImageItemList.add(customImageItem);
- // Setting combo list.
- combo.add(customImageItem.getImageName());
- index = baseImageItemList.size() -1;
-
- customImageItemList.add(new BaseImageItem(customImageItem));
+ if (checkBaseImageFile(baseImageItem.getFilePath())) {
+ baseImageItemList.add(baseImageItem);
+ }
}
-
- combo.select(index);
- setCurrentBaseImage(index);
}
- private void setCurrentBaseImage(int index) {
- currentBaseImageItem = baseImageItemList.get(index);
-
-// if (currentBaseImageItem.isStandard()) {
-// currentCustomImageItem = null;
-// } else {
-// currentCustomImageItem = currentBaseImageItem;
-// }
-
- setValue(value);
- getListener().changePropertyView(value, isCreateMode());
+ private void storeCustomImage(BaseImageItem customImageItem) {
+ int index = -1;
+ for (int i = 0; i < customImageItemList.size(); i++) {
+ BaseImageItem item = customImageItemList.get(i);
+ if (item.equals(customImageItem)) {
+ index = i;
+ break;
+ }
+ }
- if(isCreateMode()) {
- getListener().changeCreateConfirmButton();
+ if (index == -1) {
+ if (checkBaseImageFile(customImageItem.getFilePath())) {
+ customImageItemList.add(new BaseImageItem(customImageItem));
+ }
}
}
return imageName;
}
+ public void setValue(VMPropertyValue value) {
+ setFileName(value.baseImagePathName);
+ setFilePath(value.baseImagePath);
+ setStandard(value.isStandard);
+ setImageName(value.baseName);
+ setProfile(value.profile);
+ setSkinShape(value.skinShape);
+ setVersion(value.version);
+ }
+
public void setImageName(String imageName) {
this.imageName = imageName;
}
typeItems.add(tempItem);
createItem = new TreeItem(tempItem, SWT.NONE);
- rowItem = new CreateMarker(createItem, p.getImageList().get(0));
+ rowItem = new CreateMarker(createItem, p);
createItem.setData(rowItem);
createItems.add(createItem);
/*
import org.eclipse.swt.widgets.TreeItem;
import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.platform.BaseImage;
+import org.tizen.emulator.manager.platform.Profile;
import org.tizen.emulator.manager.resources.FontResources;
import org.tizen.emulator.manager.resources.ImageResources;
import org.tizen.emulator.manager.ui.VMsMainView;
class CreateMarker implements TreeMarker {
private BaseImage image = null;
+ private Profile profile = null;
TreeItem item;
- public CreateMarker(TreeItem item, BaseImage image) {
+
+ public CreateMarker(TreeItem item, Profile profile) {
item.setText("<< Create new... >>");
// TODO
Font font = FontResources.TREE_CREATE_FONT.getFont();
item.setFont(font);
- this.image =image;
+ this.profile = profile;
+ this.image =profile.getImageList().get(0);
this.item = item;
}
-
+
public BaseImage getBaseImage() {
return image;
}
public TreeItem getItem() {
return item;
}
+
+ public Profile getProfile() {
+ return profile;
+ }
}
abstract class Container {
case SWT.KEYPAD_CR:
if(data instanceof CreateMarker) {
VMsMainView.getInstance().drawCreateVM(
- ((CreateMarker)data).getBaseImage(), true);
+ ((CreateMarker)data).getProfile(), true);
return;
} else if (data instanceof PropertyContent) {
if (!VMsMainView.getInstance().isModifyMode()) {
// TODO : select template using platform
if (data instanceof CreateMarker) {
VMsMainView.getInstance().drawCreateVM(
- ((CreateMarker)data).getBaseImage(), false);
+ ((CreateMarker)data).getProfile(), false);
//setSelectProperty();
vmsTree.setSelection(((CreateMarker) data).getItem());
isSelection = false;
Profile profile = VMsMainView.getInstance().getProfile();
createItem = new TreeItem(vmsTree, SWT.NONE);
- rowItem = new CreateMarker(createItem, profile.getImageList().get(0));
+ rowItem = new CreateMarker(createItem, profile);
createItem.setData(rowItem);
VMProperty prop = null;
import java.util.List;
import org.tizen.emulator.manager.logging.EMLogger;
+import org.tizen.emulator.manager.platform.Profile;
+import org.tizen.emulator.manager.platform.ProfileList;
import org.tizen.emulator.manager.platform.Skin;
import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.StringResources;
EmulatorVMList.getInstance().storeXML(property);
// Save last created property file.
- File f = new File(newVM.baseImage.getLastCreatedPropertyPath());
- boolean isCreated = true;
- if (!f.exists()) {
- try {
- isCreated = f.createNewFile();
- } catch (IOException e) {
- isCreated = false;
- EMLogger.getLogger().warning(e.getMessage());
+ boolean isCreated = false;
+ File f = null;
+ Profile p = ProfileList.getProfile(newVM.profile);
+ if (p != null) {
+ f = new File(p.getLastCreatedPropertyPath());
+ if (!f.exists()) {
+ try {
+ isCreated = f.createNewFile();
+ } catch (IOException e) {
+ isCreated = false;
+ EMLogger.getLogger().warning(e.getMessage());
+ }
+ } else {
+ isCreated = true;
}
}
if (isCreated) {
import java.io.File;
+import org.tizen.emulator.manager.platform.BaseImage;
import org.tizen.emulator.manager.plugin.EMPlugin;
import org.tizen.emulator.manager.plugin.ExtensionItem;
import org.tizen.emulator.manager.plugin.PluginStringResources;
return profile + "-" + version;
}
+ public boolean compareImage(BaseImage image) {
+ // profile, version, base(image name), path
+ if (!image.getProfile().equals(getImageProfile())) {
+ return false;
+ }
+ if (!image.getVersion().equals(getImageVersion())) {
+ return false;
+ }
+ if (!image.getName().equals(getBaseImageName())) {
+ return false;
+ }
+ if (!image.getPath().equals(getBaseImagePath())) {
+ return false;
+ }
+
+ return true;
+ }
+
public EmulatorConfiguration getConfiguration() {
return configuration;
}