<commit_before>package de.ptb.epics.eve.viewer.views.messagesview.ui;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import org.apache.log4j.Logger;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.State;
import org.eclipse.core.databinding.observable.list.IListChangeListener;
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.part.ViewPart;

import de.ptb.epics.eve.util.ui.swt.FontHelper;
import de.ptb.epics.eve.viewer.Activator;
import de.ptb.epics.eve.viewer.views.messagesview.FilterSettings;
import de.ptb.epics.eve.viewer.views.messagesview.IMessageList;
import de.ptb.epics.eve.viewer.views.messagesview.LevelFilter;
import de.ptb.epics.eve.viewer.views.messagesview.Levels;
import de.ptb.epics.eve.viewer.views.messagesview.MessageFilter;
import de.ptb.epics.eve.viewer.views.messagesview.MessageList;
import de.ptb.epics.eve.viewer.views.messagesview.SourceFilter;
import de.ptb.epics.eve.viewer.views.messagesview.TimeViewerComparator;

/**
 * 
 * @author ?
 * @author <NAME>
 */
public final class MessagesView extends ViewPart implements PropertyChangeListener {
	private static final Logger LOGGER = Logger.getLogger(MessagesView.class
			.getName());
	
	// the only element in this view is a table viewer for the messages
	private TableViewer tableViewer;
	
	private FilterSettings filterSettings;
	
	private boolean scrollLock;
	
	private IMemento memento;
	private static final String SHOW_VIEWER_MESSAGES_MEMENTO = "showViewerMessages";
	private static final String SHOW_ENGINE_MESSAGES_MEMENTO = "showEngineMessages";
	private static final String MESSAGE_LEVEL_MEMENTO = "messageLevel";
	private static final String AUTO_SCROLL_MEMENTO = "scrollLock";
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void init(IViewSite site, IMemento memento) throws PartInitException {
		super.init(site, memento);
		this.memento = memento;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void createPartControl(final Composite parent) {
		this.tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | 
				SWT.V_SCROLL);

		// the first column contains the time
		TableViewerColumn timeColumn = new TableViewerColumn(this.tableViewer,
				SWT.LEFT);
		timeColumn.getColumn().setText("Time");
		timeColumn.getColumn().setWidth(220);

		// second column: source (the sender of the message)
		TableViewerColumn sourceColumn = new TableViewerColumn(this.tableViewer, 
				SWT.LEFT);
		sourceColumn.getColumn().setText("Source");
		sourceColumn.getColumn().setWidth(80);

		// third column: the type (e.g. I for Info or E for Error)
		TableViewerColumn typeColumn = new TableViewerColumn(this.tableViewer, 
				SWT.LEFT);
		typeColumn.getColumn().setText("");
		typeColumn.getColumn().setWidth(25);
		//typeColumn.getColumn().addSelectionListener(
		//		new TypeColumnSelectionListener());
		
		// fourth column: the text (contents) of the message
		TableViewerColumn messageColumn = new TableViewerColumn(
				this.tableViewer, SWT.LEFT);
		messageColumn.getColumn().setText("Message");
		messageColumn.getColumn().setWidth(300);

		this.tableViewer.getTable().setHeaderVisible(true);
		this.tableViewer.getTable().setLinesVisible(true);

		this.tableViewer.setContentProvider(new ObservableListContentProvider());
		this.tableViewer.setLabelProvider(new LabelProvider());
		
		this.tableViewer.setInput(Activator.getDefault().
				getMessageList().getList());
		
		IMessageList messageList = Activator.getDefault().getMessageList();
		messageList.addPropertyChangeListener(
				MessageList.SOURCE_MAX_WIDTH_PROP, this);
		messageList.addPropertyChangeListener(
				MessageList.MESSAGE_MAX_WIDTH_PROP, this);
		messageList.getList().addListChangeListener(new IListChangeListener() {
			@Override
			public void handleListChange(ListChangeEvent event) {
				if (!scrollLock) {
					LOGGER.debug("new element & auto scroll on -> show top");
					tableViewer.getTable().setTopIndex(0);
				}
			}
		});
		
		this.filterSettings = new FilterSettings();
		this.restoreState();
		MessageFilter sourceFilter = new SourceFilter(this.filterSettings);
		MessageFilter levelFilter = new LevelFilter(this.filterSettings);
		
		this.tableViewer.setFilters(new ViewerFilter[] { sourceFilter,
				levelFilter });
		
		this.tableViewer.setComparator(new TimeViewerComparator());
		
		this.refreshToggleButton();
	}
	
	/**
	 * @param scrollLock
	 * @since 1.24
	 */
	public void setScrollLock(boolean scrollLock) {
		this.scrollLock = scrollLock;
	}
	
	/*
	 * @since 1.24
	 */<commit_msg>fixed bug #3577: active listeners after Message View is disposed<commit_after>package de.ptb.epics.eve.viewer.views.messagesview.ui;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import org.apache.log4j.Logger;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.State;
import org.eclipse.core.databinding.observable.list.IListChangeListener;
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.part.ViewPart;

import de.ptb.epics.eve.util.ui.swt.FontHelper;
import de.ptb.epics.eve.viewer.Activator;
import de.ptb.epics.eve.viewer.views.messagesview.FilterSettings;
import de.ptb.epics.eve.viewer.views.messagesview.IMessageList;
import de.ptb.epics.eve.viewer.views.messagesview.LevelFilter;
import de.ptb.epics.eve.viewer.views.messagesview.Levels;
import de.ptb.epics.eve.viewer.views.messagesview.MessageFilter;
import de.ptb.epics.eve.viewer.views.messagesview.MessageList;
import de.ptb.epics.eve.viewer.views.messagesview.SourceFilter;
import de.ptb.epics.eve.viewer.views.messagesview.TimeViewerComparator;

/**
 * 
 * @author ?
 * @author <NAME>
 */
public final class MessagesView extends ViewPart implements PropertyChangeListener {
	private static final Logger LOGGER = Logger.getLogger(MessagesView.class
			.getName());
	
	// the only element in this view is a table viewer for the messages
	private TableViewer tableViewer;
	
	private FilterSettings filterSettings;
	
	private boolean scrollLock;
	
	private IMemento memento;
	private static final String SHOW_VIEWER_MESSAGES_MEMENTO = "showViewerMessages";
	private static final String SHOW_ENGINE_MESSAGES_MEMENTO = "showEngineMessages";
	private static final String MESSAGE_LEVEL_MEMENTO = "messageLevel";
	private static final String AUTO_SCROLL_MEMENTO = "scrollLock";

	private IMessageList messageList;
	private IListChangeListener messageListListChangeListener;
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void init(IViewSite site, IMemento memento) throws PartInitException {
		super.init(site, memento);
		this.memento = memento;
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void createPartControl(final Composite parent) {
		this.tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | 
				SWT.V_SCROLL);

		// the first column contains the time
		TableViewerColumn timeColumn = new TableViewerColumn(this.tableViewer,
				SWT.LEFT);
		timeColumn.getColumn().setText("Time");
		timeColumn.getColumn().setWidth(220);

		// second column: source (the sender of the message)
		TableViewerColumn sourceColumn = new TableViewerColumn(this.tableViewer, 
				SWT.LEFT);
		sourceColumn.getColumn().setText("Source");
		sourceColumn.getColumn().setWidth(80);

		// third column: the type (e.g. I for Info or E for Error)
		TableViewerColumn typeColumn = new TableViewerColumn(this.tableViewer, 
				SWT.LEFT);
		typeColumn.getColumn().setText("");
		typeColumn.getColumn().setWidth(25);
		//typeColumn.getColumn().addSelectionListener(
		//		new TypeColumnSelectionListener());
		
		// fourth column: the text (contents) of the message
		TableViewerColumn messageColumn = new TableViewerColumn(
				this.tableViewer, SWT.LEFT);
		messageColumn.getColumn().setText("Message");
		messageColumn.getColumn().setWidth(300);

		this.tableViewer.getTable().setHeaderVisible(true);
		this.tableViewer.getTable().setLinesVisible(true);

		this.tableViewer.setContentProvider(new ObservableListContentProvider());
		this.tableViewer.setLabelProvider(new LabelProvider());
		
		this.tableViewer.setInput(Activator.getDefault().
				getMessageList().getList());
		
		this.messageList = Activator.getDefault().getMessageList();
		this.messageList.addPropertyChangeListener(
				MessageList.SOURCE_MAX_WIDTH_PROP, this);
		this.messageList.addPropertyChangeListener(
				MessageList.MESSAGE_MAX_WIDTH_PROP, this);
		this.messageListListChangeListener = new IListChangeListener() {
			@Override
			public void handleListChange(ListChangeEvent event) {
				if (!scrollLock) {
					LOGGER.debug("new element & auto scroll on -> show top");
					tableViewer.getTable().setTopIndex(0);
				}
			}
		};
		this.messageList.getList().addListChangeListener(
				this.messageListListChangeListener);
		
		this.filterSettings = new FilterSettings();
		this.restoreState();
		MessageFilter sourceFilter = new SourceFilter(this.filterSettings);
		MessageFilter levelFilter = new LevelFilter(this.filterSettings);
		
		this.tableViewer.setFilters(new ViewerFilter[] { sourceFilter,
				levelFilter });
		
		this.tableViewer.setComparator(new TimeViewerComparator());
		
		this.refreshToggleButton();
	}
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void dispose() {
		messageList.removePropertyChangeListener(
				MessageList.SOURCE_MAX_WIDTH_PROP, this);
		messageList.removePropertyChangeListener(
				MessageList.MESSAGE_MAX_WIDTH_PROP, this);
		messageList.getList().removeListChangeListener(
				this.messageListListChangeListener);
		super.dispose();
	}
	
	/**
	 * @param scrollLock
	 * @since 1.24
	 */
	public void setScrollLock(boolean scrollLock) {
		this.scrollLock = scrollLock;
	}
	
	/*
	 * @since 1.24
	 */
{'fraction_non_alphanumeric': 0.10940392447241762, 'fraction_numerical': 0.0037023324694557573, 'mean_word_length': 5.128757799205899, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '4675184', 'n_tokens_mistral': 3653, 'n_tokens_neox': 3330, 'n_words': 605}