From: jihye424.kim Date: Mon, 7 Sep 2015 04:44:11 +0000 (+0900) Subject: VMListTable: add sorting table items function to table column X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e30ebb3c5d6c8718cb1ad212a9c8755a0071d5ed;p=sdk%2Femulator%2Femulator-manager.git VMListTable: add sorting table items function to table column - 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 --- diff --git a/src/org/tizen/emulator/manager/platform/Profile.java b/src/org/tizen/emulator/manager/platform/Profile.java index e7989d5..5360b29 100644 --- a/src/org/tizen/emulator/manager/platform/Profile.java +++ b/src/org/tizen/emulator/manager/platform/Profile.java @@ -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 { 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 index 0000000..652317e --- /dev/null +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ItemProfilePair.java @@ -0,0 +1,57 @@ +/* + * Emulator Manager + * + * Copyright (C) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: + * JiHye Kim + * Minkee Lee + * SeokYeon Hwang + * Sangho Park + * + * 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; + } + } + +} diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButton.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButton.java index 28842bc..1273d10 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButton.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/ProfileButton.java @@ -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); + } } } diff --git a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java index 51d57be..97d0bc6 100644 --- a/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java +++ b/src/org/tizen/emulator/manager/ui/renewal/tableviewer/VMListTable.java @@ -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); + } }); }