<commit_before>package org.tigris.subversion.subclipse.ui.dialogs;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.TeamException;
import org.tigris.subversion.subclipse.core.ISVNLocalResource;
import org.tigris.subversion.subclipse.core.ISVNRemoteResource;
import org.tigris.subversion.subclipse.core.history.ILogEntry;
import org.tigris.subversion.subclipse.core.history.LogEntry;
import org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot;
import org.tigris.subversion.subclipse.ui.ISVNUIConstants;
import org.tigris.subversion.subclipse.ui.Policy;
import org.tigris.subversion.subclipse.ui.SVNUIPlugin;
import org.tigris.subversion.subclipse.ui.history.ChangePathsTableProvider;
import org.tigris.subversion.subclipse.ui.history.HistoryTableProvider;
import org.tigris.subversion.svnclientadapter.SVNRevision;

public class HistoryDialog extends Dialog {
    private IResource resource;
    private ISVNRemoteResource remoteResource;
	private HistoryTableProvider historyTableProvider;
	private ChangePathsTableProvider changePathsTableProvider;
	private TableViewer tableHistoryViewer;
    private TableViewer tableChangePathViewer;
	private TextViewer textViewer;
	private Button stopOnCopyButton;
	private Button getAllButton;
	private Button getNextButton;
	private ILogEntry[] entries;
	private IDialogSettings settings;
	private ILogEntry[] selectedEntries;
	private IPreferenceStore store;
	private SVNRevision revisionStart = SVNRevision.HEAD;
	private boolean getNextEnabled = true;
	
	private static final int WIDTH_HINT = 500;
	private final static int LOG_HEIGHT_HINT = 200;
	private final static int COMMENT_HEIGHT_HINT = 100;
	private final static int PATHS_HEIGHT_HINT = 200;

    public HistoryDialog(Shell parentShell, IResource resource) {
        super(parentShell);
		int shellStyle = getShellStyle();
		setShellStyle(shellStyle | SWT.RESIZE);
        this.resource = resource;
		settings = SVNUIPlugin.getPlugin().getDialogSettings();
		store = SVNUIPlugin.getPlugin().getPreferenceStore();
    }
    
    public HistoryDialog(Shell parentShell, ISVNRemoteResource remoteResource) {
        super(parentShell);
		int shellStyle = getShellStyle();
		setShellStyle(shellStyle | SWT.RESIZE);
        this.remoteResource = remoteResource;
		settings = SVNUIPlugin.getPlugin().getDialogSettings();
		store = SVNUIPlugin.getPlugin().getPreferenceStore();
    }    
    
	protected Control createDialogArea(Composite parent) {
		getLogEntries();
	    if (resource == null)
	        getShell().setText(Policy.bind("HistoryDialog.title") + " - " + remoteResource.getName()); //$NON-NLS-1$ //$NON-NLS-2$
	    else
	        getShell().setText(Policy.bind("HistoryDialog.title") + " - " + resource.getName()); //$NON-NLS-1$ //$NON-NLS-2$
		Composite composite = new Composite(parent, SWT.NULL);
		composite.setLayout(new GridLayout());
		GridData data = new GridData(GridData.FILL_BOTH);
		composite.setLayoutData(data);
		
		historyTableProvider = new HistoryTableProvider();
		historyTableProvider.setRemoteResource(remoteResource);
		tableHistoryViewer = historyTableProvider.createTable(composite);
		data = new GridData(GridData.FILL_BOTH);
		data.widthHint = WIDTH_HINT;
		data.heightHint = LOG_HEIGHT_HINT;
		tableHistoryViewer.getTable().setLayoutData(data);
		tableHistoryViewer.setContentProvider(new IStructuredContentProvider() {
            public void dispose() {
            }
            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            }
            public Object[] getElements(Object inputElement) {
                return entries;
            }	    
		});
		tableHistoryViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                ISelection selection = event.getSelection();
				if (selection == null || !(selection instanceof IStructuredSelection)) {
					textViewer.setDocument(new Document("")); //$NON-NLS-1$
                    changePathsTableProvider.setInput(null);
					return;
				}
				IStructuredSelection ss = (IStructuredSelection)selection;
				if (ss.size() != 1) {
					textViewer.setDocument(new Document("")); //$NON-NLS-1$
                    changePathsTableProvider.setInput(null);
					return;
				}
				LogEntry entry = (LogEntry)ss.getFirstElement();
				textViewer.setDocument(new Document(entry.getComment()));
                changePathsTableProvider.setInput(entry);                     
            }		    
		});
		tableHistoryViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                okPressed();
            }	    
		});
		
		tableHistoryViewer.setInput(remoteResource);
		
		textViewer = new TextViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.READ_ONLY);
		data = new GridData(GridData.FILL_BOTH);
		data.heightHint = COMMENT_HEIGHT_HINT;
		data.widthHint = WIDTH_HINT;
		textViewer.getControl().setLayoutData(data);
		
		changePathsTableProvider = new ChangePathsTableProvider(composite);
        changePathsTableProvider.setContentProvider(new IStructuredContentProvider() {

			public Object[] getElements(Object inputElement) {
                if ((inputElement == null) || (!(inputElement instanceof ILogEntry))) {
                    return null;
                }
                ILogEntry logEntry = (ILogEntry)inputElement;
				return logEntry.getLogEntryChangePaths();
			}

			public void dispose() {
			}

			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
			}
        });
        
		data = new GridData(GridData.FILL_BOTH);
		data.heightHint = PATHS_HEIGHT_HINT;
		data.widthHint = WIDTH_HINT;
		tableChangePathViewer.getTable().setLayoutData(data);
		
		stopOnCopyButton = new Button(composite, SWT.CHECK);
		stopOnCopyButton.setText(Policy.bind("HistoryView.stopOnCopy"));
		stopOnCopyButton.setSelection(store.getBoolean(ISVNUIConstants.PREF_STOP_ON_COPY));
		stopOnCopyButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				store.setValue(ISVNUIConstants.PREF_STOP_ON_COPY, stopOnCopyButton.getSelection());				
				revisionStart = SVNRevision.HEAD;
				getLogEntries();
				tableHistoryViewer.refresh();
			}
		});
		
		return composite;
	}
	
	private void getLogEntries() {
	   BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
	        public void run() {
	            try {
		            if (remoteResource == null) {
		                ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
						if ( localResource != null
						        && !localResource.getStatus().isAdded()
						        && localResource.getStatus().isManaged() ) {
						    remoteResource = localResource.getBaseResource();
						}
		            }
		            if (remoteResource != null) {
						SVNRevision pegRevision = remoteResource.getRevision();
						SVNRevision revisionEnd = new SVNRevision.Number(0);<commit_msg>Fixed a NPE in the Show History dialog.<commit_after>package org.tigris.subversion.subclipse.ui.dialogs;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.core.resources.IResource;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.TextViewer;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.BusyIndicator;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.team.core.TeamException;
import org.tigris.subversion.subclipse.core.ISVNLocalResource;
import org.tigris.subversion.subclipse.core.ISVNRemoteResource;
import org.tigris.subversion.subclipse.core.history.ILogEntry;
import org.tigris.subversion.subclipse.core.history.LogEntry;
import org.tigris.subversion.subclipse.core.resources.SVNWorkspaceRoot;
import org.tigris.subversion.subclipse.ui.ISVNUIConstants;
import org.tigris.subversion.subclipse.ui.Policy;
import org.tigris.subversion.subclipse.ui.SVNUIPlugin;
import org.tigris.subversion.subclipse.ui.history.ChangePathsTableProvider;
import org.tigris.subversion.subclipse.ui.history.HistoryTableProvider;
import org.tigris.subversion.svnclientadapter.SVNRevision;

public class HistoryDialog extends Dialog {
    private IResource resource;
    private ISVNRemoteResource remoteResource;
	private HistoryTableProvider historyTableProvider;
	private ChangePathsTableProvider changePathsTableProvider;
	private TableViewer tableHistoryViewer;
	private TextViewer textViewer;
	private Button stopOnCopyButton;
	private Button getAllButton;
	private Button getNextButton;
	private ILogEntry[] entries;
	private IDialogSettings settings;
	private ILogEntry[] selectedEntries;
	private IPreferenceStore store;
	private SVNRevision revisionStart = SVNRevision.HEAD;
	private boolean getNextEnabled = true;
	
	private static final int WIDTH_HINT = 500;
	private final static int LOG_HEIGHT_HINT = 200;
	private final static int COMMENT_HEIGHT_HINT = 100;

    public HistoryDialog(Shell parentShell, IResource resource) {
        super(parentShell);
		int shellStyle = getShellStyle();
		setShellStyle(shellStyle | SWT.RESIZE);
        this.resource = resource;
		settings = SVNUIPlugin.getPlugin().getDialogSettings();
		store = SVNUIPlugin.getPlugin().getPreferenceStore();
    }
    
    public HistoryDialog(Shell parentShell, ISVNRemoteResource remoteResource) {
        super(parentShell);
		int shellStyle = getShellStyle();
		setShellStyle(shellStyle | SWT.RESIZE);
        this.remoteResource = remoteResource;
		settings = SVNUIPlugin.getPlugin().getDialogSettings();
		store = SVNUIPlugin.getPlugin().getPreferenceStore();
    }    
    
	protected Control createDialogArea(Composite parent) {
		getLogEntries();
	    if (resource == null)
	        getShell().setText(Policy.bind("HistoryDialog.title") + " - " + remoteResource.getName()); //$NON-NLS-1$ //$NON-NLS-2$
	    else
	        getShell().setText(Policy.bind("HistoryDialog.title") + " - " + resource.getName()); //$NON-NLS-1$ //$NON-NLS-2$
		Composite composite = new Composite(parent, SWT.NULL);
		composite.setLayout(new GridLayout());
		GridData data = new GridData(GridData.FILL_BOTH);
		composite.setLayoutData(data);
		
		historyTableProvider = new HistoryTableProvider();
		historyTableProvider.setRemoteResource(remoteResource);
		tableHistoryViewer = historyTableProvider.createTable(composite);
		data = new GridData(GridData.FILL_BOTH);
		data.widthHint = WIDTH_HINT;
		data.heightHint = LOG_HEIGHT_HINT;
		tableHistoryViewer.getTable().setLayoutData(data);
		tableHistoryViewer.setContentProvider(new IStructuredContentProvider() {
            public void dispose() {
            }
            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            }
            public Object[] getElements(Object inputElement) {
                return entries;
            }	    
		});
		tableHistoryViewer.addSelectionChangedListener(new ISelectionChangedListener() {
            public void selectionChanged(SelectionChangedEvent event) {
                ISelection selection = event.getSelection();
				if (selection == null || !(selection instanceof IStructuredSelection)) {
					textViewer.setDocument(new Document("")); //$NON-NLS-1$
                    changePathsTableProvider.setInput(null);
					return;
				}
				IStructuredSelection ss = (IStructuredSelection)selection;
				if (ss.size() != 1) {
					textViewer.setDocument(new Document("")); //$NON-NLS-1$
                    changePathsTableProvider.setInput(null);
					return;
				}
				LogEntry entry = (LogEntry)ss.getFirstElement();
				textViewer.setDocument(new Document(entry.getComment()));
                changePathsTableProvider.setInput(entry);                     
            }		    
		});
		tableHistoryViewer.addDoubleClickListener(new IDoubleClickListener() {
            public void doubleClick(DoubleClickEvent event) {
                okPressed();
            }	    
		});
		
		tableHistoryViewer.setInput(remoteResource);
		
		textViewer = new TextViewer(composite, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.BORDER | SWT.READ_ONLY);
		data = new GridData(GridData.FILL_BOTH);
		data.heightHint = COMMENT_HEIGHT_HINT;
		data.widthHint = WIDTH_HINT;
		textViewer.getControl().setLayoutData(data);
		
		changePathsTableProvider = new ChangePathsTableProvider(composite);
        changePathsTableProvider.setContentProvider(new IStructuredContentProvider() {

			public Object[] getElements(Object inputElement) {
                if ((inputElement == null) || (!(inputElement instanceof ILogEntry))) {
                    return null;
                }
                ILogEntry logEntry = (ILogEntry)inputElement;
				return logEntry.getLogEntryChangePaths();
			}

			public void dispose() {
			}

			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
			}
        });
		
		stopOnCopyButton = new Button(composite, SWT.CHECK);
		stopOnCopyButton.setText(Policy.bind("HistoryView.stopOnCopy"));
		stopOnCopyButton.setSelection(store.getBoolean(ISVNUIConstants.PREF_STOP_ON_COPY));
		stopOnCopyButton.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent e) {
				store.setValue(ISVNUIConstants.PREF_STOP_ON_COPY, stopOnCopyButton.getSelection());				
				revisionStart = SVNRevision.HEAD;
				getLogEntries();
				tableHistoryViewer.refresh();
			}
		});
		
		return composite;
	}
	
	private void getLogEntries() {
	   BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {
	        public void run() {
	            try {
		            if (remoteResource == null) {
		                ISVNLocalResource localResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
						if ( localResource != null
						        && !localResource.getStatus().isAdded()
						        && localResource.getStatus().isManaged() ) {
						    remoteResource = localResource.getBaseResource();
						}
		            }
		            if (remoteResource != null) {
						SVNRevision pegRevision = remoteResource.getRevision();
						SVNRevision revisionEnd = new SVNRevision.Number(0);
{'fraction_non_alphanumeric': 0.09951219512195122, 'fraction_numerical': 0.0022560975609756096, 'mean_word_length': 4.00793893129771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '679549', 'n_tokens_mistral': 5218, 'n_tokens_neox': 4714, 'n_words': 817}