Imported Upstream version 1.0.0
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / dialogs / FilterDialog.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.clientcontroller.view.dialogs;
18
19 import java.util.ArrayList;
20 import java.util.Collections;
21 import java.util.Map;
22
23 import oic.simulator.clientcontroller.manager.LogManager;
24
25 import org.eclipse.jface.dialogs.TrayDialog;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Control;
34 import org.eclipse.swt.widgets.Group;
35 import org.eclipse.swt.widgets.Shell;
36
37 /**
38  * This class shows a dialog for filtering logs based on severity levels.
39  */
40 public class FilterDialog extends TrayDialog {
41     private Map<Integer, Boolean> severities;
42
43     public FilterDialog(Shell shell, Map<Integer, Boolean> severities) {
44         super(shell);
45         this.severities = severities;
46     }
47
48     @Override
49     protected void configureShell(Shell shell) {
50         super.configureShell(shell);
51     }
52
53     @Override
54     protected Control createDialogArea(Composite parent) {
55         Composite composite = (Composite) super.createDialogArea(parent);
56         createSeverityGroup(composite);
57         getShell().setText("Filter details");
58         return composite;
59     }
60
61     /**
62      * Dynamically creates a check-box list for severity levels for user to
63      * choose from
64      */
65     private void createSeverityGroup(Composite parent) {
66         Group group = new Group(parent, SWT.NONE);
67         group.setLayout(new GridLayout());
68         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
69         gd.widthHint = 275;
70         group.setLayoutData(gd);
71         group.setText("Severity Levels");
72
73         ArrayList<Integer> arrayList = new ArrayList<Integer>(
74                 severities.keySet());
75         Collections.sort(arrayList);
76         for (final Integer i : arrayList) {
77             final Button checkbox = new Button(group, SWT.CHECK);
78             checkbox.setText(LogManager.getSeverityName(i));
79             checkbox.setSelection(severities.get(i));
80             checkbox.addSelectionListener(new SelectionAdapter() {
81
82                 @Override
83                 public void widgetSelected(SelectionEvent e) {
84                     severities.put(i, checkbox.getSelection());
85                 }
86             });
87         }
88     }
89
90     @Override
91     public boolean isHelpAvailable() {
92         return false;
93     }
94 }