public class EmulatorManager {
private static EmulatorManager instance;
-
+
Display display;
Shell shell;
-
+
Image icon;
private MainDialog mainDialog;
private Launcher launcher;
-
+
public EmulatorManager() {
this.display = new Display();
-
+
shell = new Shell(display);
shell.setSize(700, 500);
shell.setText("Emulator Manager");
shell.setLayout(new FillLayout());
-
+
InputStream is = this.getClass().getClassLoader().getResourceAsStream("res/em.ico");
if(is != null) {
icon = new Image(display, is);
shell.setImage(icon);
}
}
-
+
public static EmulatorManager getInstance() {
return instance;
}
public Display getDisplay() {
return display;
}
-
+
public Shell getShell() {
return shell;
}
-
+
public MainDialog getMainDialog() {
return mainDialog;
}
-
+
public Launcher getLauncher() {
return launcher;
}
-
+
private void preare() {
mainDialog = new MainDialog();
private void DrawUI() {
mainDialog.draw();
-
+
shell.open();
-
+
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
-
+
public void launchVM(VMsProperty property) {
Launcher.launch(property);
}
else {
EmulatorVMs.getInstance().setVMsBaseDirectory(FileIO.getInstance().getTizenVmsPath());
}
-
+
try {
EmulatorVMs.getInstance().loadProperties();
} catch (Exception e) {
e.printStackTrace();
}
-
+
instance = new EmulatorManager();
instance.preare();
instance.DrawUI();
-
+
instance.dispose();
}
}
private final static String etc_suffix = File.separator +"etc";
private final static String log_suffix = File.separator +"logs";
private final static String x86_kernel_suffix = File.separator +"kernel-img";
-
+
private static String currentPath;
private static String emulatorPath;
private static String sdkPath;
-
+
private static String sdbPath;
// Emulator
private static String binPath;
static {
// emulator-manager.jar file path
- {
+ {
File jar = null;
try {
jar = new File(EmulatorManager.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
emulatorPath = currentPath + File.separator + "..";
sdkPath = emulatorPath + File.separator + "..";
-
+
// SDB path
{
String sdb_suffix;
sdb_suffix = File.separator +"SDK" + File.separator + "sdb" + File.separator + "sdb.exe";
else
sdb_suffix = File.separator +"SDK" + File.separator + "sdb" + File.separator + "sdb";
-
+
sdbPath = sdkPath + sdb_suffix;
}
arcPath = emulatorPath + arch_suffix;
etcPath = emulatorPath + etc_suffix;
iconPath = emulatorPath + icon_suffix;
-
+
dataPath = arcPath + data_suffix;
confPath = arcPath + conf_suffix;
baseImagePath = arcPath + baseimg_suffix;
-
+
x86KernelPath = dataPath + x86_kernel_suffix;
biosPath = dataPath + bios_suffix;
vmsPath = EmulatorVMs.getInstance().getVMsBaseDirectory();
public static FileIO getInstance() {
return instance;
}
-
+
public String getSdkRoot(){
return sdkPath;
}
public String getBinPath(){
return binPath;
}
-
+
public String getArchPath(){
return arcPath;
}
- // ~/tizen_sdk/Emulator/skins/icons/vtm.ico
- public String getIconPath(){
+ // ~/tizen_sdk/Emulator/skins/icons/vtm.ico
+ public String getIconPath(){
return iconPath;
}
-
+
public String getDataPath(){
return dataPath;
}
public String getConfPath(){
return confPath;
}
-
+
public String getTizenVmsPath() {
return vmsPath;
}
-
+
public String getTizenVmsArchPath() {
return vmsArchPath;
}
-
+
public String getBaseimgPath(){
return baseImagePath;
}
-
+
public String getEtcPath(){
return etcPath;
}
public String getKernelPath(){
return x86KernelPath;
}
-
+
// ~/tizen_sdk/Emulator/x86/data/pc-bios/bios.bin
public String getBiosPath() {
return biosPath;
public String getVirtualTargetPath(String name) {
return getTizenVmsArchPath() + File.separator + name;
}
-
+
public String getVirtualTargetLogPath(String name) {
return getVirtualTargetPath(name) + log_suffix;
}
int portNo;
String StrPortNo = "";
int c;
-
+
//check if there is another Emulator instance with the same name
String PortPath = new FileIO().getTizenVmsArchPath() + File.separator + property.getName() + File.separator + ".port";
File file = new File(PortPath);
} catch(Exception e1) {
e1.printStackTrace();
}
-
+
//FIXME
/*
Socket so = null;
try {
Socket so = new Socket("localhost", Integer.parseInt(StrPortNo) +1 );
- so.close();
+ so.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
+ " root=/dev/vda rw"
+ " ip=10.0.2.16::10.0.2.2:255.255.255.0::eth0:none 5");
}
-
+
if(isLinux > -1 && isFileshare) { //linux and use fileshare [non-kernel option]
cmd.add("-virtfs");
cmd.add("local,path=" + property.getConfiguration().getUsability().getFileSharing().getPath() +",security_model=none,mount_tag=fileshare");
}
-
+
if(isSDcard) {
cmd.add("-drive");
cmd.add("file=" + sdcard + ",if=virtio");
cmd.add("base=utc");
cmd.add(kvm);
/*
- if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1 && property.getConfiguration().getUsability().isHwVirtualization()) {
+ if (System.getProperty("os.name").toLowerCase().indexOf("linux") > -1 && property.getConfiguration().getUsability().isHwVirtualization()) {
File fi = new File("/dev/kvm");
exists = fi.exists();
if(exists) {
}
}
*/
- // cmd.add("-redir");
- // cmd.add("tcp:1202:10.0.2.16:22");
+ // cmd.add("-redir");
+ // cmd.add("tcp:1202:10.0.2.16:22");
//System.out.println(cmd);
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.directory(new File(fio.getBinPath()));
-
+
Process process = pb.start();
final InputStream in1 = new BufferedInputStream(process.getInputStream());
import org.tizen.emulator.manager.ui.detail.DetailTableView;
import org.tizen.emulator.manager.ui.vmstree.VMsTable;
import org.tizen.emulator.manager.vms.EmulatorVMs;
+import org.tizen.emulator.manager.vms.VMProcess;
import org.tizen.emulator.manager.vms.VMsProperty;
import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
private Button rightButton;
private Shell shell;
-
+
public MainDialog() {
this.shell = EmulatorManager.getInstance().getShell();
}
-
- public void draw() {
+
+ public void draw() {
Composite mainComposite = new Composite(shell, SWT.NONE);
mainComposite.setLayout(new GridLayout(1, false));
Button refreshButton = new Button(buttonComposite, SWT.PUSH);
refreshButton.setText("Refresh");
+ refreshButton.setToolTipText("refresh list of virtual machine");
refreshButton.setImage(ResourceRegistry.getImage(ImageName.REFRESH));
refreshButton.addSelectionListener(new SelectionListener() {
@Override
deleteButton = new Button(buttonComposite, SWT.PUSH);
deleteButton.setText("Delete");
+ deleteButton.setToolTipText("delete selected virtual machine");
deleteButton.setImage(ResourceRegistry.getImage(ImageName.DELETE));
deleteButton.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
- deleteVirtualTarget();
+ deleteVirtualMachine();
detailView.closeDetailView();
refreshProperties();
}
resetButton = new Button(buttonComposite, SWT.PUSH);
resetButton.setText("Reset");
+ resetButton.setToolTipText("format os of virtual machine");
resetButton.setImage(ResourceRegistry.getImage(ImageName.RESET));
- //TODO
- resetButton.setEnabled(false);
+ resetButton.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ resetVirtualMachine();
+ }
+
+ });
}
// LEFT : detail table
}
}
+ public void resetVirtualMachine() {
+ ArrayList<VMsProperty> list = imageListTable.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();
+ }
+ }
+
// TOOD : error checking
- public void deleteVirtualTarget() {
+ public void deleteVirtualMachine() {
ArrayList<VMsProperty> list = imageListTable.getSelectionItem();
MessageBox msg = new MessageBox(shell, SWT.ICON_INFORMATION | SWT.OK | SWT.CANCEL);
msg.setText("INFO");
if (response == SWT.OK) {
for (VMsProperty property : list) {
String path = EmulatorVMs.getInstance().getVMsBaseDirectory()
- + File.separator + property.getArch().toString()
- + File.separator + property.getName();
+ + File.separator + property.getArch().toString()
+ + File.separator + property.getName();
File vtFolder = new File(path);
if (vtFolder.exists()) {
for (File dir : vtFolder.listFiles()) {
public void openDetailView(VMsProperty property) {
deleteButton.setEnabled(true);
- // TODO
- //resetButton.setEnabled(true);
+ resetButton.setEnabled(true);
leftButton.setText(Launch);
leftButton.setImage(ResourceRegistry.getImage(ImageName.LAUNCH));
} else {
deleteButton.setEnabled(false);
}
- // TODO
- //resetButton.setEnabled(false);
+ resetButton.setEnabled(false);
detailView.closeDetailView();
}
public void openModifyView(VMsProperty property) {
deleteButton.setEnabled(false);
- // TODO
- //resetButton.setEnabled(false);
+ resetButton.setEnabled(false);
leftButton.setText(Confirm);
leftButton.setImage(ResourceRegistry.getImage(ImageName.CONFIRM));
-
rightButton.setText(Cancel);
rightButton.setImage(ResourceRegistry.getImage(ImageName.CANCEL));
- detailView.openModifyView(property);
+ leftButton.setEnabled(false);
+ rightButton.setEnabled(true);
+
+ detailView.openModifyView(property, leftButton);
}
public void openCreateDetailView(boolean isDefault) {
deleteButton.setEnabled(false);
- // TODO
- //resetButton.setEnabled(false);
+ resetButton.setEnabled(false);
leftButton.setText(Launch);
leftButton.setImage(ResourceRegistry.getImage(ImageName.LAUNCH));
public void openCreateDetailView() {
deleteButton.setEnabled(false);
- // TODO
- //resetButton.setEnabled(false);
+ resetButton.setEnabled(false);
leftButton.setText(Launch);
leftButton.setImage(ResourceRegistry.getImage(ImageName.LAUNCH));
public void openCreateView() {
deleteButton.setEnabled(false);
- // TODO
- //resetButton.setEnabled(false);
+ resetButton.setEnabled(false);
leftButton.setText(Confirm);
leftButton.setImage(ResourceRegistry.getImage(ImageName.CONFIRM));
rightButton.setText(Cancel);
rightButton.setImage(ResourceRegistry.getImage(ImageName.CANCEL));
- detailView.openCreateView(rightButton, leftButton);
+ detailView.openCreateView(leftButton);
}
public void dispose() {
public enum ImageName {
CANCEL("cancel"), CONFIRM("confirm"), CREATE("create"), DELETE("delete"), DETAILS("details"),
FOLDER("folder"), MODIFY("modify"), REFRESH("refresh"), RESET("reset"), LAUNCH("launch");
-
+
String name;
-
+
ImageName(String name) {
this.name = name;
}
-
+
@Override
public String toString() {
return name;
}
}
-
+
private static ResourceRegistry instance;
-
+
Map<ImageName, Image> imagesMap = new HashMap<ImageName, Image>();
static {
}
}
}
-
+
public static Image getImage(ImageName imageName) {
return instance.imagesMap.get(imageName);
}
-
+
public static void dispose() {
for(Image image : instance.imagesMap.values()) {
image.dispose();
}
}
-
+
private ResourceRegistry() {}
}
private static String Detail = "Datail";
private MainDialog mainDialog;
- private Table detailTable;
+ private Table detailTable;
private TableColumn tableColumn;
private boolean isDetailOpened = false;
private boolean isCreateState = false;
private boolean isModifyState = false;
private boolean isDefaultCreate;
-
+
private VMsProperty currentProperty;
private VMPropertyView vmView = null;
isDetailOpened = false;
}
- public void openModifyView(VMsProperty property)
+ public void openModifyView(VMsProperty property, Button confirmButton)
{
isModifyState = true;
tableColumn.setText(Modify);
if (vmView == null) {
return;
}
- vmView.modifyView();
+ vmView.modifyView(confirmButton);
}
-
+
public void closeModifyView()
{
isModifyState = false;
}
}
- public void openCreateView(Button rightButton, Button leftButton) {
+ public void openCreateView( Button confirmButton) {
isCreateState = true;
tableColumn.setText(Create);
return;
}
- vmView.createView(rightButton, leftButton);
+ vmView.createView(confirmButton);
}
public void closeCreateView()
import org.eclipse.swt.widgets.Text;
import org.tizen.emulator.manager.ui.ResourceRegistry;
import org.tizen.emulator.manager.ui.ResourceRegistry.ImageName;
-import org.tizen.emulator.manager.vm.VMCreateHelper;
-import org.tizen.emulator.manager.vm.VMProcess;
-import org.tizen.emulator.manager.vm.VMPropertyValue;
-import org.tizen.emulator.manager.vm.VMViewWidget;
+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.VMViewWidget;
import org.tizen.emulator.manager.vms.VMsProperty;
enum CItem{
public class VMPropertyView {
private static String SEFARATOR = File.separator;
- private VMCreateHelper helper;
- private VMViewWidget widget;
- private VMProcess process;
- private VMsProperty property;
+ private VMCreateHelper helper;
+ private VMViewWidget widget;
+ private VMProcess process;
+ private VMsProperty property;
private Table table;
- private Image image = null;
+ private Image image = null;
private VMPropertyValue oldValue = null;
- private VMPropertyValue newValue = null;
+ private VMPropertyValue newValue = null;
private boolean isCreateMode = true;
public VMPropertyView(Table table) {
- this.helper = new VMCreateHelper();
- this.process = new VMProcess();
- this.widget = new VMViewWidget();
+ this.helper = new VMCreateHelper();
+ this.process = new VMProcess();
+ this.widget = new VMViewWidget();
this.table = table;
// InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("res/folder.png");
widget.itemList.get(CItem.ShareType.ordinal()).setText(0, CItem.ShareType.toString());
widget.itemList.get(CItem.SharePath.ordinal()).setText(0, CItem.SharePath.toString());
}
-
+
private void settingDetailColumn() {
table.clearAll();
widget.itemList.get(DItem.ImageName.ordinal()).setText(0, CItem.ImageName.toString());
settingDetailColumn();
}
- this.property = property;
+ this.property = property;
oldValue = new VMPropertyValue();
oldValue.settingValue(property);
widget.itemList.get(CItem.SharePath.ordinal()).setText(1, oldValue.fileSharePathName);
}
- public void modifyView() {
+ public void modifyView(Button confirm) {
newValue = new VMPropertyValue(oldValue);
+ widget.confirmButton = confirm;
+
createNameArea(table);
createBaseImageArea(table);
createDisplayArea(table);
settingModifyTableEditor();
}
- public void createView(Button cancle, Button confirm) {
+ public void createView(Button confirm) {
newValue = new VMPropertyValue(oldValue);
- widget.cancelButton = cancle;
widget.confirmButton = confirm;
createNameArea(table);
}
private void settingModifyTableEditor() {
- TableEditor editor = new TableEditor(table);
- editor.grabHorizontal = true;
+ TableEditor editor = new TableEditor(table);
+ editor.grabHorizontal = true;
editor.setEditor(widget.imageNameText, widget.itemList.get(DItem.ImageName.ordinal()), 1);
editor = new TableEditor(table);
}
private void settingCreateTableEditor() {
- TableEditor editor = new TableEditor(table);
- editor.grabHorizontal = true;
+ TableEditor editor = new TableEditor(table);
+ editor.grabHorizontal = true;
editor.setEditor(widget.imageNameText, widget.itemList.get(CItem.ImageName.ordinal()), 1);
editor = new TableEditor(table);
}
if (!oldValue.imageName.equals(newValue.imageName)
- && helper.checkDupulicateName(newValue.imageName)) {
+ && helper.checkDupulicateName(newValue.imageName)) {
widget.nameinfoLabel.setText("The same name exists!");
widget.confirmButton.setEnabled(false);
return;
widget.selectBaseImageButton.setEnabled(false);
}
}
-
+
private void createBaseImageListener() {
widget.selectBaseImageButton.addSelectionListener(new SelectionListener() {
@Override
@Override
public void widgetSelected(SelectionEvent e) {
newValue.resolution = widget.resolutionCombo.getItem(widget.resolutionCombo.getSelectionIndex());
+ if (!isCreateMode) {
+ checkModifyState();
+ }
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
@Override
public void modifyText(ModifyEvent e) {
newValue.dpi = widget.DIPspinner.getSelection();
+ if (!isCreateMode) {
+ checkModifyState();
+ }
}
});
}
createSDCardListener();
}
-
+
private void createSDCardListener() {
widget.SDCardTypeCombo.addSelectionListener(new SelectionListener() {
@Override
newValue.isSDCardSupport = false;
widget.SDCardPathCombo.setEnabled(false);
}
+
+ if (!isCreateMode) {
+ checkModifyState();
+ }
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
- });
+ });
widget.SDCardPathCombo.addSelectionListener(new SelectionListener() {
@Override
newValue.SDCardPath = widget.SDCardPathCombo.getItem(i);
newValue.SDCardPathName = widget.SDCardPathCombo.getItem(i);
}
+
+ if (!isCreateMode) {
+ checkModifyState();
+ }
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
public void widgetSelected(SelectionEvent e) {
String str = widget.ramSizeCombo.getItem(widget.ramSizeCombo.getSelectionIndex());
newValue.ramSize = Integer.valueOf(str.substring(0, str.length()-3));
+
+ if (!isCreateMode) {
+ checkModifyState();
+ }
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
newValue.isFileShareSupport = false;
widget.selectShareFolderButton.setEnabled(false);
}
+
+ if (!isCreateMode) {
+ checkModifyState();
+ }
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
- });
+ });
widget.selectShareFolderButton.addSelectionListener(new SelectionListener() {
@Override
newValue.fileSharePath = path;
widget.selectShareFolderButton.setText(path.substring(path.lastIndexOf(SEFARATOR) + 1, path.length()));
}
+
+ if (!isCreateMode) {
+ checkModifyState();
+ }
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
});
}
+ private void checkModifyState() {
+ boolean isModify =false;
+ if (!newValue.resolution.equals(oldValue.resolution)) {
+ isModify = true;
+ }
+ if (newValue.dpi != oldValue.dpi) {
+ isModify = true;
+ }
+
+ if (newValue.isSDCardSupport != oldValue.isSDCardSupport) {
+ isModify = true;
+ } else if (newValue.isSDCardSupport && !newValue.SDCardPath.equals(oldValue.SDCardPath)) {
+ isModify = true;
+ }
+
+ if (newValue.ramSize != oldValue.ramSize) {
+ isModify = true;
+ }
+
+ if (newValue.isFileShareSupport != oldValue.isFileShareSupport) {
+ isModify = true;
+ } else if (newValue.isFileShareSupport && !newValue.fileSharePath.equals(oldValue.fileSharePath)) {
+ isModify = true;
+ }
+
+ if (isModify) {
+ widget.confirmButton.setEnabled(true);
+ } else {
+ widget.confirmButton.setEnabled(false);
+ }
+ }
+
public void close() {
widget.close();
}
add(0, "320x480");
add(1, "480x800");
add(2, "600x1024");
- add(3, "720X1280");
+ add(3, "720x1280");
setDefaultIndex(3);
}
-
+
public int findIndex(String r) {
String[] strArray = getList();
String s = null;
setDefaultIndex(0);
}
-
+
public int findIndex(String size) {
String[] strArray = getList();
String s = null;
// TODO: Support dynamic column editing...
public class ContentProvider {
static final int numberOfColumns = 4;
-
+
String[] columnTitles = new String[] { "Name", "Resolution", "Density", "RAM size" };
public String[] getColumnTitles() {
public String[] getColumnContents(VMsProperty property) {
String[] texts = new String[numberOfColumns];
-
+
texts[0] = property.getName();
DeviceType deviceType = property.getConfiguration().getDevice();
DisplayType displayType = deviceType.getDisplay();
texts[1] = displayType.getResolution().getWidth()
+ " x " + displayType.getResolution().getHeight();
-
+
texts[2] = displayType.getDensity().getValue() + "";
texts[3] = deviceType.getRAM().getSize().getValue() + "";
-
+
return texts;
}
public void prepare(final Tree vmsTree) {
treeMenu = new Menu(vmsTree);
-
+
final MenuItem launchItem = new MenuItem(treeMenu, SWT.NONE);
launchItem.setText("Launch");
launchItem.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
if(vmsTree.getSelectionCount() > 1)
return;
-
+
VMsProperty property = ((PropertyContent)vmsTree.getSelection()[0].getData()).property;
EmulatorManager.getInstance().launchVM(property);
}
}
@Override
public void widgetSelected(SelectionEvent arg0) {
- EmulatorManager.getInstance().getMainDialog().deleteVirtualTarget();
+ EmulatorManager.getInstance().getMainDialog().deleteVirtualMachine();
}
});
final MenuItem resetItem = new MenuItem(treeMenu, SWT.NONE);
resetItem.setText("Reset");
- resetItem.setEnabled(false);
-
+ resetItem.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetDefaultSelected(SelectionEvent arg0) {
+ }
+ @Override
+ public void widgetSelected(SelectionEvent arg0) {
+ EmulatorManager.getInstance().getMainDialog().resetVirtualMachine();
+ }
+
+ });
+
new MenuItem(treeMenu, SWT.SEPARATOR);
-
- final MenuItem createItem = new MenuItem(treeMenu, SWT.NONE);
- createItem.setText("Clone");
- createItem.setEnabled(false);
-
+
+ final MenuItem cloneItem = new MenuItem(treeMenu, SWT.NONE);
+ cloneItem.setText("Clone");
+ cloneItem.setEnabled(false);
+
treeMenu.addMenuListener(new MenuListener() {
@Override
public void menuShown(MenuEvent e) {
if(vmsTree.getSelectionCount() == 0)
return;
-
+
for(MenuItem menuItem : treeMenu.getItems()) {
menuItem.setEnabled(true);
}
-
+
if(vmsTree.getSelectionCount() > 1) {
for(TreeItem treeItem : vmsTree.getSelection()) {
RowItem rowItem = (RowItem)treeItem.getData();
break;
}
}
- createItem.setEnabled(false);
+ cloneItem.setEnabled(false);
launchItem.setEnabled(false);
modifyItem.setEnabled(false);
}
deleteItem.setEnabled(false);
resetItem.setEnabled(false);
modifyItem.setEnabled(false);
- createItem.setEnabled(false);
+ cloneItem.setEnabled(false);
return;
} else {
- resetItem.setEnabled(false);
- createItem.setEnabled(false);
+ cloneItem.setEnabled(false);
}
}
}
-
+
@Override
public void menuHidden(MenuEvent e) {}
});
class PropertyContent extends RowItem {
VMsProperty property;
-
+
public PropertyContent(VMsProperty property, ContentProvider provider, TreeItem item) {
this.property = property;
item.setText(provider.getColumnContents(property));
abstract class TreeMarker extends RowItem {
public TreeMarker(String text, TreeItem item) {
item.setText(text);
- }
+ }
}
class CreateMarker extends TreeMarker {
public class VMsTable {
MainDialog mainDialog;
-
+
Tree vmsTree;
ContentProvider contentProvider = new ContentProvider();
ContextMenu contextMenu = new ContextMenu();
-
+
EmulatorVMs fsImage = EmulatorVMs.getInstance();
-
+
public VMsTable(MainDialog mainDialog, Composite parent) {
this.mainDialog = mainDialog;
-
+
this.vmsTree = new Tree(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
-
+
vmsTree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
+
vmsTree.setHeaderVisible(true);
vmsTree.setLinesVisible(true);
-
+
for(String columnTitle : contentProvider.getColumnTitles()) {
TreeColumn treeColumn = new TreeColumn(vmsTree, SWT.NONE);
treeColumn.setText(columnTitle);
}
-
+
refreshTableList();
pack();
contextMenu.prepare(vmsTree);
Menu tableMenu = contextMenu.getMenu();
vmsTree.setMenu(tableMenu);
-
+
vmsTree.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
if(vmsTree.getSelectionCount() == 0)
return;
-
+
if(vmsTree.getSelectionCount() > 1) {
VMsTable.this.mainDialog.closeDetailView();
}
else {
Object data = vmsTree.getSelection()[0].getData();
-
+
if(!(data instanceof RowItem))
- return;
-
+
if (vmsTree.getSelection()[0].getData() instanceof CreateMarker) {
if (vmsTree.getSelection()[0].getParentItem().getText().equals("Custom")) {
VMsTable.this.mainDialog.openCreateDetailView(false);
VMsTable.this.mainDialog.closeDetailView();
return;
}
-
+
PropertyContent content = (PropertyContent)data;
VMsTable.this.mainDialog.openDetailView(content.property);
}
}
-
+
@Override
public void widgetDefaultSelected(SelectionEvent e) {
if(vmsTree.getSelectionCount() > 1) {
}
});
}
-
+
private void pack() {
for(TreeColumn column : vmsTree.getColumns()) {
column.pack();
public void refreshTableList() {
refreshTableList(null);
}
-
+
private void refreshTableList(String text) {
boolean x86Selected = mainDialog.x86RadioButton.getSelection();
- boolean armSelected = mainDialog.armRadioButton.getSelection();
-
+ boolean armSelected = mainDialog.armRadioButton.getSelection();
+
vmsTree.removeAll();
-
+
VMsProperty[] properties = (VMsProperty[])fsImage.getProperties();
RowItem rowItem = null;
-
+
TreeItem customItem = new TreeItem(vmsTree, SWT.NONE);
rowItem = new CustomVMsMarker(customItem);
customItem.setData(rowItem);
-
+
TreeItem createItem = new TreeItem(customItem, SWT.NONE);
rowItem = new CreateMarker(createItem);
createItem.setData(rowItem);
Map<String, TreeItem> itemsMap = new HashMap<String, TreeItem>();
-
+
// FIXME !!
// TODO: We insert "1.0" now...
TreeItem tempItem = new TreeItem(vmsTree, SWT.NONE);
rowItem = new StandardVMsMarker("1.0", tempItem);
tempItem.setData(rowItem);
-
+
itemsMap.put("1.0", tempItem);
-
+
createItem = new TreeItem(tempItem, SWT.NONE);
rowItem = new CreateMarker(createItem);
createItem.setData(rowItem);
continue;
}
- TreeItem propertyItem = null;
-
+ TreeItem propertyItem = null;
+
if(FSImageType.standard == properties[i].getImageType()) {
String version = properties[i].getConfiguration().getBaseInformation().getDiskImage().getVersion();
propertyItem = itemsMap.get(version);
rowItem = new CreateMarker(createItem);
createItem.setData(rowItem);
}
-
propertyItem = new TreeItem(propertyItem, SWT.NONE);
}
else {
- propertyItem = new TreeItem(customItem, SWT.NONE);
+ propertyItem = new TreeItem(customItem, SWT.NONE);
}
-
+
rowItem = new PropertyContent(properties[i], contentProvider, propertyItem);
propertyItem.setData(rowItem);
}
}
-
-
+
createItem.setExpanded(true);
customItem.setExpanded(true);
for(TreeItem item : itemsMap.values()) {
data = vmsTree.getSelection()[i].getData();
if(!(data instanceof RowItem))
continue;
-
+
if (data instanceof CreateMarker || data instanceof TreeMarker) {
return 0;
}
-
+
count++;
}
return count;
}
return list;
- }
+ }
}
\ No newline at end of file
instance = new EmulatorVMs();
}
}
-
+
static String vmsBaseDirectoryName = System.getProperty("user.home")
+ File.separator + ".tizen_vms";
List<VMsProperty> propertiesList = new ArrayList<VMsProperty>();
-
+
ObjectFactory objectFactory = new ObjectFactory();
public static EmulatorVMs getInstance() {
return instance;
}
-
+
public void setVMsBaseDirectory(String baseVMsDir) {
vmsBaseDirectoryName = baseVMsDir;
-
+
File fi = new File(vmsBaseDirectoryName);
if(!fi.exists())
fi.mkdirs();
- }
-
+ }
+
public String getVMsBaseDirectory() {
return vmsBaseDirectoryName;
}
-
+
public ObjectFactory getObjectFactory() {
return objectFactory;
}
-
+
public void refreshProperties() {
try {
loadProperties();
e.printStackTrace();
}
}
-
+
public void loadProperties() throws Exception {
propertiesList.clear();
// traverse VMs...
File vmsBaseDirectory = new File(vmsBaseDirectoryName);
-
+
for(File archDir : vmsBaseDirectory.listFiles(new FileFilter() {
-
@Override
public boolean accept(File pathname) {
if(!pathname.isDirectory())
return false;
-
+
if("x86".equals(pathname.getName()) || "arm".equals(pathname.getName()))
return true;
-
+
return false;
}
})) {
-
for(File vmsDir : archDir.listFiles(new FileFilter() {
-
@Override
public boolean accept(File pathname) {
if(!pathname.isDirectory())
return false;
-
return true;
}
})) {
-
String configFilename = vmsDir.getName() + ".xml";
File configFile = new File(vmsDir, configFilename);
if(!configFile.exists())
continue ; // FIXME
-
VMsProperty property = parseXML(configFile);
-
propertiesList.add(property);
}
}
private VMsProperty parseXML(File configFile) {
JAXBContext context = null;
JAXBElement<EmulatorConfiguration> element = null;
-
+
try {
context = JAXBContext.newInstance(EmulatorConfiguration.class);
} catch (JAXBException e) {
e.printStackTrace();
}
-
return new VMsProperty(configFile, element.getValue());
}
-
+
public VMsProperty getProperty(String name) {
if(name == null) return null;
-
+
for(VMsProperty property : propertiesList) {
if(name.equals(property.getName()))
return property;
}
-
+
return null;
}
-
+
public VMsProperty[] getProperties() {
return propertiesList.toArray(new VMsProperty[propertiesList.size()]);
- }
+ }
public boolean storeXML(VMsProperty property) {
JAXBContext context = null;
-
+
try {
context = JAXBContext.newInstance(EmulatorConfiguration.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-
+
if(!property.configFile.exists()) {
property.configFile.getParentFile().mkdirs();
}
-
+
marshaller.marshal(property.getConfiguration(), new FileOutputStream(property.configFile));
} catch (JAXBException e) {
e.printStackTrace();
-
+
return false;
} catch (FileNotFoundException e) {
e.printStackTrace();
-
+
return false;
}
-
+
return true;
}
-
+
public VMsProperty getNewProperty(String name, Architecture arch) {
String configDirectoryName = vmsBaseDirectoryName + File.separator +
arch.toString() + File.separator + name;
String configFilename = configDirectoryName + File.separator + name + ".xml";
-
+
File configFile = new File(configFilename);
-
+
EmulatorConfiguration ec = objectFactory.createEmulatorConfiguration();
-
+
// ec.setBaseInformation(objectFactory.createBaseInformationType());
// ec.setUsability(objectFactory.createUsabilityType());
// ec.setSkin(objectFactory.createSkinType());
// .
// .
// .
-
+
return new VMsProperty(configFile, ec);
}
-
+
public static void main(String[] args) {
EmulatorVMs fsImage = EmulatorVMs.getInstance();
try {
} catch (Exception e) {
e.printStackTrace();
}
-
+
for(VMsProperty property : fsImage.getProperties()) {
System.out.println(property.getName());
}
-
+
VMsProperty property = fsImage.getNewProperty("test6", Architecture.x86);
fsImage.storeXML(property);
}
-package org.tizen.emulator.manager.vm;
+package org.tizen.emulator.manager.vms;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
-import org.tizen.emulator.manager.vms.EmulatorVMs;
-import org.tizen.emulator.manager.vms.VMsProperty;
import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
public class VMCreateHelper {
// TODO: default x86
return checkDupulicateName(t, Architecture.x86.toString());
}
-
+
public boolean checkDupulicateName(String t, String arc) {
VMsProperty[] properties = (VMsProperty[])EmulatorVMs.getInstance().getProperties();
for (VMsProperty p : properties) {
@Override
public void handleEvent(Event event) {
event.doit = false;
-
}
});
-
+
GridData gd = new GridData(GridData.FILL, GridData.FILL, true, false);
combo.setLayoutData(gd);
return combo;
}
-
+
public void addComboItem(Combo combo, Object[] items) {
addComboItem(combo, items, 0);
}
-package org.tizen.emulator.manager.vm;
+package org.tizen.emulator.manager.vms;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import org.tizen.emulator.manager.tool.FileIO;
-import org.tizen.emulator.manager.vms.EmulatorVMs;
-import org.tizen.emulator.manager.vms.VMsProperty;
import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
import org.tizen.emulator.manager.vms.xml.DisplayType.Resolution;
import org.tizen.emulator.manager.vms.xml.EmulatorConfiguration;
private static String SEFARATOR = File.separator;
private FileIO filePath;
private String errorMessage;
-
+
// for modify
private boolean isModify = false;
oldVM.resolutionType.setHeight(Integer.valueOf(newVM.resolution.substring(i+1,newVM.resolution.length())));
property.getConfiguration().getDevice().getDisplay().setResolution(oldVM.resolutionType);
}
-
+
if (newVM.dpi != oldVM.dpi) {
isModify = true;
property.getConfiguration().getDevice().getDisplay().getDensity().setValue(newVM.dpi);
isModify = true;
property.getConfiguration().getDevice().getStorage().getSDCard().setDiskImage(newVM.SDCardPath);
}
-
+
if (newVM.ramSize != oldVM.ramSize) {
isModify = true;
property.getConfiguration().getDevice().getRAM().getSize().setValue(newVM.ramSize);
}
-
+
if (newVM.isFileShareSupport != oldVM.isFileShareSupport) {
isModify = true;
if (newVM.isFileShareSupport && !newVM.fileSharePath.isEmpty()) {
folderPath = folder.getAbsolutePath() + SEFARATOR;
File log = new File(filePath.getVirtualTargetLogPath(newVM.imageName));
-
+
folder.mkdirs();
if (!createDiskImage()) {
deleteFolder(folder);
return null;
}
-
+
if (!createRam()) {
deleteFolder(folder);
return null;
ec.setBaseInformation(factory.createBaseInformationType());
ec.setUsability(factory.createUsabilityType());
ec.setDevice(factory.createDeviceType());
-
+
ec.getBaseInformation().setName(newVM.imageName);
ec.getBaseInformation().setArchitecture(Architecture.x86.toString());
-
+
ec.getBaseInformation().setDiskImage(factory.createBaseInformationTypeDiskImage());
if (newVM.isDefaultImage) {
ec.getBaseInformation().getDiskImage().setType("standard");
ec.getBaseInformation().getDiskImage().getCurrentDiskImage().setFormat("qcow2");
ec.getBaseInformation().getDiskImage().getCurrentDiskImage().setValue(
String.format("%semulimg-%s.%s", folderPath, newVM.imageName, Architecture.x86.toString()));
-
+
ec.getUsability().setLogging(factory.createUsabilityTypeLogging());
ec.getUsability().getLogging().setLevel("NONE");
ec.getUsability().setHwVirtualization(true);
-
+
ec.getUsability().setFileSharing(factory.createUsabilityTypeFileSharing());
if (!newVM.fileSharePath.isEmpty()) {
ec.getUsability().getFileSharing().setPath(newVM.fileSharePath);
}
-
+
ec.getDevice().setDisplay(factory.createDisplayType());
ec.getDevice().getDisplay().setResolution(factory.createDisplayTypeResolution());
ec.getDevice().getDisplay().getResolution().setWidth(newVM.resolutionType.getWidth());
ec.getDevice().getDisplay().getResolution().setHeight(newVM.resolutionType.getHeight());
-
+
ec.getDevice().getDisplay().setDensity(factory.createDisplayTypeDensity());
ec.getDevice().getDisplay().getDensity().setUnit("dpi");
ec.getDevice().getDisplay().getDensity().setValue(newVM.dpi);
-
+
ec.getDevice().setRAM(factory.createRamType());
ec.getDevice().getRAM().setSize(factory.createRamTypeSize());
ec.getDevice().getRAM().getSize().setUnit("MiB");
ec.getDevice().getRAM().getSize().setValue(newVM.ramSize);
-
+
ec.getDevice().setStorage(factory.createStorageType());
ec.getDevice().getStorage().setSDCard(factory.createStorageTypeSDCard());
if (newVM.isSDCardSupport) {
return false;
}
+ String targetPath = String.format("%semulimg-%s.%s", folderPath, newVM.imageName, Architecture.x86.toString());
+ if (!createBaseImage(newVM.baseImagePath, targetPath)) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public boolean createBaseImage(String baseImagePath, String targetImagePath) {
String exe_path = filePath.getBinPath() + SEFARATOR + "qemu-img";
List<String> cmd = new ArrayList<String>();
cmd.add(exe_path);
cmd.add("create");
cmd.add("-b");
- cmd.add(newVM.baseImagePath);
+ cmd.add(baseImagePath);
cmd.add("-f");
cmd.add("qcow2");
- cmd.add(String.format("%semulimg-%s.%s", folderPath, newVM.imageName, Architecture.x86.toString()));
+ cmd.add(targetImagePath);
ProcessBuilder pb = new ProcessBuilder(cmd);
try {
pb.start();
setErrorMessage("Emulator image create failed!\n" + e.getMessage());
return false;
}
-
return true;
}
setErrorMessage("Create new image path is failed!");
return false;
}
-
+
FileReader in = null;
FileWriter out = null;
try {
in = new FileReader(src);
out = new FileWriter(dest);
-
+
int c;
while((c = in.read()) != -1) {
out.write(c);
-package org.tizen.emulator.manager.vm;
+package org.tizen.emulator.manager.vms;
import java.io.File;
-import org.tizen.emulator.manager.vms.VMsProperty;
import org.tizen.emulator.manager.vms.xml.DisplayType.Resolution;
public class VMPropertyValue {
public String arcType;
public String imageName;
-
+
public boolean isDefaultImage;
public String baseImagePath;
public String baseImagePathName;
public boolean isSDCardSupport;
public String SDCardPath;
public String SDCardPathName;
-
+
public int ramSize;
-
+
public boolean isFileShareSupport;
public String fileSharePath;
public String fileSharePathName;
isSDCardSupport = oldTarget.isSDCardSupport;
SDCardPath = oldTarget.SDCardPath;
SDCardPathName = oldTarget.SDCardPathName;
-
+
ramSize = oldTarget.ramSize;
-
+
isFileShareSupport = oldTarget.isFileShareSupport;
fileSharePath = oldTarget.fileSharePath;
fileSharePathName = oldTarget.fileSharePathName;
public void defaultSetting(boolean isDefault) {
arcType = "x86"; // TODO
imageName = "";
-
+
isDefaultImage = isDefault;
baseImagePath = "";
baseImagePathName = isDefault ? "( emulimg-1.0.x86 )" : " ( None )";
isSDCardSupport = false;
SDCardPath = "";
SDCardPathName = "( None )";
-
+
ramSize = 512;
-
+
isFileShareSupport = false;
fileSharePath = "";
fileSharePathName = "( None )";
}
-
+
public void settingValue(VMsProperty property) {
arcType = property.getArch().toString();
imageName = property.getName();
-
+
isDefaultImage = property.getConfiguration().getBaseInformation().getDiskImage().getType().equals("standard") ? true : false;
baseImagePath = property.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage().getValue();
baseImagePathName = baseImagePath.substring
SDCardPath = "";
SDCardPathName = "( None )";
}
-
+
fileSharePath = property.getConfiguration().getUsability().getFileSharing().getPath();
if (fileSharePath != null) {
isFileShareSupport = true;
-package org.tizen.emulator.manager.vm;
+package org.tizen.emulator.manager.vms;
import java.util.ArrayList;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.TableItem;
-
-
public class VMViewWidget {
public Table table;
selectShareFolderButton.dispose();
}
}
-
public class VMsProperty {
File configFile;
-
+
EmulatorConfiguration rootElement;
-
+
public VMsProperty(File configFile, EmulatorConfiguration element) {
this.configFile = configFile;
this.rootElement = element;
- }
+ }
public String getName() {
if(rootElement.getBaseInformation() == null)
return null;
-
+
return rootElement.getBaseInformation().getName();
}
public Architecture getArch() {
return FSImageType.standard.toString().equals(rootElement.getBaseInformation().getDiskImage().getType()) ?
FSImageType.standard : FSImageType.custom;
}
-
+
public EmulatorConfiguration getConfiguration() {
return rootElement;
}
-
+
public enum Architecture {
x86("x86"), ARM("ARM");
-
+
private String arch;
-
+
Architecture(String arch) {
this.arch = arch;
}
public enum FSImageType {
standard("standard"), custom("custom");
-
+
private String type;
-
+
FSImageType(String type) {
this.type = type;
}
public String toString() {
return type;
- }
+ }
};
}
\ No newline at end of file