]> git.argeo.org Git - gpl/argeo-slc.git/blob - eclipse/plugins/org.argeo.slc.client.ui/src/main/java/org/argeo/slc/client/ui/editors/ProcessLogPage.java
Improve logging
[gpl/argeo-slc.git] / eclipse / plugins / org.argeo.slc.client.ui / src / main / java / org / argeo / slc / client / ui / editors / ProcessLogPage.java
1 package org.argeo.slc.client.ui.editors;
2
3 import java.text.DateFormat;
4 import java.text.SimpleDateFormat;
5 import java.util.List;
6
7 import org.argeo.slc.execution.ExecutionStep;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.widgets.Composite;
10 import org.eclipse.swt.widgets.Control;
11 import org.eclipse.swt.widgets.Display;
12 import org.eclipse.swt.widgets.Text;
13 import org.eclipse.ui.forms.editor.FormEditor;
14 import org.eclipse.ui.forms.editor.FormPage;
15 import org.eclipse.ui.forms.widgets.FormToolkit;
16
17 public class ProcessLogPage extends FormPage {
18 public final static String ID = "processLogPage";
19
20 private DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
21
22 /** Where the log is displayed. */
23 private Text text;
24 /**
25 * Stores logs received before the text was shown. TODO : rather store in in
26 * JCR and reads it from there.
27 */
28 private StringBuffer beforeTextInit = new StringBuffer("");
29
30 public ProcessLogPage(FormEditor editor) {
31 super(editor, ID, "Log");
32 }
33
34 @Override
35 public synchronized void createPartControl(Composite parent) {
36 // bypass createFormContent
37 FormToolkit tk = getEditor().getToolkit();
38 // parent.setLayout(new FillLayout());
39 text = tk.createText(parent, "", SWT.MULTI | SWT.H_SCROLL
40 | SWT.V_SCROLL);
41 text.setEditable(false);
42
43 // transfer the existing buffer the first time
44 if (beforeTextInit.length() > 0) {
45 text.append(beforeTextInit.toString());
46 // clear buffer
47 beforeTextInit.setLength(0);
48 }
49
50 }
51
52 // @Override
53 // protected synchronized void createFormContent(IManagedForm mf) {
54 // ScrolledForm form = mf.getForm();
55 // form.setExpandHorizontal(true);
56 // form.setExpandVertical(true);
57 // // form.setText("Log");
58 // FillLayout mainLayout = new FillLayout();
59 // form.getBody().setLayout(mainLayout);
60 //
61 // FormToolkit tk = getManagedForm().getToolkit();
62 // text = tk.createText(form.getBody(), "", SWT.MULTI | SWT.H_SCROLL
63 // | SWT.V_SCROLL);
64 // text.setEditable(false);
65 // // transfer the existing buffer the first time
66 // if (beforeTextInit.length() > 0) {
67 // text.append(beforeTextInit.toString());
68 // // clear buffer
69 // beforeTextInit.setLength(0);
70 // }
71 // }
72
73 public synchronized void addSteps(List<ExecutionStep> steps) {
74 final StringBuffer buf = new StringBuffer("");
75 for (ExecutionStep step : steps) {
76 buf.append(dateFormat.format(step.getTimestamp()));
77 buf.append(' ');
78 if (step.getType().equals(ExecutionStep.PHASE_START)) {
79 buf.append("## START ").append(step.getLog());
80 buf.append('\n');
81 } else if (step.getType().equals(ExecutionStep.PHASE_END)) {
82 buf.append("## END ").append(step.getLog());
83 buf.append("\n");
84 } else {
85 buf.append(step.getLog());
86 }
87 }
88
89 if (text != null) {
90 Display.getDefault().asyncExec(new Runnable() {
91 public void run() {
92 text.append(buf.toString());
93 }
94 });
95 } else
96 beforeTextInit.append(buf);
97 }
98
99 @Override
100 public Control getPartControl() {
101 return text;
102 }
103
104 @Override
105 public void setFocus() {
106 if (text != null)
107 text.setFocus();
108 }
109
110 }