1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45 package de.nierbeck.timeTrack.views;
46
47 import java.text.DateFormat;
48 import java.text.ParseException;
49 import java.util.ArrayList;
50 import java.util.Arrays;
51 import java.util.Calendar;
52 import java.util.Date;
53 import java.util.GregorianCalendar;
54 import java.util.Iterator;
55 import java.util.List;
56 import java.util.Observable;
57 import java.util.Observer;
58
59 import javax.xml.bind.JAXBException;
60
61 import org.eclipse.core.internal.resources.Folder;
62 import org.eclipse.core.resources.IResource;
63 import org.eclipse.core.runtime.IAdaptable;
64 import org.eclipse.jface.action.Action;
65 import org.eclipse.jface.action.IMenuListener;
66 import org.eclipse.jface.action.IMenuManager;
67 import org.eclipse.jface.action.IToolBarManager;
68 import org.eclipse.jface.action.MenuManager;
69 import org.eclipse.jface.action.Separator;
70 import org.eclipse.jface.text.ITextSelection;
71 import org.eclipse.jface.viewers.DoubleClickEvent;
72 import org.eclipse.jface.viewers.IDoubleClickListener;
73 import org.eclipse.jface.viewers.ISelection;
74 import org.eclipse.jface.viewers.IStructuredSelection;
75 import org.eclipse.jface.viewers.TableViewer;
76 import org.eclipse.swt.SWT;
77 import org.eclipse.swt.events.FocusEvent;
78 import org.eclipse.swt.events.FocusListener;
79 import org.eclipse.swt.graphics.FontMetrics;
80 import org.eclipse.swt.graphics.GC;
81 import org.eclipse.swt.graphics.Point;
82 import org.eclipse.swt.layout.FillLayout;
83 import org.eclipse.swt.layout.RowData;
84 import org.eclipse.swt.layout.RowLayout;
85 import org.eclipse.swt.widgets.Button;
86 import org.eclipse.swt.widgets.Combo;
87 import org.eclipse.swt.widgets.Composite;
88 import org.eclipse.swt.widgets.Event;
89 import org.eclipse.swt.widgets.Group;
90 import org.eclipse.swt.widgets.Label;
91 import org.eclipse.swt.widgets.Listener;
92 import org.eclipse.swt.widgets.Menu;
93 import org.eclipse.swt.widgets.Table;
94 import org.eclipse.swt.widgets.TableColumn;
95 import org.eclipse.swt.widgets.Text;
96 import org.eclipse.ui.IActionBars;
97 import org.eclipse.ui.IEditorInput;
98 import org.eclipse.ui.ISelectionListener;
99 import org.eclipse.ui.ISelectionService;
100 import org.eclipse.ui.ISharedImages;
101 import org.eclipse.ui.IWorkbenchActionConstants;
102 import org.eclipse.ui.IWorkbenchPage;
103 import org.eclipse.ui.IWorkbenchPart;
104 import org.eclipse.ui.PlatformUI;
105 import org.eclipse.ui.part.ViewPart;
106
107 import de.nierbeck.timeTrack.Assert;
108 import de.nierbeck.timeTrack.StopWatch;
109 import de.nierbeck.timeTrack.TimeTrackEntriesManager;
110 import de.nierbeck.timeTrack.TimeTrackLog;
111 import de.nierbeck.timeTrack.TimeTrackPlugin;
112 import de.nierbeck.timeTrack.actions.DeleteAction;
113 import de.nierbeck.timeTrack.actions.DoubleClickAction;
114 import de.nierbeck.timeTrack.model.EntryType;
115 import de.nierbeck.timeTrack.model.ObjectFactory;
116 import de.nierbeck.timeTrack.preferences.PreferenceConstants;
117
118 /***
119 * This sample class demonstrates how to plug-in a new workbench view. The view
120 * shows data obtained from the model. The sample creates a dummy model on the
121 * fly, but a real implementation would connect to the model available either in
122 * this or another plug-in (e.g. the workspace). The view is connected to the
123 * model using a content provider.
124 * <p>
125 * The view uses a label provider to define how model objects should be
126 * presented in the view. Each view can present the same model objects using
127 * different labels and icons, if needed. Alternatively, a single label provider
128 * can be shared between views in order to ensure that objects of the same type
129 * are presented in the same way everywhere.
130 * <p>
131 */
132
133 public class TimeTrackView extends ViewPart implements Observer {
134
135 private TableViewer tbv;
136
137 private TimeTrackEntriesManager entries;
138
139 private StopWatch stopWatch;
140
141 private ObjectFactory objFactory = new ObjectFactory();
142
143 private String[] projects;
144
145 private String[] tasks;
146
147 private String[] comments;
148
149 private Combo projectCombo;
150
151 private Combo taskCombo;
152
153 private Combo commentCombo;
154
155 private Button breakButton;
156
157 private Button newTaskButton;
158
159 private Text timeField;
160
161
162 private Text durationField;
163
164 private Text dateField;
165
166
167 private Action deleteAction;
168
169 private Action copyAction;
170
171 private Action pasteAction;
172
173 private DoubleClickAction doubleClickAction;
174
175 private EntryType copyEntry;
176
177 private ISelectionListener selectionListener;
178
179 private Table table = null;
180
181 private Group workHistory;
182
183 private boolean startup = true;
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216 /***
217 * The constructor.
218 */
219 public TimeTrackView() {
220 }
221
222 /***
223 * Method for the test case
224 *
225 * @return TableViewer
226 */
227 public final TableViewer getTableViewer() {
228 return tbv;
229 }
230
231 private void fillArray(String[] strings, ArrayList array) {
232 Iterator iterator = array.iterator();
233 int i = 0;
234 while (iterator.hasNext()) {
235 strings[i] = (String) iterator.next();
236 i++;
237 }
238 }
239
240 private void fillProjectData() {
241
242 Iterator iterator = entries.getEntryIterator();
243
244 ArrayList project = new ArrayList();
245 String stringProject = entries.getCurrentSelected().getProject();
246 if (stringProject != null && stringProject.length() > 0)
247 project.add(stringProject);
248 ArrayList task = new ArrayList();
249 String stringTask = entries.getCurrentSelected().getTask();
250 if (stringTask != null && stringTask.length() > 0)
251 task.add(stringTask);
252 ArrayList comment = new ArrayList();
253 String stringComment = entries.getCurrentSelected().getComment();
254 if (stringComment != null && stringComment.length() > 0)
255 comment.add(stringComment);
256
257 while (iterator.hasNext()) {
258 EntryType entry = (EntryType) iterator.next();
259 stringProject = entry.getProject();
260 if (stringProject != null && stringProject.length() > 0
261 && !project.contains(stringProject))
262 project.add(stringProject);
263 stringTask = entry.getTask();
264 if (stringTask != null && stringTask.length() > 0
265 && !task.contains(stringTask))
266 task.add(stringTask);
267 stringComment = entry.getComment();
268 if (stringComment != null && stringComment.length() > 0
269 && !comment.contains(stringComment))
270 comment.add(stringComment);
271 }
272
273 try {
274 projects = new String[project.size()];
275 fillArray(projects, project);
276 tasks = new String[task.size()];
277 fillArray(tasks, task);
278 comments = new String[comment.size()];
279 fillArray(comments, comment);
280 } catch (Exception e) {
281 TimeTrackLog.logError("failed to create JAXBContext", e);
282 }
283 }
284
285 /***
286 * This is a callback that will allow us to create the viewer and initialize
287 * it.
288 *
289 * @param parent - the Parent Composite
290 */
291 public final void createPartControl(Composite parent) {
292
293
294 entries = TimeTrackPlugin.getTimeTrackManager();
295 entries.addObserver(this);
296 fillProjectData();
297
298 RowLayout rowL = new RowLayout();
299 rowL.wrap = true;
300 rowL.type = SWT.HORIZONTAL;
301 RowLayout outerRow = new RowLayout();
302 outerRow.type = SWT.VERTICAL;
303
304 FillLayout fill = new FillLayout(SWT.VERTICAL);
305
306 parent.setLayout(fill);
307
308 Group currentTask = new Group(parent, SWT.TOP);
309 currentTask.setText(Messages.getString("TimeTrackView.current.task"));
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326 workHistory = new Group(parent, SWT.TOP | SWT.V_SCROLL);
327
328 workHistory.setText(Messages.getString("TimeTrackView.work.history"));
329
330 workHistory.setLayout(new FillLayout());
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347 Label projectLabel = new Label(currentTask, SWT.HORIZONTAL
348 | SWT.SHADOW_NONE | SWT.WRAP);
349 projectLabel.setText("Project:");
350
351 projectLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 15,
352 43, 14));
353 projectCombo = new Combo(currentTask, SWT.DROP_DOWN);
354
355 projectCombo.setItems(projects);
356 projectCombo.setSize(200, 200);
357 projectCombo.setTextLimit(30);
358
359 projectCombo.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 30,
360 172, 21));
361 Label taskLabel = new Label(currentTask, SWT.NONE);
362 taskLabel.setText("Task:");
363
364 taskLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(192, 15, 41,
365 12));
366 taskCombo = new Combo(currentTask, SWT.DROP_DOWN);
367
368 taskCombo.setItems(tasks);
369 taskCombo.setSize(200, 200);
370 taskCombo.setTextLimit(30);
371
372 taskCombo.setBounds(new org.eclipse.swt.graphics.Rectangle(192, 30,
373 166, 21));
374 Label commentLabel = new Label(currentTask, SWT.NONE);
375 commentLabel.setText("Comment:");
376 commentLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(372, 14,
377 61, 13));
378 commentCombo = new Combo(currentTask, SWT.DROP_DOWN);
379 commentCombo.setItems(comments);
380 commentCombo.setBounds(new org.eclipse.swt.graphics.Rectangle(372, 29,
381 346, 21));
382
383 GC gc = new GC(commentCombo);
384 FontMetrics fm = gc.getFontMetrics();
385 int width = 45 * fm.getAverageCharWidth();
386 int height = fm.getHeight();
387 gc.dispose();
388 Point point = commentCombo.computeSize(width, height);
389 commentCombo.setSize(point);
390 commentCombo.setTextLimit(45);
391
392
393
394
395
396
397 Label dateLabel = new Label(currentTask, SWT.NONE);
398 dateLabel.setText(Messages.getString("TimeTrackView.date"));
399
400 dateLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 55, 47,
401 21));
402 Calendar startTime = entries.getCurrentSelected().getStartTime();
403
404 dateField = new Text(currentTask, SWT.BORDER);
405 dateField.setText(TimeTrackFormater.DATEFORMAT.format(startTime
406 .getTime()));
407
408 dateField.setBounds(new org.eclipse.swt.graphics.Rectangle(90, 55, 91,
409 21));
410 timeField = new Text(currentTask, SWT.BORDER);
411 timeField.setText(TimeTrackFormater.TIMEFORMAT.format(startTime
412 .getTime()));
413
414 timeField.setBounds(new org.eclipse.swt.graphics.Rectangle(191, 54, 71,
415 21));
416 Label durationLabel = new Label(currentTask, SWT.NONE);
417 durationLabel.setText(Messages.getString("TimeTrackView.duration"));
418
419 durationLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(268, 54,
420 65, 21));
421
422 durationField = new Text(currentTask, SWT.BORDER);
423 durationField.setBounds(new org.eclipse.swt.graphics.Rectangle(339, 55,
424 65, 21));
425 RowData durationData = new RowData(50, 12);
426 durationField.setLayoutData(durationData);
427
428 durationField.setText(Long.toString(entries.getCurrentSelected()
429 .getDuration()));
430
431
432 breakButton = new Button(currentTask, SWT.PUSH);
433 breakButton.setText(Messages.getString("TimeTrackView.break"));
434
435 breakButton.setBounds(new org.eclipse.swt.graphics.Rectangle(440, 55,
436 65, 21));
437 newTaskButton = new Button(currentTask, SWT.PUSH);
438 newTaskButton.setText(Messages.getString("TimeTrackView.endTask"));
439
440 newTaskButton.setBounds(new org.eclipse.swt.graphics.Rectangle(510, 55,
441 211, 20));
442
443
444
445 createTable();
446
447 tbv = new TableViewer(table);
448
449 tbv.setContentProvider(new EntriesContentProvider());
450 tbv.setLabelProvider(new EntriesLabelProvider());
451
452
453
454
455
456
457
458 tbv.setInput(entries);
459
460
461 stopWatch = new StopWatch(entries);
462 stopWatch.start();
463
464 hookListeners();
465 hookContextMenu();
466 makeActions();
467 hookDoubleClickAction();
468 contributeToActionBars();
469 addSelectionListener();
470
471 startup = false;
472 }
473
474 /***
475 * connects the Listeners to the Comboboxes / Buttons
476 */
477 private void hookListeners() {
478
479
480 breakButton.addListener(SWT.Selection, new Listener() {
481
482 public void handleEvent(Event event) {
483 Assert.notNull(entries);
484 newCurrentSelected(
485 Messages.getString("TimeTrackView.setProject.break"),
486 "",
487 Messages
488 .getString("TimeTrackView.setProject.break.comment"));
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527 }
528
529 });
530
531
532 newTaskButton.addListener(SWT.Selection, new Listener() {
533
534 public void handleEvent(Event event) {
535 Assert.notNull(entries);
536 newCurrentSelected("", "", "");
537 }
538
539 });
540
541
542 projectCombo.addFocusListener(new FocusListener() {
543
544 public void focusGained(FocusEvent e) {
545
546
547 }
548
549 public void focusLost(FocusEvent e) {
550 String project = projectCombo.getText();
551 entries.getCurrentSelected().setProject(project);
552 String[] items = projectCombo.getItems();
553 List list = Arrays.asList(items);
554 if (list.contains(project)) {
555 int i = list.indexOf(project);
556 projectCombo.select(i);
557 } else {
558 projectCombo.add(project);
559 }
560 }
561 });
562 projectCombo.addListener(SWT.Selection, new Listener() {
563
564 public void handleEvent(Event event) {
565 String project = projectCombo.getText();
566 entries.getCurrentSelected().setProject(project);
567 }
568
569 });
570
571
572 taskCombo.addFocusListener(new FocusListener() {
573
574 public void focusGained(FocusEvent e) {
575
576
577 }
578
579 public void focusLost(FocusEvent e) {
580 String task = taskCombo.getText();
581 entries.getCurrentSelected().setTask(task);
582 String[] items = taskCombo.getItems();
583 List list = Arrays.asList(items);
584 if (list.contains(task)) {
585 int i = list.indexOf(task);
586 taskCombo.select(i);
587 } else {
588 taskCombo.add(task);
589 }
590 }
591
592 });
593 taskCombo.addListener(SWT.Selection, new Listener() {
594
595 public void handleEvent(Event event) {
596 String task = taskCombo.getText();
597 entries.getCurrentSelected().setTask(task);
598 }
599
600 });
601
602
603 commentCombo.addFocusListener(new FocusListener() {
604
605 public void focusGained(FocusEvent e) {
606
607
608 }
609
610 public void focusLost(FocusEvent e) {
611 String comment = commentCombo.getText();
612 entries.getCurrentSelected().setComment(comment);
613 String[] items = commentCombo.getItems();
614 List list = Arrays.asList(items);
615 if (list.contains(comment)) {
616 int i = list.indexOf(comment);
617 commentCombo.select(i);
618 } else {
619 commentCombo.add(comment);
620 }
621 }
622
623 });
624 commentCombo.addListener(SWT.Selection, new Listener() {
625
626 public void handleEvent(Event event) {
627 String comment = commentCombo.getText();
628 entries.getCurrentSelected().setComment(comment);
629 }
630 });
631
632
633 timeField.addFocusListener(new FocusListener() {
634
635 public void focusGained(FocusEvent e) {
636
637
638 }
639
640 public void focusLost(FocusEvent e) {
641 String time = timeField.getText();
642 String date = dateField.getText();
643
644 time = Assert.timeValidation(time);
645
646
647 Date cal = null;
648 DateFormat dateTimeFormat = DateFormat.getDateTimeInstance();
649
650 try {
651 dateTimeFormat.parse(time);
652 } catch (ParseException e2) {
653 TimeTrackLog.logError("Time Parse Exeption", e2);
654
655 }
656
657 try {
658 cal = dateTimeFormat.parse(date + " " + time);
659 } catch (ParseException e1) {
660 TimeTrackLog.logError("ParseException", e1);
661 }
662
663 Calendar calendar = GregorianCalendar.getInstance();
664 calendar.setTime(cal);
665
666 entries.getCurrentSelected().setStartTime(calendar);
667
668 stopWatch.updateDuration();
669
670 long duration = entries.getCurrentSelected().getDuration();
671 durationField.setText(Long.toString(duration));
672 timeField.setText(time);
673 }
674
675 });
676
677 durationField.addFocusListener(new FocusListener() {
678
679 public void focusGained(FocusEvent e) {
680
681 long duration = entries.getCurrentSelected().getDuration();
682 durationField.setText(Long.toString(duration));
683 }
684
685 public void focusLost(FocusEvent e) {
686
687 long duration = entries.getCurrentSelected().getDuration();
688 durationField.setText(Long.toString(duration));
689 }
690
691 });
692 }
693
694 private void hookContextMenu() {
695 MenuManager menuMgr = new MenuManager("#PopupMenu");
696 menuMgr.setRemoveAllWhenShown(true);
697 menuMgr.addMenuListener(new IMenuListener() {
698 public void menuAboutToShow(IMenuManager manager) {
699 TimeTrackView.this.fillContextMenu(manager);
700 }
701 });
702 Menu menu = menuMgr.createContextMenu(tbv.getControl());
703 tbv.getControl().setMenu(menu);
704 getSite().registerContextMenu(menuMgr, tbv);
705 }
706
707 private void contributeToActionBars() {
708 IActionBars bars = getViewSite().getActionBars();
709 fillLocalPullDown(bars.getMenuManager());
710 fillLocalToolBar(bars.getToolBarManager());
711 }
712
713 private void fillLocalPullDown(IMenuManager manager) {
714 manager.add(deleteAction);
715 manager.add(new Separator());
716 manager.add(copyAction);
717 manager.add(pasteAction);
718 }
719
720 private void fillContextMenu(IMenuManager manager) {
721 manager.add(deleteAction);
722 manager.add(copyAction);
723 manager.add(pasteAction);
724
725 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
726 }
727
728 private void fillLocalToolBar(IToolBarManager manager) {
729 manager.add(deleteAction);
730 manager.add(copyAction);
731 manager.add(pasteAction);
732 }
733
734 private void makeActions() {
735
736 deleteAction = new DeleteAction(tbv, entries);
737 deleteAction.setText(Messages
738 .getString("TimeTrackView.deleteAction.text"));
739 deleteAction.setToolTipText(Messages
740 .getString("TimeTrackView.deleteAction.toolTip"));
741 deleteAction.setImageDescriptor(PlatformUI.getWorkbench()
742 .getSharedImages().getImageDescriptor(
743 ISharedImages.IMG_TOOL_DELETE));
744
745 copyAction = new Action() {
746 public void run() {
747
748
749 Object obj = ((IStructuredSelection) tbv.getSelection())
750 .getFirstElement();
751 int i = entries.getEntry().indexOf(obj);
752 EntryType entry = (EntryType) entries.getEntry().get(i);
753 copyEntry = entry;
754 }
755 };
756 copyAction.setText(Messages.getString("TimeTrackView.copyAction.text"));
757 copyAction.setToolTipText(Messages
758 .getString("TimeTrackView.copyAction.toolTip"));
759 copyAction.setImageDescriptor(PlatformUI.getWorkbench()
760 .getSharedImages().getImageDescriptor(
761 ISharedImages.IMG_TOOL_COPY));
762
763 pasteAction = new Action() {
764 public void run() {
765
766
767 if (copyEntry == null)
768 return;
769
770 Object obj = ((IStructuredSelection) tbv.getSelection())
771 .getFirstElement();
772 int i = entries.getEntry().indexOf(obj);
773
774 entries.getEntry().add(i, copyEntry);
775 copyEntry = null;
776 tbv.setInput(entries);
777 }
778 };
779 pasteAction.setText(Messages
780 .getString("TimeTrackView.pasteAction.text"));
781 pasteAction.setToolTipText(Messages
782 .getString("TimeTrackView.pasteAction.toolTip"));
783 pasteAction.setImageDescriptor(PlatformUI.getWorkbench()
784 .getSharedImages().getImageDescriptor(
785 ISharedImages.IMG_TOOL_PASTE));
786
787 doubleClickAction = new DoubleClickAction(tbv);
788 }
789
790 private void hookDoubleClickAction() {
791 tbv.addDoubleClickListener(new IDoubleClickListener() {
792 public void doubleClick(DoubleClickEvent event) {
793 doubleClickAction.run(tbv.getSelection());
794 }
795 });
796 }
797
798 /***
799 * Passing the focus request to the viewer's control.
800 */
801 public final void setFocus() {
802 tbv.getControl().setFocus();
803 }
804
805 /***
806 * Method createColumns.
807 *
808 * @param tbv
809 */
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828 private void addSelectionListener() {
829 ISelectionService selectionService = getSite().getPage()
830 .getWorkbenchWindow().getSelectionService();
831 selectionListener = new ISelectionListener() {
832 public void selectionChanged(IWorkbenchPart part, ISelection sel) {
833 processSelection(part, sel);
834 }
835 };
836 selectionService.addSelectionListener(selectionListener);
837
838
839
840 IWorkbenchPage activePage = getSite().getPage().getWorkbenchWindow()
841 .getActivePage();
842 IWorkbenchPart part = null;
843 if (activePage != null)
844 part = activePage.getActiveEditor();
845
846 processSelection(part, selectionService.getSelection());
847
848 }
849
850 /***
851 * Process the given selection. If it is not a structured selection, the
852 * event is discarded. If the selection is a resource (or has a resource),
853 * updates the resource view. Otherwise, the resource view is cleaned out.
854 *
855 * @param selection
856 * the selection object to be processed
857 */
858 private final void processSelection(IWorkbenchPart part, ISelection selection) {
859
860 if (!((selection instanceof IStructuredSelection) || selection instanceof ITextSelection))
861 return;
862
863 if (selection instanceof IStructuredSelection) {
864
865 IResource resource = null;
866
867 IStructuredSelection structuredSel = (IStructuredSelection) selection;
868 if (!structuredSel.isEmpty()) {
869 Object item = ((IStructuredSelection) selection)
870 .getFirstElement();
871
872 if (item instanceof IResource)
873 resource = (IResource) item;
874 else if (item instanceof IAdaptable)
875 resource = (IResource) ((IAdaptable) item)
876 .getAdapter(IResource.class);
877
878 if (resource == null)
879 return;
880
881 if (resource instanceof Folder) {
882 return;
883 }
884
885 EntryType currentSelected = entries.getCurrentSelected();
886
887
888 if ((!resource.getName().equalsIgnoreCase(
889 currentSelected.getTask()))
890 || (!resource.getProject().getName().equalsIgnoreCase(
891 currentSelected.getProject()))) {
892
893 newCurrentSelected(resource.getProject().getName(),
894 resource.getName(), "");
895
896 }
897 }
898 } else if (selection instanceof ITextSelection && part != null) {
899 IEditorInput input = part.getSite().getWorkbenchWindow()
900 .getActivePage().getActiveEditor().getEditorInput();
901
902 if (input == null)
903 return;
904
905 IResource resource = (IResource) input.getAdapter(IResource.class);
906 EntryType currentSelected = entries.getCurrentSelected();
907
908 if ((!resource.getName()
909 .equalsIgnoreCase(currentSelected.getTask()))
910 || (!resource.getProject().getName().equalsIgnoreCase(
911 currentSelected.getProject()))) {
912
913 newCurrentSelected(resource.getProject().getName(), resource
914 .getName(), "");
915
916 }
917 }
918 }
919
920 /***
921 *
922 */
923 private void newCurrentSelected(final String project, final String task, final String comment) {
924 EntryType oldEntry = entries.getCurrentSelected();
925 EntryType currentSelected = null;
926 long duration = 0;
927 int interval = 0;
928 if (oldEntry != null) {
929 duration = oldEntry.getDuration();
930 interval = TimeTrackPlugin.getDefault().getPreferenceStore()
931 .getInt(PreferenceConstants.P_UPDATE_INTERVALL);
932
933
934
935
936
937
938 }
939
940 if (duration < interval && !startup && oldEntry != null) {
941 TimeTrackLog
942 .logInfo("Duration smaler than "+interval+", consider it as tripple Click");
943 currentSelected = oldEntry;
944
945 } else {
946 entries.getEntry().add(oldEntry);
947 try {
948 entries.setCurrentSelected(objFactory.createEntryType());
949 } catch (JAXBException e) {
950 TimeTrackLog.logError(this + "handleEvent()", e);
951 }
952
953 currentSelected = entries.getCurrentSelected();
954 }
955
956
957
958
959 currentSelected.setProject(project);
960 projectCombo.setText(currentSelected.getProject());
961 projectCombo.add(currentSelected.getProject());
962 currentSelected.setTask(task);
963 taskCombo.setText(currentSelected.getTask());
964 taskCombo.add(currentSelected.getTask());
965 currentSelected.setComment(comment);
966 commentCombo.setText(currentSelected.getComment());
967 commentCombo.add(currentSelected.getComment());
968 Calendar cal = GregorianCalendar.getInstance();
969
970
971 currentSelected.setStartTime(cal);
972 dateField.setText(TimeTrackFormater.DATEFORMAT.format(cal.getTime()));
973 timeField.setText(TimeTrackFormater.TIMEFORMAT.format(cal.getTime()));
974 durationField.setText("0");
975 currentSelected.setDuration(0);
976
977 if (duration >= interval || startup) {
978 tbv.insert(currentSelected, 0);
979 entries.saveState();
980 }
981
982
983
984
985
986
987 }
988
989 /***
990 * This method initializes table
991 *
992 */
993 private void createTable() {
994 table = new Table(workHistory, SWT.SINGLE | SWT.BORDER
995 | SWT.FULL_SELECTION);
996 table.setHeaderVisible(true);
997 table.setLinesVisible(true);
998 TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
999 tableColumn1.setWidth(150);
1000 tableColumn1.setText(Messages.getString("ColumnEnum.startDate"));
1001 TableColumn tableColumn2 = new TableColumn(table, SWT.NONE);
1002 tableColumn2.setWidth(150);
1003 tableColumn2.setText(Messages.getString("ColumnEnum.duration"));
1004 TableColumn tableColumn3 = new TableColumn(table, SWT.NONE);
1005 tableColumn3.setWidth(150);
1006 tableColumn3.setText(Messages.getString("ColumnEnum.project"));
1007 TableColumn tableColumn4 = new TableColumn(table, SWT.NONE);
1008 tableColumn4.setWidth(150);
1009 tableColumn4.setText(Messages.getString("ColumnEnum.task"));
1010 TableColumn tableColumn5 = new TableColumn(table, SWT.NONE);
1011 tableColumn5.setWidth(150);
1012 tableColumn5.setText(Messages.getString("ColumnEnum.comment"));
1013 }
1014
1015 /***
1016 * updates the listeners
1017 *
1018 * @param o - the Observable
1019 * @param arg - the argument
1020 */
1021 public final void update(Observable o, Object arg) {
1022 entries = TimeTrackPlugin.getTimeTrackManager();
1023 EntryType currentSelected = entries.getCurrentSelected();
1024 fillProjectData();
1025 tbv.setInput(entries);
1026 tbv.refresh();
1027 projectCombo.removeAll();
1028 projectCombo.setItems(projects);
1029 projectCombo.setText(currentSelected.getProject() == null ? ""
1030 : currentSelected.getProject());
1031 taskCombo.removeAll();
1032 taskCombo.setItems(tasks);
1033 taskCombo.setText(currentSelected.getTask() == null ? ""
1034 : currentSelected.getTask());
1035 commentCombo.removeAll();
1036 commentCombo.setItems(comments);
1037 commentCombo.setText(currentSelected.getComment() == null ? ""
1038 : currentSelected.getComment());
1039 }
1040
1041 }