Eclipse plug-in for service provider.
[platform/upstream/iotivity.git] / service / simulator / java / eclipse-plugin / ServiceProviderPlugin / src / oic / simulator / serviceprovider / view / LogDetailsDialog.java
1 package oic.simulator.serviceprovider.view;
2
3 import java.text.DateFormat;
4 import java.util.Date;
5
6 import org.eclipse.jface.dialogs.Dialog;
7 import org.eclipse.jface.dialogs.IDialogConstants;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.graphics.Image;
10 import org.eclipse.swt.layout.GridData;
11 import org.eclipse.swt.layout.GridLayout;
12 import org.eclipse.swt.layout.RowData;
13 import org.eclipse.swt.layout.RowLayout;
14 import org.eclipse.swt.widgets.Button;
15 import org.eclipse.swt.widgets.Composite;
16 import org.eclipse.swt.widgets.Control;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.swt.widgets.Text;
20
21 public class LogDetailsDialog extends Dialog {
22     private final String severity;
23     private final Date   date;
24     private final String message;
25     private final Image  severityIcon;
26
27     public LogDetailsDialog(Shell parentShell, String severity,
28             Image severityIcon, Date date, String message) {
29         super(parentShell);
30         this.severity = severity;
31         this.severityIcon = severityIcon;
32         this.message = message;
33         this.date = date;
34     }
35
36     @Override
37     protected boolean isResizable() {
38         return true;
39     }
40
41     @Override
42     protected void configureShell(Shell shell) {
43         super.configureShell(shell);
44     }
45
46     @Override
47     protected Control createDialogArea(Composite parent) {
48         getShell().setText("Logged event details");
49
50         Composite container = (Composite) super.createDialogArea(parent);
51
52         GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
53         container.setLayoutData(layoutData);
54         container.setLayout(new GridLayout(2, false));
55
56         GridData gd;
57
58         Label l1 = new Label(container, SWT.NONE);
59         l1.setText("Severity:");
60         gd = new GridData();
61         gd.widthHint = 100;
62         l1.setLayoutData(gd);
63
64         Composite y = new Composite(container, SWT.NONE);
65         gd = new GridData();
66         gd.grabExcessHorizontalSpace = true;
67         y.setLayoutData(gd);
68         y.setLayout(new RowLayout(SWT.HORIZONTAL));
69
70         Label l2 = new Label(y, SWT.NONE);
71         l2.setImage(severityIcon);
72         l2.setLayoutData(new RowData());
73         Label l3 = new Label(y, SWT.NONE);
74         l3.setText(severity);
75         l3.setLayoutData(new RowData());
76
77         Label l4 = new Label(container, SWT.NONE);
78         l4.setText("Date:");
79         gd = new GridData();
80         gd.widthHint = 100;
81         l4.setLayoutData(gd);
82
83         Label l5 = new Label(container, SWT.NONE);
84         DateFormat dateFormat = DateFormat.getDateTimeInstance(
85                 DateFormat.SHORT, DateFormat.SHORT);
86         l5.setText(dateFormat.format(date));
87         gd = new GridData();
88         gd.grabExcessHorizontalSpace = true;
89         l5.setLayoutData(gd);
90
91         new Label(container, SWT.NONE); // separator
92
93         Label l6 = new Label(container, SWT.NONE);
94         l6.setText("Message details");
95         gd = new GridData();
96         gd.horizontalSpan = 2;
97         l6.setLayoutData(gd);
98
99         Text text = new Text(container, SWT.MULTI | SWT.READ_ONLY
100                 | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
101         if (message != null) {
102             text.setText(message);
103         } else {
104             text.setText("No description available");
105         }
106         gd = new GridData(SWT.FILL, SWT.FILL, true, true);
107         gd.horizontalSpan = 2;
108         gd.heightHint = 350;
109         gd.widthHint = 500;
110         text.setLayoutData(gd);
111
112         return container;
113     }
114
115     @Override
116     protected Button createButton(Composite parent, int id, String label,
117             boolean defaultButton) {
118         if (id == IDialogConstants.CANCEL_ID) {
119             return null;
120         }
121         return super.createButton(parent, id, label, defaultButton);
122     }
123 }