From b183cb5f63104c7204f54814c32abde9930735ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mr=20Adrian=20Nor=C3=A5s?= <adrian.corma@gmail.com>
Date: Fri, 22 Jul 2011 07:56:20 +0000
Subject: [PATCH] Added comments. Removed an extension that was not used.

---
 .../plugin.xml                                | 10 ----
 .../handlers/GenerateAalApp.java              | 23 ++++----
 .../handlers/ImportHandler.java               | 13 +----
 .../wizards/ImportExternalWizard.java         | 52 +++++++++++++++---
 .../wizards/ImportExternalWizardPage.java     | 54 +++++++++++++++++--
 .../xmlparser/ProjectObject.java              | 25 +++++++++
 .../xmlparser/XmlParser.java                  | 45 ++++++++++------
 7 files changed, 164 insertions(+), 58 deletions(-)

diff --git a/depotclient/org.universaal.tools.importthirdpartyproject/plugin.xml b/depotclient/org.universaal.tools.importthirdpartyproject/plugin.xml
index 52a15aec7..68778c908 100644
--- a/depotclient/org.universaal.tools.importthirdpartyproject/plugin.xml
+++ b/depotclient/org.universaal.tools.importthirdpartyproject/plugin.xml
@@ -6,7 +6,6 @@
          point="org.eclipse.ui.commands">
       <command
             name="Import Third Party Application"
-            categoryId="org.universaal.tools.newwizard.plugin.command"
             id="org.universaal.importexternalproject.commands.importthirdparty">
       </command>
    </extension>
@@ -17,15 +16,6 @@
             class="org.universaal.tools.importexternalproject.handlers.ImportHandler">
       </handler>
    </extension>
-   <extension
-         point="org.eclipse.ui.bindings">
-      <key
-            commandId="org.universaal.importexternalproject.commands.sampleCommand"
-            contextId="org.eclipse.ui.contexts.window"
-            sequence="M1+6"
-            schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
-      </key>
-   </extension>
    <extension
          point="org.eclipse.ui.menus">
       <menuContribution
diff --git a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/handlers/GenerateAalApp.java b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/handlers/GenerateAalApp.java
index f16076d59..0e83ee6ec 100644
--- a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/handlers/GenerateAalApp.java
+++ b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/handlers/GenerateAalApp.java
@@ -41,6 +41,13 @@ import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.part.FileEditorInput;
 
+/**
+ * Generates a file named "aalapp.xml" at the root of the currently selected
+ * project in the Package Explorer. Opens the file with an xml-editor after it
+ * is created.
+ * @author Adrian
+ *
+ */
 public class GenerateAalApp extends AbstractHandler {
 
 	@Override
@@ -51,11 +58,9 @@ public class GenerateAalApp extends AbstractHandler {
 				getActiveWorkbenchWindow().getSelectionService();
 		IStructuredSelection structured = (IStructuredSelection) service
                 .getSelection("org.eclipse.jdt.ui.PackageExplorer");
-		IProject project=null;
-		Object element;
-		IPath path;
 		
-		element = structured.getFirstElement();
+		IProject project=null;
+		Object element = structured.getFirstElement();
 		
 		if(element instanceof IResource){
 			project = ((IResource)element).getProject();
@@ -67,16 +72,15 @@ public class GenerateAalApp extends AbstractHandler {
 			project = jProject.getProject();
 		}
 		
-		String string = project.getLocation().toPortableString();
-		System.out.println(string);
+		String projectLocation = project.getLocation().toPortableString();
 
-		File file = new File(string, "aalapp.xml");
+		File file = new File(projectLocation, "aalapp.xml");
 		try {
 			file.createNewFile();
 			project.refreshLocal(IProject.DEPTH_ONE, new NullProgressMonitor());
-//			IFileStore fileStore = EFS.getLocalFileSystem().getStore(file.toURI());
-//			IDE.openEditorOnFileStore( page, fileStore );
 			IFile fileToOpen;
+			
+			//Loop until the file is created, so that it can be opened.
 			do{
 				fileToOpen = project.getFile("aalapp.xml");
 			}while(fileToOpen==null);
@@ -84,6 +88,7 @@ public class GenerateAalApp extends AbstractHandler {
 			IEditorDescriptor desc = PlatformUI.getWorkbench().
 			        getEditorRegistry().getDefaultEditor(file.getName());
 			page.openEditor(new FileEditorInput(fileToOpen), desc.getId());
+			
 		} catch (IOException e1) {
 			// TODO Auto-generated catch block
 			e1.printStackTrace();
diff --git a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/handlers/ImportHandler.java b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/handlers/ImportHandler.java
index 6f7aef8bb..e4487c9df 100644
--- a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/handlers/ImportHandler.java
+++ b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/handlers/ImportHandler.java
@@ -29,21 +29,10 @@ import org.eclipse.ui.handlers.HandlerUtil;
 import org.universaal.tools.importexternalproject.wizards.ImportExternalWizard;
 
 /**
- * Our sample handler extends AbstractHandler, an IHandler base class.
- * @see org.eclipse.core.commands.IHandler
- * @see org.eclipse.core.commands.AbstractHandler
+ * Starts the Import Third Party Application wizard
  */
 public class ImportHandler extends AbstractHandler {
-	/**
-	 * The constructor.
-	 */
-	public ImportHandler() {
-	}
 
-	/**
-	 * the command has been executed, so extract extract the needed information
-	 * from the application context.
-	 */
 	public Object execute(ExecutionEvent event) throws ExecutionException {
 
 		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
diff --git a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/wizards/ImportExternalWizard.java b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/wizards/ImportExternalWizard.java
index 396bdd9ff..5dfe1ebd8 100644
--- a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/wizards/ImportExternalWizard.java
+++ b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/wizards/ImportExternalWizard.java
@@ -19,7 +19,6 @@
 package org.universaal.tools.importexternalproject.wizards;
 
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -59,23 +58,31 @@ import org.universaal.tools.importexternalproject.xmlparser.ProjectObject;
 import org.universaal.tools.importexternalproject.xmlparser.XmlParser;
 import org.universaal.tools.importthirdparty.preferences.PreferenceConstants;
 
+/**
+ * Main part of the Import Third Party Application wizard.
+ * @author Adrian
+ *
+ */
 public class ImportExternalWizard extends Wizard implements IImportWizard {
 
-	private File file;
 	private ProjectObject chosenProject;
 	private ImportExternalWizardPage page;
 	private String xml;
 	private IWorkbenchWindow window;
 
+	/**
+	 * Default constructor. Called if the wizard is started from File->Import.
+	 */
 	public ImportExternalWizard(){
-		window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+		this.window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
 		page = new ImportExternalWizardPage(true);
 		initFiles();
 	}
 
 	/**
 	 * Added another constructor to be able to know if the wizard was started 
-	 * by the command or from the Import-extension.
+	 * by the command or from the Import-Wizard-extension. This is done to give
+	 * the window the correct size, no matter where it is started from.
 	 */
 	public ImportExternalWizard(IWorkbenchWindow window){
 		this.window = window;
@@ -84,6 +91,11 @@ public class ImportExternalWizard extends Wizard implements IImportWizard {
 
 	}
 
+	/**
+	 * Fetches the information from the "projects.xml"-file stored at the saved
+	 * URL, and saves it in a string that will be used to build the list of 
+	 * projects.
+	 */
 	private void initFiles(){
 
 		StringBuilder sb = new StringBuilder();
@@ -126,6 +138,16 @@ public class ImportExternalWizard extends Wizard implements IImportWizard {
 		return false;
 	}
 
+	/**
+	 * Checks first if the chosen project has a registered SVN URL. If it does
+	 * not, the project can not be checked out.
+	 * This method uses the Subversive API to first create a new Repository 
+	 * location based on the SVN URL belonging to the project about to be 
+	 * checked out. After this repository location has been created and verified,
+	 * it locates the project in question, and creates a composite operation, 
+	 * so that it can both check out the project, and then remove the SVN 
+	 * Repository from the list of stored repositories.
+	 */
 	@Override
 	public boolean performFinish() {
 		if(!chosenProject.getSvnUrl().equals(XmlParser.FIELD_EMPTY)){
@@ -180,6 +202,12 @@ public class ImportExternalWizard extends Wizard implements IImportWizard {
 		}
 	}
 
+	/**
+	 * Implements IRunnableWithProgress so that the Wizard can display a 
+	 * progressbar while it is checking out the project from SVN.
+	 * @author Adrian
+	 *
+	 */
 	private class Progress implements IRunnableWithProgress{
 
 		private Job job;
@@ -194,6 +222,8 @@ public class ImportExternalWizard extends Wizard implements IImportWizard {
 			if(arg0==null){
 				arg0 = new NullProgressMonitor();
 			}
+			//IProgressMonitor.UNKNOWN means that the progressbar can not show
+			//how much work that remains.
 			arg0.beginTask("Test!", IProgressMonitor.UNKNOWN);
 			arg0.setTaskName("Importing project. This might take some time.");
 			while(job.getState()!=0){
@@ -213,14 +243,20 @@ public class ImportExternalWizard extends Wizard implements IImportWizard {
 		addPage(page);
 	}
 
-	public File getFiles(){
-		return file;
-	}
-
+	/**
+	 * Returns the String containing the xml fetched from the web.
+	 * @return String containing xml
+	 */
 	public String getXML(){
 		return xml;
 	}
 
+	/**
+	 * When a user selects a project in the list of projects in the wizard, 
+	 * this method is called by the list's SelectionListener so that the main
+	 * part of the wizard knows the selection.
+	 * @param input The chosen project in the list
+	 */
 	public void setChosen(ProjectObject input){
 		this.chosenProject = input;
 	}
diff --git a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/wizards/ImportExternalWizardPage.java b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/wizards/ImportExternalWizardPage.java
index e2fac03f5..eca5e0561 100644
--- a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/wizards/ImportExternalWizardPage.java
+++ b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/wizards/ImportExternalWizardPage.java
@@ -47,11 +47,16 @@ import org.eclipse.wb.swt.SWTResourceManager;
 import org.universaal.tools.importexternalproject.xmlparser.ProjectObject;
 import org.universaal.tools.importexternalproject.xmlparser.XmlParser;
 
+/**
+ * The only page of the Import Third Party Application wizard.
+ * 
+ * @author Adrian
+ *
+ */
 public class ImportExternalWizardPage extends WizardPage {
 	private Table table;
 	private TableColumn nameClm, dateClm, authorClm;
 	private ProjectObject[] projects;
-//	private File files;
 	private String files;
 	private TableViewer tableViewer;
 	private StyledText styledText;
@@ -61,6 +66,13 @@ public class ImportExternalWizardPage extends WizardPage {
 	private Button btnListAll;
 	private boolean importExtension;
 
+	/**
+	 * Creates the page, and sets title. The boolean input tells the object
+	 * whether it was created by the command, or launched from the File->Import.
+	 * This is done to give the window the correct size no matter where it is
+	 * created from.
+	 * @param input true if created by File->Import. False otherwise.
+	 */
 	protected ImportExternalWizardPage(boolean input) {
 		super("Import external project");
 		setTitle("Import External Project.");
@@ -71,10 +83,11 @@ public class ImportExternalWizardPage extends WizardPage {
 	@Override
 	public void createControl(Composite parent) {
 
+		//Sets the size if it was created by File->Import.
 		if(importExtension){
 			getWizard().getContainer().getShell().setSize(850, 500);
 		}
-		System.out.println("createControl");
+		
 		Composite container = new Composite(parent, SWT.NULL);
 		setControl(container);
 		container.setLayout(new GridLayout(4, false));
@@ -143,9 +156,15 @@ public class ImportExternalWizardPage extends WizardPage {
 		@Override
 		public void dispose() {
 			// TODO Auto-generated method stub
-
 		}
 
+		/**
+		 * This is used to update the list when the user enters a searchterm,
+		 * and presses Search. It first searches for matches by name, and then
+		 * by tags. Name-matches are given a flag to show that they matched by 
+		 * name, and will always be displayed before the projects that only match
+		 * by tags.
+		 */
 		@Override
 		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
 			setPageComplete(false);
@@ -193,6 +212,10 @@ public class ImportExternalWizardPage extends WizardPage {
 
 	private class ChoiceListener implements ISelectionChangedListener{
 
+		/**
+		 * Marks the page as complete so that the wizard can be finished, and 
+		 * also sets the currentproject in the main part of the wizard.
+		 */
 		@Override
 		public void selectionChanged(SelectionChangedEvent arg0) {
 			setPageComplete(true);
@@ -207,6 +230,12 @@ public class ImportExternalWizardPage extends WizardPage {
 		}
 	}
 
+	/**
+	 * SelectionListener tied to the Search-button. It sets the searchstring as
+	 * new input for the TableViewer, and triggers a search for that string.
+	 * @author Adrian
+	 *
+	 */
 	private class Search implements SelectionListener{
 
 		@Override
@@ -222,6 +251,13 @@ public class ImportExternalWizardPage extends WizardPage {
 		}
 	}
 	
+	/**
+	 * SelectionListener tied to the List All-button. It sets an empty string 
+	 * as input for the TableViewer, and as a result, the tableviewer displays
+	 * all projects in the xml-file.
+	 * @author Adrian
+	 *
+	 */
 	private class ListAll implements SelectionListener{
 
 		@Override
@@ -235,6 +271,13 @@ public class ImportExternalWizardPage extends WizardPage {
 		
 	}
 	
+	/**
+	 * Disables the wizard "Finish"-button when the search-field has focus. 
+	 * Workaround to avoid users accidentally pressing enter to do a search, as 
+	 * this would instead finish the wizard and import a selected project.
+	 * @author Adrian
+	 *
+	 */
 	private class SearchFieldFocusListener implements FocusListener{
 
 		@Override
@@ -251,6 +294,11 @@ public class ImportExternalWizardPage extends WizardPage {
 		
 	}
 	
+	/**
+	 * Builds the description that is displayed in the StyledText-box.
+	 * @param res - The ProjectObject that will be described.
+	 * @return String containing a formatted description.
+	 */
 	private String buildDescription(ProjectObject res){
 		String description = 
 				"Project homepage: \n"+
diff --git a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/xmlparser/ProjectObject.java b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/xmlparser/ProjectObject.java
index 0ac382a44..a80fe42fc 100644
--- a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/xmlparser/ProjectObject.java
+++ b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/xmlparser/ProjectObject.java
@@ -20,6 +20,14 @@ package org.universaal.tools.importexternalproject.xmlparser;
 
 import java.util.ArrayList;
 
+/**
+ * Collects all data about projects described in the projects.xml-file.
+ * Implements comparable so that objects marked that their name matched a 
+ * search-string will always be displayed before objects that only matched by 
+ * tags after sorting the list.
+ * @author Adrian
+ *
+ */
 public class ProjectObject implements Comparable<ProjectObject>{
 	
 	
@@ -32,6 +40,19 @@ public class ProjectObject implements Comparable<ProjectObject>{
 	private ArrayList<String> tags;
 	private boolean nameMatch;
 	
+	/**
+	 * All parameters should be self-explanatory, except the namematch-boolean.
+	 * If the name of this project matched the search-string, namematch must be
+	 * set to True, so that, after sorting the list, this will always be placed
+	 * before objects that only matched the search-string by tags.
+	 * @param iName
+	 * @param iUrl
+	 * @param iSvnUrl
+	 * @param iDesc
+	 * @param iDev
+	 * @param iDate
+	 * @param nameMatch
+	 */
 	public ProjectObject(String iName, String iUrl, String iSvnUrl, String iDesc, String iDev,
 			String iDate, boolean nameMatch){
 		this.name = iName;
@@ -96,6 +117,10 @@ public class ProjectObject implements Comparable<ProjectObject>{
 		}
 	}
 	
+	/**
+	 * Returns the SVN URL without everything after the third slash.
+	 * @return
+	 */
 	public String getHostingSite(){
 		int temp = "https://".length()+1;
 		int SLASH_INDEX = svnurl.indexOf('/', temp);
diff --git a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/xmlparser/XmlParser.java b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/xmlparser/XmlParser.java
index 3b1a8a0c5..217a19dd8 100644
--- a/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/xmlparser/XmlParser.java
+++ b/depotclient/org.universaal.tools.importthirdpartyproject/src/org/universaal/tools/importexternalproject/xmlparser/XmlParser.java
@@ -32,10 +32,14 @@ import org.w3c.dom.NodeList;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
+/**
+ * Parses and searches in the downloaded projects.xml-file.
+ * @author Adrian
+ *
+ */
 public class XmlParser {
 
 	public static final String FIELD_EMPTY = "Not given.";
-//	private ArrayList<File> resultList;
 	private DocumentBuilderFactory factory;
 	private DocumentBuilder dBuilder;
 
@@ -49,6 +53,17 @@ public class XmlParser {
 		}
 	}
 
+	/**
+	 * Searches through the xml-file for any projects with tags matching the
+	 * entered search-string. If any are found, it creates a ProjectObject that
+	 * it enters all the information about the matching project into, and then
+	 * places this project into the result-ArrayList the method received as 
+	 * input.
+	 * @param xml - The xml text that will be searched.
+	 * @param result - ArrayList of ProjectObject where all matches will be placed.
+	 * @param tag - The entered search-string.
+	 * @return True if any matches, false if not.
+	 */
 	public boolean searchTags(String xml, 
 			ArrayList<ProjectObject> result, String tag){
 
@@ -76,20 +91,6 @@ public class XmlParser {
 					}
 
 				if(match){
-//					String resName, resUrl, resSvnUrl, resDesc, resDev, resDate;
-//					resName = ((Element) currentProject.getElementsByTagName("name").item(0)).getFirstChild().getNodeValue();
-//					resUrl = ((Element) currentProject.getElementsByTagName("url").item(0)).getFirstChild().getNodeValue();
-//					resSvnUrl = ((Element) currentProject.getElementsByTagName("svnurl").item(0)).getFirstChild().getNodeValue();
-//					resDesc = ((Element) currentProject.getElementsByTagName("description").item(0)).getFirstChild().getNodeValue();
-//					resDev = ((Element) currentProject.getElementsByTagName("developer").item(0)).getFirstChild().getNodeValue();
-//					resDate = ((Element) currentProject.getElementsByTagName("date").item(0)).getFirstChild().getNodeValue();
-//					ProjectObject projObj = new ProjectObject(resName, resUrl, resSvnUrl, resDesc, resDev, resDate, false);
-//					for(int i=0; i<nList.getLength(); i++){
-//						Element node = (Element) nList.item(i);
-//						String currentTag = node.getFirstChild().getNodeValue();
-//						projObj.addTag(currentTag);
-//					}
-//					result.add(projObj);
 					String resName, resUrl, resSvnUrl, resDesc, resDev, resDate;
 					try{
 						resName = ((Element) currentProject.getElementsByTagName("name").item(0)).getFirstChild().getNodeValue();
@@ -147,7 +148,19 @@ public class XmlParser {
 		return match;
 	}
 
-	public boolean searchNames(String xml, ArrayList<ProjectObject> result, String name){
+	/**
+	 * Searches through the xml-file for any projects with names matching the
+	 * entered search-string. If any are found, it creates a ProjectObject that
+	 * it enters all the information about the matching project into, and then
+	 * places this project into the result-ArrayList the method received as 
+	 * input.
+	 * @param xml - The xml text that will be searched.
+	 * @param result - ArrayList of ProjectObject where all matches will be placed.
+	 * @param name - The entered search-string.
+	 * @return True if any matches, false if not.
+	 */
+	public boolean searchNames(String xml, ArrayList<ProjectObject> result,
+			String name){
 
 		boolean match;
 		boolean foundName = false;
-- 
GitLab