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  package com.atlassian.theplugin.idea.crucible.tree;
17  
18  import com.atlassian.theplugin.commons.crucible.api.model.RecentlyOpenReviewsFilter;
19  import com.atlassian.theplugin.crucible.model.CrucibleReviewListModel;
20  import com.atlassian.theplugin.idea.ui.tree.paneltree.AbstractTreeNode;
21  import com.atlassian.theplugin.idea.ui.tree.paneltree.SelectableLabel;
22  
23  import javax.swing.*;
24  
25  /**
26   * @author Jacek Jaroczynski
27   */
28  public class CrucibleRecentlyOpenFilterTreeNode extends AbstractTreeNode {
29  	private static final String NAME = "Recently Viewed Reviews";
30  	private final CrucibleReviewListModel reviewListModel;
31  	private RecentlyOpenReviewsFilter recenltyOpenFilter;
32  
33  	public CrucibleRecentlyOpenFilterTreeNode(final RecentlyOpenReviewsFilter recentlyOpenReviewsFilter,
34  			CrucibleReviewListModel reviewListModel) {
35  		super(NAME, null, null);
36  		this.reviewListModel = reviewListModel;
37  		this.recenltyOpenFilter = recentlyOpenReviewsFilter;
38  	}
39  
40  	public String toString() {
41  		int cnt = reviewListModel.getReviewCount(recenltyOpenFilter);
42  		String txt = NAME;
43  		if (cnt > -1) {
44  			txt += " (" + cnt + ")";
45  		}
46  		return txt;
47  	}
48  
49  	public JComponent getRenderer(JComponent c, boolean selected, boolean expanded, boolean hasFocus) {
50  		String txt = selected ? "<html>" + toString() : NAME;
51  		return new SelectableLabel(selected, c.isEnabled(), c.getFont(), txt, ICON_HEIGHT);
52  	}
53  
54  	public RecentlyOpenReviewsFilter getRecentlyOpenReviewsFilter() {
55  		return recenltyOpenFilter;
56  	}
57  }