|
Lines 10-25
Link Here
|
| 10 |
import java.text.MessageFormat; |
10 |
import java.text.MessageFormat; |
| 11 |
|
11 |
|
| 12 |
import org.eclipse.jface.dialogs.MessageDialog; |
12 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
|
13 |
import org.eclipse.jface.layout.GridDataFactory; |
| 13 |
import org.eclipse.mylyn.tasks.core.*; |
14 |
import org.eclipse.mylyn.tasks.core.*; |
|
|
15 |
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin; |
| 14 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditor; |
16 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditor; |
| 15 |
import org.eclipse.mylyn.xplanner.ui.XPlannerMylynUIPlugin; |
17 |
import org.eclipse.mylyn.xplanner.ui.XPlannerMylynUIPlugin; |
| 16 |
import org.eclipse.mylyn.xplanner.ui.XPlannerRepositoryUtils; |
18 |
import org.eclipse.mylyn.xplanner.ui.XPlannerRepositoryUtils; |
|
|
19 |
import org.eclipse.swt.SWT; |
| 20 |
import org.eclipse.swt.events.SelectionEvent; |
| 21 |
import org.eclipse.swt.events.SelectionListener; |
| 22 |
import org.eclipse.swt.graphics.Point; |
| 17 |
import org.eclipse.swt.layout.GridLayout; |
23 |
import org.eclipse.swt.layout.GridLayout; |
| 18 |
import org.eclipse.swt.widgets.Composite; |
24 |
import org.eclipse.swt.widgets.*; |
| 19 |
import org.eclipse.swt.widgets.Control; |
25 |
import org.eclipse.ui.*; |
| 20 |
import org.eclipse.ui.IEditorInput; |
|
|
| 21 |
import org.eclipse.ui.IEditorSite; |
| 22 |
import org.eclipse.ui.forms.editor.FormEditor; |
26 |
import org.eclipse.ui.forms.editor.FormEditor; |
|
|
27 |
import org.eclipse.ui.forms.widgets.FormToolkit; |
| 23 |
import org.eclipse.ui.forms.widgets.ImageHyperlink; |
28 |
import org.eclipse.ui.forms.widgets.ImageHyperlink; |
| 24 |
|
29 |
|
| 25 |
/** |
30 |
/** |
|
Lines 27-35
Link Here
|
| 27 |
* @author Helen Bershadskaya |
32 |
* @author Helen Bershadskaya |
| 28 |
*/ |
33 |
*/ |
| 29 |
public class XPlannerTaskEditor extends AbstractRepositoryTaskEditor |
34 |
public class XPlannerTaskEditor extends AbstractRepositoryTaskEditor |
| 30 |
implements XPlannerEditorAttributeProvider { |
35 |
implements XPlannerEditorAttributeProvider, ITaskTimingListener, SelectionListener { |
| 31 |
|
36 |
|
| 32 |
private XPlannerTaskEditorExtraControls extraControls; |
37 |
private XPlannerTaskEditorExtraControls extraControls; |
|
|
38 |
private Button useTimeTrackingButton; |
| 39 |
private Button addToCurrentTimeButton; |
| 40 |
private Button replaceCurrentTimeButton; |
| 41 |
private Button roundToHalfHourButton; |
| 42 |
|
| 43 |
private boolean useAutoTimeTracking; |
| 44 |
private boolean roundToHalfHour; |
| 45 |
private boolean addToCurrentTime; |
| 33 |
|
46 |
|
| 34 |
public XPlannerTaskEditor(FormEditor editor) { |
47 |
public XPlannerTaskEditor(FormEditor editor) { |
| 35 |
super(editor); |
48 |
super(editor); |
|
Lines 44-50
Link Here
|
| 44 |
|
57 |
|
| 45 |
@Override |
58 |
@Override |
| 46 |
protected void addRadioButtons(Composite buttonComposite) { |
59 |
protected void addRadioButtons(Composite buttonComposite) { |
| 47 |
//TODO -- ? |
60 |
createTimeTrackingPanel(buttonComposite); |
| 48 |
} |
61 |
} |
| 49 |
|
62 |
|
| 50 |
@Override |
63 |
@Override |
|
Lines 150-157
Link Here
|
| 150 |
} |
163 |
} |
| 151 |
|
164 |
|
| 152 |
if (errorMessage == null) { |
165 |
if (errorMessage == null) { |
|
|
166 |
savePreferenceSettings(); |
| 153 |
super.submitToRepository(); |
167 |
super.submitToRepository(); |
|
|
168 |
|
| 154 |
} |
169 |
} |
| 155 |
} |
170 |
} |
| 156 |
|
171 |
|
|
|
172 |
private void loadValuesFromPreferenceSettings() { |
| 173 |
// auto tracking |
| 174 |
boolean useTimeTrackingPreference = XPlannerMylynUIPlugin.getBooleanPreference(XPlannerMylynUIPlugin.USE_AUTO_TIME_TRACKING_PREFERENCE_NAME); |
| 175 |
useTimeTrackingButton.setSelection(useTimeTrackingPreference); |
| 176 |
setUseAutoTimeTracking(useTimeTrackingPreference); |
| 177 |
|
| 178 |
// rounding |
| 179 |
boolean roundToHalfHourPreference = XPlannerMylynUIPlugin.getBooleanPreference(XPlannerMylynUIPlugin.ROUND_AUTO_TIME_TRACKING_TO_HALF_HOUR_PREFERENCE_NAME); |
| 180 |
roundToHalfHourButton.setSelection(roundToHalfHourPreference); |
| 181 |
setRoundToHalfHour(roundToHalfHourPreference); |
| 182 |
|
| 183 |
// add or replace |
| 184 |
boolean addToCurrentTimePreference = XPlannerMylynUIPlugin.getBooleanPreference(XPlannerMylynUIPlugin.ADD_AUTO_TRACKED_TIME_TO_REPOSITORY_VALUE_PREFERENCE_NAME); |
| 185 |
addToCurrentTimeButton.setSelection(addToCurrentTimePreference); |
| 186 |
replaceCurrentTimeButton.setSelection(!addToCurrentTimePreference); |
| 187 |
setAddToCurrentTime(addToCurrentTimePreference); |
| 188 |
} |
| 189 |
|
| 190 |
private void savePreferenceSettings() { |
| 191 |
// auto tracking |
| 192 |
XPlannerMylynUIPlugin.setBooleanPreference( |
| 193 |
XPlannerMylynUIPlugin.USE_AUTO_TIME_TRACKING_PREFERENCE_NAME, isUseAutoTimeTracking()); |
| 194 |
|
| 195 |
// rounding |
| 196 |
XPlannerMylynUIPlugin.setBooleanPreference( |
| 197 |
XPlannerMylynUIPlugin.ROUND_AUTO_TIME_TRACKING_TO_HALF_HOUR_PREFERENCE_NAME, isRoundToHalfHour()); |
| 198 |
|
| 199 |
// add or replace |
| 200 |
XPlannerMylynUIPlugin.setBooleanPreference( |
| 201 |
XPlannerMylynUIPlugin.ADD_AUTO_TRACKED_TIME_TO_REPOSITORY_VALUE_PREFERENCE_NAME, isAddToCurrentTime()); |
| 202 |
} |
| 203 |
|
| 204 |
private void createTimeTrackingPanel(Composite parent) { |
| 205 |
FormToolkit toolkit = new FormToolkit(getSite().getShell().getDisplay()); |
| 206 |
Composite timeTrackingComposite = toolkit.createComposite(parent, SWT.NONE); |
| 207 |
|
| 208 |
GridDataFactory.fillDefaults().span(4, 1).applyTo(timeTrackingComposite); |
| 209 |
timeTrackingComposite.setLayout(new GridLayout(1, false)); |
| 210 |
|
| 211 |
useTimeTrackingButton = toolkit.createButton(timeTrackingComposite, "Update actual task time from Mylyn's time tracker", SWT.CHECK); |
| 212 |
GridDataFactory.fillDefaults().span(1, 1).grab(true, false).applyTo(useTimeTrackingButton); |
| 213 |
useTimeTrackingButton.addSelectionListener(this); |
| 214 |
|
| 215 |
roundToHalfHourButton = toolkit.createButton(timeTrackingComposite, "Round time to half hour", SWT.CHECK); |
| 216 |
GridDataFactory.fillDefaults().indent(new Point(15, 5)).applyTo(roundToHalfHourButton); |
| 217 |
roundToHalfHourButton.addSelectionListener(this); |
| 218 |
|
| 219 |
Composite updateMethodComposite = toolkit.createComposite(timeTrackingComposite); |
| 220 |
GridDataFactory.fillDefaults().indent(new Point(10, 0)).applyTo(updateMethodComposite); |
| 221 |
updateMethodComposite.setLayout(new GridLayout(2, true)); |
| 222 |
addToCurrentTimeButton = toolkit.createButton(updateMethodComposite, "Add to current repository time", SWT.RADIO); |
| 223 |
GridDataFactory.fillDefaults().applyTo(addToCurrentTimeButton); |
| 224 |
addToCurrentTimeButton.setSelection(true); // just for a single radio default |
| 225 |
addToCurrentTimeButton.addSelectionListener(this); |
| 226 |
|
| 227 |
replaceCurrentTimeButton = toolkit.createButton(updateMethodComposite, "Replace current repository time", SWT.RADIO); |
| 228 |
GridDataFactory.fillDefaults().applyTo(replaceCurrentTimeButton); |
| 229 |
replaceCurrentTimeButton.addSelectionListener(this); |
| 230 |
|
| 231 |
TasksUiPlugin.getTaskListManager().addTimingListener(this); |
| 232 |
loadValuesFromPreferenceSettings(); |
| 233 |
updateTimeTrackingControls(); |
| 234 |
} |
| 235 |
|
| 236 |
private void updateTimeTrackingControls() { |
| 237 |
boolean enabled = isUseAutoTimeTracking(); |
| 238 |
|
| 239 |
roundToHalfHourButton.setEnabled(enabled); |
| 240 |
addToCurrentTimeButton.setEnabled(enabled); |
| 241 |
replaceCurrentTimeButton.setEnabled(enabled); |
| 242 |
} |
| 243 |
|
| 244 |
@Override |
| 245 |
public void dispose() { |
| 246 |
savePreferenceSettings(); |
| 247 |
TasksUiPlugin.getTaskListManager().removeTimingListener(this); |
| 248 |
super.dispose(); |
| 249 |
} |
| 250 |
|
| 251 |
public void close() { |
| 252 |
savePreferenceSettings(); |
| 253 |
super.close(); |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* ITaskTimingListener Implementation |
| 258 |
*/ |
| 259 |
public void elapsedTimeUpdated(AbstractTask task, final long newElapsedTime) { |
| 260 |
// only auto-update actual time if user chose to do so |
| 261 |
if (!isUseAutoTimeTracking()) { |
| 262 |
return; |
| 263 |
} |
| 264 |
|
| 265 |
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { |
| 266 |
public void run() { |
| 267 |
extraControls.updateActualTimeWithElapsed(newElapsedTime, |
| 268 |
isAddToCurrentTime(), isRoundToHalfHour()); |
| 269 |
}}); |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
public void setUseAutoTimeTracking(boolean useTimeTracking) { |
| 274 |
this.useAutoTimeTracking = useTimeTracking; |
| 275 |
} |
| 276 |
|
| 277 |
public boolean isUseAutoTimeTracking() { |
| 278 |
return useAutoTimeTracking; |
| 279 |
} |
| 280 |
|
| 281 |
private void forceElapsedTimeUpdated() { |
| 282 |
AbstractTask task = TasksUiPlugin.getTaskListManager().getTaskList().getTask(getRepositoryTaskData().getHandleIdentifier()); |
| 283 |
long elapsedTimeMillis = TasksUiPlugin.getTaskActivityManager().getElapsedTime( |
| 284 |
TasksUiPlugin.getTaskListManager().getTaskList().getTask(getRepositoryTaskData().getHandleIdentifier())); |
| 285 |
|
| 286 |
elapsedTimeUpdated(task, elapsedTimeMillis); |
| 287 |
} |
| 288 |
|
| 289 |
public void widgetDefaultSelected(SelectionEvent e) { |
| 290 |
Object source = e.getSource(); |
| 291 |
|
| 292 |
if (source.equals(useTimeTrackingButton)) { |
| 293 |
updateTimeTrackingControls(); |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
public void widgetSelected(SelectionEvent e) { |
| 298 |
Object source = e.getSource(); |
| 299 |
|
| 300 |
if (source.equals(useTimeTrackingButton)) { |
| 301 |
setUseAutoTimeTracking(useTimeTrackingButton.getSelection()); |
| 302 |
|
| 303 |
if (isUseAutoTimeTracking()) { |
| 304 |
forceElapsedTimeUpdated(); |
| 305 |
} |
| 306 |
|
| 307 |
updateTimeTrackingControls(); |
| 308 |
} |
| 309 |
else if (source.equals(roundToHalfHourButton)) { |
| 310 |
setRoundToHalfHour(roundToHalfHourButton.getSelection()); |
| 311 |
forceElapsedTimeUpdated(); |
| 312 |
} |
| 313 |
else if (source.equals(replaceCurrentTimeButton)) { |
| 314 |
setAddToCurrentTime(!replaceCurrentTimeButton.getSelection()); |
| 315 |
if (!isAddToCurrentTime()) { |
| 316 |
forceElapsedTimeUpdated(); |
| 317 |
} |
| 318 |
} |
| 319 |
else if (source.equals(addToCurrentTimeButton)) { |
| 320 |
setAddToCurrentTime(addToCurrentTimeButton.getSelection()); |
| 321 |
if (isAddToCurrentTime()) { |
| 322 |
forceElapsedTimeUpdated(); |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
private boolean isRoundToHalfHour() { |
| 328 |
return roundToHalfHour; |
| 329 |
} |
| 330 |
|
| 331 |
private void setRoundToHalfHour(boolean roundToHalfHour) { |
| 332 |
this.roundToHalfHour = roundToHalfHour; |
| 333 |
} |
| 334 |
|
| 335 |
private boolean isAddToCurrentTime() { |
| 336 |
return addToCurrentTime; |
| 337 |
} |
| 338 |
|
| 339 |
private void setAddToCurrentTime(boolean addToCurrentTime) { |
| 340 |
this.addToCurrentTime = addToCurrentTime; |
| 341 |
} |
| 157 |
} |
342 |
} |