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.GeneralComment;
20  import com.atlassian.theplugin.idea.crucible.ReviewData;
21  import com.atlassian.theplugin.idea.ui.tree.AtlassianClickAction;
22  import com.atlassian.theplugin.idea.ui.tree.AtlassianTreeNode;
23  import com.atlassian.theplugin.util.CommentPanelBuilder;
24  
25  import javax.swing.*;
26  import javax.swing.tree.TreeCellRenderer;
27  import java.awt.*;
28  
29  public class GeneralCommentTreeNode extends CommentTreeNode {
30  	private GeneralComment comment;
31  	private static final TreeCellRenderer MY_RENDERER = new MyRenderer();
32  
33  	public GeneralCommentTreeNode(ReviewData review, GeneralComment comment, AtlassianClickAction action) {
34  		super(action);
35  		this.review = review;
36  		this.comment = comment;
37  	}
38  
39  	public GeneralCommentTreeNode(final GeneralCommentTreeNode node) {
40  		super(node.getAtlassianClickAction());
41  		this.review = node.review;
42  		this.comment = node.comment;
43  	}
44  
45  	public GeneralComment getComment() {
46  		return comment;
47  	}
48  
49  	public TreeCellRenderer getTreeCellRenderer() {
50  		return MY_RENDERER;
51  	}
52  
53  	public AtlassianTreeNode getClone() {
54  		return new GeneralCommentTreeNode(this);
55  	}
56  
57  	private static class MyRenderer implements TreeCellRenderer {
58  		public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded,
59  				boolean leaf, int row, boolean hasFocus) {
60  			GeneralCommentTreeNode node = (GeneralCommentTreeNode) value;
61  			JPanel panel;
62  			if (node.isEditable()) {
63  				panel = CommentPanelBuilder.createEditPanelOfGeneralComment(
64  						node.getReview(), node.getComment());
65  			} else {
66  				panel = CommentPanelBuilder.createViewPanelOfGeneralComment(
67  						node.getReview(), node.getComment());
68  			}
69  			panel.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder")
70  					: BorderFactory.createEmptyBorder(1, 1, 1, 1));
71  			return panel;
72  
73  		}
74  	}
75  }