12d0c59794c778cca78a8b80e4e4d3c0ea382d0a
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ClientControllerPlugin / src / oic / simulator / clientcontroller / view / dialogs / LogDetailsDialog.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.text.DateFormat;
20 import java.util.Date;
21
22 import org.eclipse.jface.dialogs.Dialog;
23 import org.eclipse.jface.dialogs.IDialogConstants;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.graphics.Image;
26 import org.eclipse.swt.layout.GridData;
27 import org.eclipse.swt.layout.GridLayout;
28 import org.eclipse.swt.layout.RowData;
29 import org.eclipse.swt.layout.RowLayout;
30 import org.eclipse.swt.widgets.Button;
31 import org.eclipse.swt.widgets.Composite;
32 import org.eclipse.swt.widgets.Control;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.swt.widgets.Text;
36
37 /**
38  * This class shows detailed information about a log. The dialog will be opened
39  * on double-clicking a log entry in the log view.
40  */
41 public class LogDetailsDialog extends Dialog {
42     private final String severity;
43     private final Date   date;
44     private final String message;
45     private final Image  severityIcon;
46
47     public LogDetailsDialog(Shell parentShell, String severity,
48             Image severityIcon, Date date, String message) {
49         super(parentShell);
50         this.severity = severity;
51         this.severityIcon = severityIcon;
52         this.message = message;
53         this.date = date;
54     }
55
56     @Override
57     protected boolean isResizable() {
58         return true;
59     }
60
61     @Override
62     protected void configureShell(Shell shell) {
63         super.configureShell(shell);
64     }
65
66     @Override
67     protected Control createDialogArea(Composite parent) {
68         getShell().setText("Logged event details");
69
70         Composite container = (Composite) super.createDialogArea(parent);
71
72         GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
73         container.setLayoutData(layoutData);
74         container.setLayout(new GridLayout(2, false));
75
76         GridData gd;
77
78         Label l1 = new Label(container, SWT.NONE);
79         l1.setText("Severity:");
80         gd = new GridData();
81         gd.widthHint = 100;
82         l1.setLayoutData(gd);
83
84         Composite y = new Composite(container, SWT.NONE);
85         gd = new GridData();
86         gd.grabExcessHorizontalSpace = true;
87         y.setLayoutData(gd);
88         y.setLayout(new RowLayout(SWT.HORIZONTAL));
89
90         Label l2 = new Label(y, SWT.NONE);
91         l2.setImage(severityIcon);
92         l2.setLayoutData(new RowData());
93         Label l3 = new Label(y, SWT.NONE);
94         l3.setText(severity);
95         l3.setLayoutData(new RowData());
96
97         Label l4 = new Label(container, SWT.NONE);
98         l4.setText("Date:");
99         gd = new GridData();
100         gd.widthHint = 100;
101         l4.setLayoutData(gd);
102
103         Label l5 = new Label(container, SWT.NONE);
104         DateFormat dateFormat = DateFormat.getDateTimeInstance(
105                 DateFormat.SHORT, DateFormat.SHORT);
106         l5.setText(dateFormat.format(date));
107         gd = new GridData();
108         gd.grabExcessHorizontalSpace = true;
109         l5.setLayoutData(gd);
110
111         new Label(container, SWT.NONE); // separator
112
113         Label l6 = new Label(container, SWT.NONE);
114         l6.setText("Message details");
115         gd = new GridData();
116         gd.horizontalSpan = 2;
117         l6.setLayoutData(gd);
118
119         Text text = new Text(container, SWT.MULTI | SWT.READ_ONLY
120                 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
121         if (message != null) {
122             text.setText(message);
123         } else {
124             text.setText("No description available");
125         }
126         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
127         gd.horizontalSpan = 2;
128         gd.heightHint = 350;
129         gd.widthHint = 500;
130         text.setLayoutData(gd);
131
132         return container;
133     }
134
135     @Override
136     protected Button createButton(Composite parent, int id, String label,
137             boolean defaultButton) {
138         if (id == IDialogConstants.CANCEL_ID) {
139             return null;
140         }
141         return super.createButton(parent, id, label, defaultButton);
142     }
143 }