4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Wooyoung Cho <wooyoung1.cho@samsung.com>
8 * Shihyun Kim <shihyun.kim@samsung.com>
9 * Taeyoung Son <taeyoung2.son@samsung.com>
10 * Yongsung kim <yongsung1.kim@samsung.com>
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
29 package org.tizen.installmanager.ui.model;
32 import org.eclipse.jface.viewers.ColumnLabelProvider;
33 import org.eclipse.jface.viewers.ILabelProviderListener;
34 import org.eclipse.jface.viewers.ViewerCell;
35 import org.eclipse.swt.SWT;
36 import org.eclipse.swt.graphics.Point;
37 import org.eclipse.swt.widgets.Display;
38 import org.tizen.installmanager.ui.model.Item.CheckState;
39 import org.tizen.installmanager.ui.model.Item.InstallState;
40 import org.tizen.installmanager.ui.page.PackageListPage;
44 * This class provide the text and/or image for each column of a given element. Used by PackageListPage.
45 * @see PackageListPage
46 * @author Taeyoung Son <taeyoung2.son@samsung.com>
48 public class ItemLabelProvider extends ColumnLabelProvider {
51 public void addListener(ILabelProviderListener listener) {
55 public void dispose() {
59 public boolean isLabelProperty(Object element, String property) {
64 public void removeListener(ILabelProviderListener listener) {
67 // public String getToolTipText(Object element) {
68 // String description = "Tooltip (" + element + ")";
69 // if (element instanceof Item && viewController != null) {
70 // String pkgName = ((Item) element).getPackageName();
71 // description = viewController.getDescription(pkgName);
74 // return description;
77 public Point getToolTipShift(Object object) {
78 return new Point(5, 5);
81 public int getToolTipTimeDisplyed(Object object) {
85 public void update(ViewerCell cell) {
86 int columnIndex = cell.getColumnIndex();
87 Object element = cell.getElement();
89 switch (columnIndex) {
91 if (element instanceof Item) {
92 result = ((Item) element).getDisplayName();
96 if (element instanceof Item) {
97 result = ((Item) element).getStateToString();
101 if (element instanceof Item) {
102 result = displaySize(element);
106 if (element instanceof Item) {
107 result = ((Item) element).getInstalledVersion();
112 if (result != null) {
113 cell.setText(result);
116 if (element instanceof Item) {
117 InstallState state = ((Item)element).getInstallState();
118 if (state == InstallState.UPDATE || state == InstallState.UNINSTALL) {
119 cell.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
124 private String displaySize(Object element) {
125 Item item = (Item) element;
127 if (item.getCheckState() == CheckState.UNCHECKED) {
130 return sizeToKB(item.getSize());
134 private String sizeToKB(Long size) {
139 double sizeB = (double)size;
140 double sizeK = sizeB / 1024.0;
141 double sizeM = sizeK / 1024.0;
143 String retSize = String.format("%.1f", sizeM) + "M";
144 if (retSize.equals("0.0M")) {
145 retSize = String.format("%.1f", sizeK) + "K";