BaseImageDialog: add 'BaseImageFile' and 'Platform' item
authorjihye424.kim <jihye424.kim@samsung.com>
Sun, 25 Oct 2015 02:23:16 +0000 (11:23 +0900)
committerJiHye Kim <jihye424.kim@samsung.com>
Thu, 29 Oct 2015 02:43:41 +0000 (11:43 +0900)
- 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 <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/BaseImageFileItem.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/renewal/item/modify/baseimage/PlatformItem.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/renewal/item/modify/common/FileDialogItem.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/common/NameItem.java
src/org/tizen/emulator/manager/ui/renewal/item/modify/common/ProfileItem.java

index c7ae68a..cea5511 100644 (file)
@@ -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 (file)
index 0000000..a042ef6
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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 (file)
index 0000000..4d01870
--- /dev/null
@@ -0,0 +1,125 @@
+
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * Minkee Lee <minkee.lee@samsung.com>
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho1206.park@samsung.com>
+ *
+ * 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();
+       }
+}
index a2334ad..bbdfc2e 100644 (file)
@@ -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();
 }
index 13392dc..be1cc62 100644 (file)
@@ -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();
+               }
+       }
 }
index 03413e6..7469b54 100644 (file)
@@ -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);