FileDocCategorySizeDatePackage
UIExitUtilsSWT.javaAPI DocAzureus 3.0.3.45958Thu Aug 02 12:19:36 BST 2007org.gudy.azureus2.ui.swt

UIExitUtilsSWT

public class UIExitUtilsSWT extends Object
author
TuxPaper
created
Nov 6, 2006

Fields Summary
private static boolean
skipCloseCheck
Constructors Summary
Methods Summary
public static booleancanClose(org.gudy.azureus2.core3.global.GlobalManager globalManager, boolean bForRestart)

return

		if (skipCloseCheck) {
			return true;
		}
		
		if (COConfigurationManager.getBooleanParameter("confirmationOnExit")) {
			if (!getExitConfirmation(bForRestart)) {
				return false;
			}
		}

		if (globalManager != null) {
			ArrayList listUnfinished = new ArrayList();
			Object[] dms = globalManager.getDownloadManagers().toArray();
			for (int i = 0; i < dms.length; i++) {
				DownloadManager dm = (DownloadManager) dms[i];
				if (dm.getState() == DownloadManager.STATE_SEEDING
						&& dm.getDownloadState().isOurContent()
						&& dm.getStats().getAvailability() < 2) {
					TRTrackerScraperResponse scrape = dm.getTrackerScrapeResponse();
					int numSeeds = scrape.getSeeds();
					long seedingStartedOn = dm.getStats().getTimeStartedSeeding();
					if ((numSeeds > 0) && (seedingStartedOn > 0)
							&& (scrape.getScrapeStartTime() > seedingStartedOn))
						numSeeds--;

					if (numSeeds == 0) {
						listUnfinished.add(dm);
					}
				}
			}

			if (listUnfinished.size() > 0) {
				boolean allowQuit;
				final List flistUnfinished = listUnfinished;
				if (listUnfinished.size() == 1) {
					allowQuit = Utils.execSWTThreadWithBool("quitSeeding",
							new AERunnableBoolean() {
								public boolean runSupport() {
									String title = MessageText.getString("Content.alert.notuploaded.title");
									String text = MessageText.getString(
											"Content.alert.notuploaded.text",
											new String[] {
												((DownloadManager) flistUnfinished.get(0)).getDisplayName(),
												MessageText.getString("Content.alert.notuploaded.quit")
											});

									MessageBoxShell mb = new MessageBoxShell(
											Utils.findAnyShell(),
											title,
											text,
											new String[] {
												MessageText.getString("UpdateWindow.quit"),
												MessageText.getString("Content.alert.notuploaded.button.abort")
											}, 1, null, null, false, 0);
									mb.setRelatedObject(((DownloadManager) flistUnfinished.get(0)));

									return mb.open() == 0;
								}
							});
				} else {
					allowQuit = Utils.execSWTThreadWithBool("quitSeeding",
							new AERunnableBoolean() {
								public boolean runSupport() {
									String sList = "";
									for (int i = 0; i < flistUnfinished.size() && i < 5; i++) {
										DownloadManager dm = ((DownloadManager) flistUnfinished.get(i));
										if (sList != "") {
											sList += "\n";
										}
										sList += dm.getDisplayName();
									}

									String title = MessageText.getString("Content.alert.notuploaded.multi.title");
									String text = MessageText.getString(
											"Content.alert.notuploaded.multi.text",
											new String[] {
												"" + flistUnfinished.size(),
												MessageText.getString("Content.alert.notuploaded.quit"),
												sList
											});

									MessageBoxShell mb = new MessageBoxShell(
											Utils.findAnyShell(),
											title,
											text,
											new String[] {
												MessageText.getString("UpdateWindow.quit"),
												MessageText.getString("Content.alert.notuploaded.button.abort")
											}, 1, null, null, false, 0);

									return mb.open() == 0;
								}
							});
				}
				return allowQuit;
			}
		}

		return true;
	
private static booleangetExitConfirmation(boolean for_restart)

return
true, if the user choosed OK in the exit dialog
author
Rene Leonhardt

		int result = Utils.openMessageBox(Utils.findAnyShell(), SWT.ICON_WARNING
				| SWT.YES | SWT.NO, for_restart
				? "MainWindow.dialog.restartconfirmation"
				: "MainWindow.dialog.exitconfirmation", (String[]) null);

		return result == SWT.YES;
	
public static voidsetSkipCloseCheck(boolean b)

	
	     
		skipCloseCheck = b;
	
public static voiduiShutdown()

		// problem with closing down web start as AWT threads don't close properly
		if (SystemProperties.isJavaWebStartInstance()) {

			Thread close = new AEThread("JWS Force Terminate") {
				public void runSupport() {
					try {
						Thread.sleep(2500);

					} catch (Throwable e) {

						Debug.printStackTrace(e);
					}

					SESecurityManager.exitVM(1);
				}
			};

			close.setDaemon(true);

			close.start();
		}