- Reloading property when click modify, create, delete, reset, export-as buttons
- Refresh view(reloading all properies) when click refresh button
Change-Id: If72f3f0886a525f46f9f69466b2b528bda682b5a
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
import org.tizen.emulator.manager.ui.tabfolder.ProfileTabFolder;
import org.tizen.emulator.manager.ui.tabfolder.ProfileTabItem;
import org.tizen.emulator.manager.ui.widgets.ImageButton;
+import org.tizen.emulator.manager.vms.VMProperty;
import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator;
import org.tizen.emulator.manager.vms.helper.RefreshWorker;
if (isClear) {
tabFolder.getSelection().draw();
} else {
- tabFolder.getSelection().redraw();
+ redraw();
}
}
+ public static void refreshVMProperty(VMProperty prop) {
+ prop.reloadProperty();
+ redraw();
+ }
+
+ public static void redraw() {
+ tabFolder.getSelection().redraw();
+ }
+
public void dispose() {
ImageResources.dispose();
ColorResources.dispose();
this.shell = MainDialog.getShell();
}
- public void resetVirtualMachine(VMProperty property) throws VMWorkerException {
+ public boolean resetVirtualMachine(VMProperty property) throws VMWorkerException {
MessageDialog msg = new MessageDialog();
-/*
- try {
- property.getWorker().isRunningNow();
- } catch (VMWorkerException e) {
- msg.openInfoDialog("Not allowed to reset active VMs."
- + StringResources.NEW_LINE
- + e.getMessage());
- return;
- }
-*/
+
if (property.isRunning()) {
msg.openInfoDialog("Not allowed to reset active VMs."
+ StringResources.NEW_LINE
+ "[" + property.getName()
+ "] is running now...");
- return;
+ return false;
}
int response = msg.openSelectionDialog("This VM will be formatted."
+ StringResources.NEW_LINE + "Are you sure you want to continue?");
if (response != SWT.OK) {
- return;
+ return false;
}
property.getWorker().resetVM();
+ return true;
}
public boolean deleteVirtualMachine(VMProperty property) throws VMWorkerException {
public boolean deleteVirtualMachine(VMProperty property, boolean needCheck) throws VMWorkerException {
MessageDialog msg = new MessageDialog();
- /*
- try {
- property.getWorker().isRunningNow();
- } catch (VMWorkerException e) {
- msg.openInfoDialog("Not allowed to delete active VMs."
- + StringResources.NEW_LINE
- + e.getMessage());
- return false;
- }
- */
+
if (property.isRunning()) {
msg.openInfoDialog("Not allowed to delete active VMs."
+ StringResources.NEW_LINE
return true;
}
-
- public void createBaseImage(VMProperty property) throws VMWorkerException {
+
+ public boolean createBaseImage(VMProperty property) throws VMWorkerException {
MessageDialog msg = new MessageDialog();
- /*
- try {
- property.getWorker().isRunningNow();
- } catch (VMWorkerException e) {
- msg.openInfoDialog("Not allowed to 'Export as base image' active VMs."
- + StringResources.NEW_LINE
- + e.getMessage());
- return;
- }
- */
if (property.isRunning()) {
msg.openInfoDialog("Not allowed to 'Exprot as base image' active VMs."
+ StringResources.NEW_LINE
+ "[" + property.getName()
+ "] is running now...");
- return;
+ return false;
}
FileDialog fd = new FileDialog(shell, SWT.SAVE);
String path = null;
path = fd.open();
if (path == null) {
- return;
+ return false;
}
property.getWorker().createNewBaseImage(property, path);
+ return true;
}
public void cloneVirtualMachine(VMProperty property) {
MessageDialog msg = new MessageDialog();
- /*
- try {
- property.getWorker().isRunningNow();
- } catch (VMWorkerException e) {
- msg.openWarningDialog("Not allowed to 'Clone' while source VM is running."
- + StringResources.NEW_LINE
- + e.getMessage());
- return;
- }
- */
if (property.isRunning()) {
msg.openInfoDialog("Not allowed to 'Clone' active VMs."
import org.tizen.emulator.manager.resources.StringResources;
import org.tizen.emulator.manager.ui.dialog.MessageDialog;
import org.tizen.emulator.manager.vms.Creator;
+import org.tizen.emulator.manager.vms.EmulatorVMList;
import org.tizen.emulator.manager.vms.VMProperty;
import org.tizen.emulator.manager.vms.VMPropertyValue;
import org.tizen.emulator.manager.vms.helper.VMLauncherException;
private boolean isCreateMode = false;
private boolean setFocus = false;
- private boolean isNeedRefresh = false;
private static VMsMainView view = new VMsMainView();
public static VMsMainView getInstance() {
return view;
}
}
- if (this.isNeedRefresh()) {
- refreshViewer();
- }
-
- // set focus vm button
- // drawDetailVM(currentImage.getVmsList().indexOf(property));
+ reloadProperty();
redraw();
}
}
setCurrentProperty(prop);
+ //
+ EmulatorVMList.getInstance().addProperty(prop);
+ currentProfile.addEmulator(prop);
+ //
+
+ MainDialog.redraw();
return true;
}
return false;
}
+ MainDialog.refreshVMProperty(currentProperty);
return true;
}
private MenuHandling handling = new MenuHandling();
public boolean createBaseImage() {
try {
- handling.createBaseImage(currentProperty);
+ if (handling.createBaseImage(currentProperty)) {
+ reloadProperty();
+ return true;
+ }
} catch (VMWorkerException e) {
new MessageDialog().openInfoDialog(
"Filaed to export as base image ("
if (e.isNeedRefresh()) {
MainDialog.refreshVMPropertyList(false);
}
- return false;
}
- if (this.isNeedRefresh()) {
- refreshViewer();
- }
-
- return true;
+ return false;
}
public boolean deleteEmulator() {
public boolean deleteEmulator(boolean needCheck) {
try {
if (handling.deleteVirtualMachine(currentProperty, needCheck)) {
- currentProperty = null;
- MainDialog.refreshVMPropertyList(false);
+ int index = currentProfile.getEmulatorList().indexOf(currentProperty) - 1;
+ currentProfile.getEmulatorList().remove(currentProperty);
+ currentProperty = (index < 0 ? null : currentProfile.getEmulatorList().get(index));
+ MainDialog.redraw();
+ return true;
}
} catch (VMWorkerException e) {
new MessageDialog().openWarningDialog(
if (e.isNeedRefresh()) {
MainDialog.refreshVMPropertyList(false);
}
- return false;
}
- return true;
+
+ return false;
}
public boolean resetEmulator() {
try {
- handling.resetVirtualMachine(currentProperty);
+ if (handling.resetVirtualMachine(currentProperty)) {
+ reloadProperty();
+ return true;
+ }
} catch (VMWorkerException e) {
new MessageDialog().openInfoDialog(
"Failed to reset Emulator ("
}
}
- if (this.isNeedRefresh()) {
- refreshViewer();
- }
-
- return true;
- }
-
- public boolean isNeedRefresh() {
- return isNeedRefresh;
- }
-
- public void setNeedRefresh(boolean isNeedRefresh) {
- this.isNeedRefresh = isNeedRefresh;
+ return false;
}
- public void refreshViewer() {
- if (isNeedRefresh) {
- MainDialog.refreshVMPropertyList(false);
- isNeedRefresh = false;
+ public void reloadProperty() {
+ if (getCurrentProperty().getWorker().isModified()) {
+ MainDialog.refreshVMProperty(currentProperty);
String msg = "Emulator proerty is reloaded, because emulator property had beend modified by other emulator manager.";
EMLogger.getLogger().info(msg);
MainDialog.getStatusBar().info(msg);
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
-import org.tizen.emulator.manager.platform.CustomBaseImage;
import org.tizen.emulator.manager.platform.Platform;
import org.tizen.emulator.manager.plugin.ExtensionItem;
import org.tizen.emulator.manager.resources.ColorResources;
static void modify(VMProperty property, VMPropertyValue newVM) throws VMWorkerException {
VMPropertyValue oldVM = property.getPropertyValue();
if(oldVM.equals(newVM)) {// if nothing if modified...
- return;
+ throw new VMWorkerException("Value of new property is the same value of saved property.");
}
modifyFileShare(newVM);
if (!newVM.resolution.equals(oldVM.resolution)) {
private boolean isRunning = false;
- public void setPropertyValue(VMPropertyValue value) {
- this.value = value;
- }
-
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
+ /**
+ * Create a new VMProperty instance from xml property file and xml configuration
+ * @param propertyFile property file saved in data directory
+ * @param element xml configuration of property file
+ */
public VMProperty(File propertyFile, EmulatorConfiguration element) {
this.propertyFile = propertyFile;
this.lastModified = propertyFile.lastModified();
this.configuration = element;
}
+ /**
+ * Creates a new VMProperty instance from default value
+ * This is used for creating new emulator
+ * @param value default value of emulator
+ */
+ public VMProperty(VMPropertyValue value) {
+ this.value = value;
+ }
+
public void initVMWorker() {
ExtensionItem item = null;
if (getPropertyValue().baseImage == null) {
}
- // TODO
- public VMProperty(VMPropertyValue value) {
- this.value = value;
+ public void reloadProperty() {
+ this.configuration = EmulatorVMList.getInstance().parseXML(this);
+ this.lastModified = propertyFile.lastModified();
+
+ this.value.settingConfigure(this);
}
public VMPropertyValue getPropertyValue() {
this.value = new VMPropertyValue(this);
}
return value;
- //return new VMsPropertyValue(this); // FIXME
+ }
+
+ public void setPropertyValue(VMPropertyValue value) {
+ this.value = value;
}
public File getPropertyFile() {
return worker;
}
+ public boolean isRunning() {
+ return isRunning;
+ }
+ public void setRunning(boolean isRunning) {
+ this.isRunning = isRunning;
+ }
+
+ public EmulatorConfiguration getConfiguration() {
+ return configuration;
+ }
+
public String getName() {
if(configuration == null
|| configuration.getBaseInformation() == null) {
return true;
}
- public EmulatorConfiguration getConfiguration() {
- return configuration;
- }
-
- public boolean isRunning() {
- return isRunning;
- }
- public void setRunning(boolean isRunning) {
- this.isRunning = isRunning;
- }
-
public void setCPU(int cpu, boolean isCreateElement) {
if (configuration != null) {
if (isCreateElement && configuration.getDevice().getCPU() == null) {
private VMPropertyValue(){} // for clone
+ /**
+ * Constructs a new VMPropertyValue by using base image.
+ * This is used for creating new emulator.
+ * @param image base image of emulator
+ */
public VMPropertyValue(BaseImage image) {
this(image, image.getDefaultProperty());
}
+ /**
+ * Constructs a new VMPropertyValue by using base image and property.
+ * This is used for creating new emulator.
+ * @param image base image of emulator
+ * @param template default property of emulator
+ */
public VMPropertyValue(BaseImage image, VMProperty template) {
- this.baseImage = image;
- this.template = template;
+ assert image == null;
+
+ if (image == null) {
+ return;
+ }
+
+ this.baseImage = image;
+ this.template = template;
vmsName = "";
- if (this.baseImage == null) {
- isStandard = false;
- settingDefault(isStandard, template);
- } else {
- baseImagePath = image.getPath();
- baseImagePathName = image.getPathName();
- archType = image.getCpu();
- profile = image.getProfile();
- version = image.getVersion();
- baseName = image.getName();
- skinShape = image.getSkinShape();
-
- if (image instanceof CustomBaseImage) {
- isStandard = false;
- if (template != null &&
- template.getConfiguration().getBaseInformation().getDiskImage().getBaseDiskImage() != null) {
- if (baseImagePath == null) {
- baseImagePath = template.getPropertyValue().baseImagePath;
- }
- if (baseImagePathName == null) {
- baseImagePathName = template.getPropertyValue().baseImagePathName;
- }
- baseName = template.getConfiguration().getBaseInformation().getDiskImage().getBase();
- }
- } else {
- isStandard = true;
- }
+ baseImagePath = image.getPath();
+ baseImagePathName = image.getPathName();
+ archType = image.getCpu();
+ profile = image.getProfile();
+ version = image.getVersion();
+ baseName = image.getName();
+ skinShape = image.getSkinShape();
- settingConfigure(template);
+ if (image instanceof CustomBaseImage) {
+ isStandard = false;
+ } else {
+ isStandard = true;
}
+
+ settingConfigure(template);
}
+ /**
+ * Constructs a new VMPropertyValue by using property.
+ * This property is saved property of emulator in data directory
+ * @param property property of emulator
+ */
public VMPropertyValue(VMProperty property) {
assert property == null;
if (property != null) {
this.template = property;
- vmsName = property.getName();
- archType = property.getArch().toString();
- // TODO
+ vmsName = property.getName();
+ archType = property.getArch().toString();
+
if (property.getImageProfile() != null) {
profile = property.getImageProfile();
} else {
dest.extendedOptions.addAll(this.extendedOptions);
cloneAdvancedOptions(dest.advancedOptionList);
-// dest.advancedOptionList.addAll(this.advancedOptionList);
return dest;
}
return true;
}
- private void settingConfigure(VMProperty property) {
+ void settingConfigure(VMProperty property) {
if (property == null) {
- settingConfigure();
return;
}
+
Resolution re = null;
for (RESOLUTION d : RESOLUTION.values()) {
re = property.getConfiguration().getDevice().getDisplay().getResolution();
}
- private void settingConfigure() {
- // HD(720x1280)
- resolution = RESOLUTION.HD;
- dpi = RESOLUTION.HD.getDPI(); // this value be related to resolution
-
- skinPath = null;
-
- keyType = 1;
- //
-
- ramSize = RAM_SIZE.RAM512.getSize();
-
- cpu = 1;
-
- isFileShareSupport = false;
- fileSharePath = "";
- fileSharePathName = StringResources.None;
-
- isHWVirtualization = CheckVirtualization.getInstance().isSupportVirtualization();
- isGLAcceleration = CheckVirtualization.getInstance().isSupportGPU();
-
- maxTouchCount = maxTouch;
-
- addOptions = null;
- ociOptions = null;
-
- isSupportSuspend = false;
- extendedOptions = new ArrayList<ExtendedOptionType>();
- }
-
- private void settingDefault(boolean isStandard, VMProperty template) {
- vmsName = "";
- archType = isStandard ? template.getArch().toString() : "x86";
-
- baseImagePath = "";
- baseImagePathName = isStandard ? (archType.equals("x86") ? "( emulimg.x86 )" : "( emulimg.arm )") : StringResources.None;
- // TODO
- profile = PlatformStringResources.MobileProfile;
-
- settingConfigure(template);
- }
-
public OptionType getAdvancedOption(String optionName) {
for (OptionType option : advancedOptionList) {
if (option.getName().equals(optionName)) {
import org.tizen.emulator.manager.logging.EMLogger;
import org.tizen.emulator.manager.resources.FilePathResources;
import org.tizen.emulator.manager.resources.StringResources;
-import org.tizen.emulator.manager.ui.VMsMainView;
import org.tizen.emulator.manager.vms.helper.CheckingRunningEmulator;
import org.tizen.emulator.manager.vms.helper.QemuImgProc;
import org.tizen.emulator.manager.vms.helper.VMLauncherException;
private String baseImagePartPath = null;
private Object lock = new Object();
private ILauncher launcher;
+ private boolean isModified;
public void sendRemoteLog(String msg) {
true);
}
- if (isModified()) {
+ checkPropertyModification();
+ if (isModified) {
property = EmulatorVMList.getInstance().parseXML(
property.getPropertyFile());
if (property == null) {
throw new VMWorkerException(
"Failed to load modified property.", true);
}
- if (!EmulatorManager.isConsoleMode()) {
- VMsMainView.getInstance().setNeedRefresh(true);
- }
}
// Do argument validation.
}
} catch (VMWorkerException e) {
- if (!EmulatorManager.isConsoleMode()) {
- VMsMainView.getInstance().setNeedRefresh(false);
- }
throw e;
} finally {
// lock.release
true);
}
- // TODO
- if (isModified()) {
+ checkPropertyModification();
+ if (isModified) {
throw new VMWorkerException(
"This VM had been modified by other emulator manager.",
true);
true);
}
- // TODO
- if (isModified()) {
- if (!EmulatorManager.isConsoleMode()) {
- VMsMainView.getInstance().setNeedRefresh(true);
- }
- }
-
+ checkPropertyModification();
isRunningNow();
baseImagePath = dest;
}
}
} catch (VMWorkerException e) {
- if (!EmulatorManager.isConsoleMode()) {
- VMsMainView.getInstance().setNeedRefresh(false);
- }
throw e;
} finally {
// lock.release
WorkerLock.release();
}
+ // TODO: This code will be moved console source
if (EmulatorManager.isConsoleMode()) {
System.out.println("Wait....while creating base image."
+ StringResources.NEW_LINE
true);
}
- if (isModified()) {
- if (!EmulatorManager.isConsoleMode()) {
- VMsMainView.getInstance().setNeedRefresh(true);
- }
- }
-
+ checkPropertyModification();
isRunningNow();
String basePath = property.getConfiguration().getBaseInformation()
Creator.createSwapImage(swapBasePath, swapTargetPath);
}
} catch (VMWorkerException e) {
- VMsMainView.getInstance().setNeedRefresh(false);
throw e;
} finally {
// lock.relese
Creator.create(newValue);
}
- public boolean isModified() {
+ private void checkPropertyModification() {
if (property.getLastModifedPropertyFile() != property.getPropertyFile()
.lastModified()) {
- return true;
+ this.isModified = true;
}
-
- return false;
+ this.isModified = false;
}
// check if the emulator instance with the same name is running now.
}
}
- // Remove directory files recursively.
- // Return false if one or more files fail to delete.
+ /**
+ * Remove directory files recursively.
+ * @param file vm property directory path
+ * @return Return false if one or more files fail to delete.
+ */
public static boolean deleteFile(File file) {
boolean result = true;
if (!file.exists()) {
return result;
}
+
+ /**
+ * If property had been modified by other emulator manager(cli),
+ * this method will be return true.
+ * @return return true if property had been modified
+ */
+ public boolean isModified() {
+ return isModified;
+ }
}
/*