Dialog: make new message box for delete base image
authorjihye424.kim <jihye424.kim@samsung.com>
Thu, 29 Oct 2015 06:45:38 +0000 (15:45 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 30 Oct 2015 06:32:59 +0000 (15:32 +0900)
- you can delete base image file when delete base image object

Change-Id: I102d591f37fd70d53ccedbd5bde5b77748bfff30
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/renewal/resources/FontResources.java
src/org/tizen/emulator/manager/ui/renewal/dialog/DeleteMessageBox.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/renewal/dialog/MessageBox.java

index d97a4ab..170c5a0 100644 (file)
@@ -46,7 +46,7 @@ public enum FontResources {
        COMBO_BUTTON("combo_button_font", resizeDefaultFont(9)),
        MESSAGE_BOX_TITLE("msg_box_title", resizeDefaultFont(10)),
        MESSAGE_BOX_CONTENTS("msg_box_contents", resizeDefaultFont(9)),
-
+       MESSAGE_BOX_CONTENTS_BOLD("msg_box_contetns_bold", setDefaultFontStyleAndSize(SWT.BOLD, 9)),
        DEFAULT_FONT_10("default_font_10", resizeDefaultFont(10)),
        DEFAULT_FONT_9("default_font_9", resizeDefaultFont(9)),
        DEFAULT_FONT_8("default_font_8", resizeDefaultFont(8));
diff --git a/src/org/tizen/emulator/manager/ui/renewal/dialog/DeleteMessageBox.java b/src/org/tizen/emulator/manager/ui/renewal/dialog/DeleteMessageBox.java
new file mode 100644 (file)
index 0000000..7659133
--- /dev/null
@@ -0,0 +1,169 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@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.dialog;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Listener;
+import org.tizen.emulator.manager.platform.BaseImage;
+import org.tizen.emulator.manager.renewal.resources.ColorResources;
+import org.tizen.emulator.manager.renewal.resources.FontResources;
+import org.tizen.emulator.manager.resources.StringResources;
+import org.tizen.emulator.manager.ui.renewal.widgets.CheckBoxButton;
+import org.tizen.emulator.manager.ui.renewal.widgets.CustomScrolledComposite;
+import org.tizen.emulator.manager.vms.VMProperty;
+
+public class DeleteMessageBox extends MessageBox {
+       private final int CONTENTS_WIDTH = 450;
+       private final int CONTENTS_HEIGHT = 150;
+       private final int ADD_EMULATORS_HEIGHT = 50;
+       private final int SPACING = 15;
+
+       private BaseImage image;
+       private boolean needDeleteFile = false;
+       private CheckBoxButton deleteCheck;
+
+       public DeleteMessageBox(BaseImage image) {
+               super(shell, SWT.CANCEL | SWT.OK, true);
+               this.image = image;
+       }
+
+
+
+       @Override
+       protected void makeContentsBox() {
+               scrolledList = new CustomScrolledComposite(dialog, SWT.V_SCROLL | SWT.H_SCROLL);
+               Composite contentsBox = new Composite(scrolledList, SWT.NONE);
+               scrolledList.setContent(contentsBox);
+               scrolledList.setBackground(ColorResources.MESSAGE_BOX_CONTENTS_BG.getColor());
+               contentsBox.setBackground(ColorResources.MESSAGE_BOX_CONTENTS_BG.getColor());
+
+               // TOOD
+               contentsWidth = CONTENTS_WIDTH;
+               contentsHeight = CONTENTS_HEIGHT;
+               if (!image.isEemulatorListEmpty()) {
+                       contentsHeight += ADD_EMULATORS_HEIGHT;
+               }
+               contentsBox.setBounds(0, 0, contentsWidth, contentsHeight);
+
+               int spacing = SPACING;
+               int textHeight = 20;
+               int checkBoxWidth = 15;
+
+               Label label = new Label(contentsBox, SWT.WRAP);
+               label.setText("Are you sure you want to delete base image from the table?");
+               label.setBackground(ColorResources.MESSAGE_BOX_CONTENTS_BG.getColor());
+               label.setForeground(ColorResources.MESSAGE_BOX_CONTENTS_FONT.getColor());
+               label.setFont(FontResources.MESSAGE_BOX_CONTENTS.getFont());
+               label.setBounds(SPACING, spacing, CONTENTS_WIDTH, textHeight);
+               spacing = spacing + SPACING + textHeight;
+
+               if (!image.isEemulatorListEmpty()) {
+                       String name = "";
+
+                       for (VMProperty prop : image.getEmulatorList()) {
+                               if (!name.isEmpty()) {
+                                       name += ", ";
+                               }
+                               name += prop.getName();
+                       }
+                       String message =
+                                       "Emulators using this base image may not work."
+                                       + StringResources.NEW_LINE
+                                       + "Emulator name: " + name;
+                       label = new Label(contentsBox, SWT.WRAP);
+                       label.setText(message);
+                       label.setBackground(ColorResources.MESSAGE_BOX_CONTENTS_BG.getColor());
+                       label.setForeground(ColorResources.MESSAGE_BOX_CONTENTS_FONT.getColor());
+                       label.setFont(FontResources.MESSAGE_BOX_CONTENTS_BOLD.getFont());
+                       label.setBounds(SPACING, spacing, CONTENTS_WIDTH, textHeight * 2);
+                       spacing = spacing + SPACING + textHeight * 2;
+
+               }
+
+               if (image.isFilePathExist()) {
+                       deleteCheck = new CheckBoxButton(contentsBox, SWT.NONE);
+                       deleteCheck.setSelection(false);
+                       deleteCheck.addListener(SWT.Selection, checkBoxListener);
+                       deleteCheck.setBounds(SPACING, spacing, checkBoxWidth, checkBoxWidth);
+
+                       label = new Label(contentsBox, SWT.WRAP);
+                       label.setText("Delete base image file on disk(cannot be undone)");
+                       label.setBackground(ColorResources.MESSAGE_BOX_CONTENTS_BG.getColor());
+                       label.setForeground(ColorResources.MESSAGE_BOX_CONTENTS_FONT.getColor());
+                       label.setFont(FontResources.MESSAGE_BOX_CONTENTS_BOLD.getFont());
+                       label.setBounds(SPACING + 15 + 5, spacing, CONTENTS_WIDTH, textHeight);
+
+                       spacing = spacing + SPACING + textHeight;
+               } else {
+                       label = new Label(contentsBox, SWT.WRAP);
+                       label.setText("Base image file has already been deleted.");
+                       label.setBackground(ColorResources.MESSAGE_BOX_CONTENTS_BG.getColor());
+                       label.setForeground(ColorResources.MESSAGE_BOX_CONTENTS_FONT.getColor());
+                       label.setFont(FontResources.MESSAGE_BOX_CONTENTS_BOLD.getFont());
+                       label.setBounds(SPACING, spacing, CONTENTS_WIDTH, textHeight);
+
+                       spacing = spacing + SPACING + textHeight;
+               }
+
+               label = new Label(contentsBox, SWT.WRAP);
+               label.setText("Base image loaction:"
+                               + StringResources.NEW_LINE
+                               + "  " + image.getPath());
+               label.setBackground(ColorResources.MESSAGE_BOX_CONTENTS_BG.getColor());
+               label.setForeground(ColorResources.MESSAGE_BOX_CONTENTS_FONT.getColor());
+               label.setFont(FontResources.MESSAGE_BOX_CONTENTS.getFont());
+               label.setBounds(SPACING, spacing, contentsWidth, contentsHeight - spacing);
+       }
+
+       private Listener checkBoxListener = new Listener() {
+               @Override
+               public void handleEvent(Event e) {
+                       switch(e.type) {
+                       case SWT.Selection:
+                               needDeleteFile = ((CheckBoxButton)e.widget).isSelection();
+                       default:
+                                       break;
+                       }
+               }
+       };
+
+       @Override
+       public void setMessage(final String message) {
+               // not used
+       }
+
+       public boolean needDeleteFile() {
+               return needDeleteFile;
+       }
+}
index 1b3aa41..4bfcdfa 100644 (file)
@@ -64,7 +64,7 @@ public class MessageBox {
        private final int SPACING = 15;
 
        private Shell parent;
-       private Shell dialog;
+       protected Shell dialog;
        private int width = MIN_WIDTH;
        private int height = MIN_HEIGHT;
 
@@ -77,13 +77,15 @@ public class MessageBox {
        private int returnValue = SWT.OK;
 
        private Label titleLabel = null;
-       private CustomScrolledComposite scrolledList = null;
+       protected CustomScrolledComposite scrolledList = null;
        private StyledText contentsBox = null;
+       protected int contentsWidth = 0;
+       protected int contentsHeight = 0;
 
        private Composite titleComp = null;
 
        // TODO: Icon SWT.ICON_ERROR ...
-       private static final Shell shell;
+       protected static final Shell shell;
        static {
                shell = MainDialog.getShell();
        }
@@ -201,7 +203,7 @@ public class MessageBox {
                DragHandler.set(dialog, null, titleLabel, titleComp);
        }
 
-       private void makeContentsBox() {
+       protected void makeContentsBox() {
                scrolledList = new CustomScrolledComposite(dialog, SWT.V_SCROLL | SWT.H_SCROLL);
                contentsBox = new StyledText(scrolledList, SWT.NONE);
 
@@ -217,6 +219,9 @@ public class MessageBox {
                contentsBox.setRightMargin(SPACING);
                contentsBox.setEnabled(false);
                contentsBox.pack();
+
+               contentsWidth = contentsBox.getSize().x;
+               contentsHeight = contentsBox.getSize().y;
        }
 
        private int buttonCount = 1;
@@ -254,8 +259,8 @@ public class MessageBox {
        private Rectangle computeDialogBounds() {
                Rectangle result = new Rectangle(0, 0, 0, 0);
                Rectangle parentRect = parent.getBounds();
-               width  = Math.max(width, contentsBox.getSize().x + 6); // add scroll bar spacing
-               height = Math.max(height, contentsBox.getSize().y + TITLE_HEIGHT + BOTTOM_HEIGHT + 6);
+               width  = Math.max(width, contentsWidth + 6); // add scroll bar spacing
+               height = Math.max(height, contentsHeight + TITLE_HEIGHT + BOTTOM_HEIGHT + 6);
 
                result.width  = width = Math.min(width, MAX_WIDTH);
                result.height = height = Math.min(height, MAX_HEIGHT);