• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.ddmuilib.logcat;
17 
18 import org.eclipse.jface.viewers.ITableLabelProvider;
19 import org.eclipse.jface.viewers.LabelProvider;
20 import org.eclipse.swt.graphics.Image;
21 
22 /**
23  * A JFace label provider for the LogCat filters. It expects elements of type
24  * {@link LogCatFilter}.
25  */
26 public final class LogCatFilterLabelProvider extends LabelProvider implements ITableLabelProvider {
27     @Override
getColumnImage(Object arg0, int arg1)28     public Image getColumnImage(Object arg0, int arg1) {
29         return null;
30     }
31 
32     /**
33      * Implements {@link ITableLabelProvider#getColumnText(Object, int)}.
34      * @param element an instance of {@link LogCatFilter}
35      * @param index index of the column
36      * @return text to use in the column
37      */
38     @Override
getColumnText(Object element, int index)39     public String getColumnText(Object element, int index) {
40         if (!(element instanceof LogCatFilter)) {
41             return null;
42         }
43 
44         LogCatFilter f = (LogCatFilter) element;
45 
46         if (f.getUnreadCount() == 0) {
47             return f.getName();
48         } else {
49             return String.format("%s (%d)", f.getName(), f.getUnreadCount());
50         }
51     }
52 }
53