package ch.elexis.agenda.ui.provider;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import ch.elexis.agenda.data.Termin;
import ch.rgw.tools.TimeSpan;
import ch.rgw.tools.TimeTool;

public class TermineLabelProvider extends LabelProvider implements ITableLabelProvider {
	
	@Override
	public Image getColumnImage(Object element, int columnIndex){
		return null;
	}
	
	@Override
	public String getColumnText(Object element, int columnIndex){
		if (element instanceof Termin) {
			Termin termin = (Termin) element;
			TimeSpan ts = termin.getTimeSpan();
			
			// get day, start and end time
			TimeTool tt = new TimeTool();
			tt.setDate(termin.getDay());
			String day = tt.toString(TimeTool.DATE_GER);
			
			tt.setTime(ts.from);
			String from = tt.toString(TimeTool.TIME_SMALL);
			
			tt.setTime(ts.until);
			String until = tt.toString(TimeTool.TIME_SMALL);
			
			String label =
				day + ", " + from + " - " + until + " (" + termin.getType() + ", "
					+ termin.getStatus() + ")";
			return label;
		}
		return element.toString();
	}
}

@@ -603,16 +603,68 @@
 lement;%0A
+%09%09%09StringBuilder sbLabel = new StringBuilder();%0A%09%09%09%0A
 %09%09%09TimeS
@@ -708,35 +708,11 @@
 %09// 
-get day, start and end time
+day
 %0A%09%09%09
@@ -780,21 +780,23 @@
 %0A%09%09%09
-String day = 
+sbLabel.append(
 tt.t
@@ -821,21 +821,64 @@
 ATE_GER)
+)
 ;%0A%09%09%09
+sbLabel.append(%22, %22);%0A%09%09%09%0A%09%09%09// start time
 %0A%09%09%09tt.s
@@ -901,22 +901,23 @@
 %0A%09%09%09
-String from = 
+sbLabel.append(
 tt.t
@@ -940,29 +940,71 @@
 .TIME_SMALL)
+)
 ;%0A%09%09%09
+sbLabel.append(%22 - %22);%0A%09%09%09%0A%09%09%09// end time
 %0A%09%09%09tt.setTi
@@ -1024,23 +1024,23 @@
 %0A%09%09%09
-String until = 
+sbLabel.append(
 tt.t
@@ -1067,16 +1067,17 @@
 E_SMALL)
+)
 ;%0A%09%09%09%0A%09%09
@@ -1081,127 +1081,429 @@
 %0A%09%09%09
-String label =%0A%09%09%09%09day + %22, %22 + from + %22 - %22 + until + %22 (%22 + termin.getType() + %22, %22%0A%09%09%09%09%09+ termin.getStatus() + 
+// type%0A%09%09%09sbLabel.append(%22 (%22);%0A%09%09%09sbLabel.append(termin.getType());%0A%09%09%09sbLabel.append(%22, %22);%0A%09%09%09// status%0A%09%09%09sbLabel.append(termin.getStatus());%0A%09%09%09sbLabel.append(%22), %22);%0A%09%09%09%0A%09%09%09// bereich%0A%09%09%09sbLabel.append(termin.getBereich());%0A%09%09%09%0A%09%09%09// grund if set%0A%09%09%09if (termin.getGrund() != null && !termin.getGrund().isEmpty()) %7B%0A%09%09%09%09sbLabel.append(%22 (%22);%0A%09%09%09%09sbLabel.append(termin.getGrund());%0A%09%09%09%09sbLabel.append(
 %22)%22
+)
 ;%0A
+%09%09%09%7D%0A%09%09%09%0A
 %09%09%09r
@@ -1512,13 +1512,26 @@
 urn 
-l
+sbL
 abel
+.toString()
 ;%0A%09%09

include 'Bereich and 'Grund' in appointment label