View Javadoc

1   /**
2    * Copyright (C) 2008 Atlassian
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 com.atlassian.theplugin.idea.ui.tree.file;
18  
19  import com.atlassian.theplugin.commons.crucible.ValueNotYetInitialized;
20  import com.atlassian.theplugin.commons.crucible.api.model.ReviewAdapter;
21  import com.atlassian.theplugin.idea.ui.tree.AtlassianClickAction;
22  import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode;
23  import com.intellij.ui.ColoredTreeCellRenderer;
24  import com.intellij.ui.SimpleTextAttributes;
25  import static com.intellij.ui.SimpleTextAttributes.STYLE_ITALIC;
26  import com.intellij.util.Icons;
27  
28  import javax.swing.*;
29  import javax.swing.tree.TreeCellRenderer;
30  import java.awt.*;
31  
32  /**
33   * Created by IntelliJ IDEA.
34   * User: lguminski
35   * Date: Jul 15, 2008
36   * Time: 6:03:26 AM
37   * To change this template use File | Settings | File Templates.
38   */
39  public class CrucibleChangeSetTitleNode extends FileNode {
40  	private ReviewAdapter review;
41  	private static final TreeCellRenderer MY_RENDERER = new CrucibleChangeSetTitleNodeRenderer();
42  
43  	public CrucibleChangeSetTitleNode(ReviewAdapter review, AtlassianClickAction action) {
44  		super(review.getName(), action);
45  		this.review = review;
46  	}
47  
48  	public CrucibleChangeSetTitleNode(final CrucibleChangeSetTitleNode node) {
49  		super(node.getReview().getName(), node.getAtlassianClickAction());
50  		this.review = node.review;
51  	}
52  
53  	@Override
54  	public TreeCellRenderer getTreeCellRenderer() {
55  		return MY_RENDERER;
56  	}
57  
58  	public ReviewAdapter getReview() {
59  		return review;
60  	}
61  
62  	public void setReview(ReviewAdapter review) {
63  		this.review = review;
64  	}
65  
66  	private static class CrucibleChangeSetTitleNodeRenderer extends ColoredTreeCellRenderer {
67  		private static final SimpleTextAttributes TEXT_ITALIC = new SimpleTextAttributes(STYLE_ITALIC, null);
68  		private static final SimpleTextAttributes RED_ITALIC = new SimpleTextAttributes(STYLE_ITALIC, Color.red);
69  
70  		public void customizeCellRenderer(JTree tree, Object value, boolean selected, boolean expanded,
71  										  boolean leaf, int row, boolean hasFocus) {
72  			CrucibleChangeSetTitleNode node = (CrucibleChangeSetTitleNode) value;
73  			append(node.getReview().getPermId().getId(), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD,
74  					Color.GRAY));
75  			append(" ", SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
76  			append(node.getReview().getName(), SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES);
77  			try {
78  				int noOfDefects = node.getReview().getNumberOfVersionedCommentsDefects()
79  						+ node.getReview().getNumberOfGeneralCommentsDefects();
80  
81  				int noOfComments = node.getReview().getNumberOfGeneralComments() 
82  						+ node.getReview().getNumberOfVersionedComments();
83  
84  //				for (GeneralComment comment : generalComments) {
85  //					noOfComments += comment.getReplies().size();
86  //					if (comment.isDefectRaised()) {
87  //						++noOfDefects;
88  //					}
89  //				}
90  //				for (VersionedComment vComment : versionedComments) {
91  //					if (vComment.isDefectRaised()) {
92  //						++noOfDefects;
93  //					}
94  //				}
95  				append(" ",	TEXT_ITALIC);
96  				append(String.valueOf(noOfComments), TEXT_ITALIC);
97  				append(" comment", TEXT_ITALIC);
98  				if (noOfComments != 1) {
99  					append("s", TEXT_ITALIC);
100 				}
101 				if (noOfDefects > 0) {
102 					append(" (", TEXT_ITALIC);
103 					append(String.valueOf(noOfDefects),	RED_ITALIC);
104 					append(" defect", RED_ITALIC);
105 					if (noOfDefects != 1) {
106 						append("s", RED_ITALIC);
107 					}
108 					append(")", TEXT_ITALIC);
109 				}
110 			} catch (ValueNotYetInitialized valueNotYetInitialized) {
111 				// ignore
112 			}
113 			setIcon(expanded ? Icons.DIRECTORY_OPEN_ICON : Icons.DIRECTORY_CLOSED_ICON);
114 		}
115 	}
116 
117 	public AtlassianTreeNode getClone() {
118 		return new CrucibleChangeSetTitleNode(this);
119 	}
120 
121 	public int compareTo(Object o) {
122 		if (o instanceof CrucibleChangeSetTitleNode) {
123 			return 0;
124 		}
125 		// this node should always be the first node
126 		return -1;
127 	}
128 }