KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > history > DateHistoryCategory


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.history;
12
13 import java.util.ArrayList JavaDoc;
14 import com.ibm.icu.util.Calendar;
15
16 import org.eclipse.team.core.history.IFileRevision;
17
18 public class DateHistoryCategory extends AbstractHistoryCategory {
19     
20     private String JavaDoc name;
21     private Calendar fromDate;
22     private Calendar toDate;
23     
24     private IFileRevision[] revisions;
25     
26     /**
27      * Creates a new instance of DateCVSHistoryCategory.
28      *
29      * @param name the name of this category
30      * @param fromDate the start date for this category or <code>null</code> if you want everything up to the end date
31      * @param toDate the end point for this category or <code>null</code> if you want just all entries in the
32      * start date
33      */

34     public DateHistoryCategory(String JavaDoc name, Calendar fromDate, Calendar toDate){
35         this.name = name;
36         this.fromDate = fromDate;
37         this.toDate = toDate;
38     }
39     
40     /* (non-Javadoc)
41      * @see org.eclipse.team.internal.ccvs.ui.AbstractCVSHistoryCategory#getName()
42      */

43     public String JavaDoc getName() {
44         return name;
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.team.internal.ccvs.ui.AbstractCVSHistoryCategory#collectFileRevisions(org.eclipse.team.core.history.IFileRevision[], boolean)
49      */

50     public boolean collectFileRevisions(IFileRevision[] fileRevisions, boolean shouldRemove) {
51         
52         ArrayList JavaDoc pertinentRevisions = new ArrayList JavaDoc();
53         ArrayList JavaDoc nonPertinentRevisions = new ArrayList JavaDoc();
54         
55         for (int i = 0; i < fileRevisions.length; i++) {
56             //get the current file revision's date
57
Calendar fileRevDate = Calendar.getInstance();
58             fileRevDate.setTimeInMillis(fileRevisions[i].getTimestamp());
59             
60             int fileRevDay = fileRevDate.get(Calendar.DAY_OF_YEAR);
61             int fileRevYear = fileRevDate.get(Calendar.YEAR);
62             
63             if (fromDate == null){
64                 //check to see if this revision is within the toDate range
65
if (((fileRevDay<toDate.get(Calendar.DAY_OF_YEAR)) && (fileRevYear == toDate.get(Calendar.YEAR))) ||
66                     (fileRevYear < toDate.get(Calendar.YEAR))){
67                     pertinentRevisions.add(fileRevisions[i]);
68                 } else {
69                     //revision is equal or later then the to date, add to rejects list
70
nonPertinentRevisions.add(fileRevisions[i]);
71                 }
72             } else if (toDate == null){
73                 //check to see if this revision falls on the same day as the fromDate
74
if ((fileRevDay == fromDate.get(Calendar.DAY_OF_YEAR)) &&
75                     (fileRevYear == fromDate.get(Calendar.YEAR))){
76                     pertinentRevisions.add(fileRevisions[i]);
77                 } else {
78                     nonPertinentRevisions.add(fileRevisions[i]);
79                 }
80             } else {
81                 //check the range
82
if ((fileRevYear >= fromDate.get(Calendar.YEAR)) &&
83                     (fileRevYear <= toDate.get(Calendar.YEAR)) &&
84                     (fileRevDay >= fromDate.get(Calendar.DAY_OF_YEAR)) &&
85                     (fileRevDay < toDate.get(Calendar.DAY_OF_YEAR))
86                 ) {
87                     pertinentRevisions.add(fileRevisions[i]);
88                 } else {
89                     nonPertinentRevisions.add(fileRevisions[i]);
90                 }
91             }
92         }
93         
94         //check mode
95
if (shouldRemove){
96             //TODO: pass in an object containing the file revision arrays and modify the contents
97
/*IFileRevision[] tempRevision = (IFileRevision[]) nonPertinentRevisions.toArray(new IFileRevision[nonPertinentRevisions.size()]);
98             System.arraycopy(tempRevision, 0, fileRevisions, 0, tempRevision.length);*/

99         }
100         
101         if (pertinentRevisions.size() > 0){
102             IFileRevision[] tempRevision = (IFileRevision[]) pertinentRevisions.toArray(new IFileRevision[pertinentRevisions.size()]);
103             revisions = new IFileRevision[tempRevision.length];
104             System.arraycopy(tempRevision, 0, revisions, 0, tempRevision.length);
105             return true;
106         }
107         
108         return false;
109     }
110
111     /* (non-Javadoc)
112      * @see org.eclipse.team.internal.ccvs.ui.AbstractCVSHistoryCategory#getRevisions()
113      */

114     public IFileRevision[] getRevisions() {
115         return revisions;
116     }
117
118     /* (non-Javadoc)
119      * @see org.eclipse.team.internal.ccvs.ui.AbstractCVSHistoryCategory#hasRevisions()
120      */

121     public boolean hasRevisions() {
122         if (revisions != null && revisions.length > 0)
123             return true;
124         
125         return false;
126     }
127
128 }
129
Popular Tags