View Javadoc

1   package com.atlassian.theplugin.idea.bamboo.build;
2   
3   import com.atlassian.theplugin.commons.util.DateUtil;
4   import com.atlassian.theplugin.idea.Constants;
5   import com.atlassian.theplugin.idea.bamboo.BambooBuildAdapterIdea;
6   import com.atlassian.theplugin.idea.bamboo.tree.BuildTreeNode;
7   import com.atlassian.theplugin.idea.ui.BoldLabel;
8   
9   import javax.swing.*;
10  import java.awt.*;
11  import java.awt.event.ActionEvent;
12  import java.awt.event.ActionListener;
13  import java.util.Collection;
14  
15  /**
16   * User: jgorycki
17   * Date: Jan 7, 2009
18   * Time: 1:33:07 PM
19   */
20  public class BuildDetailsPanel extends JPanel implements ActionListener {
21  
22  	private final BambooBuildAdapterIdea build;
23  
24  	private JLabel relativeBuildTime = new JLabel();
25  	private static final int MAX_NR_OF_COMMITTERS_TO_LIST_IN_A_DETAILED_WAY = 3;
26  
27  	public BuildDetailsPanel(BambooBuildAdapterIdea build) {
28  		this.build = build;
29  		setLayout(new GridBagLayout());
30  
31  		setLayout(new GridBagLayout());
32  
33  		GridBagConstraints gbc = new GridBagConstraints();
34  		gbc.gridx = 0;
35  		gbc.gridy = 0;
36  		gbc.weightx = 1.0;
37  		gbc.weighty = 1.0;
38  		gbc.fill = GridBagConstraints.BOTH;
39  
40  	   	refreshBuildRelativeTime();
41  		
42  		JScrollPane scroll = new JScrollPane(createBody());
43  		scroll.setBorder(BorderFactory.createEmptyBorder());
44  		add(scroll, gbc);
45  	}
46  
47  	public JPanel createBody() {
48  		JPanel p = new JPanel();
49  		p.setLayout(new GridBagLayout());
50  		p.setBackground(Color.WHITE);
51  
52  		GridBagConstraints gbc1 = new GridBagConstraints();
53  		GridBagConstraints gbc2 = new GridBagConstraints();
54  		gbc1.gridx = 0;
55  		gbc2.gridx = 1;
56  		gbc1.gridy = 0;
57  		gbc2.gridy = 0;
58  		gbc1.weighty = 0.0;
59  		gbc2.weighty = 0.0;
60  		gbc1.weightx = 0.0;
61  		gbc2.weightx = 1.0;
62  		gbc1.fill = GridBagConstraints.NONE;
63  		gbc2.fill = GridBagConstraints.HORIZONTAL;
64  		gbc1.insets = new Insets(Constants.DIALOG_MARGIN / 2, Constants.DIALOG_MARGIN,
65  				Constants.DIALOG_MARGIN / 2, Constants.DIALOG_MARGIN);
66  		gbc2.insets = new Insets(Constants.DIALOG_MARGIN / 2, Constants.DIALOG_MARGIN,
67  				Constants.DIALOG_MARGIN / 2, Constants.DIALOG_MARGIN);
68  		gbc1.anchor = GridBagConstraints.FIRST_LINE_START;
69  		gbc2.anchor = GridBagConstraints.FIRST_LINE_START;
70  
71  
72  		p.add(new BoldLabel("State"), gbc1);
73  		p.add(new JLabel(build.getAdjustedStatus().getName(), build.getIcon(), SwingConstants.LEFT), gbc2);
74  		gbc1.gridy++;
75  		gbc2.gridy++;
76  		gbc1.insets = new Insets(0, Constants.DIALOG_MARGIN, Constants.DIALOG_MARGIN / 2, Constants.DIALOG_MARGIN);
77  		gbc2.insets = new Insets(0, Constants.DIALOG_MARGIN, Constants.DIALOG_MARGIN / 2, Constants.DIALOG_MARGIN);
78  		p.add(new BoldLabel("Last Build"), gbc1);
79  		p.add(new JLabel(build.getBuildNumberAsString()), gbc2);
80  		gbc1.gridy++;
81  		gbc2.gridy++;
82  		p.add(new BoldLabel("When"), gbc1);
83  		p.add(relativeBuildTime, gbc2);
84  		// we don't have any way to get build duration yet
85  //		gbc1.gridy++;
86  //		gbc2.gridy++;
87  //		p.add(new BoldLabel("Build Duration"), gbc1);
88  //		p.add(HGW???, gbc2);
89  		gbc1.gridy++;
90  		gbc2.gridy++;
91  
92  		StringBuilder reason = new StringBuilder(build.getReason());
93  		Collection<String> committers = build.getCommiters();
94  		// bleeeee, ugly ugly
95  		if (committers.size() > 0 && reason.toString().equals(BuildTreeNode.CODE_HAS_CHANGED)) {
96  			reason = new StringBuilder("Code was changed by ");
97  			if (committers.size() > MAX_NR_OF_COMMITTERS_TO_LIST_IN_A_DETAILED_WAY) {
98  				reason.append(committers.size()).append(" people");
99  			} else {
100 				int i = 0;
101 				for (String committer : committers) {
102 					reason.append(committer);
103 					if (++i < committers.size()) {
104 						reason.append(", ");
105 					}
106 				}
107 			}
108 		}
109 		p.add(new BoldLabel("Build Reason"), gbc1);
110 		p.add(new JLabel(reason.toString()), gbc2);
111 		gbc1.gridy++;
112 		gbc2.gridy++;
113 		p.add(new BoldLabel("Tests"), gbc1);
114 		p.add(new JLabel(build.getTestsPassedSummary() + " failed"), gbc2);
115 
116 		gbc1.gridy++;
117 		gbc1.gridwidth = 2;
118 		gbc1.weighty = 1.0;
119 		gbc1.fill = GridBagConstraints.VERTICAL;
120 		JPanel filler = new JPanel();
121 		filler.setOpaque(true);
122 		filler.setBackground(Color.WHITE);
123 		p.add(filler, gbc1);
124 
125 		return p;
126 	}
127 
128 	public void actionPerformed(ActionEvent e) {
129 		refreshBuildRelativeTime();
130 	}
131 
132 	private void refreshBuildRelativeTime() {
133 		relativeBuildTime.setText(DateUtil.getRelativeBuildTime(build.getCompletionDate()));
134 	}
135 }