1 package com.proalpha.pds.gitutils.mylyn;
4 import java.util.regex.Matcher;
5 import java.util.regex.Pattern;
7 import org.eclipse.jface.dialogs.Dialog;
8 import org.eclipse.jface.dialogs.IDialogConstants;
9 import org.eclipse.jface.layout.GridDataFactory;
10 import org.eclipse.jface.layout.GridLayoutFactory;
11 import org.eclipse.jface.resource.JFaceResources;
12 import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
13 import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
14 import org.eclipse.jface.viewers.ITreeContentProvider;
15 import org.eclipse.jface.viewers.LabelProvider;
16 import org.eclipse.jface.viewers.StyledString;
17 import org.eclipse.jface.viewers.TreeViewer;
18 import org.eclipse.jface.viewers.TreeViewerColumn;
19 import org.eclipse.jface.viewers.Viewer;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.layout.GridData;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.swt.widgets.Control;
25 import org.eclipse.swt.widgets.Group;
26 import org.eclipse.swt.widgets.Label;
27 import org.eclipse.swt.widgets.Shell;
28 import org.eclipse.swt.widgets.Text;
29 import org.eclipse.swt.widgets.Tree;
30 import org.eclipse.swt.widgets.TreeColumn;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
38 private final List<ActionResult> results;
39 private String status =
"OK";
42 protected Control createDialogArea(Composite parent) {
44 Composite main =
new Composite(parent, SWT.NONE);
45 GridLayoutFactory.swtDefaults().applyTo(main);
46 GridDataFactory.fillDefaults().indent(0, 0).grab(
true,
true).applyTo(main);
47 main.setLayout(
new GridLayout(1,
false));
49 Composite composite =
new Composite(main, SWT.NONE);
50 composite.setLayoutData(
new GridData(SWT.FILL, SWT.CENTER,
false,
false, 1, 1));
51 composite.setLayout(
new GridLayout(2,
false));
52 Label lblNewLabel =
new Label(composite, SWT.NONE);
53 lblNewLabel.setLayoutData(
new GridData(SWT.RIGHT, SWT.CENTER,
false,
false, 1, 1));
54 lblNewLabel.setText(
"Result Status:");
56 Text text =
new Text(composite, SWT.READ_ONLY);
57 text.setLayoutData(
new GridData(SWT.FILL, SWT.CENTER,
true,
false, 1, 1));
58 text.setText(this.status);
59 text.setFont(JFaceResources.getFont(
"Courier New"));
60 if (this.status.equalsIgnoreCase(
"OK"))
61 text.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_DARK_GREEN));
63 text.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
65 Group grpPerformedActions =
new Group(main, SWT.NONE);
66 grpPerformedActions.setLayoutData(
new GridData(SWT.FILL, SWT.FILL,
false,
false, 1, 1));
67 grpPerformedActions.setText(
"Performed Actions");
69 TreeViewer succViewer =
new TreeViewer(grpPerformedActions);
70 Tree succTree = succViewer.getTree();
71 succTree.setBounds(5, 20, 460, 250);
72 fillTreeView(succViewer, this.results);
83 this.results = results;
86 if (!result.getStatus().equalsIgnoreCase(
"OK"))
87 this.status =
"WARNING";
92 protected void createButtonsForButtonBar(Composite parent) {
93 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.CLOSE_LABEL,
true);
97 protected void configureShell(Shell newShell) {
98 super.configureShell(newShell);
99 newShell.setText(
"Checkout Result: " + this.status);
102 private void fillTreeView(TreeViewer treeViewer, List<ActionResult> results) {
104 TreeViewerColumn treeViewerColumnStatus =
new TreeViewerColumn(treeViewer, SWT.NONE);
105 TreeColumn trclmnNewColumnStatus = treeViewerColumnStatus.getColumn();
106 trclmnNewColumnStatus.setWidth(75);
107 trclmnNewColumnStatus.setText(
"Status");
108 treeViewerColumnStatus.setLabelProvider(
new DelegatingStyledCellLabelProvider(
new StatusLabelProvider()));
110 TreeViewerColumn treeViewerColumnAction =
new TreeViewerColumn(treeViewer, SWT.NONE);
111 TreeColumn trclmnNewColumnAction = treeViewerColumnAction.getColumn();
112 trclmnNewColumnAction.setWidth(600);
113 trclmnNewColumnAction.setText(
"Action");
114 trclmnNewColumnAction.setAlignment(SWT.LEFT);
115 treeViewerColumnAction.setLabelProvider(
new DelegatingStyledCellLabelProvider(
new ActionLabelProvider()));
117 treeViewer.setContentProvider(
new ResultProvider());
118 treeViewer.setInput(results);
120 treeViewer.getTree().setHeaderVisible(
true);
121 treeViewer.getTree().setLinesVisible(
true);
126 private final Object[] emptyArray =
new Object[0];
128 public void inputChanged(Viewer v, Object oldInput, Object newInput) {
132 public void dispose() {
136 public Object[] getElements(Object inputElement) {
137 if (inputElement instanceof List) {
138 return ((List<?>) inputElement).toArray();
144 public Object[] getChildren(Object parentElement) {
147 return result.getLog().toArray();
153 public Object getParent(Object element) {
158 public boolean hasChildren(Object element) {
161 return !result.getLog().isEmpty();
168 class StatusLabelProvider
extends LabelProvider implements IStyledLabelProvider {
171 public StyledString getStyledText(Object element) {
174 return new StyledString(result.getStatus());
175 }
else if (element instanceof String) {
176 return new StyledString(
"LOG");
183 class ActionLabelProvider
extends LabelProvider implements IStyledLabelProvider {
186 public StyledString getStyledText(Object element) {
187 if (element instanceof ActionResult) {
188 ActionResult result = (ActionResult) element;
189 return new StyledString(result.getAction());
190 }
else if (element instanceof String) {
191 return new StyledString(getShortLog((String) element));
196 private String getShortLog(String logLine) {
198 Pattern p = Pattern.compile(
"([\\d-]+) ([\\d:]+)([,\\d]+) (DEBUG|WARNING|ERROR|INFO) \\[(.*?)\\] (.*)");
199 Matcher m = p.matcher(logLine);
ActionResultDialog(Shell parentShell, List< ActionResult > results)