Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / logger / LogContentProvider.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.util.ArrayList;
20 import java.util.List;
21
22 import org.eclipse.jface.viewers.ITreeContentProvider;
23 import org.eclipse.jface.viewers.Viewer;
24
25 /**
26  * Maintains simulator log entries and provides content to the log view.
27  */
28 public class LogContentProvider implements ITreeContentProvider {
29
30     List<LogEntry> logEntryList = new ArrayList<LogEntry>();
31
32     @SuppressWarnings("unchecked")
33     @Override
34     public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
35         logEntryList = (List<LogEntry>) newInput;
36     }
37
38     @Override
39     public Object[] getChildren(Object element) {
40         return new Object[0];
41     }
42
43     @Override
44     public Object[] getElements(Object input) {
45         return logEntryList.toArray();
46     }
47
48     @Override
49     public Object getParent(Object element) {
50         return null;
51     }
52
53     @Override
54     public boolean hasChildren(Object element) {
55         return false;
56     }
57
58     @Override
59     public void dispose() {
60     }
61
62     public synchronized void addLog(LogEntry newElement) {
63         logEntryList.add(newElement);
64     }
65 }