### Eclipse Workspace Patch 1.0 #P org.eclipse.team.ui Index: src/org/eclipse/team/internal/ui/synchronize/SubscriberRefreshSchedule.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SubscriberRefreshSchedule.java,v retrieving revision 1.18 diff -u -r1.18 SubscriberRefreshSchedule.java --- src/org/eclipse/team/internal/ui/synchronize/SubscriberRefreshSchedule.java 18 Dec 2006 14:54:45 -0000 1.18 +++ src/org/eclipse/team/internal/ui/synchronize/SubscriberRefreshSchedule.java 12 Aug 2008 15:34:04 -0000 @@ -7,10 +7,10 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Trevor S. Kaufman - bug 156152 *******************************************************************************/ package org.eclipse.team.internal.ui.synchronize; -import com.ibm.icu.text.DateFormat; import java.util.Date; import org.eclipse.core.runtime.jobs.Job; @@ -20,6 +20,9 @@ import org.eclipse.ui.IMemento; import org.eclipse.ui.actions.ActionFactory; +import com.ibm.icu.text.DateFormat; +import com.ibm.icu.util.Calendar; + /** * Schedule to refresh a subscriber at a specified interval. The schedule can be disabled or enabled * and will create the refresh job. @@ -28,6 +31,8 @@ */ public class SubscriberRefreshSchedule { private long refreshInterval = 3600; // 1 hour default + private Date refreshStart; + private boolean runOnce = false; private boolean enabled = false; @@ -46,6 +51,16 @@ * Key for schedule in memento */ private static final String CTX_REFRESHSCHEDULE_ENABLED = TeamUIPlugin.ID + ".CTX_REFRESHSCHEDULE_ENABLED"; //$NON-NLS-1$ + + /** + * Key for start date in memento + */ + private static final String CTX_REFRESHSCHEDULE_START = TeamUIPlugin.ID + ".CTX_REFRESHSCHEDULE_START"; //$NON-NLS-1$ + + /** + * Key for run once in memento + */ + private static final String CTX_REFRESHSCHEDULE_RUNONCE = TeamUIPlugin.ID + ".CTX_REFRESHSCHEDULE_RUNONCE"; //$NON-NLS-1$ private IRefreshSubscriberListener refreshSubscriberListener = new IRefreshSubscriberListener() { public void refreshStarted(IRefreshEvent event) { @@ -69,6 +84,10 @@ public SubscriberRefreshSchedule(IRefreshable refreshable) { this.refreshable = refreshable; RefreshParticipantJob.addRefreshListener(refreshSubscriberListener); + + Calendar cal = Calendar.getInstance(); + cal.clear(); + refreshStart = cal.getTime(); } /** @@ -126,9 +145,18 @@ } job.setRefreshInterval(getRefreshInterval()); job.setRestartOnCancel(true); - job.setReschedule(true); + job.setReschedule(!runOnce); // Schedule delay is in mills. - job.schedule(getRefreshInterval() * 1000); + Calendar now = Calendar.getInstance(); + Calendar start = Calendar.getInstance(); + start.setTime(refreshStart); + start.set(now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DATE)); + + if (now.after(start)) { + start.add(Calendar.DATE, 1); + } + long offset = start.getTimeInMillis() - now.getTimeInMillis(); + job.schedule(offset); } protected void stopJob() { @@ -148,6 +176,8 @@ public void saveState(IMemento memento) { memento.putString(CTX_REFRESHSCHEDULE_ENABLED, Boolean.toString(enabled)); memento.putInteger(CTX_REFRESHSCHEDULE_INTERVAL, (int)refreshInterval); + memento.putString(CTX_REFRESHSCHEDULE_START, Long.toString(refreshStart.getTime())); + memento.putString(CTX_REFRESHSCHEDULE_RUNONCE, Boolean.toString(runOnce)); } public static SubscriberRefreshSchedule init(IMemento memento, IRefreshable refreshable) { @@ -155,7 +185,14 @@ if(memento != null) { String enabled = memento.getString(CTX_REFRESHSCHEDULE_ENABLED); int interval = memento.getInteger(CTX_REFRESHSCHEDULE_INTERVAL).intValue(); + String startString = memento.getString(CTX_REFRESHSCHEDULE_START); + String runOnce = memento.getString(CTX_REFRESHSCHEDULE_RUNONCE); + if (startString != null) { + long start = Long.parseLong(startString); + schedule.setRefreshStartTime(new Date(start)); + } schedule.setRefreshInterval(interval); + schedule.setRunOnce("true".equals(runOnce) ? true : false); //$NON-NLS-1$ schedule.setEnabled("true".equals(enabled) ? true : false, false /* don't start job */); //$NON-NLS-1$ } // Use the defaults if a schedule hasn't been saved or can't be found. @@ -212,4 +249,32 @@ public IRefreshable getRefreshable() { return refreshable; } + + public Date getRefreshStartTime() { + return refreshStart; + } + + public void setRefreshStartTime(Date refreshStart) { + if(refreshStart != getRefreshStartTime()) { + stopJob(); + this.refreshStart = refreshStart; + if(isEnabled()) { + startJob(); + } + } + } + + public boolean getRunOnce() { + return runOnce; + } + + public void setRunOnce(boolean runOnce) { + if (runOnce != getRunOnce()) { + startJob(); + this.runOnce = runOnce; + if (isEnabled()) { + startJob(); + } + } + } } Index: src/org/eclipse/team/internal/ui/synchronize/ConfigureSynchronizeScheduleComposite.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/ConfigureSynchronizeScheduleComposite.java,v retrieving revision 1.14 diff -u -r1.14 ConfigureSynchronizeScheduleComposite.java --- src/org/eclipse/team/internal/ui/synchronize/ConfigureSynchronizeScheduleComposite.java 21 Jun 2006 19:26:16 -0000 1.14 +++ src/org/eclipse/team/internal/ui/synchronize/ConfigureSynchronizeScheduleComposite.java 12 Aug 2008 15:34:04 -0000 @@ -8,12 +8,14 @@ * Contributors: * IBM Corporation - initial API and implementation * Sebastian Davids - bug 54630 + * Trevor S. Kaufman - bug 156152 *******************************************************************************/ package org.eclipse.team.internal.ui.synchronize; +import java.util.Date; + +import org.eclipse.jface.dialogs.*; import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; @@ -22,15 +24,13 @@ import org.eclipse.swt.graphics.GC; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.*; import org.eclipse.team.internal.ui.TeamUIMessages; import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.ui.synchronize.ISynchronizeParticipant; +import com.ibm.icu.util.Calendar; + /** * A composite that allows editing a subscriber refresh schedule. A validator can be used to allow * containers to show page completion. @@ -42,9 +42,12 @@ private SubscriberRefreshSchedule schedule; private Button userRefreshOnly; private Button enableBackgroundRefresh; - private Text time; + private Text timeInterval; private Combo hoursOrSeconds; private IPageValidator validator; + private DateTime startTime; + private Button immediately; + private Button runOnce; public ConfigureSynchronizeScheduleComposite(Composite parent, SubscriberRefreshSchedule schedule, IPageValidator validator) { super(parent, SWT.NONE); @@ -72,7 +75,13 @@ hours = true; } hoursOrSeconds.select(hours ? 0 : 1); - time.setText(Long.toString(minutes)); + timeInterval.setText(Long.toString(minutes)); + runOnce.setSelection(schedule.getRunOnce()); + + Date start = schedule.getRefreshStartTime(); + Calendar cal = Calendar.getInstance(); + cal.setTime(start); + startTime.setTime(cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND)); } /* (non-Javadoc) @@ -135,7 +144,7 @@ gridData.horizontalSpan = 2; composite.setLayoutData(gridData); final GridLayout gridLayout_1 = new GridLayout(); - gridLayout_1.numColumns = 3; + gridLayout_1.numColumns = 4; gridLayout_1.marginWidth = 0; gridLayout_1.marginHeight = 0; gridLayout_1.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fontMetrics, IDialogConstants.HORIZONTAL_SPACING); @@ -143,19 +152,39 @@ composite.setLayout(gridLayout_1); { final Label label = new Label(composite, SWT.NONE); + label.setText(TeamUIMessages.ConfigureRefreshScheduleDialog_3a); + } + { + startTime = new DateTime(composite, SWT.TIME | SWT.BORDER); + final GridData gridData_1 = new GridData(); + gridData_1.horizontalSpan = 2; + startTime.setLayoutData(gridData_1); + + } + { + immediately = new Button(composite, SWT.CHECK); + immediately.setText(TeamUIMessages.ConfigureRefreshScheduleDialog_3b); + immediately.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateEnablements(); + } + }); + } + { + final Label label = new Label(composite, SWT.NONE); label.setText(TeamUIMessages.ConfigureRefreshScheduleDialog_4); } { - time = new Text(composite, SWT.BORDER | SWT.RIGHT); + timeInterval = new Text(composite, SWT.BORDER | SWT.RIGHT); final GridData gridData_1 = new GridData(); gridData_1.widthHint = 35; - time.setLayoutData(gridData_1); - time.addModifyListener(new ModifyListener() { + timeInterval.setLayoutData(gridData_1); + timeInterval.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { updateEnablements(); } }); - time.addVerifyListener(new VerifyListener() { + timeInterval.addVerifyListener(new VerifyListener() { public void verifyText(VerifyEvent e) { String string = e.text; char [] chars = new char [string.length ()]; @@ -174,6 +203,15 @@ hoursOrSeconds.setItems(new String[] { TeamUIMessages.ConfigureRefreshScheduleDialog_5, TeamUIMessages.ConfigureRefreshScheduleDialog_6 }); // hoursOrSeconds.setLayoutData(new GridData()); } + { + runOnce = new Button(composite, SWT.CHECK); + runOnce.setText("Run Once"); //$NON-NLS-1$ + runOnce.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + updateEnablements(); + } + }); + } } initializeValues(); } @@ -182,18 +220,33 @@ * @see org.eclipse.jface.dialogs.Dialog#okPressed() */ public void saveValues() { - int hours = hoursOrSeconds.getSelectionIndex(); - try { - long seconds = Long.parseLong(time.getText()); - if(hours == 0) { - seconds = seconds * 3600; - } else { - seconds = seconds * 60; - } - schedule.setRefreshInterval(seconds); - } catch (NumberFormatException e) { - // keep old value + if (!runOnce.getSelection()) { + int hours = hoursOrSeconds.getSelectionIndex(); + try { + long seconds = Long.parseLong(timeInterval.getText()); + if(hours == 0) { + seconds = seconds * 3600; + } else { + seconds = seconds * 60; + } + schedule.setRefreshInterval(seconds); + } catch (NumberFormatException e) { + // keep old value + } + } else { + schedule.setRunOnce(runOnce.getSelection()); } + + Calendar cal = Calendar.getInstance(); + if (! immediately.getSelection()) { + cal.set(Calendar.HOUR_OF_DAY, startTime.getHours()); + cal.set(Calendar.MINUTE, startTime.getMinutes()); + cal.set(Calendar.SECOND, startTime.getSeconds()); + } else { + cal.add(Calendar.SECOND, 1); // ensure time is today + } + schedule.setRefreshStartTime(cal.getTime()); + if(schedule.isEnabled() != enableBackgroundRefresh.getSelection()) { schedule.setEnabled(enableBackgroundRefresh.getSelection(), true /* allow to start */); } @@ -216,7 +269,7 @@ validator.setComplete(null); } else { try { - long number = Long.parseLong(time.getText()); + long number = Long.parseLong(timeInterval.getText()); if(number <= 0) { validator.setComplete(TeamUIMessages.ConfigureRefreshScheduleDialog_7); } else { @@ -226,8 +279,19 @@ validator.setComplete(TeamUIMessages.ConfigureRefreshScheduleDialog_8); } } - time.setEnabled(enableBackgroundRefresh.getSelection()); + timeInterval.setEnabled(enableBackgroundRefresh.getSelection()); hoursOrSeconds.setEnabled(enableBackgroundRefresh.getSelection()); + runOnce.setEnabled(enableBackgroundRefresh.getSelection()); + if (runOnce.isEnabled()) { + timeInterval.setEnabled(!runOnce.getSelection()); + hoursOrSeconds.setEnabled(!runOnce.getSelection()); + } + + startTime.setEnabled(enableBackgroundRefresh.getSelection()); + immediately.setEnabled(enableBackgroundRefresh.getSelection()); + if (immediately.isEnabled()) { + startTime.setEnabled(!immediately.getSelection()); + } } private Label createWrappingLabel(Composite parent, String text, int indent, int horizontalSpan) { Index: src/org/eclipse/team/internal/ui/messages.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/messages.properties,v retrieving revision 1.237 diff -u -r1.237 messages.properties --- src/org/eclipse/team/internal/ui/messages.properties 28 Jul 2008 12:00:58 -0000 1.237 +++ src/org/eclipse/team/internal/ui/messages.properties 12 Aug 2008 15:34:04 -0000 @@ -7,6 +7,7 @@ # # Contributors: # IBM Corporation - initial API and implementation +# Trevor S. Kaufman - - bug 156152 ############################################################################### ############################################### # Message catalog for org.eclipse.team.ui @@ -239,7 +240,9 @@ ConfigureMultipleProjectsWizard_1=There are still projects that have not been shared. Finishing the wizard now will leave them in that state. ConfigureRefreshScheduleDialog_2=Do not schedule the synchronize operation to run periodically. ConfigureRefreshScheduleDialog_3=Using the following schedule: -ConfigureRefreshScheduleDialog_4=Every: +ConfigureRefreshScheduleDialog_3a=Synchronize at: +ConfigureRefreshScheduleDialog_3b=Immediately +ConfigureRefreshScheduleDialog_4=Repeat Every: ConfigureRefreshScheduleDialog_5=hour(s) ConfigureRefreshScheduleDialog_6=minute(s) ConfigureRefreshScheduleDialog_7=Number must be a positive number greater than 0 Index: src/org/eclipse/team/internal/ui/TeamUIMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/TeamUIMessages.java,v retrieving revision 1.70 diff -u -r1.70 TeamUIMessages.java --- src/org/eclipse/team/internal/ui/TeamUIMessages.java 28 Jul 2008 12:00:58 -0000 1.70 +++ src/org/eclipse/team/internal/ui/TeamUIMessages.java 12 Aug 2008 15:34:03 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM - Initial API and implementation + * Trevor S. Kaufman - - bug 156152 *******************************************************************************/ package org.eclipse.team.internal.ui; @@ -412,6 +413,8 @@ public static String ConfigureRefreshScheduleDialog_1a; public static String ConfigureRefreshScheduleDialog_2; public static String ConfigureRefreshScheduleDialog_3; + public static String ConfigureRefreshScheduleDialog_3a; + public static String ConfigureRefreshScheduleDialog_3b; public static String ConfigureRefreshScheduleDialog_4; public static String ConfigureRefreshScheduleDialog_5; public static String ConfigureRefreshScheduleDialog_6;