1 11 package org.eclipse.team.internal.ccvs.ui; 12 13 import java.util.Date ; 14 15 import org.eclipse.jface.dialogs.*; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.*; 21 import org.eclipse.ui.PlatformUI; 22 23 import com.ibm.icu.util.Calendar; 24 25 public class CVSHistoryFilterDialog extends TrayDialog { 26 27 private CVSHistoryFilter historyFilter; 28 29 private Button orRadio; 31 private Button andRadio; 32 private Text author; 33 private Text comment; 34 private DateTime fromDate; 35 private DateTime toDate; 36 37 public CVSHistoryFilterDialog(Shell shell) { 38 super(shell); 39 } 40 41 protected void configureShell(Shell newShell) { 42 super.configureShell(newShell); 43 newShell.setText(CVSUIMessages.HistoryFilterDialog_title); 44 } 45 46 protected Control createDialogArea(Composite parent) { 47 Composite topLevel = new Composite(parent, SWT.NONE); 48 GridLayout layout = new GridLayout(); 49 layout.numColumns = 2; 50 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 51 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 52 topLevel.setLayout(layout); 53 54 Label label = new Label(topLevel, SWT.NONE); 56 GridData data = new GridData(GridData.FILL_HORIZONTAL); 57 data.horizontalSpan = 2; 58 label.setLayoutData(data); 59 label.setText(CVSUIMessages.HistoryFilterDialog_showMatching); 60 61 andRadio = new Button(topLevel, SWT.RADIO); 62 andRadio.setText(CVSUIMessages.HistoryFilterDialog_matchingAll); 63 data = new GridData(GridData.FILL_HORIZONTAL); 64 data.horizontalSpan = 2; 65 andRadio.setLayoutData(data); 66 andRadio.setSelection(true); 67 68 orRadio = new Button(topLevel, SWT.RADIO); 69 orRadio.setText(CVSUIMessages.HistoryFilterDialog_matchingAny); 70 data = new GridData(GridData.FILL_HORIZONTAL); 71 data.horizontalSpan = 2; 72 orRadio.setLayoutData(data); 73 74 label = new Label(topLevel, SWT.NONE); 76 label.setText(CVSUIMessages.HistoryFilterDialog_author); 77 author = new Text(topLevel, SWT.BORDER); 78 author.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 79 80 label = new Label(topLevel, SWT.NONE); 82 label.setText(CVSUIMessages.HistoryFilterDialog_comment); 83 comment = new Text(topLevel, SWT.BORDER); 84 comment.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 85 86 label = new Label(topLevel, SWT.NONE); 88 label.setText(CVSUIMessages.HistoryFilterDialog_fromDate); 89 fromDate = new DateTime(topLevel, SWT.DATE); 90 91 label = new Label(topLevel, SWT.NONE); 93 label.setText(CVSUIMessages.HistoryFilterDialog_toDate); 94 toDate = new DateTime(topLevel, SWT.DATE); 95 96 initializeValues(); 97 98 PlatformUI.getWorkbench().getHelpSystem().setHelp(topLevel, IHelpContextIds.HISTORY_FILTER_DIALOG); 100 Dialog.applyDialogFont(parent); 101 return topLevel; 102 } 103 104 void initializeValues() { 105 if (historyFilter == null) 106 return; 107 if (historyFilter.author != null) { 108 author.setText(historyFilter.author); 109 } 110 if (historyFilter.comment != null) { 111 comment.setText(historyFilter.comment); 112 } 113 orRadio.setSelection(historyFilter.isOr); 114 andRadio.setSelection(!historyFilter.isOr); 115 Calendar calendar = Calendar.getInstance(); 116 if (historyFilter.fromDate != null) { 117 calendar.setTime(historyFilter.fromDate); 118 fromDate.setDay(calendar.get(Calendar.DATE)); 119 fromDate.setMonth(calendar.get(Calendar.MONTH)); 120 fromDate.setYear(calendar.get(Calendar.YEAR)); 121 } 122 if (historyFilter.toDate != null) { 123 calendar.setTime(historyFilter.toDate); 124 toDate.setDay(calendar.get(Calendar.DATE)); 125 toDate.setMonth(calendar.get(Calendar.MONTH)); 126 toDate.setYear(calendar.get(Calendar.YEAR)); 127 } 128 } 129 130 133 protected void buttonPressed(int buttonId) { 134 if (IDialogConstants.CANCEL_ID == buttonId) { 135 super.buttonPressed(buttonId); 136 return; 137 } 138 Date fromDate = getFromDate(); 139 Date toDate = getToDate(); 140 141 historyFilter = new CVSHistoryFilter(author.getText(), comment.getText(), fromDate, toDate, orRadio.getSelection()); 143 144 super.buttonPressed(buttonId); 145 } 146 147 154 private Calendar getCalendar(DateTime dateWidget) { 155 Calendar calendar = Calendar.getInstance(); 156 if (isFutureDate(dateWidget, calendar)) { 157 return null; 158 } 159 calendar.set(Calendar.YEAR, dateWidget.getYear()); 160 calendar.set(Calendar.MONTH, dateWidget.getMonth()); 161 calendar.set(Calendar.DATE, dateWidget.getDay()); 162 163 calendar.set(Calendar.HOUR_OF_DAY, 0); 166 calendar.set(Calendar.MINUTE, 0); 167 calendar.set(Calendar.SECOND, 0); 168 return calendar; 169 } 170 171 private boolean isFutureDate(DateTime dateWidget, Calendar calendar) { 172 if (calendar.get(Calendar.YEAR) < dateWidget.getYear()) 173 return true; 174 if (calendar.get(Calendar.YEAR) == dateWidget.getYear()) { 175 if (calendar.get(Calendar.MONTH) < dateWidget.getMonth()) 176 return true; 177 if (calendar.get(Calendar.MONTH) == dateWidget.getMonth() 178 && calendar.get(Calendar.DAY_OF_MONTH) <= dateWidget.getDay()) 179 return true; 180 } 181 return false; 182 } 183 184 private Date getFromDate() { 186 Calendar calendar = getCalendar(fromDate); 187 if (calendar == null) 188 return null; 189 190 calendar.set(Calendar.HOUR_OF_DAY, 0); 193 calendar.set(Calendar.MINUTE, 0); 194 calendar.set(Calendar.SECOND, 0); 195 return calendar.getTime(); 196 } 197 198 private Date getToDate() { 200 Calendar calendar = getCalendar(toDate); 201 if (calendar == null) 202 return null; 203 204 calendar.set(Calendar.HOUR_OF_DAY, 23); 207 calendar.set(Calendar.MINUTE, 59); 208 calendar.set(Calendar.SECOND, 59); 209 return calendar.getTime(); 210 } 211 212 216 public CVSHistoryFilter getFilter() { 217 return historyFilter; 218 } 219 220 223 public void setFilter(CVSHistoryFilter filter) { 224 this.historyFilter = filter; 225 } 226 227 } 228 | Popular Tags |