Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / logger / LogLabelProvider.java
1 /*
2  * Copyright 2015 Samsung Electronics All Rights Reserved.
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
17 package oic.simulator.logger;
18
19 import java.text.DateFormat;
20 import java.text.SimpleDateFormat;
21
22 import oic.simulator.serviceprovider.manager.LogManager;
23
24 import org.eclipse.jface.viewers.ITableLabelProvider;
25 import org.eclipse.jface.viewers.LabelProvider;
26 import org.eclipse.swt.graphics.Image;
27
28 /**
29  * Label provider which determines what data has to be shown in the log view.
30  */
31 public class LogLabelProvider extends LabelProvider implements
32         ITableLabelProvider {
33
34     DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
35
36     @Override
37     public Image getColumnImage(Object element, int columnIndex) {
38         if (columnIndex == 0) {
39             LogEntry entry = (LogEntry) element;
40             return LogManager.getSeverityIcon(entry.getSeverity());
41         }
42         return null;
43     }
44
45     @Override
46     public String getColumnText(Object element, int columnIndex) {
47         LogEntry entry = (LogEntry) element;
48         if (columnIndex == 0) {
49             return LogManager.getSeverityName(entry.getSeverity());
50         } else if (columnIndex == 1) {
51             return dateFormat.format(entry.getDate());
52         } else {
53             return entry.getMessage();
54         }
55     }
56
57 }