[jbosstools-commits] JBoss Tools SVN: r39807 - in trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples: dialog and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Mar 23 18:19:10 EDT 2012


Author: snjeza
Date: 2012-03-23 18:19:10 -0400 (Fri, 23 Mar 2012)
New Revision: 39807

Removed:
   trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/DescriptionToolTip.java
Modified:
   trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/DownloadRuntimeDialog.java
Log:
JBIDE-11127 After downloading a runtime all other runtimes in the install locations are added

Deleted: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/DescriptionToolTip.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/DescriptionToolTip.java	2012-03-23 21:23:48 UTC (rev 39806)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/DescriptionToolTip.java	2012-03-23 22:19:10 UTC (rev 39807)
@@ -1,69 +0,0 @@
-/*************************************************************************************
- * Copyright (c) 2008-2011 Red Hat, Inc. and others.
- * All rights reserved. This program and the accompanying materials 
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * 
- * Contributors:
- *     JBoss by Red Hat - Initial implementation.
- ************************************************************************************/
-package org.jboss.tools.project.examples;
-
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.window.ToolTip;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Text;
-
-/**
- * 
- * @author snjeza
- *
- */
-public class DescriptionToolTip extends ToolTip {
-
-	private String description;
-
-	public DescriptionToolTip(Control control, String description) {
-		super(control);
-		this.description = description;
-		setHideOnMouseDown(true);
-		setPopupDelay(400);
-		
-	}
-
-	@Override
-	protected Composite createToolTipContentArea(Event event, Composite parent) {
-		// Create the content area
-		parent.setLayout(new GridLayout());
-		Composite composite = new Composite(parent, SWT.NONE);
-		GridLayout layout = new GridLayout();
-		layout.marginHeight = 2;
-		layout.marginLeft = 2;
-		composite.setLayout(layout);
-		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-		gd.widthHint = 300;
-		composite.setLayoutData(gd);
-		composite.setBackground(parent.getDisplay().getSystemColor(
-				SWT.COLOR_INFO_BACKGROUND));
-		Text text = new Text(composite,
-				SWT.READ_ONLY | SWT.MULTI | SWT.WRAP);
-		gd = new GridData(SWT.FILL, SWT.FILL, true, true);
-		GC gc = new GC(parent);
-		gd.heightHint = Dialog.convertHeightInCharsToPixels(gc
-				.getFontMetrics(), (description.length()/40) + 1);
-		gc.dispose();
-		text.setLayoutData(gd);
-		text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
-		text.setText(description);
-		
-		return composite;
-	}
-
-}

Modified: trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/DownloadRuntimeDialog.java
===================================================================
--- trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/DownloadRuntimeDialog.java	2012-03-23 21:23:48 UTC (rev 39806)
+++ trunk/examples/plugins/org.jboss.tools.project.examples/src/org/jboss/tools/project/examples/dialog/DownloadRuntimeDialog.java	2012-03-23 22:19:10 UTC (rev 39807)
@@ -17,9 +17,12 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URL;
+import java.util.Enumeration;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.IStatus;
@@ -70,6 +73,7 @@
  */
 public class DownloadRuntimeDialog extends Dialog {
 
+	private static final String SEPARATOR = "/";
 	private static final String FOLDER_IS_REQUIRED = "This folder is required";
 	private static final String FOLDER_IS_NOT_WRITABLE = "This folder does not exist or is not writable";
 	private static final String DELETE_ON_EXIT = "deleteOnExit";
@@ -429,6 +433,16 @@
 				file.delete();
 				return Status.CANCEL_STATUS;
 			}
+			String root = getRoot(file, monitor);
+			if (monitor.isCanceled()) {
+				return Status.CANCEL_STATUS;
+			}
+			if (root != null) {
+				File rootFile = new File(selectedDirectory, root);
+				if (rootFile != null && rootFile.exists()) {
+					selectedDirectory = rootFile.getAbsolutePath();
+				}
+			}
 			createRuntimes(selectedDirectory, monitor);
 		} catch (IOException e) {
 			ProjectExamplesActivator.log(e);
@@ -456,6 +470,46 @@
 		return Status.OK_STATUS;
 	}
 	
+	private String getRoot(File file, IProgressMonitor monitor) {
+		ZipFile zipFile = null;
+		String root = null;
+		try {
+			zipFile = new ZipFile(file);
+			Enumeration<? extends ZipEntry> entries = zipFile.entries();
+			while (entries.hasMoreElements()) {
+				if (monitor.isCanceled()) {
+					return null;
+				}
+				ZipEntry entry = (ZipEntry) entries.nextElement();
+				String entryName = entry.getName();
+				if (entryName == null || entryName.isEmpty() 
+						|| entryName.startsWith(SEPARATOR) || entryName.indexOf(SEPARATOR) == -1) {
+					return null;
+				}
+				String directory = entryName.substring(0, entryName.indexOf(SEPARATOR));
+				if (root == null) {
+					root = directory;
+					continue;
+				}
+				if (!directory.equals(root)) {
+					return null;
+				}
+			}
+		} catch (IOException e) {
+			ProjectExamplesActivator.log(e);
+			return null;
+		} finally {
+			if (zipFile != null) {
+				try {
+					zipFile.close();
+				} catch (IOException e) {
+					// ignore
+				}
+			}
+		}
+		return root;
+	}
+
 	private Shell getActiveShell() {
 		Display display = Display.getDefault();
 		if (display != null) {



More information about the jbosstools-commits mailing list