From b77466ce5a1024e78f10178859875a992960c0f5 Mon Sep 17 00:00:00 2001 From: "jihye424.kim" Date: Sun, 25 Oct 2015 10:38:39 +0900 Subject: [PATCH] BaseImage: make base image create dialog - you can make custom base image using 'BaseImageCreateDialog' Change-Id: Ieb89701bd013a5f2326e466ce841e6d68e08bd3d Signed-off-by: jihye424.kim --- .../ui/renewal/dialog/BaseImageCreateDialog.java | 61 ++++++++++++++ .../dialoghandler/BaseImageDialogHandler.java | 72 +++++++++++++++++ .../ui/renewal/item/modify/comp/PropertyValue.java | 54 ++++++++++++- .../renewal/tableviewer/BaseImageTableViewer.java | 92 ++++++++++++++++++++-- 4 files changed, 270 insertions(+), 9 deletions(-) create mode 100644 src/org/tizen/emulator/manager/ui/renewal/dialog/BaseImageCreateDialog.java create mode 100644 src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialog/BaseImageCreateDialog.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/BaseImageCreateDialog.java new file mode 100644 index 0000000..a6c26a9 --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/dialog/BaseImageCreateDialog.java @@ -0,0 +1,61 @@ +/* + * 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.dialog; + +import java.util.List; + +import org.eclipse.swt.widgets.Shell; +import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageValue; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ModifyDialogItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.comp.PropertyValue; + +public class BaseImageCreateDialog extends ModifyDialog { + private final static String TITLE = "New Base Image"; + public final static int WIDTH = 484; + private final static int HEIGHT = 305; + + public BaseImageCreateDialog(Shell parent) { + super(parent, TITLE, WIDTH, HEIGHT); + } + + public void create(CustomBaseImageValue imageValue, List itemList) { + // create title, buttons + // init body + super.create(new PropertyValue(imageValue), itemList); + } + + @Override + public void changeItemList(String profile) { + for (ModifyDialogItem item : itemList) { + item.changeItemValue(propertyValue); + } + } +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java b/src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java new file mode 100644 index 0000000..c7ae68a --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java @@ -0,0 +1,72 @@ +/* + * 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.dialoghandler; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +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.common.ModifyDialogItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.NameItem; +import org.tizen.emulator.manager.ui.renewal.item.modify.common.ProfileItem; + +public class BaseImageDialogHandler { + public static CustomBaseImageValue create() { + BaseImageCreateDialog dialog + = new BaseImageCreateDialog(MainDialog.getShell()); + + dialog.setDialogMode(DIALOG_MODE.CREATE); + CustomBaseImageValue value = new CustomBaseImageValue(); + dialog.create(value, getDefaultItemList() ); + + if (dialog.open() == SWT.OK) { + dialog.saveDataInto(value); + return value; + } + + return null; + } + + public static List getDefaultItemList() { + List itemList = new ArrayList(); + + itemList.add(new NameItem("name", "Image Name")); + itemList.add(new ProfileItem()); + //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/comp/PropertyValue.java b/src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java index 90d3382..e13335b 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java +++ b/src/org/tizen/emulator/manager/ui/renewal/item/modify/comp/PropertyValue.java @@ -41,7 +41,9 @@ import org.tizen.emulator.manager.devices.DeviceTemplate; import org.tizen.emulator.manager.devices.DeviceTemplateValue; import org.tizen.emulator.manager.devices.SubDevice; import org.tizen.emulator.manager.devices.SubDeviceItem; +import org.tizen.emulator.manager.platform.Platform; import org.tizen.emulator.manager.platform.Skin; +import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageValue; import org.tizen.emulator.manager.vms.RESOLUTION; import org.tizen.emulator.manager.vms.SKIN_SHAPE; import org.tizen.emulator.manager.vms.VMPropertyValue; @@ -55,14 +57,20 @@ public class PropertyValue { private static String VALUE_OFF = "off"; - // VMPropertyValue or DeviceTemplateValue + // VMPropertyValue or DeviceTemplateValue or CustomBaseImageValue private VMPropertyValue vmValue; private DeviceTemplateValue templateValue; + private CustomBaseImageValue baseImageValue; public Object getValue() { if (vmValue != null) { return vmValue; } + + if (baseImageValue != null) { + return baseImageValue; + } + return templateValue; } @@ -72,6 +80,10 @@ public class PropertyValue { } else if (value instanceof DeviceTemplateValue) { templateValue = (DeviceTemplateValue)value; + + } else if (value instanceof CustomBaseImageValue) { + baseImageValue = (CustomBaseImageValue)value; + } } @@ -80,11 +92,14 @@ public class PropertyValue { return vmValue != null; } - public boolean isTemplateValue() { return templateValue != null; } + public boolean isBaseImageValue() { + return baseImageValue != null; + } + public String getFileSharingPath() { if (isVMValue()) { return vmValue.fileSharePath; @@ -119,9 +134,10 @@ public class PropertyValue { public String getName() { if (isVMValue()) { return vmValue.vmsName; - } else if (isTemplateValue()){ return templateValue.getName(); + } else if (isBaseImageValue()) { + return baseImageValue.getName(); } return ""; @@ -131,9 +147,10 @@ public class PropertyValue { public void setName(String name) { if (isVMValue()) { vmValue.vmsName = name; - } else if (isTemplateValue()) { templateValue.setName(name); + } else if (isBaseImageValue()) { + baseImageValue.setName(name); } } @@ -151,6 +168,8 @@ public class PropertyValue { return vmValue.baseImage.getProfile(); } else if (isTemplateValue()) { return templateValue.getProfile(); + } else if (isBaseImageValue()) { + return baseImageValue.getProfile(); } return ""; } @@ -161,6 +180,8 @@ public class PropertyValue { // do nothing } else if (isTemplateValue()) { templateValue.setProfile(profile); + } else if (isBaseImageValue()) { + baseImageValue.setProfile(profile); } } @@ -415,6 +436,31 @@ public class PropertyValue { return false; } + public String getImageFilePath() { + if (isBaseImageValue()) { + return baseImageValue.getFilePath(); + } + return ""; + } + + public void setImageFilePath(String path) { + if (isBaseImageValue()) { + baseImageValue.setFilePath(path); + } + } + + public void setPlatform(Platform platform) { + if (isBaseImageValue()) { + baseImageValue.setPlatform(platform); + baseImageValue.setPlatformName(platform.getName()); + } + } + + public void setDescription(String message) { + if (isBaseImageValue()) { + baseImageValue.setDescription(message); + } + } private static boolean checkOn(String onOffVal) { if (onOffVal.equals(VALUE_ON)) { diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/BaseImageTableViewer.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/BaseImageTableViewer.java index 7a3cbd2..b931b94 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/BaseImageTableViewer.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/BaseImageTableViewer.java @@ -49,11 +49,14 @@ import org.tizen.emulator.manager.EmulatorManager; import org.tizen.emulator.manager.platform.BaseImage; import org.tizen.emulator.manager.platform.Profile; import org.tizen.emulator.manager.platform.ProfileList; +import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageValue; +import org.tizen.emulator.manager.platform.baseimage.CustomBaseImageWorker; import org.tizen.emulator.manager.renewal.resources.ColorResources; import org.tizen.emulator.manager.renewal.resources.FontResources; import org.tizen.emulator.manager.renewal.resources.ImageResources; import org.tizen.emulator.manager.renewal.resources.PatchImageResources; import org.tizen.emulator.manager.ui.renewal.MainDialog; +import org.tizen.emulator.manager.ui.renewal.dialoghandler.BaseImageDialogHandler; import org.tizen.emulator.manager.ui.renewal.widgets.Hyperlink; import org.tizen.emulator.manager.ui.renewal.widgets.ImageButton; import org.tizen.emulator.manager.ui.renewal.widgets.NinePatchResourceInfo; @@ -68,6 +71,7 @@ public class BaseImageTableViewer extends AbstractTableViewer { private static final int BUTTON_HEIGHT = 26; private Hyperlink templateList; + private ImageButton refreshButton; private Composite comp; private boolean isTableInitialize = false; @@ -77,12 +81,17 @@ public class BaseImageTableViewer extends AbstractTableViewer { private ImageButton backButton; private ImageButton createButton; + private ImageButton modifyButton; private ImageButton deleteButton; public BaseImageTableViewer(Shell shell, String key) { super(shell, key); } + public void refreshBaseImageList() { + // TODO + } + @Override void setTitleImage() { setTtileBackgroundImage(ImageResources.BASEIMAGE_LIST_TITLE_IMAGE.getImage()); @@ -113,7 +122,25 @@ public class BaseImageTableViewer extends AbstractTableViewer { @Override void setIconMenu() { - // TODO + refreshButton = new ImageButton(getTopComp(), SWT.PUSH); + refreshButton.setToolTipText("reloading base image list"); + refreshButton.setImages(ImageResources.BUTTON_REFRESH_NML.getImage(), + ImageResources.BUTTON_REFRESH_HOVER.getImage(), + ImageResources.BUTTON_REFRESH_HOVER.getImage(), + ImageResources.BUTTON_REFRESH_HOVER.getImage()); + + refreshButton.addSelectionListener(new SelectionListener() { + @Override + public void widgetDefaultSelected(SelectionEvent arg0) { + } + + @Override + public void widgetSelected(SelectionEvent arg0) { + refreshBaseImageList(); + } + }); + + addIconMenu(refreshButton); } @Override @@ -171,7 +198,7 @@ public class BaseImageTableViewer extends AbstractTableViewer { } TableItem item = table.getSelection()[0]; - deleteBaseImage(item, true); + deleteBaseImage(item); } }); @@ -261,6 +288,9 @@ public class BaseImageTableViewer extends AbstractTableViewer { } private void setTableItemProperty(TableItem item, BaseImage image) { + if (!image.isFilePathExist()) { + item.setImage(0, ImageResources.ICON_STATE_ERROR.getImage()); + } item.setText(2, image.getName()); item.setText(3, image.getPlatformName()); item.setText(4, image.getPathName()); @@ -292,6 +322,26 @@ public class BaseImageTableViewer extends AbstractTableViewer { } }); + modifyButton = new ImageButton(comp, SWT.PUSH); + modifyButton.setToolTipText("modify custom base image"); + modifyButton.setBackground(null); + modifyButton.setImages(ImageResources.BUTTON_MODIFY_NORMAL.getImage(), + ImageResources.BUTTON_MODIFY_HOVER.getImage(), + ImageResources.BUTTON_MODIFY_HOVER.getImage(), + ImageResources.BUTTON_MODIFY_DISABLE.getImage()); + modifyButton.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + if (event.type == SWT.Selection) { + TableItem[] items = table.getSelection(); + if (items != null && items.length > 0) { + modifyBaseImage(items[0]); + } + + } + } + }); + deleteButton = new ImageButton(comp, SWT.PUSH); deleteButton.setToolTipText("delete base image"); deleteButton.setBackground(null); @@ -305,12 +355,13 @@ public class BaseImageTableViewer extends AbstractTableViewer { if (event.type == SWT.Selection) { TableItem[] items = table.getSelection(); if (items != null && items.length > 0) { - deleteBaseImage(items[0], false); + deleteBaseImage(items[0]); } } } }); + modifyButton.setEnabled(false); deleteButton.setEnabled(false); } @@ -400,10 +451,32 @@ public class BaseImageTableViewer extends AbstractTableViewer { }; private void createBaseImage() { - // TODO + CustomBaseImageValue value = BaseImageDialogHandler.create(); + if (value != null) { + BaseImage image = CustomBaseImageWorker.createCustomBaseImage(value); + if (image == null) { + // TODO + return; + } + + ProfileButton pButton = null; + for (ProfileButton button : profileButtonList) { + if (button.getProfileName().equals(value.getProfile())) { + pButton = button; + } + } + + if (pButton != null) { + addTableItem(pButton, image, 0); + } + } } - private void deleteBaseImage(TableItem item, boolean needCheck) { + private void modifyBaseImage(TableItem item) { + //TODO + } + + private void deleteBaseImage(TableItem item) { // TODO } @@ -414,8 +487,10 @@ public class BaseImageTableViewer extends AbstractTableViewer { BaseImage image = (BaseImage)table.getSelection()[0].getData(); if (image.isStandard()) { deleteButton.setEnabled(false); + modifyButton.setEnabled(false); } else { deleteButton.setEnabled(true); + modifyButton.setEnabled(true); } } } @@ -457,6 +532,13 @@ public class BaseImageTableViewer extends AbstractTableViewer { workerButtonData.top = new FormAttachment(0, 13); workerButtonData.width = BUTTON_WIDTH; workerButtonData.height = BUTTON_HEIGHT; + modifyButton.setLayoutData(workerButtonData); + + workerButtonData = new FormData(); + workerButtonData.right = new FormAttachment(modifyButton, -5); + workerButtonData.top = new FormAttachment(0, 13); + workerButtonData.width = BUTTON_WIDTH; + workerButtonData.height = BUTTON_HEIGHT; createButton.setLayoutData(workerButtonData); workerButtonData = new FormData(); -- 2.7.4