View Javadoc

1   /* ======================================
2    * Copyright (c) 2004-2005 Achim Nierbeck
3    * All rights reserved.
4    *
5    * You may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *       http://www.gnu.org/licenses/lgpl.html
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   * ======================================
16   */
17  
18  /*
19   * TimeTrackView.java
20   * $Revision: 1.15 $
21   * Date 14.12.2005
22   * 
23  /* ======================================
24   * Copyright (c) 2004-2005 Achim Nierbeck
25   * All rights reserved.
26   *
27   * You may not use this file except in compliance with the License.
28   * You may obtain a copy of the License at
29   *
30   *       http://www.gnu.org/licenses/lgpl.html
31   *
32   * Unless required by applicable law or agreed to in writing, software
33   * distributed under the License is distributed on an "AS IS" BASIS,
34   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35   * See the License for the specific language governing permissions and
36   * limitations under the License.
37   * ======================================
38   */
39  
40  /*
41   * $Author: nierbeck $ 
42   * $Date: 2006/02/04 13:12:48 $ 
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 	// private TextObserver durationField;
162 	private Text durationField;
163 
164 	private Text dateField;
165 
166 	// private TableViewer viewer;
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 	 * The content provider class is responsible for providing objects to the
187 	 * view. It can wrap existing objects in adapters or simply return objects
188 	 * as-is. These objects may be sensitive to the current input of the view,
189 	 * or ignore it and always show the same content (like Task List, for
190 	 * example).
191 	 */
192 
193 	/*
194 	 * class ViewContentProvider implements IStructuredContentProvider { public
195 	 * void inputChanged(Viewer v, Object oldInput, Object newInput) { }
196 	 * 
197 	 * public void dispose() { }
198 	 * 
199 	 * public Object[] getElements(Object parent) { return new String[] { "One",
200 	 * "Two", "Three" }; } }
201 	 * 
202 	 * class ViewLabelProvider extends LabelProvider implements
203 	 * ITableLabelProvider { public String getColumnText(Object obj, int index) {
204 	 * return getText(obj); }
205 	 * 
206 	 * public Image getColumnImage(Object obj, int index) { return
207 	 * getImage(obj); }
208 	 * 
209 	 * public Image getImage(Object obj) { return
210 	 * PlatformUI.getWorkbench().getSharedImages().getImage(
211 	 * ISharedImages.IMG_OBJ_ELEMENT); } }
212 	 */
213 
214 	// class NameSorter extends ViewerSorter {
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 		// entries = TimeTrackEntriesManager.getTimeTrackEntriesManager();
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")); //$NON-NLS-1$
310 		// Composite groupAndButton = new Composite(parent, SWT.TOP);
311 		// GridLayout gridLayout = new GridLayout();
312 		// gridLayout.numColumns = 2;
313 		// gridLayout.makeColumnsEqualWidth = false;
314 		// groupAndButton.setLayout(gridLayout);
315 		// Group currentTask = new Group(groupAndButton, SWT.NONE);
316 
317 		// GridData dataTaskGroup = new GridData();
318 		// dataTaskGroup.widthHint = 520;
319 		// dataTaskGroup.heightHint = 60;
320 		// dataTaskGroup.verticalAlignment = GridData.FILL;
321 		// currentTask.setLayoutData(dataTaskGroup);
322 
323 		// Composite buttonComposite = new Composite(groupAndButton, SWT.NONE);
324 		// buttonComposite.setLayout(new GridLayout());
325 
326 		workHistory = new Group(parent, SWT.TOP | SWT.V_SCROLL);
327 		// Angezeigten Titel setzten
328 		workHistory.setText(Messages.getString("TimeTrackView.work.history")); //$NON-NLS-1$
329 
330 		workHistory.setLayout(new FillLayout()); // Generated
331 		// der pause-knopf!!
332 		// breakButton = new Button(buttonComposite, SWT.CENTER);
333 		// breakButton.setText(Messages.getString("TimeTrackView.break"));
334 		// //$NON-NLS-1$
335 		//
336 		// newTaskButton = new Button(buttonComposite, SWT.PUSH);
337 		// newTaskButton.setText(Messages.getString("TimeTrackView.endTask"));
338 		// //$NON-NLS-1$
339 
340 		// erste Zeile im currentTask
341 		// Composite currentRow1 = new Composite(currentTask, SWT.CENTER);
342 
343 		// GridLayout gridRow2 = new GridLayout(7,false);
344 
345 		// currentRow1.setLayout(rowL);
346 		// currentRow1.setBounds(currentTask.getBounds());
347 		Label projectLabel = new Label(currentTask, SWT.HORIZONTAL
348 				| SWT.SHADOW_NONE | SWT.WRAP);
349 		projectLabel.setText("Project:"); //$NON-NLS-1$
350 
351 		projectLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 15,
352 				43, 14)); // Generated
353 		projectCombo = new Combo(currentTask, SWT.DROP_DOWN);
354 		// activityCombo.setItem(0,"");
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)); // Generated
361 		Label taskLabel = new Label(currentTask, SWT.NONE);
362 		taskLabel.setText("Task:"); //$NON-NLS-1$
363 
364 		taskLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(192, 15, 41,
365 				12)); // Generated
366 		taskCombo = new Combo(currentTask, SWT.DROP_DOWN);
367 		// projectCombo.setItem(0,"");
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)); // Generated
374 		Label commentLabel = new Label(currentTask, SWT.NONE);
375 		commentLabel.setText("Comment:"); //$NON-NLS-1$
376 		commentLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(372, 14,
377 				61, 13)); // Generated
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 		// Zweite Zeile
393 		// Composite currentRow2 = new Composite(currentTask, SWT.CENTER);
394 		// currentRow2.setLayout(rowL);
395 
396 		// Datum
397 		Label dateLabel = new Label(currentTask, SWT.NONE);
398 		dateLabel.setText(Messages.getString("TimeTrackView.date")); //$NON-NLS-1$
399 
400 		dateLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(10, 55, 47,
401 				21)); // Generated
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)); // Generated
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)); // Generated
416 		Label durationLabel = new Label(currentTask, SWT.NONE);
417 		durationLabel.setText(Messages.getString("TimeTrackView.duration")); //$NON-NLS-1$
418 
419 		durationLabel.setBounds(new org.eclipse.swt.graphics.Rectangle(268, 54,
420 				65, 21)); // Generated
421 		// durationField = new TextObserver(currentTask, SWT.BORDER);
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 		// entries.addObserver(durationField);
428 		durationField.setText(Long.toString(entries.getCurrentSelected()
429 				.getDuration()));
430 
431 		// knoepchas
432 		breakButton = new Button(currentTask, SWT.PUSH);
433 		breakButton.setText(Messages.getString("TimeTrackView.break")); //$NON-NLS-1$
434 
435 		breakButton.setBounds(new org.eclipse.swt.graphics.Rectangle(440, 55,
436 				65, 21)); // Generated
437 		newTaskButton = new Button(currentTask, SWT.PUSH);
438 		newTaskButton.setText(Messages.getString("TimeTrackView.endTask")); //$NON-NLS-1$
439 
440 		newTaskButton.setBounds(new org.eclipse.swt.graphics.Rectangle(510, 55,
441 				211, 20)); // Generated
442 		// Workspace
443 		// Tableviewer
444 
445 		createTable();
446 
447 		tbv = new TableViewer(table);
448 
449 		tbv.setContentProvider(new EntriesContentProvider());
450 		tbv.setLabelProvider(new EntriesLabelProvider());
451 		// Table table = tbv.getTable();
452 		// table.setSize(table.getParent().getSize());
453 
454 		// createColumns(tbv);
455 		// tbv.getTable().setHeaderVisible(true);
456 		// tbv.getTable().setLinesVisible(true);
457 
458 		tbv.setInput(entries);
459 
460 		// stop Uhr
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 		// break button listeners
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 				 * EntryType oldEntry = entries.getCurrentSelected(); //
491 				 * Assert.notNull(oldEntry); if (oldEntry != null)
492 				 * entries.getEntry().add(oldEntry); try {
493 				 * entries.setCurrentSelected(objFactory.createEntryType()); }
494 				 * catch (JAXBException e) { IStatus status = new
495 				 * Status(IStatus.ERROR, TimeTrackPlugin.PI_RUNTIME, 1, this +
496 				 * "handleEvent()", e); logger.log(status); //
497 				 * logger.error("handleEvent()", e); //$NON-NLS-1$ } EntryType
498 				 * currentSelected = entries.getCurrentSelected();
499 				 * currentSelected.setProject(Messages.getString("TimeTrackView.setProject.break"));
500 				 * //$NON-NLS-1$
501 				 * projectCombo.setText(currentSelected.getProject());
502 				 * projectCombo.add(currentSelected.getProject());
503 				 * currentSelected.setTask(""); //$NON-NLS-1$
504 				 * taskCombo.setText(""); //$NON-NLS-1$ taskCombo.add("");
505 				 * //$NON-NLS-1$
506 				 * currentSelected.setComment(Messages.getString("TimeTrackView.setProject.break.comment"));
507 				 * //$NON-NLS-1$
508 				 * commentCombo.setText(currentSelected.getComment());
509 				 * commentCombo.add(currentSelected.getComment()); Calendar cal =
510 				 * GregorianCalendar.getInstance(); // Date date = new
511 				 * Date(System.currentTimeMillis()); // cal.setTime(date); //
512 				 * currentSelected.setStartTime(cal);
513 				 * currentSelected.setStartTime(cal);
514 				 * dateField.setText(TimeTrackFormater.DATEFORMAT.format(cal.getTime()));
515 				 * timeField.setText(TimeTrackFormater.TIMEFORMAT.format(cal.getTime()));
516 				 * durationField.setText("0"); //$NON-NLS-1$
517 				 * currentSelected.setDuration(0); tbv.setInput(entries); try {
518 				 * marshall(); } catch (FileNotFoundException e) { IStatus
519 				 * status = new Status(IStatus.ERROR,
520 				 * TimeTrackPlugin.PI_RUNTIME, 1, "filenotfound", e);
521 				 * logger.log(status); // logger.error("filenotfound", e);
522 				 * //$NON-NLS-1$ } catch (JAXBException e) { IStatus status =
523 				 * new Status(IStatus.ERROR, TimeTrackPlugin.PI_RUNTIME, 1, this +
524 				 * "handleEvent().marshall()", e); logger.log(status); //
525 				 * logger.error("handleEvent().marshall()", e); //$NON-NLS-1$ }
526 				 */
527 			}
528 
529 		});
530 
531 		// new task button listeners
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 		// project Combo listeners
542 		projectCombo.addFocusListener(new FocusListener() {
543 
544 			public void focusGained(FocusEvent e) {
545 				// TODO Auto-generated method stub
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 		// taskCombo Listeners
572 		taskCombo.addFocusListener(new FocusListener() {
573 
574 			public void focusGained(FocusEvent e) {
575 				// TODO Auto-generated method stub
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 		// commentcombo listeners
603 		commentCombo.addFocusListener(new FocusListener() {
604 
605 			public void focusGained(FocusEvent e) {
606 				// TODO Auto-generated method stub
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 		// date field listeners
633 		timeField.addFocusListener(new FocusListener() {
634 
635 			public void focusGained(FocusEvent e) {
636 				// TODO Auto-generated method stub
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 				//date = Assert.dateValidation(date);
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 					// showMessage(Messages.getString("TimeTrackView.copy.message"));
655 				}
656 
657 				try {
658 					cal = dateTimeFormat.parse(date + " " + time); //$NON-NLS-1$
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 				// update duration by the way
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 				// update duration
681 				long duration = entries.getCurrentSelected().getDuration();
682 				durationField.setText(Long.toString(duration));
683 			}
684 
685 			public void focusLost(FocusEvent e) {
686 				// update duration
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"); //$NON-NLS-1$
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 		// Other plug-ins can contribute there actions here
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")); //$NON-NLS-1$
739 		deleteAction.setToolTipText(Messages
740 				.getString("TimeTrackView.deleteAction.toolTip")); //$NON-NLS-1$
741 		deleteAction.setImageDescriptor(PlatformUI.getWorkbench()
742 				.getSharedImages().getImageDescriptor(
743 						ISharedImages.IMG_TOOL_DELETE));
744 
745 		copyAction = new Action() {
746 			public void run() {
747 				// showMessage(Messages.getString("TimeTrackView.copy.message"));
748 				// //$NON-NLS-1$
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")); //$NON-NLS-1$
757 		copyAction.setToolTipText(Messages
758 				.getString("TimeTrackView.copyAction.toolTip")); //$NON-NLS-1$
759 		copyAction.setImageDescriptor(PlatformUI.getWorkbench()
760 				.getSharedImages().getImageDescriptor(
761 						ISharedImages.IMG_TOOL_COPY));
762 
763 		pasteAction = new Action() {
764 			public void run() {
765 				// showMessage(Messages.getString("TimeTrackView.paste.message"));
766 				// //$NON-NLS-1$
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")); //$NON-NLS-1$
781 		pasteAction.setToolTipText(Messages
782 				.getString("TimeTrackView.pasteAction.toolTip")); //$NON-NLS-1$
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 	 * private void createColumns(TableViewer tbv) { TableColumn[] columns = new
812 	 * TableColumn[5];
813 	 * 
814 	 * for (int i = 0; i < 5; i++) { columns[i] = new
815 	 * TableColumn(tbv.getTable(), SWT.CENTER); String text = null;
816 	 * 
817 	 * 
818 	 * switch (i) { case 0 : text = "Start Date"; break; case 1 : text =
819 	 * "Duration"; break; case 2 : text = "Activity"; break; case 3 : text =
820 	 * "Project"; break; case 4 : text = "Task"; break; }
821 	 * 
822 	 * 
823 	 * text = ((ColumnEnum) ColumnEnum.find(i)).getName();
824 	 * 
825 	 * columns[i].setText(text); columns[i].setWidth(150); } }
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 		// since we are during startup we should check here for the current
839 		// editor
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 		// if it is not a strucutured selection, ignore
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 				// when resource is set we can look if something has changed.
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 			if (duration < interval && !startup) {
934 				TimeTrackLog
935 						.logInfo("Duration smaler than 2, consider it as tripple Click");
936 				return;
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); //$NON-NLS-1$
960 		projectCombo.setText(currentSelected.getProject());
961 		projectCombo.add(currentSelected.getProject());
962 		currentSelected.setTask(task); //$NON-NLS-1$
963 		taskCombo.setText(currentSelected.getTask()); //$NON-NLS-1$
964 		taskCombo.add(currentSelected.getTask()); //$NON-NLS-1$
965 		currentSelected.setComment(comment); //$NON-NLS-1$
966 		commentCombo.setText(currentSelected.getComment());
967 		commentCombo.add(currentSelected.getComment());
968 		Calendar cal = GregorianCalendar.getInstance();
969 		// Date date = new Date(System.currentTimeMillis());
970 		// cal.setTime(date);
971 		currentSelected.setStartTime(cal);
972 		dateField.setText(TimeTrackFormater.DATEFORMAT.format(cal.getTime()));
973 		timeField.setText(TimeTrackFormater.TIMEFORMAT.format(cal.getTime()));
974 		durationField.setText("0"); //$NON-NLS-1$
975 		currentSelected.setDuration(0);
976 		//tbv.setInput(entries);
977 		if (duration >= interval || startup) {
978 			tbv.insert(currentSelected, 0);
979 			entries.saveState();
980 		}
981 		// try {
982 		// } catch (FileNotFoundException e) {
983 		// TimeTrackLog.logError("filenotfound", e);
984 		// } catch (JAXBException e) {
985 		// TimeTrackLog.logError(this + "handleEvent().marshall()", e);
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); // Generated
997 		table.setLinesVisible(true); // Generated
998 		TableColumn tableColumn1 = new TableColumn(table, SWT.NONE);
999 		tableColumn1.setWidth(150); // Generated
1000 		tableColumn1.setText(Messages.getString("ColumnEnum.startDate")); // Generated
1001 		TableColumn tableColumn2 = new TableColumn(table, SWT.NONE);
1002 		tableColumn2.setWidth(150); // Generated
1003 		tableColumn2.setText(Messages.getString("ColumnEnum.duration")); // Generated
1004 		TableColumn tableColumn3 = new TableColumn(table, SWT.NONE);
1005 		tableColumn3.setWidth(150); // Generated
1006 		tableColumn3.setText(Messages.getString("ColumnEnum.project")); // Generated
1007 		TableColumn tableColumn4 = new TableColumn(table, SWT.NONE);
1008 		tableColumn4.setWidth(150); // Generated
1009 		tableColumn4.setText(Messages.getString("ColumnEnum.task")); // Generated
1010 		TableColumn tableColumn5 = new TableColumn(table, SWT.NONE);
1011 		tableColumn5.setWidth(150); // Generated
1012 		tableColumn5.setText(Messages.getString("ColumnEnum.comment")); // Generated
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 } // @jve:decl-index=0:visual-constraint="25,37"