Base Image: modify delete function
authorjihye424.kim <jihye424.kim@samsung.com>
Mon, 2 Nov 2015 07:33:55 +0000 (16:33 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Mon, 2 Nov 2015 08:24:53 +0000 (17:24 +0900)
- can not delete base image object if vm using base image exist
- can not delete base image file if other base image using base image file exist
- add error font color to table

Change-Id: I55c88ddcf22a585b81bc63d1841032644552e393
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/platform/baseimage/CustomBaseImageWorker.java
src/org/tizen/emulator/manager/renewal/resources/ColorResources.java
src/org/tizen/emulator/manager/renewal/resources/FontResources.java
src/org/tizen/emulator/manager/ui/renewal/dialog/DeleteMessageBox.java
src/org/tizen/emulator/manager/ui/renewal/dialoghandler/BaseImageDialogHandler.java
src/org/tizen/emulator/manager/ui/renewal/tableviewer/BaseImageTableViewer.java
src/org/tizen/emulator/manager/ui/table/TableItem.java

index 4b0896c..eccd3f9 100644 (file)
@@ -98,11 +98,16 @@ public class CustomBaseImageWorker {
                if (result && needDeleteFile) {
                        File file = new File(image.getPath());
                        file.delete();
+
+                       // can not delete base image file if other base image refer this file
+                       // so, this statement does not need
+                       /*
                        for (BaseImage i : CustomBaseImageLoader.getCustomBsaeImageList(false)) {
                                if (i .getPath().equals(file.getPath())) {
                                        i .setFilePathExist(false);
                                }
                        }
+                       */
                }
 
                return result;
index c0f3c20..01b77cd 100644 (file)
@@ -69,6 +69,9 @@ public enum ColorResources {
        MODIFY_ITEM_TITLE(41, 41, 41),
        MODIFY_ITEM_LINE(208, 212, 215),
 
+       ERROR_TABLE_ITEM_FONT(200, 200, 200),
+       ERROR_SELECTED_TABLE_ITEM_FONT(150, 150, 150),
+
        DEFAULT_FONT(41, 41, 41),
 
        // TODO I guess .. little brighter than MESSAGE_BOX_CONTENTS_FONT
index 3b8000a..d6dd062 100644 (file)
@@ -44,8 +44,8 @@ public enum FontResources {
 
        TABLE_VIEWER_LINK_MENU("link_menu_font", resizeDefaultFont(9)),
        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_TITLE("msg_box_title", setDefaultFontStyleAndSize(SWT.BOLD, 10)),
+       MESSAGE_BOX_CONTENTS("msg_box_contents", resizeDefaultFont(10)),
        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)),
index 7659133..ec75af2 100644 (file)
@@ -36,17 +36,15 @@ 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.platform.baseimage.CustomBaseImageLoader;
 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;
@@ -56,10 +54,9 @@ public class DeleteMessageBox extends MessageBox {
        public DeleteMessageBox(BaseImage image) {
                super(shell, SWT.CANCEL | SWT.OK, true);
                this.image = image;
+               setTitle("Delete Base Image");
        }
 
-
-
        @Override
        protected void makeContentsBox() {
                scrolledList = new CustomScrolledComposite(dialog, SWT.V_SCROLL | SWT.H_SCROLL);
@@ -68,82 +65,65 @@ public class DeleteMessageBox extends MessageBox {
                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 top = 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 = "";
+               Label label = makeLabel(contentsBox,
+                                       "Are you sure you want to delete base image from the table?");
+               label.setBounds(SPACING, top, CONTENTS_WIDTH, textHeight);
+               top = top + SPACING + textHeight;
 
-                       for (VMProperty prop : image.getEmulatorList()) {
-                               if (!name.isEmpty()) {
-                                       name += ", ";
+               if (image.isFilePathExist()) {
+                       boolean isExist = false;
+                       for (BaseImage i : CustomBaseImageLoader.getCustomBsaeImageList(false)) {
+                               if (i != image && i.getPath().equals(image.getPath())) {
+                                       isExist = true;
+                                       break;
                                }
-                               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());
+                       if (!isExist) {
+                               deleteCheck = new CheckBoxButton(contentsBox, SWT.NONE);
+                               deleteCheck.setSelection(false);
+                               deleteCheck.addListener(SWT.Selection, checkBoxListener);
+                               deleteCheck.setBounds(SPACING, top, checkBoxWidth, checkBoxWidth);
+
+                               label = makeLabel(contentsBox,
+                                               "Delete base image file on disk(cannot be undone)");
+                               label.setFont(FontResources.MESSAGE_BOX_CONTENTS_BOLD.getFont());
+                               label.setBounds(SPACING + checkBoxWidth + 5, top, CONTENTS_WIDTH, textHeight);
+
+                               top = top + SPACING + textHeight;
+                       }
+               } else {
+                       label = makeLabel(contentsBox, "Base image file has already been deleted.");
                        label.setFont(FontResources.MESSAGE_BOX_CONTENTS_BOLD.getFont());
-                       label.setBounds(SPACING, spacing, CONTENTS_WIDTH, textHeight * 2);
-                       spacing = spacing + SPACING + textHeight * 2;
+                       label.setBounds(SPACING, top, CONTENTS_WIDTH, textHeight);
 
+                       top = top + SPACING + textHeight;
                }
 
-               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);
+               String msg = "Base image file loaction:"
+                               + StringResources.NEW_LINE
+                               + "  " + image.getPath();
 
-                       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);
+               label = makeLabel(contentsBox, msg);
+               label.setBounds(SPACING, top, CONTENTS_WIDTH, textHeight * 3);
+               top = top + textHeight * 3;
 
-                       spacing = spacing + SPACING + textHeight;
-               }
+               contentsWidth = CONTENTS_WIDTH;
+               contentsHeight = top;
 
-               label = new Label(contentsBox, SWT.WRAP);
-               label.setText("Base image loaction:"
-                               + StringResources.NEW_LINE
-                               + "  " + image.getPath());
+               contentsBox.setBounds(0, 0, contentsWidth, contentsHeight);
+       }
+
+       private Label makeLabel(Composite comp, String msg) {
+               Label label = new Label(comp, SWT.WRAP);
+               label.setText(msg);
                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);
+               return label;
        }
 
        private Listener checkBoxListener = new Listener() {
index 1db97a1..034e904 100644 (file)
@@ -70,6 +70,7 @@ public class BaseImageDialogHandler {
                } else {
                        value = openDialog("Modify Base Image", DIALOG_MODE.MODIFY, value);
                }
+
                return value;
        }
 
index c144c99..2f9d495 100644 (file)
@@ -38,6 +38,7 @@ import org.eclipse.swt.events.KeyAdapter;
 import org.eclipse.swt.events.KeyEvent;
 import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Image;
 import org.eclipse.swt.layout.FormAttachment;
 import org.eclipse.swt.layout.FormData;
@@ -293,11 +294,23 @@ public class BaseImageTableViewer extends AbstractTableViewer {
                setTableItemProperty(item, image);
        }
 
+       private Color backupTableItemForeground;
+       private Color backupTableItemSelectedForeground;
        private void setTableItemProperty(TableItem item, BaseImage image) {
                if (!image.isFilePathExist()) {
+                       if (backupTableItemForeground == null) {
+                               backupTableItemForeground = item.getForeground();
+                       }
+                       if (backupTableItemSelectedForeground == null) {
+                               backupTableItemSelectedForeground = item.getSelectedForground();
+                       }
                        item.setImage(0, ImageResources.ICON_STATE_ERROR.getImage());
+                       item.setForeground(ColorResources.ERROR_TABLE_ITEM_FONT.getColor());
+                       item.setSelectedForeground(ColorResources.ERROR_SELECTED_TABLE_ITEM_FONT.getColor());
                } else if (item.getImage(0) != null){
                        item.setImage(0, null);
+                       item.setForeground(backupTableItemForeground);
+                       item.setSelectedForeground(backupTableItemSelectedForeground);
                }
 
                item.setText(2, image.getName());
@@ -555,6 +568,7 @@ public class BaseImageTableViewer extends AbstractTableViewer {
                        BaseImage image = CustomBaseImageWorker.createCustomBaseImage(value);
                        if (image == null) {
                                // TODO
+                               MessageBox.openMessageBox("Failed to create base image");
                                return;
                        }
 
@@ -594,41 +608,48 @@ public class BaseImageTableViewer extends AbstractTableViewer {
                        return;
                }
 
-               // check running emulator
+               // emulator using this base image exist
                if (!image.isEemulatorListEmpty()) {
                        String name = "";
+                       boolean isSingular = true;
                        for (VMProperty prop : image.getEmulatorList()) {
-                               if (prop.isRunning()) {
-                                       if (!name.isEmpty()) {
-                                               name += ", ";
-                                       }
-                                       name += prop.getName();
+                               if (!name.isEmpty()) {
+                                       name += ", ";
+                                       isSingular = false;
                                }
+                               name += prop.getName();
                        }
-                       // if there is running emulator
+
                        if (!name.isEmpty()) {
                                String message = "Can not delete base image"
                                                + StringResources.NEW_LINE
-                                               + "because emulator using this base image is running status."
+                                               + (isSingular
+                                               ? "because emulator using this base image is exist."
+                                               : "because emulators using this base image are exist.")
                                                + StringResources.NEW_LINE + StringResources.NEW_LINE
-                                               + "Try again after emualtor has been terminated."
-                                               + StringResources.NEW_LINE
-                                               + "Running Emulator:"
+                                               + (isSingular
+                                               ? "Try again after emualtor has been deleted."
+                                               : "Try again after emualtors have been deleted.")
                                                + StringResources.NEW_LINE
-                                               + "  " + name;
+                                               + "Emulator: " + name
+                                               + StringResources.NEW_LINE;
                                MessageBox.openMessageBox(message);
                                return;
                        }
                }
 
+               // emulator using this base image does not exist
                DeleteMessageBox msgBox = new DeleteMessageBox(image);
                int response = msgBox.open();
                if (response != SWT.OK) {
                        return;
                }
 
+               // delete base image object and delete configure from configuration file
+               // delete base image file from disk (if select check box)
                if (!image.getWorker().deleteBaseImageConfiguration(msgBox.needDeleteFile())) {
-                       //TODO
+                       // TODO
+                       MessageBox.openMessageBox("Failed to delete base image");
                        return;
                }
 
@@ -642,10 +663,14 @@ public class BaseImageTableViewer extends AbstractTableViewer {
                        }
                }
 
+               // can not delete base image file if other base image refer this file
+               // so, this statement does not need
                // setting table item property
+               /*
                for (TableItem i : table.getItems()) {
                        setTableItemProperty(i, (BaseImage)i.getData());
                }
+               */
        }
 
        private void tableSelected() {
index 5d6dd57..31e8251 100644 (file)
@@ -304,6 +304,18 @@ public class TableItem extends Canvas {
                }
        }
 
+       public void setSelectedForeground(Color color) {
+               checkWidget();
+               if (color != null && color.isDisposed()) {
+                       SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+               }
+
+               if (!equals(selectedForeground, color)) {
+                       selectedForeground = color;
+                       parent.redraw();
+               }
+       }
+
        @Override
        public Color getForeground() {
                checkWidget();