<commit_before>package org.reldb.dbrowser.ui.updates;

import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.reldb.dbrowser.ui.IconLoader;
import org.reldb.dbrowser.ui.updates.UpdatesCheck.SendStatus;

public class UpdatesCheckDialog extends Dialog {
	
	private Label lblNewUpdatesAvailable;
	private Label lblNewUpdateURL;
	private Label lblInstructions;
	private Label lblProgress;
	private Button btnCancel;
	private Button btnGo;
	private ProgressBar progressBar;
	
	private Shell shlUpdatesCheck;
	
	private UpdatesCheck checker;
	
	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public UpdatesCheckDialog(Shell parent, int style) {
		super(parent, SWT.NONE);
		setText("Check for Updates");
		shlUpdatesCheck = createContents();
		checker = new UpdatesCheck(btnGo, lblProgress, progressBar) {
			@Override
		    public void completed(SendStatus sendStatus) {
				UpdatesCheckDialog.this.completed(sendStatus);
			}
			@Override
			public void quit() {
				UpdatesCheckDialog.this.quit();
			}
		};
	}
	
	protected void completed(SendStatus sendStatus) {
		String failHeading = "Check for Updates Failed";
		try {
			if (sendStatus.getResponse() != null && sendStatus.getResponse().startsWith("Success")) {
				String updateURL = sendStatus.getResponse().substring("Success".length() + 1).trim();
				if (!updateURL.startsWith("http")) {
					Shell parent = getParent();
					quit();
					MessageDialog.openInformation(parent,  "Check for Updates", "No new updates available.");
				} else {
					lblNewUpdatesAvailable.setVisible(true);
					lblNewUpdateURL.setVisible(true);
					lblNewUpdateURL.setText(updateURL);
					btnGo.setText("Exit");
					btnCancel.setVisible(false);
					lblProgress.setVisible(false);
					progressBar.setVisible(false);
					lblInstructions.setVisible(false);
				}
	    		return;
	        } else
	        	if (sendStatus.getException() != null) {
        			sendStatus.getException().printStackTrace();
	        		MessageDialog.openError(getParent(), failHeading, "Unable to send request: " + sendStatus.getException().toString());
	        	} else
	        		MessageDialog.openError(getParent(), failHeading, "Unable to send request: " + sendStatus.getResponse());
		} catch (Exception e1) {
    		String exceptionName = e1.getClass().getName().toString(); 
    		if (exceptionName.equals("java.lang.InterruptedException"))
    			MessageDialog.openError(getParent(), failHeading, "Check for Updates Cancelled");
    		else {
    			e1.printStackTrace();
    			MessageDialog.openError(getParent(), failHeading, "Unable to send request: " + e1.toString());
    		}
		}
	}

	protected void open() {
		shlUpdatesCheck.open();
		shlUpdatesCheck.layout();
		Display display = getParent().getDisplay();
		while (!shlUpdatesCheck.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}		
	}
	
	/**
	 * Launch the dialog.
	 * @param shell
	 */
	public static void launch(Shell shell) {
		try {
			shell.getDisplay().syncExec(new Runnable() {
				@Override
				public void run() {
					UpdatesCheckDialog checker = new UpdatesCheckDialog(shell, SWT.None);
					checker.open();
				}
			});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected void doSend() {
		if (lblNewUpdateURL.isVisible())
			quit();
		else
			checker.doSend();
	}
	
	protected void doCancel() {
		checker.doCancel();
	}
	
	protected void quit() {
		shlUpdatesCheck.dispose();
	}
	
	/** Create contents of the dialog. */
	protected Shell createContents() {
		Shell shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
		shell.setSize(600, 250);
		shell.setText(getText());
		shell.setLayout(new FormLayout());
		
		Composite panelIntro = new Composite(shell, SWT.NONE);
		panelIntro.setLayout(new GridLayout(2, false));
		FormData fd_panelIntro = new FormData();
		fd_panelIntro.top = new FormAttachment(0);
		fd_panelIntro.right = new FormAttachment(100);
		fd_panelIntro.left = new FormAttachment(0);
		panelIntro.setLayoutData(fd_panelIntro);
		
		Label lblIcon = new Label(panelIntro, SWT.NONE);
		lblIcon.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
		lblIcon.setImage(IconLoader.loadIcon("RelIcon"));
		
		lblInstructions = new Label(panelIntro, SWT.WRAP);
		lblInstructions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
		lblInstructions.setText("Press the Check for Updates button to check for updates.");
		
		lblNewUpdatesAvailable = new Label(shell, SWT.WRAP);
		lblNewUpdatesAvailable.setText("New Update Available. Click to download:");
		lblNewUpdatesAvailable.setVisible(false);
		FormData fd_lblNewUpdatesAvailable = new FormData();
		fd_lblNewUpdatesAvailable.top = new FormAttachment(panelIntro);
		fd_lblNewUpdatesAvailable.left = new FormAttachment(10);
		fd_lblNewUpdatesAvailable.right = new FormAttachment(100);
		lblNewUpdatesAvailable.setLayoutData(fd_lblNewUpdatesAvailable);
		
		lblNewUpdateURL = new Label(shell, SWT.WRAP);
		lblNewUpdateURL.setVisible(false);
		FormData fd_lblNewUpdateURL = new FormData();
		fd_lblNewUpdateURL.top = new FormAttachment(lblNewUpdatesAvailable);
		fd_lblNewUpdateURL.left = new FormAttachment(10);
		fd_lblNewUpdateURL.right = new FormAttachment(100);
		lblNewUpdateURL.setLayoutData(fd_lblNewUpdateURL);
		lblNewUpdateURL.setForeground(SWTResourceManager.getColor(SWT.COLOR_LINK_FOREGROUND));

		lblNewUpdateURL.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				org.eclipse.swt.program.Program.launch(lblNewUpdateURL.getText());
			}
		});
		lblNewUpdateURL.addMouseMoveListener(new MouseMoveListener() {
			@Override
			public void mouseMove(MouseEvent e) {
				Cursor cursor = shell.getCursor();
				if (cursor != null)
					cursor.dispose();
				cursor = new Cursor(shell.getDisplay(), SWT.CURSOR_HAND); 
				lblNewUpdateURL.setCursor(cursor);
			}
		});
		
		lblProgress = new Label(shell, SWT.NONE);
		FormData fd_lblProgress = new FormData();
		fd_lblProgress.right = new FormAttachment(100);
		lblProgress.setLayoutData(fd_lblProgress);
		lblProgress.setText("Progress...");
		
		progressBar = new ProgressBar(shell, SWT.NONE);
		FormData fd_progressBar = new FormData();
		progressBar.setLayoutData(fd_progressBar);
		
		btnCancel = new Button(shell, SWT.NONE);
		FormData fd_btnCancel = new FormData();
		btnCancel.setLayoutData(fd_btnCancel);
		btnCancel.setText("Cancel");
		btnCancel.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doCancel();
			}
		});
		
		btnGo = new Button(shell, SWT.NONE);
		fd_btnCancel.right = new FormAttachment(btnGo, -6);
		FormData fd_btnSend = new FormData();
		fd_btnSend.bottom = new FormAttachment(100, -10);
		fd_btnSend.right = new FormAttachment(100, -10);
		btnGo.setLayoutData(fd_btnSend);
		btnGo.setText("Check for Updates");
		btnGo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doSend();
			}
		});
		
		fd_btnCancel.bottom = new FormAttachment(100, -10);
		fd_btnCancel.right = new FormAttachment(btnGo, -10);
		
		fd_progressBar.bottom = new FormAttachment(btnCancel, -10);
		fd_progressBar.left = new FormAttachment(0, 10);
		fd_progressBar.right = new FormAttachment(100, -10);
		
		fd_lblProgress.bottom = new FormAttachment(progressBar, -6);
		fd_lblProgress.left = new FormAttachment(0, 10);
		
		lblProgress.setEnabled(false);
		progressBar.setEnabled(false);
		
		return shell;
	}
}
<commit_msg>Don't pop up message for no new updates.<commit_after>package org.reldb.dbrowser.ui.updates;

import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseMoveListener;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Label;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;
import org.reldb.dbrowser.ui.IconLoader;
import org.reldb.dbrowser.ui.updates.UpdatesCheck.SendStatus;

public class UpdatesCheckDialog extends Dialog {
	
	private Label lblNewUpdatesAvailable;
	private Label lblNewUpdateURL;
	private Label lblInstructions;
	private Label lblProgress;
	private Button btnCancel;
	private Button btnGo;
	private ProgressBar progressBar;
	
	private Shell shlUpdatesCheck;
	
	private UpdatesCheck checker;
	
	/**
	 * Create the dialog.
	 * @param parent
	 * @param style
	 */
	public UpdatesCheckDialog(Shell parent, int style) {
		super(parent, SWT.NONE);
		setText("Check for Updates");
		shlUpdatesCheck = createContents();
		checker = new UpdatesCheck(btnGo, lblProgress, progressBar) {
			@Override
		    public void completed(SendStatus sendStatus) {
				UpdatesCheckDialog.this.completed(sendStatus);
			}
			@Override
			public void quit() {
				UpdatesCheckDialog.this.quit();
			}
		};
	}
	
	protected void completed(SendStatus sendStatus) {
		String failHeading = "Check for Updates Failed";
		try {
			if (sendStatus.getResponse() != null && sendStatus.getResponse().startsWith("Success")) {
				String updateURL = sendStatus.getResponse().substring("Success".length() + 1).trim();
				if (updateURL.startsWith("http")) {
					lblNewUpdateURL.setVisible(true);
					lblNewUpdateURL.setText(updateURL);
				} else {
					lblNewUpdatesAvailable.setText("No new updates available.");
				}
				lblNewUpdatesAvailable.setVisible(true);
				btnGo.setText("Exit");
				btnCancel.setVisible(false);
				lblProgress.setVisible(false);
				progressBar.setVisible(false);
				lblInstructions.setVisible(false);
	        } else
	        	if (sendStatus.getException() != null) {
        			sendStatus.getException().printStackTrace();
	        		MessageDialog.openError(getParent(), failHeading, "Unable to send request: " + sendStatus.getException().toString());
	        	} else
	        		MessageDialog.openError(getParent(), failHeading, "Unable to send request: " + sendStatus.getResponse());
		} catch (Exception e1) {
    		String exceptionName = e1.getClass().getName().toString(); 
    		if (exceptionName.equals("java.lang.InterruptedException"))
    			MessageDialog.openError(getParent(), failHeading, "Check for Updates Cancelled");
    		else {
    			e1.printStackTrace();
    			MessageDialog.openError(getParent(), failHeading, "Unable to send request: " + e1.toString());
    		}
		}
	}

	protected void open() {
		shlUpdatesCheck.open();
		shlUpdatesCheck.layout();
		Display display = getParent().getDisplay();
		while (!shlUpdatesCheck.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}		
	}
	
	/**
	 * Launch the dialog.
	 * @param shell
	 */
	public static void launch(Shell shell) {
		try {
			shell.getDisplay().syncExec(new Runnable() {
				@Override
				public void run() {
					UpdatesCheckDialog checker = new UpdatesCheckDialog(shell, SWT.None);
					checker.open();
				}
			});
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	protected void doSend() {
		if (lblNewUpdatesAvailable.isVisible())
			quit();
		else
			checker.doSend();
	}
	
	protected void doCancel() {
		checker.doCancel();
	}
	
	protected void quit() {
		shlUpdatesCheck.dispose();
	}
	
	/** Create contents of the dialog. */
	protected Shell createContents() {
		Shell shell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL);
		shell.setSize(600, 250);
		shell.setText(getText());
		shell.setLayout(new FormLayout());
		
		Composite panelIntro = new Composite(shell, SWT.NONE);
		panelIntro.setLayout(new GridLayout(2, false));
		FormData fd_panelIntro = new FormData();
		fd_panelIntro.top = new FormAttachment(0);
		fd_panelIntro.right = new FormAttachment(100);
		fd_panelIntro.left = new FormAttachment(0);
		panelIntro.setLayoutData(fd_panelIntro);
		
		Label lblIcon = new Label(panelIntro, SWT.NONE);
		lblIcon.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false, 1, 1));
		lblIcon.setImage(IconLoader.loadIcon("RelIcon"));
		
		lblInstructions = new Label(panelIntro, SWT.WRAP);
		lblInstructions.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 1));
		lblInstructions.setText("Press the Check for Updates button to check for updates.");
		
		lblNewUpdatesAvailable = new Label(shell, SWT.WRAP);
		lblNewUpdatesAvailable.setText("New Update Available. Click to download:");
		lblNewUpdatesAvailable.setVisible(false);
		FormData fd_lblNewUpdatesAvailable = new FormData();
		fd_lblNewUpdatesAvailable.top = new FormAttachment(panelIntro);
		fd_lblNewUpdatesAvailable.left = new FormAttachment(10);
		fd_lblNewUpdatesAvailable.right = new FormAttachment(100);
		lblNewUpdatesAvailable.setLayoutData(fd_lblNewUpdatesAvailable);
		
		lblNewUpdateURL = new Label(shell, SWT.WRAP);
		lblNewUpdateURL.setVisible(false);
		FormData fd_lblNewUpdateURL = new FormData();
		fd_lblNewUpdateURL.top = new FormAttachment(lblNewUpdatesAvailable);
		fd_lblNewUpdateURL.left = new FormAttachment(10);
		fd_lblNewUpdateURL.right = new FormAttachment(100);
		lblNewUpdateURL.setLayoutData(fd_lblNewUpdateURL);
		lblNewUpdateURL.setForeground(SWTResourceManager.getColor(SWT.COLOR_LINK_FOREGROUND));

		lblNewUpdateURL.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseUp(MouseEvent e) {
				org.eclipse.swt.program.Program.launch(lblNewUpdateURL.getText());
			}
		});
		lblNewUpdateURL.addMouseMoveListener(new MouseMoveListener() {
			@Override
			public void mouseMove(MouseEvent e) {
				Cursor cursor = shell.getCursor();
				if (cursor != null)
					cursor.dispose();
				cursor = new Cursor(shell.getDisplay(), SWT.CURSOR_HAND); 
				lblNewUpdateURL.setCursor(cursor);
			}
		});
		
		lblProgress = new Label(shell, SWT.NONE);
		FormData fd_lblProgress = new FormData();
		fd_lblProgress.right = new FormAttachment(100);
		lblProgress.setLayoutData(fd_lblProgress);
		lblProgress.setText("Progress...");
		
		progressBar = new ProgressBar(shell, SWT.NONE);
		FormData fd_progressBar = new FormData();
		progressBar.setLayoutData(fd_progressBar);
		
		btnCancel = new Button(shell, SWT.NONE);
		FormData fd_btnCancel = new FormData();
		btnCancel.setLayoutData(fd_btnCancel);
		btnCancel.setText("Cancel");
		btnCancel.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doCancel();
			}
		});
		
		btnGo = new Button(shell, SWT.NONE);
		fd_btnCancel.right = new FormAttachment(btnGo, -6);
		FormData fd_btnSend = new FormData();
		fd_btnSend.bottom = new FormAttachment(100, -10);
		fd_btnSend.right = new FormAttachment(100, -10);
		btnGo.setLayoutData(fd_btnSend);
		btnGo.setText("Check for Updates");
		btnGo.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				doSend();
			}
		});
		
		fd_btnCancel.bottom = new FormAttachment(100, -10);
		fd_btnCancel.right = new FormAttachment(btnGo, -10);
		
		fd_progressBar.bottom = new FormAttachment(btnCancel, -10);
		fd_progressBar.left = new FormAttachment(0, 10);
		fd_progressBar.right = new FormAttachment(100, -10);
		
		fd_lblProgress.bottom = new FormAttachment(progressBar, -6);
		fd_lblProgress.left = new FormAttachment(0, 10);
		
		lblProgress.setEnabled(false);
		progressBar.setEnabled(false);
		
		return shell;
	}
}

{'fraction_non_alphanumeric': 0.11825639183282438, 'fraction_numerical': 0.007903718340219149, 'mean_word_length': 4.517674264948794, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2142022', 'n_tokens_mistral': 5983, 'n_tokens_neox': 5358, 'n_words': 1016}