/*******************************************************************************
 * Copyright (c) 2013-2016 MEDEVIT.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     MEDEVIT <office@medevit.at> - initial API and implementation
 ******************************************************************************/
package at.medevit.ch.artikelstamm.elexis.common.importer;

import java.io.FileInputStream;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import at.medevit.ch.artikelstamm.ArtikelstammHelper;
import ch.artikelstamm.elexis.common.ArtikelstammItem;
import ch.elexis.core.ui.util.ImporterPage;
import ch.elexis.core.ui.util.SWTHelper;

public class ArtikelstammImporterPage extends ImporterPage {
	private static Logger log = LoggerFactory.getLogger(ArtikelstammImporter.class);
	
	@Override
	public IStatus doImport(IProgressMonitor monitor) throws Exception{
		log.info("ArtikelstammImporterPage. doImport " + results[0]);
		ArtikelstammReferenceDataImporter ardi = new ArtikelstammReferenceDataImporter();
		return ardi.performImport(monitor, new FileInputStream(results[0]), null);
	}
	
	@Override
	public String getTitle(){
		return "Artikelstamm CH Import";
	}
	
	@Override
	public String getDescription(){
		return "Importiere Artikelstamm";
	}
	
	@Override
	public Composite createPage(Composite parent){
		Composite versionInfo = new Composite(parent, SWT.None);
		versionInfo.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
		versionInfo.setLayout(new GridLayout(2, false));
		Label lblVersion = new Label(versionInfo, SWT.None);
		lblVersion.setLayoutData(new GridData(SWT.LEFT, SWT.FILL, false, false));
		lblVersion.setText("Aktuelle Version:");
		Label lblVERSION = new Label(versionInfo, SWT.None);
		lblVERSION.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
		
		int version = ArtikelstammItem.getCurrentVersion();
		lblVERSION.setText(" v" + version + " / " + ArtikelstammHelper.monthAndYearWritten
			.format(ArtikelstammItem.getImportSetCreationDate()));
			
		Composite ret = new ImporterPage.FileBasedImporter(parent, this);
		ret.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
		ret.setLayout(new GridLayout(2, false));
		
		return ret;
	}
}

@@ -617,16 +617,39 @@
 tStream;
+%0Aimport java.util.Date;
 %0A%0Aimport
@@ -2403,44 +2403,205 @@
 ;%0A%09%09
-lblVERSION.setText(%22 v%22 + version + 
+StringBuilder sb = new StringBuilder();%0A%09%09sb.append(%22 v%22 + version);%0A%09%09Date importSetCreationDate = ArtikelstammItem.getImportSetCreationDate();%0A%09%09if (importSetCreationDate != null) %7B%0A%09%09%09sb.append(
 %22 / 
@@ -2643,16 +2643,17 @@
 Written%0A
+%09
 %09%09%09.form
@@ -2703,16 +2703,56 @@
 e()));%0A%09
+%09%7D%0A%09%09lblVERSION.setText(sb.toString());%0A
 %09%09%0A%09%09Com

Fix NPE in ArtikelstammImporterPage#createPage