VMListTable: add sorting table items function to table column
authorjihye424.kim <jihye424.kim@samsung.com>
Mon, 7 Sep 2015 04:44:11 +0000 (13:44 +0900)
committerjihye424.kim <jihye424.kim@samsung.com>
Tue, 8 Sep 2015 05:11:04 +0000 (14:11 +0900)
- profile image column is sorted using profile's priority
- add priority variable to 'Profile' class
- profile's priority: mobile -> wearable -> tv

Change-Id: Ifb9ffaaa266a38d6d17b517058ffa99f5d344c7d
Signed-off-by: jihye424.kim <jihye424.kim@samsung.com>
src/org/tizen/emulator/manager/platform/Profile.java
src/org/tizen/emulator/manager/ui/renewal/tableviewer/ItemProfilePair.java [new file with mode: 0644]
src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButton.java
src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java

index e7989d5..5360b29 100644 (file)
@@ -54,6 +54,7 @@ public class Profile {
        private boolean isSortVMList = false;
 
        private boolean isSortPlatformList = false;
+       private int priority = 10;
 
        public Profile(String name) {
                this.name = name;
@@ -260,6 +261,14 @@ public class Profile {
                }
        }
 
+       public int getPriority() {
+               return priority;
+       }
+
+       public void setPriority(int priority) {
+               this.priority = priority;
+       }
+
        static class PlatformPair implements Comparable<Object> {
                Platform prop;
 
diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ItemProfilePair.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ItemProfilePair.java
new file mode 100644 (file)
index 0000000..652317e
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Emulator Manager
+ *
+ * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:
+ * JiHye Kim <jihye424.kim@samsung.com>
+ * Minkee Lee <minkee.lee@samsung.com>
+ * SeokYeon Hwang <syeon.hwang@samsung.com>
+ * Sangho Park <sangho.p@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ */
+
+package org.tizen.emulator.manager.ui.renewal.tableviewer;
+
+import org.eclipse.swt.SWT;
+import org.tizen.emulator.manager.platform.Profile;
+import org.tizen.emulator.manager.ui.table.TableItem;
+import org.tizen.emulator.manager.ui.table.TableItemComparable;
+import org.tizen.emulator.manager.vms.VMProperty;
+
+public class ItemProfilePair extends TableItemComparable {
+       private int priority;
+       public ItemProfilePair(TableItem item, int index, int direction) {
+               super(item, index, direction);
+               Profile profile = ((VMProperty)item.getData()).getPropertyValue().baseImage.getPlatform().getProfileClass();
+               priority = profile.getPriority();
+       }
+
+       @Override
+       public int compareTo(Object o) {
+               int targetPriority = ((ItemProfilePair)o).priority;
+
+               if (direction == SWT.UP) {
+                       return priority > targetPriority ? -1 : 1;
+               } else {
+                       return priority < targetPriority ? -1 : 1;
+               }
+       }
+
+}
index 28842bc..1273d10 100644 (file)
@@ -60,6 +60,15 @@ public class ProfileButton {
 
                if (profile.getName().equals(profileName)) {
                        this.profile = profile;
+                       // set profile priority
+                       // mobile > wearable > tv
+                       if (profileName.equals("mobile")) {
+                               this.profile.setPriority(0);
+                       } else if (profileName.equals("wearable")) {
+                               this.profile.setPriority(1);
+                       } else if (profileName.equals("tv")) {
+                               this.profile.setPriority(3);
+                       }
                }
        }
 
index 51d57be..97d0bc6 100644 (file)
@@ -132,6 +132,29 @@ public class VMListTable {
                                        tableSelected();
                                }
                        }
+               });
+
+               table.getColumn(2).addListener(SWT.Selection, table.getDefaultSortListener());
+               table.getColumn(3).addListener(SWT.Selection, table.getDefaultSortListener());
+               table.getColumn(4).addListener(SWT.Selection, table.getDefaultSortListener());
+               table.getColumn(5).addListener(SWT.Selection, table.getDefaultSortListener());
+               table.getColumn(1).addListener(SWT.Selection, new Listener() {
+
+                       @Override
+                       public void handleEvent(Event event) {
+                               TableColumn column = (TableColumn)event.widget;
+                               // set column
+                               table.settingSortColumn(column);
+                               // make item compareable list
+                               int dir = table.getSortDirection();
+                               ItemProfilePair[] pairs = new ItemProfilePair[table.getItemCount()];
+                               for (int i = 0; i < table.getItemCount(); i++) {
+                                       pairs[i] = new ItemProfilePair(table.getItem(i), 1, dir);
+                               }
+                               column.setTableItemPairs(pairs);
+                               // sort table item
+                               table.defaultSortTableItem(column);
+                       }
 
                });
        }