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.crucible.model;
17  
18  import com.atlassian.theplugin.commons.crucible.api.model.CrucibleFilter;
19  import com.atlassian.theplugin.commons.crucible.api.model.ReviewAdapter;
20  import com.atlassian.theplugin.commons.crucible.api.model.notification.CrucibleNotification;
21  import com.atlassian.theplugin.idea.crucible.ReviewNotificationBean;
22  import org.jetbrains.annotations.NotNull;
23  
24  import java.util.*;
25  
26  /**
27   * User: jgorycki
28   * Date: Dec 15, 2008
29   * Time: 4:05:54 PM
30   */
31  public class SearchingCrucibleReviewListModel extends CrucibleReviewListModelListenerHolder {
32  
33  	private String searchTerm;
34  
35  	public SearchingCrucibleReviewListModel(CrucibleReviewListModel parent) {
36  		super(parent);
37  		searchTerm = "";
38  	}
39  
40  	public void setSearchTerm(@NotNull String searchTerm) {
41  
42  		if (this.searchTerm.equals(searchTerm)) {
43  			return;
44  		}
45  		this.searchTerm = searchTerm.toLowerCase();
46  
47  		modelChanged(new UpdateContext(UpdateReason.SEARCH, null, null));
48  	}
49  
50  	private Collection<ReviewAdapter> search(Collection<ReviewAdapter> col) {
51  		if (searchTerm.length() == 0) {
52  			return col;
53  		}
54  		List<ReviewAdapter> list = new ArrayList<ReviewAdapter>();
55  		for (ReviewAdapter r : col) {
56  			if (r.getPermId().getId().toLowerCase().indexOf(searchTerm) > -1
57  					|| r.getName().toLowerCase().indexOf(searchTerm) > -1) {
58  				list.add(r);
59  			}
60  		}
61  		return list;
62  	}
63  
64  	public Collection<ReviewAdapter> getReviews() {
65  		return search(parent.getReviews());
66  	}
67  
68  	public int getReviewCount(CrucibleFilter filter) {
69  		return parent.getReviewCount(filter);
70  	}
71  
72  	public int getPredefinedFiltersReviewCount() {
73  		return parent.getPredefinedFiltersReviewCount();
74  	}
75  
76  	public List<CrucibleNotification> updateReviews(long epoch, Map<CrucibleFilter, ReviewNotificationBean> reviews,
77  			UpdateReason updateReason) {
78  		return Collections.emptyList();
79  	}
80  
81  	public Collection<ReviewAdapter> getOpenInIdeReviews() {
82  		return super.getOpenInIdeReviews();
83  	}
84  
85  	public void rebuildModel(UpdateReason updateReason) {
86  	}
87  
88  	public boolean isRequestObsolete(long epoch) {
89  		return false;
90  	}
91  }