public static Image CHECKBOX_UNCHECKED_NML = getImage("btn_checkbox_unchecked_nml", "png");
public static Image CHECKBOX_CHECKED_HOVER = getImage("btn_checkbox_checked_hover", "png");
public static Image CHECKBOX_CHECKED_NML = getImage("btn_checkbox_checked_nml", "png");
- public static Image SORT_INDICATOR_UP = getImage("up", "png");
- public static Image SORT_INDICATOR_DOWN = getImage("down", "png");
+ public static Image SORT_INDICATOR_UP = getImage("icon_column_up", "png");
+ public static Image SORT_INDICATOR_DOWN = getImage("icon_column_down", "png");
public static Image getImage(String name, String extension) {
Image i = null;
package org.tizen.emulator.manager.ui.table;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.swt.SWT;
if (length != 0 && ((getStyle() & SWT.SINGLE) == 0
|| length <= 1)) {
setFocusIndex(indices[0]);
+ rearrangeItems(indices[0]);
}
-
- rearrangeItems(indices[0]);
}
public void setSelection(TableItem[] items) {}
if (column != null && column.isDisposed()) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
+ TableColumn backupSortColumn = sortColumn;
sortColumn = column;
+
+ if (backupSortColumn != null) {
+ backupSortColumn.redraw();
+ }
}
public int getSortDirection() {
return sortDirection;
}
+ /**
+ * SWT.UP: ascending order
+ * SWT.DOWN: descending order
+ * SWT.NONE
+ * @param direction
+ */
public void setSortDirection(int direction) {
checkWidget();
if ((direction & (SWT.UP | SWT.DOWN)) != 0
}
};
+ static class ItemStringPair extends TableItemComparable {
+ public ItemStringPair(TableItem item, int index, int direction) {
+ super(item, index, direction);
+ }
+
+ @Override
+ public int compareTo(Object o) {
+ TableItem target = ((ItemStringPair)o).item;
+ String targetStr = target.getText(index);
+ String sourceStr = item.getText(index);
+
+ if (direction == SWT.UP) {
+ return sourceStr.compareTo(targetStr);
+ } else {
+ return targetStr.compareTo(sourceStr);
+ }
+ }
+ }
+
private Listener sortListener = new Listener() {
@Override
public void handleEvent(Event event) {
TableColumn column = (TableColumn)event.widget;
- int index = columns.indexOf(column);
- if (index == -1) {
- return;
- }
+ settingSortColumn(column);
+ defaultSortTableItem(column);
+ }
+ };
- int dir = getSortDirection();
+ public void settingSortColumn(TableColumn column) {
- if (getSortColumn() != column) {
- setSortColumn(column);
- dir = SWT.UP;
- }
+ int dir = getSortDirection();
+ if (dir == SWT.DOWN || dir == SWT.NONE) {
+ dir = SWT.UP;
+ } else {
+ dir = SWT.DOWN;
+ }
- TableItem[] newItems = new TableItem[itemCount];
- int[] newSelection = new int[selection.length];
- newItems[0] = items[0];
- for (int i = 1; i < items.length; i++) {
- if (items[i] == null) {
- continue;
- }
- String value1 = items[i].getText(index);
- if (value1 == null) {
- continue;
- }
- int j = i - 1;
-
- while (j >= 0) {
- String value2 = newItems[j].getText(index);
- int compare = value1.compareTo(value2);
- if (compare < 0 && dir == SWT.UP) {
- newItems[j + 1] = newItems[j];
- j--;
- } else if (compare > 0 && dir == SWT.DOWN){
- newItems[j + 1] = newItems[j];
- j--;
- } else {
- break;
- }
- }
- newItems[j + 1] = items[i];
- }
- adjustItemIndices(0);
+ // set new sort column
+ if (getSortColumn() != column) {
+ setSortColumn(column);
+ dir = SWT.UP;
+ }
- for (int in = 0; in < selection.length; in++) {
- TableItem item = items[selection[in]];
- for (int i = 0; i < newItems.length; i++) {
- if (newItems[i] == item) {
- newSelection[in] = i;
- break;
- }
- }
+ setSortDirection(dir);
+ }
+
+ public void defaultSortTableItem(TableColumn column) {
+ int index = columns.indexOf(column);
+ if (index == -1) {
+ return;
+ }
+
+ TableItem[] newItems = new TableItem[itemCount];
+ int dir = getSortDirection();
+
+ TableItemComparable[] pairs = column.getTableItemPairs();
+ if (pairs == null || pairs.length != itemCount) {
+ pairs = new ItemStringPair[itemCount];
+ for (int i = 0; i < itemCount; i++) {
+ pairs[i] = new ItemStringPair(items[i], index, dir);
}
- items = newItems;
- dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
- setSortDirection(dir);
- setSelection(newSelection);
- showSelection();
}
- };
- public Listener getDifaultSortListener() {
+ Arrays.sort(pairs);
+
+ for (int i = 0; i < itemCount; i++) {
+ newItems[i] = pairs[i].getTableItem();
+ }
+
+ items = newItems;
+ adjustItemIndices(0);
+
+ showSelection();
+ }
+
+ public Listener getDefaultSortListener() {
checkWidget();
return sortListener;
}
public class TableColumn extends Canvas {
private static final int SORT_INDICATOR_WIDTH = 10;
+ private static final int SORT_INDICATOR_SPACING = 2;
private static final int SPACING = 5;
+ private static final int LINE_WIDTH = 1;
// minimum size
private static final int RESIZABLE_WIDTH = 10;
- private static final int MIN_WIDTH = 20;
+ private static final int MIN_WIDTH = 30;
private static final int HEADERPADDING_WIDTH = 30;
private final Table parent;
private String drawingText;
private boolean needRedrawingText = true;
- //private SortButton sortButton;;
private Image sortIndicator;
public TableColumn(Table parent, int style) {
gc.setForeground(ColorResources.DEFAULT_STROKE);
gc.setLineWidth(1);
- gc.drawLine(rect.width-1, 0, rect.width-1, rect.height);
+ gc.drawLine(rect.width - LINE_WIDTH , 0, rect.width - LINE_WIDTH, rect.height);
gc.setForeground(isHoverState ? selectedForeground : foreground);
if (parent.getSortColumn() == this) {
// sort column
- int x = rect.x + (rect.width - SORT_INDICATOR_WIDTH - SPACING);
+ int x = rect.x + (rect.width - SORT_INDICATOR_WIDTH - SORT_INDICATOR_SPACING);
if (parent.getSortDirection() == SWT.UP) {
sortIndicator = ImageResources.SORT_INDICATOR_UP;
} else if (parent.getSortDirection() == SWT.DOWN){
}
if (sortIndicator != null) {
Rectangle bounds = sortIndicator.getBounds();
- //sortButton.setBounds(x, 0, SORT_INDICATOR_WIDTH, rect.height);
gc.drawImage(sortIndicator, x, rect.y + (rect.height- bounds.height) / 2);
}
}
+
if (image != null || !text.isEmpty()) {
//
int imageX = rect.x;
int textX = rect.x;
int imageY = 0;
int textY = 0;
+ int width = rect.width;
+ if (sortIndicator != null) {
+ width -= SORT_INDICATOR_WIDTH - SORT_INDICATOR_SPACING;
+ }
Point imageEX = new Point(0, 0);
if (image != null) {
if (needRedrawingText) {
int textWidth = TextSizeUtil.textExtent(getFont(), text);
drawingText = text;
- if (textWidth > (rect.width - imageEX.x - 10)) {
- while (textWidth > (rect.width - 10) - TextSizeUtil.OMITLEN && drawingText.length() > 1) {
+ if (textWidth > (width - imageEX.x - 10)) {
+ while (textWidth > (width - 10) - TextSizeUtil.OMITLEN && drawingText.length() > 1) {
drawingText = drawingText.substring(0, drawingText.length() - 1);
textWidth = TextSizeUtil.textExtent(getFont(), drawingText);
}
break;
case SWT.RIGHT:
imageX += (image != null
- ? rect.width - imageEX.x - SPACING - textWidth - 10
- : rect.width - textWidth - 10);
+ ? width - imageEX.x - SPACING - textWidth - 10
+ : width - textWidth - 10);
textX += imageX + imageEX.x + SPACING;
break;
case SWT.CENTER:
imageX += (image != null
- ? rect.x + ((rect.width - image.getImageData().width - textWidth) / 2)
- : rect.x + ((rect.width - textWidth) / 2));
+ ? rect.x + ((width - image.getImageData().width - textWidth) / 2)
+ : rect.x + ((width - textWidth) / 2));
textX += imageX + imageEX.x;
break;
}
Event ev = new Event();
ev.widget = e.widget;
notifyListeners(SWT.Selection, ev);
+ redraw();
}
}
}
}
}
+
+ private TableItemComparable[] pairs;
+ public void setTableItemPairs(TableItemComparable[] pairs) {
+ this.pairs = pairs;
+ }
+
+ public TableItemComparable[] getTableItemPairs() {
+ return pairs;
+ }
}
--- /dev/null
+/*
+ * 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.table;
+
+public abstract class TableItemComparable implements Comparable<Object> {
+ protected TableItem item;
+ protected int index;
+ protected int direction;
+
+ public TableItemComparable(TableItem item, int index, int direction) {
+ this.item = item;
+ this.index = index;
+ this.direction = direction;
+ }
+
+ public TableItem getTableItem() {
+ return item;
+ }
+}