[Title] Cleanup and refactoring code
authorsyeon.hwang <syeon.hwang@samsung.com>
Fri, 23 Mar 2012 12:07:34 +0000 (21:07 +0900)
committersyeon.hwang <syeon.hwang@samsung.com>
Fri, 23 Mar 2012 12:07:34 +0000 (21:07 +0900)
[Type]
[Module] Emulator/
[Priority]
[CQ#]
[Redmine#]
[Problem]
[Cause]
[Solution]
[TestCase]

src/org/tizen/emulator/manager/ui/ArchitectureGroup.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/MainDialog.java
src/org/tizen/emulator/manager/ui/vmstree/VMsTree.java [moved from src/org/tizen/emulator/manager/ui/vmstree/VMsTable.java with 71% similarity]

diff --git a/src/org/tizen/emulator/manager/ui/ArchitectureGroup.java b/src/org/tizen/emulator/manager/ui/ArchitectureGroup.java
new file mode 100644 (file)
index 0000000..4d98f6c
--- /dev/null
@@ -0,0 +1,56 @@
+package org.tizen.emulator.manager.ui;
+
+import org.eclipse.swt.SWT;
+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.Group;
+import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
+
+public class ArchitectureGroup {
+       MainDialog dialog;
+       Group group;
+       Button x86RadioButton;
+       Button armRadioButton;
+       
+
+       public ArchitectureGroup(final MainDialog dialog, Composite archComposite) {
+               this.dialog = dialog;
+               
+               group = new Group(archComposite, SWT.NONE);
+               
+               group.setText("Emulator Architecture");
+               group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+               group.setLayout(new GridLayout(2, false));
+
+               x86RadioButton = new Button(group, SWT.RADIO);
+               x86RadioButton.setData(Architecture.x86);
+               x86RadioButton.setText("X86");
+               x86RadioButton.setSelection(true);
+
+               armRadioButton = new Button(group, SWT.RADIO);
+               armRadioButton.setData(Architecture.ARM);
+               armRadioButton.setText("ARM");
+               armRadioButton.setSelection(false);
+               // TODO : not support ARM
+               armRadioButton.setEnabled(false);
+
+               SelectionListener archSelectionListener = new SelectionListener() {
+                       @Override
+                       public void widgetSelected(SelectionEvent e) {
+                               dialog.refreshVMsTable();
+                       }
+                       @Override
+                       public void widgetDefaultSelected(SelectionEvent e) {
+                               dialog.refreshVMsTable();
+                       }
+
+               };
+
+               x86RadioButton.addSelectionListener(archSelectionListener);
+               armRadioButton.addSelectionListener(archSelectionListener);
+       }
+}
index 7732d47..e7ffba5 100644 (file)
@@ -12,7 +12,6 @@ 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.Group;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.MessageBox;
 import org.eclipse.swt.widgets.Shell;
@@ -20,11 +19,10 @@ import org.tizen.emulator.manager.EmulatorManager;
 import org.tizen.emulator.manager.tool.Launcher;
 import org.tizen.emulator.manager.ui.ResourceRegistry.ImageName;
 import org.tizen.emulator.manager.ui.detail.DetailTableView;
-import org.tizen.emulator.manager.ui.vmstree.VMsTable;
+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;
-import org.tizen.emulator.manager.vms.VMsProperty.Architecture;
 
 public class MainDialog {
        private static String Launch  = "Launch";
@@ -33,13 +31,11 @@ public class MainDialog {
        private static String Cancel  = "Cancel";
        private static String Confirm = "Confirm";
 
-       public Button x86RadioButton;
-       public Button armRadioButton;
-       
        private SashForm sashForm;
+       private ArchitectureGroup archGroup;
        
        // LEFT VIEW
-       private VMsTable imageListTable;
+       private VMsTree vmsTree;
        private Button deleteButton;
        private Button resetButton;
 
@@ -64,46 +60,19 @@ public class MainDialog {
                        Composite archComposite = new Composite(mainComposite, SWT.NONE);
                        archComposite.setLayout(new GridLayout(1, false));
                        archComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-                       Group architectureGroup = new Group(archComposite, SWT.NONE);
-                       architectureGroup.setText("Emulator Architecture");
-                       architectureGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-                       architectureGroup.setLayout(new GridLayout(2, false));
-
-                       x86RadioButton = new Button(architectureGroup, SWT.RADIO);
-                       x86RadioButton.setData(Architecture.x86);
-                       x86RadioButton.setText("X86");
-                       x86RadioButton.setSelection(true);
-
-                       armRadioButton = new Button(architectureGroup, SWT.RADIO);
-                       armRadioButton.setData(Architecture.ARM);
-                       armRadioButton.setText("ARM");
-                       armRadioButton.setSelection(false);
-                       // TODO : not support ARM
-                       armRadioButton.setEnabled(false);
+                       
+                       archGroup = new ArchitectureGroup(this, archComposite);
 
                        sashForm = new SashForm(mainComposite, SWT.HORIZONTAL);
                        sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
                        sashForm.setLayout(new FillLayout());
-                       // Left : VMs Table
+                       // Left : VMs tree
                        {
                                final Composite leftView = new Composite(sashForm, SWT.FILL);
                                GridLayout layout = getNopaddedGridLayout();
                                leftView.setLayout(layout);
 
-                               imageListTable = new VMsTable(this, leftView);
-                               SelectionListener archSelectionListener = new SelectionListener() {
-                                       @Override
-                                       public void widgetSelected(SelectionEvent e) {
-                                               imageListTable.refreshTableList();
-                                       }
-                                       @Override
-                                       public void widgetDefaultSelected(SelectionEvent e) {
-                                               imageListTable.refreshTableList();
-                                       }
-
-                               };
-                               x86RadioButton.addSelectionListener(archSelectionListener);
-                               armRadioButton.addSelectionListener(archSelectionListener);
+                               vmsTree = new VMsTree(this, leftView);
 
                                Composite buttonComposite = new Composite(leftView, SWT.NONE);
                                buttonComposite.setLayoutData(new GridData(SWT.FILL, SWT.BOTTOM, true, false));
@@ -231,7 +200,7 @@ public class MainDialog {
        }
 
        public void resetVirtualMachine() {
-               ArrayList<VMsProperty> list = imageListTable.getSelectionItem();
+               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?");
@@ -266,7 +235,7 @@ public class MainDialog {
 
        // TOOD : error checking
        public void deleteVirtualMachine() {
-               ArrayList<VMsProperty> list = imageListTable.getSelectionItem();
+               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?");       
@@ -301,9 +270,13 @@ public class MainDialog {
                }
        }
 
+       public void refreshVMsTable() {
+               vmsTree.refreshContents();
+       }
+       
        public void refreshProperties() {
                EmulatorVMs.getInstance().refreshProperties();
-               imageListTable.refreshTableList();
+               vmsTree.refreshContents();
        }
        
        public int[] getSashFormWeight() {
@@ -329,7 +302,7 @@ public class MainDialog {
        }
 
        public void closeDetailView() {
-               if (imageListTable.getSelectionContentCount() > 1) {
+               if (vmsTree.getSelectionContentCount() > 1) {
                        deleteButton.setEnabled(true);
                } else {
                        deleteButton.setEnabled(false);
@@ -410,4 +383,8 @@ public class MainDialog {
                
                return layout;
        }
+
+       public boolean isX86Selected() {
+               return archGroup.x86RadioButton.getSelection();
+       }
 }
@@ -17,10 +17,9 @@ import org.tizen.emulator.manager.EmulatorManager;
 import org.tizen.emulator.manager.ui.MainDialog;
 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.VMsProperty.FSImageType;
 
-public class VMsTable {
+public class VMsTree {
        MainDialog mainDialog;
 
        Tree vmsTree;
@@ -28,7 +27,7 @@ public class VMsTable {
 
        EmulatorVMs fsImage = EmulatorVMs.getInstance();
 
-       public VMsTable(MainDialog mainDialog, Composite parent) {
+       public VMsTree(MainDialog mainDialog, Composite parent) {
                this.mainDialog = mainDialog;
 
                this.vmsTree = new Tree(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
@@ -47,7 +46,7 @@ public class VMsTable {
                        }
                }
 
-               refreshTableList();
+               refreshContents();
                pack();
 
                contextMenu.prepare(vmsTree);
@@ -61,7 +60,7 @@ public class VMsTable {
                                        return;
 
                                if(vmsTree.getSelectionCount() > 1) {
-                                       VMsTable.this.mainDialog.closeDetailView();
+                                       VMsTree.this.mainDialog.closeDetailView();
                                }
                                else {
                                        Object data = vmsTree.getSelection()[0].getData();
@@ -71,20 +70,20 @@ public class VMsTable {
 
                                        if (vmsTree.getSelection()[0].getData() instanceof CreateMarker) {
                                                if (vmsTree.getSelection()[0].getParentItem().getText().equals("Custom")) {
-                                                       VMsTable.this.mainDialog.openCreateDetailView(false);
+                                                       VMsTree.this.mainDialog.openCreateDetailView(false);
                                                } else {
-                                                       VMsTable.this.mainDialog.openCreateDetailView(true);
+                                                       VMsTree.this.mainDialog.openCreateDetailView(true);
                                                }
                                                return;
                                        }
 
                                        if(vmsTree.getSelection()[0].getData() instanceof TreeMarker) {
-                                               VMsTable.this.mainDialog.closeDetailView();
+                                               VMsTree.this.mainDialog.closeDetailView();
                                                return;
                                        }
 
                                        PropertyContent content = (PropertyContent)data;
-                                       VMsTable.this.mainDialog.openDetailView(content.property);
+                                       VMsTree.this.mainDialog.openDetailView(content.property);
                                }
                        }
 
@@ -109,13 +108,12 @@ public class VMsTable {
                vmsTree.pack();
        }
 
-       public void refreshTableList() {
-               refreshTableList(null);
+       public void refreshContents() {
+               refreshContents(null);
        }
 
-       private void refreshTableList(String text) {
-               boolean x86Selected = mainDialog.x86RadioButton.getSelection();
-               boolean armSelected = mainDialog.armRadioButton.getSelection();
+       private void refreshContents(String text) {
+//             boolean x86Selected = mainDialog.isX86Selected();
 
                vmsTree.removeAll();
 
@@ -147,37 +145,34 @@ public class VMsTable {
                //
                //
                for(int i = 0; i < properties.length; ++i) {
-                       if((properties[i].getArch() == Architecture.x86 && x86Selected) ||
-                                       (properties[i].getArch() == Architecture.ARM && armSelected)){
-                               if(text != null && !properties[i].getName().startsWith(text)) {
-                                       continue;
-                               }
+                       if(text != null && !properties[i].getName().startsWith(text)) {
+                               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);
-                                       if(propertyItem == null) {
-                                               propertyItem = new TreeItem(vmsTree, SWT.NONE);
-                                               rowItem = new StandardVMsMarker(version, propertyItem);
-                                               propertyItem.setData(rowItem);
+                       if(FSImageType.standard == properties[i].getImageType()) {
+                               String version = properties[i].getConfiguration().getBaseInformation().getDiskImage().getVersion();
+                               propertyItem = itemsMap.get(version);
+                               if(propertyItem == null) {
+                                       propertyItem = new TreeItem(vmsTree, SWT.NONE);
+                                       rowItem = new StandardVMsMarker(version, propertyItem);
+                                       propertyItem.setData(rowItem);
 
-                                               itemsMap.put(version, propertyItem);
+                                       itemsMap.put(version, propertyItem);
 
-                                               createItem = new TreeItem(propertyItem, SWT.NONE);
-                                               rowItem = new CreateMarker(createItem);
-                                               createItem.setData(rowItem);
-                                       }
-                                       propertyItem = new TreeItem(propertyItem, SWT.NONE);
-                               }
-                               else {
-                                       propertyItem = new TreeItem(customItem, SWT.NONE);
+                                       createItem = new TreeItem(propertyItem, SWT.NONE);
+                                       rowItem = new CreateMarker(createItem);
+                                       createItem.setData(rowItem);
                                }
-
-                               rowItem = new PropertyContent(properties[i], propertyItem);
-                               propertyItem.setData(rowItem);
+                               propertyItem = new TreeItem(propertyItem, SWT.NONE);
                        }
+                       else {
+                               propertyItem = new TreeItem(customItem, SWT.NONE);
+                       }
+
+                       rowItem = new PropertyContent(properties[i], propertyItem);
+                       propertyItem.setData(rowItem);
                }
 
                createItem.setExpanded(true);