Drive: Add BatchableRequest subclass.
[chromium-blink-merge.git] / ui / base / models / table_model.cc
blob37a866f1ea2bc1f7f31ca391078031c77dedfc34
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/base/models/table_model.h"
7 #include "base/i18n/string_compare.h"
8 #include "base/logging.h"
9 #include "ui/base/l10n/l10n_util.h"
10 #include "ui/gfx/image/image_skia.h"
12 namespace ui {
14 // TableColumn -----------------------------------------------------------------
16 TableColumn::TableColumn()
17 : id(0),
18 title(),
19 alignment(LEFT),
20 width(-1),
21 percent(),
22 min_visible_width(0),
23 sortable(false) {
26 TableColumn::TableColumn(int id, Alignment alignment, int width, float percent)
27 : id(id),
28 title(l10n_util::GetStringUTF16(id)),
29 alignment(alignment),
30 width(width),
31 percent(percent),
32 min_visible_width(0),
33 sortable(false) {
36 // TableModel -----------------------------------------------------------------
38 // Used for sorting.
39 static icu::Collator* collator = NULL;
41 gfx::ImageSkia TableModel::GetIcon(int row) {
42 return gfx::ImageSkia();
45 base::string16 TableModel::GetTooltip(int row) {
46 return base::string16();
49 bool TableModel::ShouldIndent(int row) {
50 return false;
53 bool TableModel::HasGroups() {
54 return false;
57 TableModel::Groups TableModel::GetGroups() {
58 // If you override HasGroups to return true, you must override this as
59 // well.
60 NOTREACHED();
61 return std::vector<Group>();
64 int TableModel::GetGroupID(int row) {
65 // If you override HasGroups to return true, you must override this as
66 // well.
67 NOTREACHED();
68 return 0;
71 int TableModel::CompareValues(int row1, int row2, int column_id) {
72 DCHECK(row1 >= 0 && row1 < RowCount() &&
73 row2 >= 0 && row2 < RowCount());
74 base::string16 value1 = GetText(row1, column_id);
75 base::string16 value2 = GetText(row2, column_id);
76 icu::Collator* collator = GetCollator();
78 if (collator)
79 return base::i18n::CompareString16WithCollator(collator, value1, value2);
81 NOTREACHED();
82 return 0;
85 void TableModel::ClearCollator() {
86 delete collator;
87 collator = NULL;
90 icu::Collator* TableModel::GetCollator() {
91 if (!collator) {
92 UErrorCode create_status = U_ZERO_ERROR;
93 collator = icu::Collator::createInstance(create_status);
94 if (!U_SUCCESS(create_status)) {
95 collator = NULL;
96 NOTREACHED();
99 return collator;
102 } // namespace ui