From: jihye424.kim Date: Sun, 25 Oct 2015 02:23:16 +0000 (+0900) Subject: BaseImageDialog: add 'BaseImageFile' and 'Platform' item X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36a1227281d2ae93365e41261b698f229e806f4d;p=sdk%2Femulator%2Femulator-manager.git BaseImageDialog: add 'BaseImageFile' and 'Platform' item - base iamge file item -- select custom base imgae file from file dialog -- if name item is empty, base image file name will be set to name item - platform item -- select platform among platform list of selected profile -- this value determine emulator version Change-Id: Iead56d6e812bac23f761e3d4fcdd913d72492e2f Signed-off-by: jihye424.kim --- diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java b/src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java index c7ae68a..cea5511 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java +++ b/src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java @@ -38,6 +38,8 @@ import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageValue; import org.tizen.emulator.manager.ui.renewal.MainDialog; import org.tizen.emulator.manager.ui.renewal.dialog.BaseImageCreateDialog; import org.tizen.emulator.manager.ui.renewal.dialog.DIALOG_MODE; +import org.tizen.emulator.manager.ui.renewal.item.modify.baseimage.BaseImageFileItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.baseimage.PlatformItem; 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.ProfileItem; @@ -64,8 +66,8 @@ public class BaseImageDialogHandler { itemList.add(new NameItem("name", "Image Name")); itemList.add(new ProfileItem()); - //itemList.add(new PlatformItem()); - //itemList.add(new BaseImageFileItem()); + itemList.add(new PlatformItem()); + itemList.add(new BaseImageFileItem()); //itemList.add(new DescriptionItem()); return itemList; } diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/BaseImageFileItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/BaseImageFileItem.java new file mode 100644 index 0000000..a042ef6 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/BaseImageFileItem.java @@ -0,0 +1,129 @@ +/* + * 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.item.modify.baseimage; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.tizen.emulator.manager.renewal.resources.ImageResources; +import org.tizen.emulator.manager.resources.StringResources; +import org.tizen.emulator.manager.ui.renewal.MainDialog; +import org.tizen.emulator.manager.ui.renewal.dialog.MessageBox; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.FileDialogItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ModifyDialogItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue; +import org.tizen.emulator.manager.vms.VMProperty.Architecture; +import org.tizen.emulator.manager.vms.helper.HelperClass; + +public class BaseImageFileItem extends FileDialogItem { + private static final String NAME="imagefile"; + private static final String TITLE="Image File"; + private final int TEXT_BOX_WIDTH = 233; + + private String imageFilePath; + // TODO + //private File imageFile; + + private FileDialog fd; + + public BaseImageFileItem() { + super(NAME, TITLE); + } + @Override + public void create(Composite parent) { + create(parent, getTitle(), ImageResources.ICON_TITLE_IMAGE_FILE, TEXT_BOX_WIDTH); + if (imageFilePath == null || imageFilePath.isEmpty()) { + setTextBox("(select base imaeg path...)"); + } else { + setTextBox(imageFilePath); + } + } + + @Override + public void setInitialValue(PropertyValue value) { + imageFilePath = value.getImageFilePath(); + } + + @Override + public void setValue(PropertyValue value) { + value.setImageFilePath(imageFilePath); + } + + @Override + public ModifyDialogItem cloneItem() { + return new BaseImageFileItem(); + } + + @Override + protected String clickFileDialogButon() { + if (fd == null) { + fd = new FileDialog(MainDialog.getShell(), SWT.OPEN); + fd.setText("Select Base Image"); + String[] filter = null; + String[] filterName = null; + filter = new String[] { // "*.x86;*.i386;*.x86_64" + "*." + Architecture.x86.toString() + + ";*." + Architecture.i386.toString() + + ";*." + Architecture.x86_64.toString() + }; + fd.setFilterExtensions(filter); + filterName = new String[] { + "Disk Image Files (" + + "*." + Architecture.x86.toString() + + ", *." + Architecture.i386.toString() + + ", *." + Architecture.x86_64.toString() + + ")" + }; + fd.setFilterNames(filterName); + } + + String path = fd.open(); + if (path != null) { + if (!HelperClass.isPathAvaliable(path)) { + MessageBox + .openMessageBox("This base image not ready yet." + + StringResources.NEW_LINE + + "Please, select again in a few seconds."); + return null; + } + // TODO: need to check file format + return path; + } + return null; + } + + @Override + public void fileSelected() { + imageFilePath = filePath; + getDialog().getPropertyValue().setImageFilePath(imageFilePath); + getDialog().changeItemList(""); + } +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/PlatformItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/PlatformItem.java new file mode 100644 index 0000000..4d01870 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/PlatformItem.java @@ -0,0 +1,125 @@ + +/* + * 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.item.modify.baseimage; + +import org.eclipse.swt.widgets.Composite; +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.renewal.resources.ImageResources; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ComboItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ModifyDialogItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.comp.ModifyItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue; +import org.tizen.emulator.manager.ui.renewal.widgets.ComboBox; + +public class PlatformItem extends ComboItem { + private static final String TITLE = "Platform"; + private static final String NAME = "platform"; + private final int COMBO_WIDTH = 200; + + private Platform selectedPlatform; + private Profile profile; + + public PlatformItem() { + super(NAME, TITLE); + item = new ModifyItem(); + } + + @Override + public void create(Composite parent) { + item.init(parent); + item.setItemTitle(createIconTitle(item, ImageResources.ICON_TITLE_VERSION)); + item.create(); + + createCombo(item, COMBO_WIDTH); + initPlatformCombo(); + } + + private void initPlatformCombo() { + if (profile == null) { + return; + } + + if (comboBox == null) { + return; + } + + this.comboBox.clear(); + + for (Platform platform : profile.getPlatformList()) { + addComboItem(platform.getName(), platform); + } + + if (!comboBox.getItemList().isEmpty()) { + selectComboItem(0); + comboSelected(); + } + } + + private void comboSelected() { + selectedPlatform = (Platform)getSelectedData(); + // TODO + getDialog().checkValid(); + } + + @Override + public void setInitialValue(PropertyValue value) { + // TODO + } + + @Override + public void itemSelected(ComboBox comboBox) { + // This is called when combo item is selected + comboSelected(); + } + + @Override + public void setValue(PropertyValue value) { + value.setPlatform(selectedPlatform); + } + + @Override + public ModifyDialogItem cloneItem() { + return new PlatformItem(); + } + + @Override + public void changeItemValue(PropertyValue value) { + if (profile != null && profile.getName().equals(value.getProfile())) { + return; + } + + profile = ProfileList.getProfile(value.getProfile()); + initPlatformCombo(); + } +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/FileDialogItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/FileDialogItem.java index a2334ad..bbdfc2e 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/FileDialogItem.java +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/FileDialogItem.java @@ -125,12 +125,7 @@ public abstract class FileDialogItem extends ModifyDialogItem { @Override public void handleEvent(Event event) { if (event.type == SWT.Selection) { - if (dd == null) { - dd = new DirectoryDialog( - getDialog().getShell(), SWT.OPEN); - dd.setText("Select directory"); - } - String path = dd.open(); + String path = clickFileDialogButon(); if (path != null) { filePath = path; setTextBox(filePath); @@ -141,5 +136,15 @@ public abstract class FileDialogItem extends ModifyDialogItem { }); } + protected String clickFileDialogButon() { + if (dd == null) { + dd = new DirectoryDialog( + getDialog().getShell(), SWT.OPEN); + dd.setText("Select directory"); + } + + return dd.open(); + } + public abstract void fileSelected(); } diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/NameItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/NameItem.java index 13392dc..be1cc62 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/NameItem.java +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/NameItem.java @@ -30,6 +30,8 @@ package org.tizen.emulator.manager.ui.renewal.item.modify.common; +import java.io.File; + import org.eclipse.swt.widgets.Composite; import org.tizen.emulator.manager.logging.EMLogger; import org.tizen.emulator.manager.renewal.resources.ImageResources; @@ -103,11 +105,15 @@ public class NameItem extends TextInputBoxItem { } String msg = ""; - if (getDialog().getPropertyValue().isTemplateValue()) { + PropertyValue property = getDialog().getPropertyValue(); + if (property.isTemplateValue()) { msg = checkTemplateName(value); - - } else { + } else if (property.isVMValue()) { msg = checkVMName(value); + } else if (property.isBaseImageValue()) { + msg = checkBaseImageName(value); + } else { + // TODO } if (!msg.isEmpty()) { @@ -169,4 +175,30 @@ public class NameItem extends TextInputBoxItem { return errorMsg; } + public static String checkBaseImageName(String newName) { + // TODO + return ""; + } + + @Override + public void changeItemValue(PropertyValue property) { + if (!property.isBaseImageValue()) { + return; + } + if (value != null && !value.isEmpty()) { + return; + } + + String path = property.getImageFilePath(); + if (path != null && !path.isEmpty()) { + String fileName = path.substring(path + .lastIndexOf(File.separator) + 1, path.length()); + if (fileName.contains(".")) { + fileName = fileName.substring(0, fileName.lastIndexOf(".")); + } + value = fileName; + textInputBox.setText(value); + textModified(); + } + } } diff --git a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/ProfileItem.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/ProfileItem.java index 03413e6..7469b54 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/ProfileItem.java +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/common/ProfileItem.java @@ -233,9 +233,7 @@ public class ProfileItem extends ModifyDialogItem { public void handleEvent(Event e) { if (e.type == SWT.Selection) { if (!currentProfile.equals(profile)) { -// System.out.println("profile changed : " + profile); - currentProfile = profile; - getDialog().changeItemList(profile); + changedProfile(profile); } } } @@ -246,7 +244,7 @@ public class ProfileItem extends ModifyDialogItem { private void selectButton() { // TODO default - buttonMap.get(MOBILE).selectRadio(); + //buttonMap.get(MOBILE).selectRadio(); if (currentProfile.isEmpty()) { currentProfile = MOBILE; } @@ -254,10 +252,17 @@ public class ProfileItem extends ModifyDialogItem { for (String profile : buttonMap.keySet()) { if (profile.equals(currentProfile)) { buttonMap.get(profile).selectRadio(); + changedProfile(profile); } } } + private void changedProfile(String profile) { + currentProfile = profile; + getDialog().getPropertyValue().setProfile(profile); + getDialog().changeItemList(profile); + } + @Override public void setValue(PropertyValue value) { value.setProfile(currentProfile);