<commit_before>/*******************************************************************************
 * Copyright (c) 2017 MEDEVIT <<EMAIL>>.
 * 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 <<EMAIL>> - initial API and implementation
 ******************************************************************************/
package ch.elexis.core.ui.views.rechnung;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.part.ViewPart;

import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.ui.icons.Images;
import ch.elexis.core.ui.util.ViewMenus;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceActions;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceListBottomComposite;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceListContentProvider;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceListContentProvider.InvoiceEntry;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceListHeaderComposite;
import ch.elexis.data.Kontakt;
import ch.elexis.data.Mandant;
import ch.elexis.data.Rechnung;
import ch.rgw.io.Settings;
import ch.rgw.tools.Money;

public class InvoiceListView extends ViewPart {
	public static final String ID = "ch.elexis.core.ui.views.rechnung.InvoiceListView"; //$NON-NLS-1$
	
	private Settings rnStellerSettings;
	private TableViewer tableViewerInvoiceList;
	private InvoiceListHeaderComposite invoiceListHeaderComposite;
	private InvoiceListBottomComposite invoiceListBottomComposite;
	private InvoiceListContentProvider invoiceListContentProvider;
	
	/**
	 * @param rnStellerSettings
	 * @wbp.parser.constructor
	 * @wbp.eval.method.parameter rnStellerSettings new ch.rgw.io.InMemorySettings()
	 */
	InvoiceListView(Settings rnStellerSettings){
		this.rnStellerSettings = rnStellerSettings;
	}
	
	public InvoiceListView(){
		Mandant currMandant = (Mandant) ElexisEventDispatcher.getSelected(Mandant.class);
		rnStellerSettings = CoreHub.getUserSetting(currMandant.getRechnungssteller());
	}
	
	private Action reloadViewAction = new Action(Messages.RnActions_reloadAction) { //$NON-NLS-1$
		{
			setToolTipText(Messages.RnActions_reloadTooltip); //$NON-NLS-1$
			setImageDescriptor(Images.IMG_REFRESH.getImageDescriptor());
		}
		
		@Override
		public void run(){
			refresh();
		}
	};
	
	public void refresh() {
		if (invoiceListContentProvider != null) {
			invoiceListContentProvider.reload();
		}
	}
	
	@Override
	public void createPartControl(Composite parent){
		parent.setLayout(new GridLayout(1, false));
		
		invoiceListHeaderComposite = new InvoiceListHeaderComposite(parent, SWT.NONE, this);
		
		Composite compositeInvoiceList = new Composite(parent, SWT.NONE);
		compositeInvoiceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		TableColumnLayout tcl_compositeInvoiceList = new TableColumnLayout();
		compositeInvoiceList.setLayout(tcl_compositeInvoiceList);
		
		tableViewerInvoiceList =
			new TableViewer(compositeInvoiceList, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
		Table tableInvoiceList = tableViewerInvoiceList.getTable();
		tableInvoiceList.setHeaderVisible(true);
		tableInvoiceList.setLinesVisible(false);
		
		InvoiceActions invoiceActions = new InvoiceActions(tableViewerInvoiceList);
		ViewMenus viewMenu = new ViewMenus(getViewSite());
		viewMenu.createToolbar(reloadViewAction, invoiceActions.rnExportAction, invoiceActions.printListeAction, invoiceActions.addAccountExcessAction);
		
		tableViewerInvoiceList.getControl().addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e){
				if (e.keyCode == SWT.F5) {
					refresh();
				}
			}
		});
		
		TableViewerColumn tvcInvoiceNo = new TableViewerColumn(tableViewerInvoiceList, SWT.NONE);
		TableColumn tblclmnInvoiceNo = tvcInvoiceNo.getColumn();
		tblclmnInvoiceNo.setData(Rechnung.BILL_NUMBER);
		tcl_compositeInvoiceList.setColumnData(tblclmnInvoiceNo,
			new ColumnPixelData(35, true, true));
		tblclmnInvoiceNo.setText(Messages.InvoiceListView_tblclmnInvoiceNo_text);
		tvcInvoiceNo.setLabelProvider(new ColumnLabelProvider() {
			@Override
			public String getText(Object element){
				if (element instanceof InvoiceEntry) {
					return ((InvoiceEntry) element).getInvoiceNumber();<commit_msg>[5983] InvoiceListeView add missing selection handler<commit_after>/*******************************************************************************
 * Copyright (c) 2017 MEDEVIT <<EMAIL>>.
 * 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 <<EMAIL>> - initial API and implementation
 ******************************************************************************/
package ch.elexis.core.ui.views.rechnung;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.layout.TableColumnLayout;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ColumnPixelData;
import org.eclipse.jface.viewers.ColumnWeightData;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.ui.part.ViewPart;

import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.ui.icons.Images;
import ch.elexis.core.ui.util.ViewMenus;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceActions;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceListBottomComposite;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceListContentProvider;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceListContentProvider.InvoiceEntry;
import ch.elexis.core.ui.views.rechnung.invoice.InvoiceListHeaderComposite;
import ch.elexis.data.Kontakt;
import ch.elexis.data.Mandant;
import ch.elexis.data.Rechnung;
import ch.rgw.io.Settings;
import ch.rgw.tools.Money;

public class InvoiceListView extends ViewPart {
	public static final String ID = "ch.elexis.core.ui.views.rechnung.InvoiceListView"; //$NON-NLS-1$
	
	private Settings rnStellerSettings;
	private TableViewer tableViewerInvoiceList;
	private InvoiceListHeaderComposite invoiceListHeaderComposite;
	private InvoiceListBottomComposite invoiceListBottomComposite;
	private InvoiceListContentProvider invoiceListContentProvider;
	
	/**
	 * @param rnStellerSettings
	 * @wbp.parser.constructor
	 * @wbp.eval.method.parameter rnStellerSettings new ch.rgw.io.InMemorySettings()
	 */
	InvoiceListView(Settings rnStellerSettings){
		this.rnStellerSettings = rnStellerSettings;
	}
	
	public InvoiceListView(){
		Mandant currMandant = (Mandant) ElexisEventDispatcher.getSelected(Mandant.class);
		rnStellerSettings = CoreHub.getUserSetting(currMandant.getRechnungssteller());
	}
	
	private Action reloadViewAction = new Action(Messages.RnActions_reloadAction) { //$NON-NLS-1$
		{
			setToolTipText(Messages.RnActions_reloadTooltip); //$NON-NLS-1$
			setImageDescriptor(Images.IMG_REFRESH.getImageDescriptor());
		}
		
		@Override
		public void run(){
			refresh();
		}
	};
	
	public void refresh() {
		if (invoiceListContentProvider != null) {
			invoiceListContentProvider.reload();
		}
	}
	
	@Override
	public void createPartControl(Composite parent){
		parent.setLayout(new GridLayout(1, false));
		
		invoiceListHeaderComposite = new InvoiceListHeaderComposite(parent, SWT.NONE, this);
		
		Composite compositeInvoiceList = new Composite(parent, SWT.NONE);
		compositeInvoiceList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		TableColumnLayout tcl_compositeInvoiceList = new TableColumnLayout();
		compositeInvoiceList.setLayout(tcl_compositeInvoiceList);
		
		tableViewerInvoiceList =
			new TableViewer(compositeInvoiceList, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
		tableViewerInvoiceList.addSelectionChangedListener(selection -> {
			StructuredSelection ss = (StructuredSelection) selection.getSelection();
			if (!ss.isEmpty()) {
				InvoiceEntry firstElement = (InvoiceEntry) ss.getFirstElement();
				Rechnung load = Rechnung.load(firstElement.getInvoiceId());
				ElexisEventDispatcher.fireSelectionEvent(load);
			}
		});
		Table tableInvoiceList = tableViewerInvoiceList.getTable();
		tableInvoiceList.setHeaderVisible(true);
		tableInvoiceList.setLinesVisible(false);
		
		InvoiceActions invoiceActions = new InvoiceActions(tableViewerInvoiceList);
		ViewMenus viewMenu = new ViewMenus(getViewSite());
		viewMenu.createToolbar(reloadViewAction, invoiceActions.rnExportAction, invoiceActions.printListeAction, invoiceActions.addAccountExcessAction);
		
		tableViewerInvoiceList.getControl().addKeyListener(new KeyAdapter() {
			@Override
			public void keyReleased(KeyEvent e){
				if (e.keyCode == SWT.F5) {
					refresh();
				}
			}
		});
		
		TableViewerColumn tvcInvoiceNo = new TableViewerColumn(tableViewerInvoiceList, SWT.NONE);
		TableColumn tblclmnInvoiceNo = tvcInvoiceNo.getColumn();
		tblclmnInvoiceNo.setData(Rechnung.BILL_NUMBER);
		tcl_compositeInvoiceList.setColumnData(tblclmnInvoiceNo,
			new ColumnPixelData(35, true, true));
		tblclmnInvoiceNo.setText(Messages.InvoiceListView_tblclmnInvoiceNo_text);
		tvcInvoiceNo.setLabelProvider(new ColumnLabelProvider() {
			@Override
			public String getText(Object element){
				if (element instanceof InvoiceEntry) {
					return ((InvoiceEntry) element).getInvoiceNumber();
{'fraction_non_alphanumeric': 0.12655153804641123, 'fraction_numerical': 0.0034178809138334233, 'mean_word_length': 6.010718789407314, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3837574', 'n_tokens_mistral': 3758, 'n_tokens_neox': 3465, 'n_words': 571}