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;
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);
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() {
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;
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());
BaseImage image = CustomBaseImageWorker.createCustomBaseImage(value);
if (image == null) {
// TODO
+ MessageBox.openMessageBox("Failed to create base image");
return;
}
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;
}
}
}
+ // 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() {