<commit_before>
package ch.elexis.core.ui.eigenartikel;

import java.util.HashMap;

import org.eclipse.jface.viewers.ITreeContentProvider;

import ch.elexis.core.data.service.CoreModelServiceHolder;
import ch.elexis.core.model.IArticle;
import ch.elexis.core.model.ModelPackage;
import ch.elexis.core.services.IQuery;
import ch.elexis.core.services.IQuery.COMPARATOR;
import ch.elexis.core.services.IQuery.ORDER;
import ch.elexis.core.types.ArticleTyp;
import ch.elexis.core.ui.util.viewers.CommonViewer;
import ch.elexis.core.ui.util.viewers.ViewerConfigurer.ICommonViewerContentProvider;

public class EigenartikelTreeContentProvider
		implements ITreeContentProvider, ICommonViewerContentProvider {
	
	public static String FILTER_KEY = "Name";
	private CommonViewer commonViewer;
	private String filter = null;
	
	private boolean showProducts;
	
	public EigenartikelTreeContentProvider(CommonViewer cv){
		this.commonViewer = cv;
	}
	
	@Override
	public void reorder(String field){}
	
	@Override
	public void selected(){}
	
	@Override
	public void init(){}
	
	@Override
	public void startListening(){
		commonViewer.getConfigurer().getControlFieldProvider().addChangeListener(this);
	}
	
	@Override
	public void stopListening(){
		commonViewer.getConfigurer().getControlFieldProvider().removeChangeListener(this);
	}
	
	@Override
	public Object[] getElements(Object inputElement){
		IQuery<IArticle> query = CoreModelServiceHolder.get().getQuery(IArticle.class);
		query.and(ModelPackage.Literals.IARTICLE__TYP, COMPARATOR.EQUALS,
			ArticleTyp.EIGENARTIKEL);
		if (filter != null) {
			query.and(ModelPackage.Literals.IARTICLE__NAME, COMPARATOR.LIKE, "%" + filter + "%",
				true);
		}
		if (!showProducts) {
			query.and(ModelPackage.Literals.IARTICLE__PRODUCT, COMPARATOR.NOT_EQUALS, null);
		}
		query.orderBy(ModelPackage.Literals.IARTICLE__NAME, ORDER.DESC);
		return query.execute().toArray();
	}
	
	@Override
	public Object[] getChildren(Object parentElement){
		if (!showProducts) {
			return null;
		}
		if (parentElement != null && parentElement instanceof IArticle) {
			IArticle ea = (IArticle) parentElement;
			if (ea.isProduct()) {
				return ea.getPackages().toArray();
			}
		}
		return null;
	}
	
	@Override
	public Object getParent(Object element){
		return null;
	}<commit_msg>[20575] changed order by to asc in EigenartikelTreeContentProvider<commit_after>
package ch.elexis.core.ui.eigenartikel;

import java.util.HashMap;

import org.eclipse.jface.viewers.ITreeContentProvider;

import ch.elexis.core.data.service.CoreModelServiceHolder;
import ch.elexis.core.model.IArticle;
import ch.elexis.core.model.ModelPackage;
import ch.elexis.core.services.IQuery;
import ch.elexis.core.services.IQuery.COMPARATOR;
import ch.elexis.core.services.IQuery.ORDER;
import ch.elexis.core.types.ArticleTyp;
import ch.elexis.core.ui.util.viewers.CommonViewer;
import ch.elexis.core.ui.util.viewers.ViewerConfigurer.ICommonViewerContentProvider;

public class EigenartikelTreeContentProvider
		implements ITreeContentProvider, ICommonViewerContentProvider {
	
	public static String FILTER_KEY = "Name";
	private CommonViewer commonViewer;
	private String filter = null;
	
	private boolean showProducts;
	
	public EigenartikelTreeContentProvider(CommonViewer cv){
		this.commonViewer = cv;
	}
	
	@Override
	public void reorder(String field){}
	
	@Override
	public void selected(){}
	
	@Override
	public void init(){}
	
	@Override
	public void startListening(){
		commonViewer.getConfigurer().getControlFieldProvider().addChangeListener(this);
	}
	
	@Override
	public void stopListening(){
		commonViewer.getConfigurer().getControlFieldProvider().removeChangeListener(this);
	}
	
	@Override
	public Object[] getElements(Object inputElement){
		IQuery<IArticle> query = CoreModelServiceHolder.get().getQuery(IArticle.class);
		query.and(ModelPackage.Literals.IARTICLE__TYP, COMPARATOR.EQUALS,
			ArticleTyp.EIGENARTIKEL);
		if (filter != null) {
			query.and(ModelPackage.Literals.IARTICLE__NAME, COMPARATOR.LIKE, "%" + filter + "%",
				true);
		}
		if (!showProducts) {
			query.and(ModelPackage.Literals.IARTICLE__PRODUCT, COMPARATOR.NOT_EQUALS, null);
		}
		query.orderBy(ModelPackage.Literals.IARTICLE__NAME, ORDER.ASC);
		return query.execute().toArray();
	}
	
	@Override
	public Object[] getChildren(Object parentElement){
		if (!showProducts) {
			return null;
		}
		if (parentElement != null && parentElement instanceof IArticle) {
			IArticle ea = (IArticle) parentElement;
			if (ea.isProduct()) {
				return ea.getPackages().toArray();
			}
		}
		return null;
	}
	
	@Override
	public Object getParent(Object element){
		return null;
	}
{'fraction_non_alphanumeric': 0.11130210571551354, 'fraction_numerical': 0.0010743446497636442, 'mean_word_length': 5.3075880758807585, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5665742', 'n_tokens_mistral': 1656, 'n_tokens_neox': 1525, 'n_words': 273}