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();
	}
}

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;
			StringBuilder sbLabel = new StringBuilder();
			
			TimeSpan ts = termin.getTimeSpan();
			
			// day
			TimeTool tt = new TimeTool();
			tt.setDate(termin.getDay());
			sbLabel.append(tt.toString(TimeTool.DATE_GER));
			sbLabel.append(", ");
			
			// start time
			tt.setTime(ts.from);
			sbLabel.append(tt.toString(TimeTool.TIME_SMALL));
			sbLabel.append(" - ");
			
			// end time
			tt.setTime(ts.until);
			sbLabel.append(tt.toString(TimeTool.TIME_SMALL));
			
			// type
			sbLabel.append(" (");
			sbLabel.append(termin.getType());
			sbLabel.append(", ");
			// status
			sbLabel.append(termin.getStatus());
			sbLabel.append("), ");
			
			// bereich
			sbLabel.append(termin.getBereich());
			
			// grund if set
			if (termin.getGrund() != null && !termin.getGrund().isEmpty()) {
				sbLabel.append(" (");
				sbLabel.append(termin.getGrund());
				sbLabel.append(")");
			}
			
			return sbLabel.toString();
		}
		return element.toString();
	}
}

include 'Bereich and 'Grund' in appointment label