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.comment;
18  
19  import com.atlassian.theplugin.commons.crucible.api.model.CrucibleFileInfo;
20  import com.atlassian.theplugin.commons.crucible.api.model.VersionedComment;
21  import com.atlassian.theplugin.idea.crucible.ReviewData;
22  import com.atlassian.theplugin.idea.ui.tree.AtlassianClickAction;
23  import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode;
24  import com.atlassian.theplugin.util.CommentPanelBuilder;
25  
26  import javax.swing.*;
27  import javax.swing.tree.TreeCellRenderer;
28  import java.awt.*;
29  
30  public class VersionedCommentTreeNode extends CommentTreeNode {
31  	private ReviewData review;
32  	private CrucibleFileInfo file;
33  	private VersionedComment comment;
34  	private static final TreeCellRenderer MY_RENDERER = new MyTreeRenderer();
35  
36  	public VersionedCommentTreeNode(ReviewData review, CrucibleFileInfo file, VersionedComment comment,
37              AtlassianClickAction action) {
38  		super(action);
39  		this.review = review;
40  		this.file = file;
41  		this.comment = comment;
42  	}
43  
44  	public VersionedCommentTreeNode(final VersionedCommentTreeNode node) {
45  		super(node.getAtlassianClickAction());
46  		this.review = node.review;
47  		this.file = node.file;
48  		this.comment = node.comment;
49  	}
50  
51  	@Override
52      public TreeCellRenderer getTreeCellRenderer() {
53  		return MY_RENDERER;
54  	}
55  
56  	public ReviewData getReview() {
57  		return review;
58  	}
59  
60  	public CrucibleFileInfo getFile() {
61  		return file;
62  	}
63  
64  	public VersionedComment getComment() {
65  		return comment;
66  	}
67  
68  	public AtlassianTreeNode getClone() {
69  		return new VersionedCommentTreeNode(this);
70  	}
71  
72  	private static class MyTreeRenderer implements TreeCellRenderer {
73  
74  
75  		public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded,
76                  boolean leaf, int row, boolean hasFocus) {
77  			VersionedCommentTreeNode node = (VersionedCommentTreeNode) value;
78  			JPanel panel;
79  			if (node.isEditable()) {
80  				panel = CommentPanelBuilder.createEditPanelOfVersionedComment(
81  						node.getReview(), node.getFile(), node.getComment());
82  			} else {
83  				panel = CommentPanelBuilder.createViewPanelOfVersionedComment(
84  						node.getReview(), node.getFile(), node.getComment());
85  			}
86  			panel.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder")
87                      : BorderFactory.createEmptyBorder(1, 1, 1, 1));
88  			return panel;
89  		}
90  	}
91  }