package org.tizen.emulator.manager.ui;
-import java.io.File;
-import java.util.ArrayList;
-
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.tizen.emulator.manager.EmulatorManager;
import org.tizen.emulator.manager.tool.Launcher;
import org.tizen.emulator.manager.ui.detail.DetailTableView;
import org.tizen.emulator.manager.ui.vmstree.VMsTree;
import org.tizen.emulator.manager.vms.EmulatorVMs;
-import org.tizen.emulator.manager.vms.VMProcess;
import org.tizen.emulator.manager.vms.VMsProperty;
public class MainDialog {
// Create, Modify, Cancel
private Button rightButton;
+ private MenuHandling handling;
private Shell shell;
public MainDialog() {
@Override
public void widgetSelected(SelectionEvent e) {
deleteVirtualMachine();
- detailView.closeDetailView();
- refreshProperties();
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
sashForm.setWeights(new int[] { 100, 0 });
}
+
+ handling = new MenuHandling(shell, vmsTree);
}
public void resetVirtualMachine() {
- ArrayList<VMsProperty> list = vmsTree.getSelectionItem();
- MessageBox msg = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
- msg.setText("Warning");
- msg.setMessage("This virtual machine will be formatting.\nAre you sure to conitnue?");
- int response = msg.open();
- if (response == SWT.OK) {
- VMProcess process = new VMProcess();
- for (VMsProperty property : list) {
- String basePath = property.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue();
- String targetPath = property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
- if (basePath == null || basePath.isEmpty() || targetPath == null || targetPath.isEmpty()) {
- msg = new MessageBox(shell, SWT.ICON_INFORMATION);
- msg.setText("INFO");
- msg.setMessage("Fail reset virtual machine : " + property.getName());
- msg.open();
- return;
- }
-
- if(!process.createBaseImage(basePath, targetPath)) {
- msg = new MessageBox(shell, SWT.ICON_INFORMATION);
- msg.setText("INFO");
- msg.setMessage(process.getErrorMessage());
- msg.open();
- return;
- }
- }
- msg = new MessageBox(shell, SWT.ICON_INFORMATION);
- msg.setText("INFO");
- msg.setMessage("Reset completed!");
- msg.open();
- }
+ handling.resetVirtualMachine();
+ }
+
+ public void cloneVirtualMachine() {
+ handling.cloneVirtualMachine(this);
}
// TOOD : error checking
public void deleteVirtualMachine() {
- ArrayList<VMsProperty> list = vmsTree.getSelectionItem();
- MessageBox msg = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.CANCEL);
- msg.setText("INFO");
- msg.setMessage("Are you sure delete selected virtual machines?");
- int response = msg.open();
- if (response == SWT.OK) {
- for (VMsProperty property : list) {
- String path = EmulatorVMs.getInstance().getVMsBaseDirectory()
- + File.separator + property.getArch().toString()
- + File.separator + property.getName();
- File vtFolder = new File(path);
- if (vtFolder.exists()) {
- for (File dir : vtFolder.listFiles()) {
- if (dir.isFile()) {
- dir.delete();
- } else { // directory
- for (File sub : dir.listFiles()) {
- if (sub.isFile()) {
- sub.delete();
- }
- }
- dir.delete();
- }
- }
- vtFolder.delete();
- }
- }
+ if (handling.deleteVirtualMachine()) {
+ detailView.closeDetailView();
refreshProperties();
- msg = new MessageBox(shell, SWT.ICON_INFORMATION);
- msg.setText("INFO");
- msg.setMessage("Delete completed!");
- msg.open();
}
}
}
public void closeDetailView() {
- if (vmsTree.getSelectionContentCount() > 1) {
+ if (vmsTree.getCountSelectionItem() > 1) {
deleteButton.setEnabled(true);
+ resetButton.setEnabled(true);
} else {
deleteButton.setEnabled(false);
+ resetButton.setEnabled(false);
}
resetButton.setEnabled(false);
detailView.closeDetailView();
--- /dev/null
+package org.tizen.emulator.manager.ui;
+
+import java.io.File;
+import java.util.ArrayList;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.tizen.emulator.manager.EmulatorManager;
+import org.tizen.emulator.manager.ui.ResourceRegistry.ImageName;
+import org.tizen.emulator.manager.ui.detail.VMPropertyView;
+import org.tizen.emulator.manager.ui.vmstree.VMsTree;
+import org.tizen.emulator.manager.vms.EmulatorVMs;
+import org.tizen.emulator.manager.vms.VMCreateHelper;
+import org.tizen.emulator.manager.vms.VMProcess;
+import org.tizen.emulator.manager.vms.VMPropertyValue;
+import org.tizen.emulator.manager.vms.VMsProperty;
+
+public class MenuHandling {
+ private Shell shell;
+ private VMsTree listTable;
+
+ public MenuHandling(Shell shell, VMsTree imageListTable) {
+ this.shell = shell;
+ this.listTable = imageListTable;
+ }
+
+ public void resetVirtualMachine() {
+ if (listTable.getCountSelectionItem() == 1) {
+ if (!checkRunnigVM(listTable.getSelectionItem())) {
+ return;
+ }
+ }
+
+ MessageBox msg = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK | SWT.CANCEL);
+ msg.setText("Warning");
+ msg.setMessage("This emulator will be formatting.\nAre you sure to conitnue?");
+
+ int response = msg.open();
+ boolean success = false;
+ if (response == SWT.OK) {
+ if (listTable.getCountSelectionItem() == 1) {
+ if (!resetProcess(listTable.getSelectionItem())) {
+ return;
+ }
+ } else {
+ ArrayList<VMsProperty> list = listTable.getSelectionItems();
+ for (VMsProperty property : list) {
+ if (!checkRunnigVM(property)) {
+ continue;
+ }
+ if (!resetProcess(property)) {
+ continue;
+ }
+ success = true;
+ }
+ }
+ }
+
+ msg = new MessageBox(shell, SWT.ICON_INFORMATION);
+ msg.setText("INFO");
+ if (!success) {
+ msg.setMessage("Reset failed!");
+ } else {
+ msg.setMessage("Reset completed!");
+ }
+ msg.open();
+ }
+
+ private boolean checkRunnigVM(VMsProperty property) {
+ VMProcess process = new VMProcess();
+ MessageBox msg = null;
+ if (!process.checkIfRunning(property)) {
+ msg = new MessageBox(shell, SWT.ICON_INFORMATION);
+ msg.setText("INFO");
+ msg.setMessage("Emulator is running now\nEmulator Name : " + property.getName());
+ msg.open();
+ return false;
+ }
+ return true;
+ }
+
+ private boolean resetProcess(VMsProperty property) {
+ VMProcess process = new VMProcess();
+ MessageBox msg = null;
+
+ String basePath = property.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue();
+ String targetPath = property.getConfiguration().getBaseInformation().getDiskImage().getCurrentDiskImage().getValue();
+ if (basePath == null || basePath.isEmpty() || targetPath == null || targetPath.isEmpty()) {
+ msg = new MessageBox(shell, SWT.ICON_INFORMATION);
+ msg.setText("INFO");
+ msg.setMessage("Fail reset Emulator\nEmulator Name : " + property.getName());
+ msg.open();
+ return false;
+ }
+
+ if(!process.createBaseImage(basePath, targetPath)) {
+ msg = new MessageBox(shell, SWT.ICON_INFORMATION);
+ msg.setText("INFO");
+ msg.setMessage("Fail reset Emulator\nEmulator Name : " + property.getName()
+ +"\n" + process.getErrorMessage());
+ msg.open();
+ return false;
+ }
+ return true;
+ }
+
+ private boolean deleteProcess(VMsProperty property) {
+ String path = EmulatorVMs.getInstance().getVMsBaseDirectory()
+ + File.separator + property.getArch().toString()
+ + File.separator + property.getName();
+ File vtFolder = new File(path);
+ if (vtFolder.exists()) {
+ for (File dir : vtFolder.listFiles()) {
+ if (dir.isFile()) {
+ dir.delete();
+ } else { // directory
+ for (File sub : dir.listFiles()) {
+ if (sub.isFile()) {
+ sub.delete();
+ }
+ }
+ dir.delete();
+ }
+ }
+ vtFolder.delete();
+ }
+ return true;
+ }
+
+ // TOOD : error checking
+ public boolean deleteVirtualMachine() {
+ if (listTable.getCountSelectionItem() == 1) {
+ if (!checkRunnigVM(listTable.getSelectionItem())) {
+ return false;
+ }
+ }
+
+ MessageBox msg = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.CANCEL);
+ msg.setText("INFO");
+ msg.setMessage("Are you sure delete selected Emulator?");
+
+ int response = msg.open();
+ if (response == SWT.OK) {
+ if (listTable.getCountSelectionItem() == 1) {
+ if (!deleteProcess(listTable.getSelectionItem())) {
+ return false;
+ }
+ } else {
+ ArrayList<VMsProperty> list = listTable.getSelectionItems();
+ for (VMsProperty property : list) {
+ if (!checkRunnigVM(property)) {
+ continue;
+ }
+ if (!deleteProcess(property)) {
+ continue;
+ }
+ }
+ }
+ msg = new MessageBox(shell, SWT.ICON_INFORMATION);
+ msg.setText("INFO");
+ msg.setMessage("Delete completed!");
+ msg.open();
+ }
+
+ return true;
+ }
+
+ private VMsProperty property = null;
+ private VMCreateHelper helper = null;
+
+ private MainDialog main = null;
+ private Shell dialog = null;
+ private Text name = null;
+ private Label infoLabel = null;
+ private Button confirmButton = null;
+ private Button cancelButton = null;
+
+ private String vmName = null;
+ public void cloneVirtualMachine(MainDialog main) {
+ this.main = main;
+ property = listTable.getSelectionItem();
+
+ Shell dialog = makeDialog();
+ dialog.open();
+ }
+
+ private Shell makeDialog() {
+ helper = new VMCreateHelper();
+ dialog = new Shell(EmulatorManager.getInstance().getShell(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
+ dialog.setText("Cloning Emulator");
+ dialog.setSize(300, 180);
+ dialog.setLayout(new GridLayout(1, true));
+
+ Label info = new Label(dialog, SWT.WRAP);
+ info.setText("Create new Emulator \nfrom copying the selected Emulator.");
+
+ Label sep = new Label(dialog, SWT.SEPARATOR | SWT.HORIZONTAL);
+ sep.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
+
+ name = new Text(dialog, SWT.BORDER);
+ name.setTextLimit(VMPropertyView.MAX_NAME_LEN);
+ name.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
+
+ infoLabel = new Label(dialog, SWT.WRAP);
+ infoLabel.setText("Input name");
+ infoLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
+
+ Composite buttonComposite = new Composite(dialog, SWT.NONE);
+ buttonComposite.setLayout(new GridLayout(2, true));
+ buttonComposite.setLayoutData(new GridData(SWT.RIGHT, SWT.FILL, true, false));
+
+ confirmButton = new Button(buttonComposite, SWT.PUSH);
+ confirmButton.setText("Confirm");
+ confirmButton.setImage(ResourceRegistry.getImage(ImageName.CONFIRM));
+ confirmButton.setEnabled(false);
+
+ cancelButton = new Button(buttonComposite, SWT.PUSH);
+ cancelButton.setText("Cancel");
+ cancelButton.setImage(ResourceRegistry.getImage(ImageName.CANCEL));
+
+ addListener();
+
+ return dialog;
+ }
+
+ private void addListener() {
+ name.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent arg0) {
+ vmName = name.getText();
+ checkImageName();
+ }
+ });
+
+ confirmButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ VMPropertyValue vmValue = new VMPropertyValue();
+ vmValue.settingValue(property);
+ vmValue.imageName = vmName;
+
+ VMProcess process = new VMProcess();
+ VMsProperty p = process.create(vmValue);
+ MessageBox msg = new MessageBox(shell, SWT.ICON_INFORMATION);
+ msg.setText("INFO");
+ if (p != null) {
+ msg.setMessage("Success cloning Emulator!");
+ } else {
+ msg.setMessage(process.getErrorMessage());
+ }
+ msg.open();
+
+ dialog.close();
+ main.refreshProperties();
+ }
+
+ });
+
+ cancelButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ dialog.close();
+ main.refreshProperties();
+ }
+
+ });
+ }
+
+ private void checkImageName() {
+ if (vmName.length() == VMPropertyView.MAX_NAME_LEN) {
+ infoLabel.setText("Max of length is 20.");
+ confirmButton.setEnabled(false);
+ return;
+ }
+
+ if (!helper.checkString(vmName)) {
+ infoLabel.setText("Name is invalid!");
+ confirmButton.setEnabled(false);
+ return;
+ }
+
+ if (helper.checkDupulicateName(vmName, property.getArch().toString())) {
+ infoLabel.setText("The same name exists!");
+ confirmButton.setEnabled(false);
+ return;
+ }
+
+ infoLabel.setText("Input name");
+ if (vmName.isEmpty()) {
+ confirmButton.setEnabled(false);
+ } else {
+ confirmButton.setEnabled(true);
+ }
+ }
+}
}
enum DItem{
- ImageName, BaseImage, Resolution, Density,
- SDType, SDPath, RAMSize, ShareType, SharePath, Dummy;
+ ImageName("Name"), BaseImage("BaseImage"),
+ Resolution("Display Resolution"), Density("Display Density"),
+ SDType("SDCard"), SDPath("SDCard Path"), RAMSize("RAM Size"),
+ ShareType("File Sharing"), SharePath("File Sharing Path"), Dummy("");
+
+ private String value;
+ DItem(String s) {
+ value = s;
+ }
+ public String toString() {
+ return value;
+ }
+}
+
+enum DPI {
+ DPI160("320x480", 160), DPI207("480x800", 207), DPI224("600x1024", 224), DPI316("720x1280", 316);
+
+ private String resolution;
+ private int dpi;
+
+ DPI(String resolution, int dpi) {
+ this.resolution = resolution;
+ this.dpi = dpi;
+ }
+
+ public int getDPI() {
+ return dpi;
+ }
+
+ public String toString() {
+ return resolution;
+ }
}
public class VMPropertyView {
private void makeItemList() {
widget.itemList = new ArrayList<TableItem>();
- TableItem item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.ImageName.ordinal(), item);
-
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.ImageNameInfo.ordinal(), item);
-
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.BaseImage.ordinal(), item);
-
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.Resolution.ordinal(), item);
-
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.Density.ordinal(), item);
-
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.SDType.ordinal(), item);
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.SDPath.ordinal(), item);
-
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.RAMSize.ordinal(), item);
-
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.ShareType.ordinal(), item);
- item = new TableItem(table, SWT.NONE);
- widget.itemList.add(CItem.SharePath.ordinal(), item);
+ for (CItem citem : CItem.values()) {
+ TableItem item = new TableItem(table, SWT.NONE);
+ widget.itemList.add(citem.ordinal(), item);
+ }
}
private void settingCreateColumn() {
table.clearAll();
- widget.itemList.get(CItem.ImageName.ordinal()).setText(0, CItem.ImageName.toString());
- widget.itemList.get(CItem.ImageNameInfo.ordinal()).setText(0, CItem.ImageNameInfo.toString());
- widget.itemList.get(CItem.BaseImage.ordinal()).setText(0, CItem.BaseImage.toString());
-
- widget.itemList.get(CItem.Resolution.ordinal()).setText(0, CItem.Resolution.toString());
- widget.itemList.get(CItem.Density.ordinal()).setText(0, CItem.Density.toString());
-
- widget.itemList.get(CItem.SDType.ordinal()).setText(0, CItem.SDType.toString());
- widget.itemList.get(CItem.SDPath.ordinal()).setText(0, CItem.SDPath.toString());
-
- widget.itemList.get(CItem.RAMSize.ordinal()).setText(0, CItem.RAMSize.toString());
-
- widget.itemList.get(CItem.ShareType.ordinal()).setText(0, CItem.ShareType.toString());
- widget.itemList.get(CItem.SharePath.ordinal()).setText(0, CItem.SharePath.toString());
+ for (CItem citem : CItem.values()) {
+ widget.itemList.get(citem.ordinal()).setText(0, citem.toString());
+ }
}
private void settingDetailColumn() {
table.clearAll();
- widget.itemList.get(DItem.ImageName.ordinal()).setText(0, CItem.ImageName.toString());
- widget.itemList.get(DItem.BaseImage.ordinal()).setText(0, CItem.BaseImage.toString());
-
- widget.itemList.get(DItem.Resolution.ordinal()).setText(0, CItem.Resolution.toString());
- widget.itemList.get(DItem.Density.ordinal()).setText(0, CItem.Density.toString());
-
- widget.itemList.get(DItem.SDType.ordinal()).setText(0, CItem.SDType.toString());
- widget.itemList.get(DItem.SDPath.ordinal()).setText(0, CItem.SDPath.toString());
-
- widget.itemList.get(DItem.RAMSize.ordinal()).setText(0, CItem.RAMSize.toString());
-
- widget.itemList.get(DItem.ShareType.ordinal()).setText(0, CItem.ShareType.toString());
- widget.itemList.get(DItem.SharePath.ordinal()).setText(0, CItem.SharePath.toString());
+ for (DItem ditem : DItem.values()) {
+ widget.itemList.get(ditem.ordinal()).setText(0, ditem.toString());
+ }
}
public void detailView(VMsProperty property) {
editor.setEditor(widget.selectShareFolderButton, widget.itemList.get(CItem.SharePath.ordinal()), 1);
}
- static final int MAX_NAME_LEN = 20;
+ public static final int MAX_NAME_LEN = 20;
private void createNameArea(Table table) {
widget.imageNameText = new Text(table, SWT.BORDER);
widget.imageNameText.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
helper.addComboItem(widget.resolutionCombo, DisplayResoultion.getInstance().getList(),
DisplayResoultion.getInstance().findIndex(oldValue.resolution));
widget.DIPspinner = new Spinner(table, SWT.BORDER);
- // TODO : setting min, max
- widget.DIPspinner.setValues(oldValue.dpi, 0, 1000, 0, 1, 1);
+ widget.DIPspinner.setValues(oldValue.dpi, 100, 480, 0, 1, 1);
createDisplayListener();
}
@Override
public void widgetSelected(SelectionEvent e) {
newValue.resolution = widget.resolutionCombo.getItem(widget.resolutionCombo.getSelectionIndex());
+ for (DPI d : DPI.values() ) {
+ if (newValue.resolution.equals(d.toString())) {
+ newValue.dpi = d.getDPI();
+ widget.DIPspinner.setSelection(newValue.dpi);
+ }
+ }
if (!isCreateMode) {
checkModifyState();
}
VMsProperty p = null;
if (isCreateMode) {
- p = process.create(property, oldValue, newValue);
+ p = process.create(newValue);
} else {
p = process.modify(property, oldValue, newValue);
}
msg.setText("INFO");
if (p != null) {
if (isCreateMode) {
- msg.setMessage("Success creating virtual target!");
+ msg.setMessage("Success creating emulator!");
} else {
- msg.setMessage("Success modifying virtual target!");
+ msg.setMessage("Success modifying emulator!");
}
} else {
msg.setMessage(process.getErrorMessage());
final MenuItem cloneItem = new MenuItem(treeMenu, SWT.NONE);
cloneItem.setText("Clone");
- cloneItem.setEnabled(false);
+ cloneItem.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ EmulatorManager.getInstance().getMainDialog().cloneVirtualMachine();
+ }
+ });
treeMenu.addMenuListener(new MenuListener() {
@Override
modifyItem.setEnabled(false);
cloneItem.setEnabled(false);
return;
- } else {
- cloneItem.setEnabled(false);
}
}
}
return count;
}
- public ArrayList<VMsProperty> getSelectionItem() {
+ public int getCountSelectionItem() {
+ int count = 0;
+ Object data;
+ for (int i = 0; i < vmsTree.getSelectionCount(); i++) {
+ data = vmsTree.getSelection()[i].getData();
+ if(!(data instanceof RowItem))
+ continue;
+
+ if (data instanceof CreateMarker || data instanceof TreeMarker) {
+ return 0;
+ }
+
+ count++;
+ }
+ return count;
+ }
+
+ public ArrayList<VMsProperty> getSelectionItems() {
ArrayList<VMsProperty> list = new ArrayList<VMsProperty>();
VMsProperty property = null;
return list;
}
+
+ public VMsProperty getSelectionItem() {
+ return ((PropertyContent)vmsTree.getSelection()[0].getData()).property;
+
+ }
}
\ No newline at end of file
return property;
}
- public VMsProperty create(VMsProperty property, VMPropertyValue oldVM, VMPropertyValue newVM) {
+ public VMsProperty create(VMPropertyValue newVM) {
this.newVM = newVM;
this.property = EmulatorVMs.getInstance().getNewProperty
(newVM.imageName, Architecture.x86);
import org.tizen.emulator.manager.vms.xml.DisplayType.Resolution;
+
+
public class VMPropertyValue {
public String arcType;
resolutionType.setWidth(720);
resolutionType.setHeight(1280);
resolution = "720x1280";
- dpi = 207;
+ dpi = 316; // this value be related to resolution
isSDCardSupport = false;
SDCardPath = "";