[jbosstools-commits] JBoss Tools SVN: r30380 - in trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge: preferences and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Wed Apr 6 11:44:45 EDT 2011


Author: koen.aers at jboss.com
Date: 2011-04-06 11:44:44 -0400 (Wed, 06 Apr 2011)
New Revision: 30380

Added:
   trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationDialog.java
Removed:
   trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationsPreferenceHelper.java
   trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeRuntimesUpdater.java
   trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/InstalledForgeRuntimesBlock.java
Modified:
   trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/launching/ForgeInstallation.java
   trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/launching/ForgeRuntime.java
   trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationsPreferencePage.java
Log:
forge runtimes preference page fully operational, proper runtime is selected when launching forge

Modified: trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/launching/ForgeInstallation.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/launching/ForgeInstallation.java	2011-04-06 15:41:53 UTC (rev 30379)
+++ trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/launching/ForgeInstallation.java	2011-04-06 15:44:44 UTC (rev 30380)
@@ -14,8 +14,16 @@
 		return name;
 	}
 	
+	public void setName(String name) {
+		this.name = name;
+	}
+	
 	public String getLocation() {
 		return location;
 	}
+	
+	public void setLocation(String location) {
+		this.location = location;
+	}
 
 }

Modified: trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/launching/ForgeRuntime.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/launching/ForgeRuntime.java	2011-04-06 15:41:53 UTC (rev 30379)
+++ trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/launching/ForgeRuntime.java	2011-04-06 15:44:44 UTC (rev 30380)
@@ -77,7 +77,8 @@
 	private static void initializeInstallations() {
 		String installPrefsXml = ForgePlugin.getDefault().getPreferenceStore().getString(PREF_FORGE_INSTALLATIONS);
 		if (installPrefsXml == null || "".equals(installPrefsXml)) {
-			installPrefsXml = createDefaultInstallationsPreferences();
+			createInitialInstallations();
+			installPrefsXml = ForgePlugin.getDefault().getPreferenceStore().getString(PREF_FORGE_INSTALLATIONS);
 		}
 		initializeFromXml(installPrefsXml);
 	}
@@ -160,31 +161,75 @@
 		return s.toString("UTF8"); 		
 	}
 	
-	private static Document createDefaultInstallationsDocument() {
+//	private static Document createDefaultInstallationsDocument() {
+//		Document document = createEmptyDocument();
+//		if (document == null) return null;
+//		Element main = document.createElement("forgeInstallations");
+//		document.appendChild(main);
+//		String defaultLocation = ForgePlugin.getDefault().getBundle().getLocation();
+//		defaultLocation = defaultLocation.substring(15);
+//		Element defaultInstallation = document.createElement("installation");
+//		defaultInstallation.setAttribute("name", "embedded");
+//		defaultInstallation.setAttribute("location", defaultLocation); 
+//		main.appendChild(defaultInstallation);
+//		main.setAttribute("default", "embedded");
+//		return document;
+//	}
+
+//	private static String createDefaultInstallationsPreferences() {
+//		String result = null;
+//		Document document = createDefaultInstallationsDocument();
+//		try {
+//			result = serializeDocument(document);
+//		} catch (Exception e) {
+//			ForgePlugin.log(e);
+//		}
+//		return result;
+//	}
+//	
+	private static void createInitialInstallations() {
+		String defaultLocation = ForgePlugin.getDefault().getBundle().getLocation().substring(15);
+		defaultInstallation = new ForgeInstallation("embedded", defaultLocation);
+		installations = new ArrayList<ForgeInstallation>();
+		installations.add(defaultInstallation);
+		saveInstallations();
+	}
+	
+	public static void setInstallations(ForgeInstallation[] installs, ForgeInstallation defaultInstall) {
+		installations.clear();
+		for (ForgeInstallation install : installs) {
+			installations.add(install);
+		}
+		defaultInstallation = defaultInstall;
+		saveInstallations();
+	}
+	
+	private static void saveInstallations() {
+		try {
+			String xml = serializeDocument(createInstallationsDocument());
+			ForgePlugin.getDefault().getPreferenceStore().setValue(PREF_FORGE_INSTALLATIONS, xml);
+		} catch (IOException e) {
+			ForgePlugin.log(e);
+		} catch (TransformerException e) {
+			ForgePlugin.log(e);
+		}
+	}
+
+	private static Document createInstallationsDocument() {
 		Document document = createEmptyDocument();
 		if (document == null) return null;
 		Element main = document.createElement("forgeInstallations");
 		document.appendChild(main);
-		String defaultLocation = ForgePlugin.getDefault().getBundle().getLocation();
-		defaultLocation = defaultLocation.substring(15);
-		Element defaultInstallation = document.createElement("installation");
-		defaultInstallation.setAttribute("name", "embedded");
-		defaultInstallation.setAttribute("location", defaultLocation); 
-		main.appendChild(defaultInstallation);
-		main.setAttribute("default", "embedded");
+		for (ForgeInstallation installation : installations) {
+			Element element = document.createElement("installation");
+			element.setAttribute("name", installation.getName());
+			element.setAttribute("location", installation.getLocation());
+			main.appendChild(element);
+		}
+		main.setAttribute("default", defaultInstallation.getName());
 		return document;
 	}
 
-	private static String createDefaultInstallationsPreferences() {
-		String result = null;
-		Document document = createDefaultInstallationsDocument();
-		try {
-			result = serializeDocument(document);
-		} catch (Exception e) {
-			ForgePlugin.log(e);
-		}
-		return result;
-	}
 	
 	public static final ForgeRuntime INSTANCE = new ForgeRuntime();
 	public static final String STATE_NOT_RUNNING = "org.jboss.tools.seam.forge.notRunning";
@@ -219,14 +264,16 @@
 				ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, "Seam Forge");
 				workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, "org.jboss.seam.forge.shell.Bootstrap");
 				List<String> classpath = new ArrayList<String>();
-				Bundle bundle = Platform.getBundle("org.jboss.tools.seam.forge");
+//				Bundle bundle = Platform.getBundle("org.jboss.tools.seam.forge");
 				File file = null;
-				try {
-					file = FileLocator.getBundleFile(bundle);
-				} catch (IOException e1) {
-					e1.printStackTrace();
-				}
-				if (file == null) return;
+//				try {
+//					file = FileLocator.getBundleFile(bundle);
+					file = new File(ForgeRuntime.getDefaultInstallation().getLocation());
+//				} catch (IOException e1) {
+//					e1.printStackTrace();
+//				}
+//				if (file == null) return;
+				if (!file.exists()) return;
 				File[] children = file.listFiles(new FilenameFilter() {					
 					@Override
 					public boolean accept(File dir, String name) {

Added: trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationDialog.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationDialog.java	                        (rev 0)
+++ trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationDialog.java	2011-04-06 15:44:44 UTC (rev 30380)
@@ -0,0 +1,168 @@
+package org.jboss.tools.seam.forge.preferences;
+
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+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.DirectoryDialog;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+public class ForgeInstallationDialog extends Dialog {
+	
+	String title;
+	Text nameText, locationText;
+	Button locationButton;
+	
+	String name, location;
+	
+	public ForgeInstallationDialog(Shell parentShell) {
+		super(parentShell);
+	}
+	
+	public void initialize(String t, String n, String l) {
+		this.title = t;
+		this.name = n;
+		this.location = l;
+	}
+	
+	protected Control createDialogArea(Composite parent) {
+		Composite area = (Composite)super.createDialogArea(parent);
+		getShell().setText(title);
+		GridLayout gridLayout = new GridLayout();
+		gridLayout.numColumns = 3;
+		area.setLayout(gridLayout);
+		createMessageLabel(area);
+		createNameLabel(area);
+		createNameText(area);
+		createFillLabel(area);
+		createLocationLabel(area);
+		createLocationText(area);
+		createLocationButton(area);
+		createSeparator(area);
+		getShell().setText(title);
+		return area;
+	}
+	
+	protected Control createContents(Composite parent) {
+		Control result = super.createContents(parent);
+		updateOkButton();
+		return result;
+	}
+	
+	private void createSeparator(Composite area) {
+		Label separator = new Label(area, SWT.SEPARATOR | SWT.HORIZONTAL);
+		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+		gridData.horizontalSpan = 3;
+		gridData.verticalIndent = 15;
+		separator.setLayoutData(gridData);
+	}
+	
+	private void createLocationText(Composite area) {
+		locationText = new Text(area, SWT.BORDER);		
+		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+		gridData.widthHint = convertWidthInCharsToPixels(40);
+		locationText.setLayoutData(gridData);
+		locationText.setText(location == null ? "" : location);
+		locationText.addModifyListener(new ModifyListener() {
+			public void modifyText(ModifyEvent e) {
+				location = locationText.getText();
+				updateOkButton();			
+			}			
+		});
+	}
+	
+	private void createLocationButton(Composite area) {
+		locationButton = new Button(area, SWT.PUSH);
+		locationButton.setText("Search...");
+		locationButton.addSelectionListener(new SelectionAdapter() {
+			public void widgetSelected(SelectionEvent e) {
+				searchLocation();				
+			}
+		});
+	}
+	
+	private void searchLocation() {
+		DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.OPEN);
+		String result = dialog.open();
+		if (result != null) {
+			locationText.setText(result);
+		}		
+	}
+	
+	private void createLocationLabel(Composite area) {
+		Label label = new Label(area, SWT.NONE);
+		GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+		label.setLayoutData(gridData);
+		label.setText("Location :");		
+	}
+	
+	private void createFillLabel(Composite area) {
+		new Label(area, SWT.NONE);
+	}
+	
+	private void createNameText(Composite area) {
+		nameText = new Text(area, SWT.BORDER);
+		GridData gridData = new GridData();
+		gridData.widthHint = convertWidthInCharsToPixels(40);
+		nameText.setLayoutData(gridData);
+		nameText.setText(name == null ? "" : name);
+		nameText.addModifyListener(new ModifyListener() {
+			public void modifyText(ModifyEvent e) {
+				name = nameText.getText();
+				updateOkButton();			
+			}			
+		});
+	}
+	
+	private void updateOkButton() {
+		getButton(IDialogConstants.OK_ID).setEnabled(isValid());
+	}
+	
+	private boolean isValid() {
+		if (name == null || location == null) {
+			return false;
+		}
+		if ("".equals(name) || "".equals(location)) {
+			return false;
+		}
+		return true;
+	}
+	
+	private void createNameLabel(Composite area) {
+		Label label = new Label(area, SWT.NONE);
+		GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
+		label.setLayoutData(gridData);
+		label.setText("Name :");
+	}
+
+	private void createMessageLabel(Composite area) {
+		Label label = new Label(area, SWT.NONE);
+		GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING);
+		gridData.horizontalSpan = 3;
+		gridData.verticalIndent = 10;
+		label.setLayoutData(gridData);
+		label.setText("Enter a name and choose the location : ");
+	}
+	
+	public String getName() {
+		return name;
+	}
+	
+	public String getLocation() {
+		return location;
+	}
+	
+	
+
+}


Property changes on: trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationDialog.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Deleted: trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationsPreferenceHelper.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationsPreferenceHelper.java	2011-04-06 15:41:53 UTC (rev 30379)
+++ trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationsPreferenceHelper.java	2011-04-06 15:44:44 UTC (rev 30380)
@@ -1,19 +0,0 @@
-package org.jboss.tools.seam.forge.preferences;
-
-
-public class ForgeInstallationsPreferenceHelper {
-
-	public static void removeVMs() {
-		// TODO Auto-generated method stub		
-	}
-
-	public static void addVM() {
-		// TODO Auto-generated method stub		
-	}
-
-	public static void editVM() {
-		// TODO Auto-generated method stub		
-	}
-
-
-}

Modified: trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationsPreferencePage.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationsPreferencePage.java	2011-04-06 15:41:53 UTC (rev 30379)
+++ trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeInstallationsPreferencePage.java	2011-04-06 15:44:44 UTC (rev 30380)
@@ -1,25 +1,20 @@
 package org.jboss.tools.seam.forge.preferences;
 
 
-import java.util.Iterator;
+import java.util.ArrayList;
 
-import org.eclipse.jdt.launching.IVMInstall;
+import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.preference.PreferencePage;
 import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.CheckStateChangedEvent;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.ICheckStateListener;
+import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
@@ -32,19 +27,18 @@
 import org.eclipse.swt.widgets.TableColumn;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchPreferencePage;
+import org.jboss.tools.seam.forge.launching.ForgeInstallation;
 import org.jboss.tools.seam.forge.launching.ForgeRuntime;
 
 public class ForgeInstallationsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
 				
 	private final int DEFAULT_COLUMN_WIDTH = 350/3 +1;
 
-//	private InstalledForgeRuntimesBlock fJREBlock;
-	
-//	private Table runtimesTable;
 	private CheckboxTableViewer runtimesTableViewer	;
 	private Button removeButton;
 	private Button editButton;
-	private int sortColumn = 0;
+	private ArrayList<ForgeInstallation> installations = null;
+	private ForgeInstallation defaultInstallation = null;
 	
 	public ForgeInstallationsPreferencePage() {
 		super("Installed Forge Runtimes");
@@ -53,38 +47,19 @@
 	public void init(IWorkbench workbench) {
 	}
 
-//	private void initDefaultVM() {
-//		IVMInstall realDefault= JavaRuntime.getDefaultVMInstall();
-//		if (realDefault != null) {
-////			IVMInstall[] vms= fJREBlock.getJREs();
-//			IVMInstall[] vms= (IVMInstall[])runtimesTableViewer.getInput();
-//			for (int i = 0; i < vms.length; i++) {
-//				IVMInstall fakeVM= vms[i];
-//				if (fakeVM.equals(realDefault)) {
-//					verifyDefaultVM(fakeVM);
-//					break;
-//				}
-//			}
-//		}
-//	}
-	
-	protected Control createContents(Composite ancestor) {
-//		initializeDialogUnits(ancestor);		
+	protected Control createContents(Composite parent) {
 		noDefaultAndApplyButton();		
-		createLayout(ancestor);		
-		createWrapLabel(ancestor);
-		createVerticalSpacer(ancestor);	
-		createPageBody(ancestor);
-//		createInstalledForgeRuntimesBlock(ancestor);					
-		initForgeInstallations();		
-		sortByName();		
+		createLayout(parent);		
+		createWrapLabel(parent);
+		createVerticalSpacer(parent);	
+		createPageBody(parent);
+		initializeForgeInstallations();		
 		enableButtons();
-//		applyDialogFont(ancestor);
-		return ancestor;
+		return parent;
 	}
 	
-	private void createPageBody(Composite ancestor) {
-		Composite pageBody = createPageBodyControl(ancestor);					
+	private void createPageBody(Composite parent) {
+		Composite pageBody = createPageBodyControl(parent);					
 		createTitleLabel(pageBody);				
 		createRuntimesArea(pageBody);			
 		createButtonsArea(pageBody);						
@@ -97,35 +72,60 @@
 		createRemoveButton(buttons);		
 	}
 
-	private void createRemoveButton(Composite buttons) {
-		removeButton = new Button(buttons, SWT.PUSH);
+	private void createRemoveButton(Composite parent) {
+		removeButton = new Button(parent, SWT.PUSH);
 		removeButton.setText("&Remove");
 		removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	
 		removeButton.addListener(SWT.Selection, new Listener() {
 			public void handleEvent(Event evt) {
-				ForgeInstallationsPreferenceHelper.removeVMs();
+				ISelection selection = runtimesTableViewer.getSelection();
+				if (selection != null && selection instanceof IStructuredSelection) {
+					Object object = ((IStructuredSelection)selection).getFirstElement();
+					if (object != null && object instanceof ForgeInstallation) {
+						installations.remove(object);
+						refreshForgeInstallations();
+					}
+				}
 			}
 		});
 	}
 
-	private void createAddButton(Composite buttons) {
-		Button addButton = new Button(buttons, SWT.PUSH);
+	private void createAddButton(Composite parent) {
+		Button addButton = new Button(parent, SWT.PUSH);
 		addButton.setText("&Add...");
 		addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	
 		addButton.addListener(SWT.Selection, new Listener() {
 			public void handleEvent(Event evt) {
-				ForgeInstallationsPreferenceHelper.addVM();
+				ForgeInstallationDialog dialog = new ForgeInstallationDialog(null);
+				dialog.initialize("Add Forge Runtime", "", "");
+				if (dialog.open() != Dialog.CANCEL) {
+					installations.add(new ForgeInstallation(dialog.getName(), dialog.getLocation()));
+					refreshForgeInstallations();
+				}
 			}
 		});
 	}
 	
-	private void createEditButton(Composite buttons) {
-		editButton = new Button(buttons, SWT.PUSH);
+	private void createEditButton(Composite parent) {
+		editButton = new Button(parent, SWT.PUSH);
 		editButton.setText("&Edit...");
 		editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	
 		editButton.addListener(SWT.Selection, new Listener() {
 			public void handleEvent(Event evt) {
-				ForgeInstallationsPreferenceHelper.editVM();
+				ISelection selection = runtimesTableViewer.getSelection();
+				if (selection != null && selection instanceof IStructuredSelection) {
+					Object object = ((IStructuredSelection)selection).getFirstElement();
+					if (object != null && object instanceof ForgeInstallation) {
+						ForgeInstallation installation = (ForgeInstallation)object;
+						ForgeInstallationDialog dialog = new ForgeInstallationDialog(null);
+						dialog.initialize("Edit Forge Runtime", installation.getName(), installation.getLocation());
+						if (dialog.open() != Dialog.CANCEL) {
+							installation.setName(dialog.getName());
+							installation.setLocation(dialog.getLocation());
+							refreshForgeInstallations();
+						}
+					}
+				}
 			}
 		});
 	}
@@ -167,63 +167,37 @@
 				enableButtons();
 			}
 		});
-//		runtimesTableViewer.addCheckStateListener(new ICheckStateListener() {
-//			public void checkStateChanged(CheckStateChangedEvent event) {
-//				if (event.getChecked()) {
-//					setCheckedJRE((IVMInstall)event.getElement());
-//				} else {
-//					setCheckedJRE(null);
-//				}
-//			}
-//		});		
-		runtimesTableViewer.addDoubleClickListener(new IDoubleClickListener() {
-			public void doubleClick(DoubleClickEvent e) {
-				if (!runtimesTableViewer.getSelection().isEmpty()) {
-					ForgeInstallationsPreferenceHelper.editVM();
+		runtimesTableViewer.addCheckStateListener(new ICheckStateListener() {
+			public void checkStateChanged(final CheckStateChangedEvent event) {
+				Object object = event.getElement();
+				if (object != null && object instanceof ForgeInstallation) {
+					defaultInstallation = (ForgeInstallation)object;
+					refreshForgeInstallations();
 				}
 			}
-		});
+		});		
 	}
 		
 	private void createLocationColumn(Table table) {
 		TableColumn column = new TableColumn(table, SWT.NULL);
 		column.setText("Location"); 
-		column.addSelectionListener(new SelectionAdapter() {
-			public void widgetSelected(SelectionEvent e) {
-				sortByLocation();
-			}
-		});
 		column.setWidth(DEFAULT_COLUMN_WIDTH);
 	}
 
 	private void createNameColumn(Table table) {
 		TableColumn column = new TableColumn(table, SWT.NULL);
 		column.setText("Name"); 
-		column.addSelectionListener(new SelectionAdapter() {
-			public void widgetSelected(SelectionEvent e) {
-				sortByName();
-			}
-		});
 		column.setWidth(DEFAULT_COLUMN_WIDTH);
 	}
 
 	private Table createRuntimesTable(Composite parent) {
-		Table runtimesTable= new Table(parent, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
+		Table runtimesTable= new Table(parent, SWT.CHECK | SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
 		GridData gd = new GridData(GridData.FILL_BOTH);
 		gd.heightHint = 250;
 		gd.widthHint = 350;
 		runtimesTable.setLayoutData(gd);
 		runtimesTable.setHeaderVisible(true);
 		runtimesTable.setLinesVisible(true);
-		runtimesTable.addKeyListener(new KeyAdapter() {
-			public void keyPressed(KeyEvent event) {
-				if (event.character == SWT.DEL && event.stateMask == 0) {
-					if (removeButton.isEnabled()){
-						ForgeInstallationsPreferenceHelper.removeVMs();
-					}
-				}
-			}
-		});
 		return runtimesTable;
 	}
 	
@@ -259,65 +233,40 @@
 		gd.horizontalSpan = ((GridLayout)parent.getLayout()).numColumns;
 		lbl.setLayoutData(gd);
 	}
-
-	private void initForgeInstallations() {
-		runtimesTableViewer.setInput(ForgeRuntime.getInstallations());
-		runtimesTableViewer.setCheckedElements(new Object[] { ForgeRuntime.getDefaultInstallation() });
-		runtimesTableViewer.refresh();
-	}
-
-	private void sortByName() {
-		runtimesTableViewer.setComparator(new ViewerComparator() {
-			public int compare(Viewer viewer, Object e1, Object e2) {
-				if ((e1 instanceof IVMInstall) && (e2 instanceof IVMInstall)) {
-					IVMInstall left= (IVMInstall)e1;
-					IVMInstall right= (IVMInstall)e2;
-					return left.getName().compareToIgnoreCase(right.getName());
-				}
-				return super.compare(viewer, e1, e2);
+	
+	private void initializeForgeInstallations() {
+		installations = new ArrayList<ForgeInstallation>();
+		for (ForgeInstallation install : ForgeRuntime.getInstallations()) {
+			ForgeInstallation copy = new ForgeInstallation(install.getName(), install.getLocation());
+			if (install == ForgeRuntime.getDefaultInstallation()) {
+				defaultInstallation = copy;
 			}
-			
-			public boolean isSorterProperty(Object element, String property) {
-				return true;
-			}
-		});		
-		sortColumn = 1;		
+			installations.add(copy);
+		}
+		refreshForgeInstallations();
 	}
 
-	private void sortByLocation() {
-		runtimesTableViewer.setComparator(new ViewerComparator() {
-			public int compare(Viewer viewer, Object e1, Object e2) {
-				if ((e1 instanceof IVMInstall) && (e2 instanceof IVMInstall)) {
-					IVMInstall left= (IVMInstall)e1;
-					IVMInstall right= (IVMInstall)e2;
-					return left.getInstallLocation().getAbsolutePath().compareToIgnoreCase(right.getInstallLocation().getAbsolutePath());
-				}
-				return super.compare(viewer, e1, e2);
-			}
-			
-			public boolean isSorterProperty(Object element, String property) {
-				return true;
-			}
-		});		
-		sortColumn = 2;		
+	private void refreshForgeInstallations() {
+		runtimesTableViewer.setInput((ForgeInstallation[])installations.toArray(new ForgeInstallation[installations.size()]));
+		runtimesTableViewer.setCheckedElements(new Object[] { defaultInstallation });
+		runtimesTableViewer.refresh();
 	}
 
 	private void enableButtons() {
+		Object selectedObject = null;
 		IStructuredSelection selection = (IStructuredSelection) runtimesTableViewer.getSelection();
-		int selectionCount= selection.size();
-		editButton.setEnabled(selectionCount == 1);
-		if (selectionCount > 0 && selectionCount < runtimesTableViewer.getTable().getItemCount()) {
-			Iterator iterator = selection.iterator();
-			while (iterator.hasNext()) {
-				IVMInstall install = (IVMInstall)iterator.next();
-//				if (isContributed(install)) {
-//					removeButton.setEnabled(false);
-//					return;
-//				}
-			}
-			removeButton.setEnabled(true);
-		} else {
+		if (selection != null) {
+			selectedObject = selection.getFirstElement();
+		}
+		if (selectedObject == null 
+//				|| (selectedObject == runtimesTableViewer.getCheckedElements()[0])
+				|| (selectedObject instanceof ForgeInstallation 
+						&& ("embedded".equals(((ForgeInstallation)selectedObject).getName())))) {
 			removeButton.setEnabled(false);
+			editButton.setEnabled(false);
+		} else {
+			removeButton.setEnabled(selectedObject != runtimesTableViewer.getCheckedElements()[0]);
+			editButton.setEnabled(true);
 		}
 	}	
 	
@@ -325,49 +274,15 @@
 		final boolean[] canceled = new boolean[] {false};
 		BusyIndicator.showWhile(null, new Runnable() {
 			public void run() {
-//				IVMInstall defaultVM = getCurrentDefaultVM();
-////				IVMInstall[] vms = fJREBlock.getJREs();
-//				IVMInstall[] vms = (IVMInstall[])runtimesTableViewer.getInput();
-//				ForgeRuntimesUpdater updater = new ForgeRuntimesUpdater();
-//				if (!updater.updateJRESettings(vms, defaultVM)) {
-//					canceled[0] = true;
-//				}
+				ForgeInstallation[] installations = (ForgeInstallation[])runtimesTableViewer.getInput();
+				ForgeInstallation defaultInstallation = (ForgeInstallation)runtimesTableViewer.getCheckedElements()[0];
+				ForgeRuntime.setInstallations(installations, defaultInstallation);
 			}
 		});		
 		if(canceled[0]) {
 			return false;
 		}
-//		fJREBlock.saveColumnSettings(
-//				ForgePlugin.getDefault().getDialogSettings(), 
-//				ForgePlugin.PLUGIN_ID + ".forge_runtimes_preference_page_context");
 		return super.performOk();
 	}	
 	
-//	private void verifyDefaultVM(IVMInstall vm) {
-//		if (vm != null) {
-//			LibraryLocation[] locations= JavaRuntime.getLibraryLocations(vm);
-//			boolean exist = true;
-//			for (int i = 0; i < locations.length; i++) {
-//				exist = exist && new File(locations[i].getSystemLibraryPath().toOSString()).exists();
-//			}
-//			if (exist) {
-//				fJREBlock.setCheckedJRE(vm);
-//			} else {
-//				fJREBlock.removeJREs(new IVMInstall[]{vm});
-//				IVMInstall def = JavaRuntime.getDefaultVMInstall();
-//				if (def == null) {
-//					fJREBlock.setCheckedJRE(null);
-//				} else {
-//					fJREBlock.setCheckedJRE(def);
-//				}
-//				return;
-//			}
-//		} else {
-//			fJREBlock.setCheckedJRE(null);
-//		}
-//	}
-	
-//	private IVMInstall getCurrentDefaultVM() {
-//		return fJREBlock.getCheckedJRE();
-//	}
 }

Deleted: trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeRuntimesUpdater.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeRuntimesUpdater.java	2011-04-06 15:41:53 UTC (rev 30379)
+++ trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/ForgeRuntimesUpdater.java	2011-04-06 15:44:44 UTC (rev 30380)
@@ -1,106 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation 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:
- *     IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.jboss.tools.seam.forge.preferences;
-
-import java.lang.reflect.InvocationTargetException;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jdt.internal.launching.VMDefinitionsContainer;
-import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.IVMInstallType;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.jboss.tools.seam.forge.ForgePlugin;
-
-/**
- * Processes add/removed/changed VMs.
- */
-public class ForgeRuntimesUpdater {
-	
-	// the VMs defined when this updated is instantiated
-	private VMDefinitionsContainer fOriginalVMs;	
-	
-	/**
-	 * Contstructs a new VM updater to update VM install settings.
-	 */
-	public ForgeRuntimesUpdater() {
-		fOriginalVMs = new VMDefinitionsContainer();
-		IVMInstall def = JavaRuntime.getDefaultVMInstall();
-		if (def != null) {
-			fOriginalVMs.setDefaultVMInstallCompositeID(JavaRuntime.getCompositeIdFromVM(def));
-		}
-	
-		IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
-		for (int i = 0; i < types.length; i++) {
-			IVMInstall[] vms = types[i].getVMInstalls();
-			for (int j = 0; j < vms.length; j++) {
-				fOriginalVMs.addVM(vms[j]);
-			}
-		}
-	}
-	
-	/**
-	 * Updates VM settings and returns whether the update was successful.
-	 * 
-	 * @param jres new installed JREs
-	 * @param defaultJRE new default VM
-	 * @return whether the update was successful
-	 */
-	public boolean updateJRESettings(IVMInstall[] jres, IVMInstall defaultJRE) {
-		
-		// Create a VM definition container
-		VMDefinitionsContainer vmContainer = new VMDefinitionsContainer();
-		
-		// Set the default VM Id on the container
-		String defaultVMId = JavaRuntime.getCompositeIdFromVM(defaultJRE);
-		vmContainer.setDefaultVMInstallCompositeID(defaultVMId);
-		
-		// Set the VMs on the container
-		for (int i = 0; i < jres.length; i++) {
-			vmContainer.addVM(jres[i]);
-		}
-		
-		
-		// Generate XML for the VM defs and save it as the new value of the VM preference
-		saveVMDefinitions(vmContainer);
-		
-		return true;
-	}
-	
-	private void saveVMDefinitions(final VMDefinitionsContainer container) {
-		IRunnableWithProgress runnable = new IRunnableWithProgress() {
-			public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
-				try {
-					monitor.beginTask("Save Forge Runtime Definitions", 100); 
-					String vmDefXML = container.getAsXML();
-					monitor.worked(40);
-					JavaRuntime.getPreferences().setValue(JavaRuntime.PREF_VM_XML, vmDefXML);
-					monitor.worked(30);
-					JavaRuntime.savePreferences();
-					monitor.worked(30);
-				}  catch (CoreException e) {
-//					JDIDebugUIPlugin.log(e);
-				} finally {
-					monitor.done();
-				}
-				
-			}
-		};
-		try {
-			ForgePlugin.getDefault().getWorkbench().getProgressService().busyCursorWhile(runnable);
-		} catch (InvocationTargetException e) {
-//			JDIDebugUIPlugin.log(e);
-		} catch (InterruptedException e) {
-//			JDIDebugUIPlugin.log(e);
-		}
-	}
-}

Deleted: trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/InstalledForgeRuntimesBlock.java
===================================================================
--- trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/InstalledForgeRuntimesBlock.java	2011-04-06 15:41:53 UTC (rev 30379)
+++ trunk/forge/plugins/org.jboss.tools.seam.forge/src/org/jboss/tools/seam/forge/preferences/InstalledForgeRuntimesBlock.java	2011-04-06 15:44:44 UTC (rev 30380)
@@ -1,891 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation 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:
- *     IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.jboss.tools.seam.forge.preferences;
-
-import java.io.File;
-import java.lang.reflect.InvocationTargetException;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.ListenerList;
-import org.eclipse.jdt.launching.AbstractVMInstall;
-import org.eclipse.jdt.launching.AbstractVMInstallType;
-import org.eclipse.jdt.launching.IVMInstall;
-import org.eclipse.jdt.launching.IVMInstallType;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jdt.launching.VMStandin;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.IDialogSettings;
-import org.eclipse.jface.dialogs.ProgressMonitorDialog;
-import org.eclipse.jface.operation.IRunnableWithProgress;
-import org.eclipse.jface.viewers.CheckStateChangedEvent;
-import org.eclipse.jface.viewers.CheckboxTableViewer;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.ICheckStateListener;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.jface.viewers.ViewerComparator;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.Image;
-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.DirectoryDialog;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-
-public class InstalledForgeRuntimesBlock implements ISelectionProvider {
-	
-	private final int DEFAULT_COLUMN_WIDTH = 350/3 +1;
-
-	
-	private Composite control;
-	private List fVMs = new ArrayList(); 
-	private CheckboxTableViewer runtimesTableViewer;
-	private Button addButton;
-	private Button removeButton;
-	private Button editButton;
-	private Button searchButton;	
-	private int fSortColumn = 0;
-	private ListenerList fSelectionListeners = new ListenerList();
-	private ISelection fPrevSelection = new StructuredSelection();
-    private Table runtimesTable;
-	private static String fgLastUsedID;	
-
-	class JREsContentProvider implements IStructuredContentProvider {		
-		public Object[] getElements(Object input) {
-			return fVMs.toArray();
-		}
-		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-		}
-		public void dispose() {
-		}
-	}
-	
-	class VMLabelProvider extends LabelProvider implements ITableLabelProvider {
-
-		public String getColumnText(Object element, int columnIndex) {
-			if (element instanceof IVMInstall) {
-				IVMInstall vm= (IVMInstall)element;
-				switch(columnIndex) {
-					case 0:
-						return vm.getName();
-					case 1:
-						return vm.getInstallLocation().getAbsolutePath();
-				}
-			}
-			return element.toString();
-		}
-
-		public Image getColumnImage(Object element, int columnIndex) {
-			return null;
-		}
-
-	}	
-	
-	public void addSelectionChangedListener(ISelectionChangedListener listener) {
-		fSelectionListeners.add(listener);
-	}
-
-	public ISelection getSelection() {
-		return new StructuredSelection(runtimesTableViewer.getCheckedElements());
-	}
-
-	public void removeSelectionChangedListener(ISelectionChangedListener listener) {
-		fSelectionListeners.remove(listener);
-	}
-
-	public void setSelection(ISelection selection) {
-		if (selection instanceof IStructuredSelection) {
-			if (!selection.equals(fPrevSelection)) {
-				fPrevSelection = selection;
-				Object jre = ((IStructuredSelection)selection).getFirstElement();
-				if (jre == null) {
-					runtimesTableViewer.setCheckedElements(new Object[0]);
-				} else {
-					runtimesTableViewer.setCheckedElements(new Object[]{jre});
-					runtimesTableViewer.reveal(jre);
-				}
-				fireSelectionChanged();
-			}
-		}
-	}
-	
-	public void createControl(Composite ancestor) {
-		control = createMainControl(ancestor);					
-		createTitleLabel();				
-		createRuntimesArea();			
-		createButtonsArea();				
-		fillWithWorkspaceForgeRuntimes();		
-		sortByName();		
-		enableButtons();
-	}
-	
-	private void createTitleLabel() {
-		Label label = new Label(control, SWT.NONE);
-		label.setText("Installed Forge Runtimes:");
-		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
-		gd.horizontalSpan = 2;
-		gd.grabExcessHorizontalSpace = false;
-		label.setLayoutData(gd);
-	}
-
-	private void createButtonsArea() {
-		Composite buttons = createButtonsComposite();
-    	createAddButton(buttons);		
-		createEditButton(buttons);		
-		createRemoveButton(buttons);		
-		createSearchButton(buttons);
-	}
-
-	private void createSearchButton(Composite buttons) {
-		searchButton = new Button(buttons, SWT.PUSH);
-		searchButton.setText("&Search...");
-		searchButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	
-		searchButton.addListener(SWT.Selection, new Listener() {
-			public void handleEvent(Event evt) {
-				search();
-			}
-		});
-	}
-
-	private void createRemoveButton(Composite buttons) {
-		removeButton = new Button(buttons, SWT.PUSH);
-		removeButton.setText("&Remove");
-		removeButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	
-		removeButton.addListener(SWT.Selection, new Listener() {
-			public void handleEvent(Event evt) {
-				removeVMs();
-			}
-		});
-	}
-
-	private void createEditButton(Composite buttons) {
-		editButton = new Button(buttons, SWT.PUSH);
-		editButton.setText("&Edit...");
-		editButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	
-		editButton.addListener(SWT.Selection, new Listener() {
-			public void handleEvent(Event evt) {
-				editVM();
-			}
-		});
-	}
-
-	private void createAddButton(Composite buttons) {
-		addButton = new Button(buttons, SWT.PUSH);
-		addButton.setText("&Add...");
-		addButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));	
-		addButton.addListener(SWT.Selection, new Listener() {
-			public void handleEvent(Event evt) {
-				addVM();
-			}
-		});
-	}
-	
-	private Composite createButtonsComposite() {
-		Composite buttons = new Composite(control, SWT.NONE);
-		GridLayout layout = new GridLayout();
-		layout.marginWidth = 0;
-		layout.marginHeight = 0;
-    	buttons.setLayout(layout);
-    	GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
-		gd.horizontalSpan = 1;
-    	buttons.setLayoutData(gd);
-		return buttons;
-	}
-
-	private Composite createMainControl(Composite ancestor) {
-    	Composite result = new Composite(ancestor, SWT.NONE);
-    	result.setLayout(new GridLayout(2, false));
-    	GridData gd = new GridData(GridData.FILL_BOTH);
-    	result.setLayoutData(gd);
-		return result;
-	}
-
-	private void createRuntimesArea() {
-		createRuntimesTable();	
-		createNameColumn();
-		createLocationColumn();		
-		createRuntimesTableViewer();
-	}
-
-	private void createRuntimesTableViewer() {
-		runtimesTableViewer = new CheckboxTableViewer(runtimesTable);			
-		runtimesTableViewer.setLabelProvider(new VMLabelProvider());
-		runtimesTableViewer.setContentProvider(new JREsContentProvider());
-		runtimesTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
-			public void selectionChanged(SelectionChangedEvent evt) {
-				enableButtons();
-			}
-		});
-		
-		runtimesTableViewer.addCheckStateListener(new ICheckStateListener() {
-			public void checkStateChanged(CheckStateChangedEvent event) {
-				if (event.getChecked()) {
-					setCheckedJRE((IVMInstall)event.getElement());
-				} else {
-					setCheckedJRE(null);
-				}
-			}
-		});
-		
-		runtimesTableViewer.addDoubleClickListener(new IDoubleClickListener() {
-			public void doubleClick(DoubleClickEvent e) {
-				if (!runtimesTableViewer.getSelection().isEmpty()) {
-					editVM();
-				}
-			}
-		});
-	}
-
-	private void createLocationColumn() {
-		TableColumn column = new TableColumn(runtimesTable, SWT.NULL);
-		column.setText("Location"); 
-		column.addSelectionListener(new SelectionAdapter() {
-			public void widgetSelected(SelectionEvent e) {
-				sortByLocation();
-			}
-		});
-		column.setWidth(DEFAULT_COLUMN_WIDTH);
-	}
-
-	private void createNameColumn() {
-		TableColumn column = new TableColumn(runtimesTable, SWT.NULL);
-		column.setText("Name"); 
-		column.addSelectionListener(new SelectionAdapter() {
-			public void widgetSelected(SelectionEvent e) {
-				sortByName();
-			}
-		});
-		column.setWidth(DEFAULT_COLUMN_WIDTH);
-	}
-
-	private void createRuntimesTable() {
-		runtimesTable= new Table(control, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
-		GridData gd = new GridData(GridData.FILL_BOTH);
-		gd.heightHint = 250;
-		gd.widthHint = 350;
-		runtimesTable.setLayoutData(gd);
-		runtimesTable.setFont(control.getFont());
-		runtimesTable.setHeaderVisible(true);
-		runtimesTable.setLinesVisible(true);
-		runtimesTable.addKeyListener(new KeyAdapter() {
-			public void keyPressed(KeyEvent event) {
-				if (event.character == SWT.DEL && event.stateMask == 0) {
-					if (removeButton.isEnabled()){
-						removeVMs();
-					}
-				}
-			}
-		});
-	}
-	
-	public String generateName(String name){
-            if (!isDuplicateName(name)) {
-                return name;
-            }
-            
-            if (name.matches(".*\\(\\d*\\)")) { //$NON-NLS-1$
-                int start = name.lastIndexOf('(');
-                int end = name.lastIndexOf(')');
-                String stringInt = name.substring(start+1, end);
-                int numericValue = Integer.parseInt(stringInt);
-                String newName = name.substring(0, start+1) + (numericValue+1) + ")"; //$NON-NLS-1$
-                return generateName(newName);
-            } else {
-                return generateName(name + " (1)"); //$NON-NLS-1$
-            }
-        }
-	
-	private void fireSelectionChanged() {
-		SelectionChangedEvent event = new SelectionChangedEvent(this, getSelection());
-		Object[] listeners = fSelectionListeners.getListeners();
-		for (int i = 0; i < listeners.length; i++) {
-			ISelectionChangedListener listener = (ISelectionChangedListener)listeners[i];
-			listener.selectionChanged(event);
-		}	
-	}
-
-	private void sortByType() {
-		runtimesTableViewer.setComparator(new ViewerComparator() {
-			public int compare(Viewer viewer, Object e1, Object e2) {
-				if ((e1 instanceof IVMInstall) && (e2 instanceof IVMInstall)) {
-					IVMInstall left= (IVMInstall)e1;
-					IVMInstall right= (IVMInstall)e2;
-					String leftType= left.getVMInstallType().getName();
-					String rightType= right.getVMInstallType().getName();
-					int res= leftType.compareToIgnoreCase(rightType);
-					if (res != 0) {
-						return res;
-					}
-					return left.getName().compareToIgnoreCase(right.getName());
-				}
-				return super.compare(viewer, e1, e2);
-			}
-			
-			public boolean isSorterProperty(Object element, String property) {
-				return true;
-			}
-		});	
-		fSortColumn = 3;			
-	}
-	
-	private void sortByName() {
-		runtimesTableViewer.setComparator(new ViewerComparator() {
-			public int compare(Viewer viewer, Object e1, Object e2) {
-				if ((e1 instanceof IVMInstall) && (e2 instanceof IVMInstall)) {
-					IVMInstall left= (IVMInstall)e1;
-					IVMInstall right= (IVMInstall)e2;
-					return left.getName().compareToIgnoreCase(right.getName());
-				}
-				return super.compare(viewer, e1, e2);
-			}
-			
-			public boolean isSorterProperty(Object element, String property) {
-				return true;
-			}
-		});		
-		fSortColumn = 1;		
-	}
-	
-	/**
-	 * Sorts by VM location.
-	 */
-	private void sortByLocation() {
-		runtimesTableViewer.setComparator(new ViewerComparator() {
-			public int compare(Viewer viewer, Object e1, Object e2) {
-				if ((e1 instanceof IVMInstall) && (e2 instanceof IVMInstall)) {
-					IVMInstall left= (IVMInstall)e1;
-					IVMInstall right= (IVMInstall)e2;
-					return left.getInstallLocation().getAbsolutePath().compareToIgnoreCase(right.getInstallLocation().getAbsolutePath());
-				}
-				return super.compare(viewer, e1, e2);
-			}
-			
-			public boolean isSorterProperty(Object element, String property) {
-				return true;
-			}
-		});		
-		fSortColumn = 2;		
-	}
-		
-	/**
-	 * Enables the buttons based on selected items counts in the viewer
-	 */
-	private void enableButtons() {
-		IStructuredSelection selection = (IStructuredSelection) runtimesTableViewer.getSelection();
-		int selectionCount= selection.size();
-		editButton.setEnabled(selectionCount == 1);
-		if (selectionCount > 0 && selectionCount < runtimesTableViewer.getTable().getItemCount()) {
-			Iterator iterator = selection.iterator();
-			while (iterator.hasNext()) {
-				IVMInstall install = (IVMInstall)iterator.next();
-				if (isContributed(install)) {
-					removeButton.setEnabled(false);
-					return;
-				}
-			}
-			removeButton.setEnabled(true);
-		} else {
-			removeButton.setEnabled(false);
-		}
-	}	
-	
-	/**
-	 * Returns if the specified VM install has been contributed
-	 * @param install
-	 * @return true if the specified VM is contributed, false otherwise
-	 */
-	private boolean isContributed(IVMInstall install) {
-		return JavaRuntime.isContributedVMInstall(install.getId());
-	}
-	
-	/**
-	 * Returns this block's control
-	 * 
-	 * @return control
-	 */
-	public Control getControl() {
-		return control;
-	}
-	
-	/**
-	 * Sets the JREs to be displayed in this block
-	 * 
-	 * @param vms JREs to be displayed
-	 */
-	protected void setJREs(IVMInstall[] vms) {
-		fVMs.clear();
-		for (int i = 0; i < vms.length; i++) {
-			fVMs.add(vms[i]);
-		}
-		runtimesTableViewer.setInput(fVMs);
-		runtimesTableViewer.refresh();
-	}
-	
-	/**
-	 * Returns the JREs currently being displayed in this block
-	 * 
-	 * @return JREs currently being displayed in this block
-	 */
-	public IVMInstall[] getJREs() {
-		return (IVMInstall[])fVMs.toArray(new IVMInstall[fVMs.size()]);
-	}
-	
-	/**
-	 * Bring up a wizard that lets the user create a new VM definition.
-	 */
-	private void addVM() {
-//		AddVMInstallWizard wizard = new AddVMInstallWizard((IVMInstall[]) fVMs.toArray(new IVMInstall[fVMs.size()]));
-//		WizardDialog dialog = new WizardDialog(getShell(), wizard);
-//		if (dialog.open() == Window.OK) {
-//			VMStandin result = wizard.getResult();
-//			if (result != null) {
-//				fVMs.add(result);
-//				fVMList.refresh();
-//				fVMList.setSelection(new StructuredSelection(result));
-//			}
-//		}
-	}
-	
-	/**
-	 * @see IAddVMDialogRequestor#vmAdded(IVMInstall)
-	 */
-	public void vmAdded(IVMInstall vm) {
-		fVMs.add(vm);
-		runtimesTableViewer.refresh();
-	}
-	
-	/**
-	 * @see IAddVMDialogRequestor#isDuplicateName(String)
-	 */
-	public boolean isDuplicateName(String name) {
-		for (int i= 0; i < fVMs.size(); i++) {
-			IVMInstall vm = (IVMInstall)fVMs.get(i);
-			if (vm.getName().equals(name)) {
-				return true;
-			}
-		}
-		return false;
-	}	
-	
-	/**
-	 * Performs the edit VM action when the Edit... button is pressed
-	 */
-	private void editVM() {
-		IStructuredSelection selection= (IStructuredSelection)runtimesTableViewer.getSelection();
-		VMStandin vm= (VMStandin)selection.getFirstElement();
-		if (vm == null) {
-			return;
-		}
-//		if (isContributed(vm)) {
-//			VMDetailsDialog dialog= new VMDetailsDialog(getShell(), vm);
-//			dialog.open();
-//		} else {
-//			EditVMInstallWizard wizard = new EditVMInstallWizard(vm, (IVMInstall[]) fVMs.toArray(new IVMInstall[fVMs.size()]));
-//			WizardDialog dialog = new WizardDialog(getShell(), wizard);
-//			if (dialog.open() == Window.OK) {
-//				VMStandin result = wizard.getResult();
-//				if (result != null) {
-//					// replace with the edited VM
-//					int index = fVMs.indexOf(vm);
-//					fVMs.remove(index);
-//					fVMs.add(index, result);
-//					fVMList.refresh();
-//					fVMList.setSelection(new StructuredSelection(result));
-//				}
-//			}
-//		}
-		
-		
-	}
-	
-	/**
-	 * Performs the remove VM(s) action when the Remove... button is pressed
-	 */
-	private void removeVMs() {
-		IStructuredSelection selection= (IStructuredSelection)runtimesTableViewer.getSelection();
-		IVMInstall[] vms = new IVMInstall[selection.size()];
-		Iterator iter = selection.iterator();
-		int i = 0;
-		while (iter.hasNext()) {
-			vms[i] = (IVMInstall)iter.next();
-			i++;
-		}
-		removeJREs(vms);
-	}	
-	
-	/**
-	 * Removes the given VMs from the table.
-	 * 
-	 * @param vms
-	 */
-	public void removeJREs(IVMInstall[] vms) {
-		IStructuredSelection prev = (IStructuredSelection) getSelection();
-		for (int i = 0; i < vms.length; i++) {
-			fVMs.remove(vms[i]);
-		}
-		runtimesTableViewer.refresh();
-		IStructuredSelection curr = (IStructuredSelection) getSelection();
-		if (!curr.equals(prev)) {
-			IVMInstall[] installs = getJREs();
-			if (curr.size() == 0 && installs.length == 1) {
-				// pick a default VM automatically
-				setSelection(new StructuredSelection(installs[0]));
-			} else {
-				fireSelectionChanged();
-			}
-		}
-	}
-	
-	/**
-	 * Search for installed VMs in the file system
-	 */
-	protected void search() {
-//		if (Platform.OS_MACOSX.equals(Platform.getOS())) {
-//			doMacSearch();
-//			return;
-//		}
-		// choose a root directory for the search 
-		DirectoryDialog dialog = new DirectoryDialog(getShell());
-		dialog.setMessage("Select a directory to search in:"); 
-		dialog.setText("Directory Selection"); 
-		String path = dialog.open();
-		if (path == null) {
-			return;
-		}
-		
-		// ignore installed locations
-		final Set exstingLocations = new HashSet();
-		Iterator iter = fVMs.iterator();
-		while (iter.hasNext()) {
-			exstingLocations.add(((IVMInstall)iter.next()).getInstallLocation());
-		}
-		
-		// search
-		final File rootDir = new File(path);
-		final List locations = new ArrayList();
-		final List types = new ArrayList();
-
-		IRunnableWithProgress r = new IRunnableWithProgress() {
-			public void run(IProgressMonitor monitor) {
-				monitor.beginTask("Searching...", IProgressMonitor.UNKNOWN); 
-				search(rootDir, locations, types, exstingLocations, monitor);
-				monitor.done();
-			}
-		};
-		
-		try {
-            ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell()) {
-                /*
-                 * Overridden createCancelButton to replace Cancel label with Stop label
-                 * More accurately reflects action taken when button pressed.
-                 * Bug [162902]
-                 */
-                protected void createCancelButton(Composite parent) {
-                    cancel = createButton(parent, IDialogConstants.CANCEL_ID,
-                            IDialogConstants.STOP_LABEL, true);
-                    if (arrowCursor == null) {
-            			arrowCursor = new Cursor(cancel.getDisplay(), SWT.CURSOR_ARROW);
-            		}
-                    cancel.setCursor(arrowCursor);
-                    setOperationCancelButtonEnabled(enableCancelButton);
-                }
-            };
-            progress.run(true, true, r);
-		} catch (InvocationTargetException e) {
-//			JDIDebugUIPlugin.log(e);
-		} catch (InterruptedException e) {
-			// canceled
-			return;
-		}
-		
-		if (locations.isEmpty()) {
-			String messagePath = path.replaceAll("&", "&&"); // @see bug 29855  //$NON-NLS-1$//$NON-NLS-2$
-//			MessageDialog.openInformation(getShell(), JREMessages.InstalledJREsBlock_12, MessageFormat.format(JREMessages.InstalledJREsBlock_13, new String[]{messagePath})); // 
-		} else {
-			iter = locations.iterator();
-			Iterator iter2 = types.iterator();
-			while (iter.hasNext()) {
-				File location = (File)iter.next();
-				IVMInstallType type = (IVMInstallType)iter2.next();
-				AbstractVMInstall vm = new VMStandin(type, createUniqueId(type));
-				String name = location.getName();
-				String nameCopy = new String(name);
-				int i = 1;
-				while (isDuplicateName(nameCopy)) {
-					nameCopy = name + '(' + i++ + ')'; 
-				}
-				vm.setName(nameCopy);
-				vm.setInstallLocation(location);
-				if (type instanceof AbstractVMInstallType) {
-					//set default java doc location
-					AbstractVMInstallType abs = (AbstractVMInstallType)type;
-					vm.setJavadocLocation(abs.getDefaultJavadocLocation(location));
-					vm.setVMArgs(abs.getDefaultVMArguments(location));
-				}
-				vmAdded(vm);
-			}
-		}
-		
-	}
-	
-	/**
-	 * Calls out to {@link MacVMSearch} to find all installed JREs in the standard
-	 * Mac OS location
-	 */
-//	private void doMacSearch() {
-//		final List added = new ArrayList();
-//		IRunnableWithProgress r = new IRunnableWithProgress() {
-//			public void run(IProgressMonitor monitor) {
-//				Set exists = new HashSet();
-//				Iterator iterator = fVMs.iterator();
-//				while (iterator.hasNext()) {
-//					IVMInstall vm = (IVMInstall) iterator.next();
-//					exists.add(vm.getId());
-//				}
-//				VMStandin[] standins = new MacVMSearch().search(monitor);
-//				for (int i = 0; i < standins.length; i++) {
-//					if (!exists.contains(standins[i].getId())) {
-//						added.add(standins[i]);
-//					}
-//				}
-//				monitor.done();
-//			}
-//		};
-//		
-//		try {
-//            ProgressMonitorDialog progress = new ProgressMonitorDialog(getShell());
-//            progress.run(true, true, r);
-//		} catch (InvocationTargetException e) {
-//			JDIDebugUIPlugin.log(e);
-//		} catch (InterruptedException e) {
-//			// canceled
-//			return;
-//		}
-//		
-//		Iterator iterator = added.iterator();
-//		while (iterator.hasNext()) {
-//			IVMInstall vm = (IVMInstall) iterator.next();
-//			vmAdded(vm);
-//		}
-//
-//	}
-
-	protected Shell getShell() {
-		return getControl().getShell();
-	}
-
-	/**
-	 * Find a unique VM id.  Check existing 'real' VMs, as well as the last id used for
-	 * a VMStandin.
-	 */
-	private String createUniqueId(IVMInstallType vmType) {
-		String id= null;
-		do {
-			id= String.valueOf(System.currentTimeMillis());
-		} while (vmType.findVMInstall(id) != null || id.equals(fgLastUsedID));
-		fgLastUsedID = id;
-		return id;
-	}	
-	
-	/**
-	 * Searches the specified directory recursively for installed VMs, adding each
-	 * detected VM to the <code>found</code> list. Any directories specified in
-	 * the <code>ignore</code> are not traversed.
-	 * 
-	 * @param directory
-	 * @param found
-	 * @param types
-	 * @param ignore
-	 */
-	protected void search(File directory, List found, List types, Set ignore, IProgressMonitor monitor) {
-		if (monitor.isCanceled()) {
-			return;
-		}
-
-		String[] names = directory.list();
-		if (names == null) {
-			return;
-		}
-		List subDirs = new ArrayList();
-		for (int i = 0; i < names.length; i++) {
-			if (monitor.isCanceled()) {
-				return;
-			}
-			File file = new File(directory, names[i]);
-//			try {
-//				monitor.subTask(MessageFormat.format(JREMessages.InstalledJREsBlock_14, new String[]{Integer.toString(found.size()),
-//						file.getCanonicalPath().replaceAll("&", "&&")}));   // @see bug 29855 //$NON-NLS-1$ //$NON-NLS-2$
-//			} catch (IOException e) {
-//			}		
-			IVMInstallType[] vmTypes = JavaRuntime.getVMInstallTypes();	
-			if (file.isDirectory()) {
-				if (!ignore.contains(file)) {
-					boolean validLocation = false;
-					
-					// Take the first VM install type that claims the location as a
-					// valid VM install.  VM install types should be smart enough to not
-					// claim another type's VM, but just in case...
-					for (int j = 0; j < vmTypes.length; j++) {
-						if (monitor.isCanceled()) {
-							return;
-						}
-						IVMInstallType type = vmTypes[j];
-						IStatus status = type.validateInstallLocation(file);
-						if (status.isOK()) {
-							found.add(file);
-							types.add(type);
-							validLocation = true;
-							break;
-						}
-					}
-					if (!validLocation) {
-						subDirs.add(file);
-					}
-				}
-			}
-		}
-		while (!subDirs.isEmpty()) {
-			File subDir = (File)subDirs.remove(0);
-			search(subDir, found, types, ignore, monitor);
-			if (monitor.isCanceled()) {
-				return;
-			}
-		}
-		
-	}	
-	
-	/**
-	 * Sets the checked JRE, possible <code>null</code>
-	 * 
-	 * @param vm JRE or <code>null</code>
-	 */
-	public void setCheckedJRE(IVMInstall vm) {
-		if (vm == null) {
-			setSelection(new StructuredSelection());
-		} else {
-			setSelection(new StructuredSelection(vm));
-		}
-	}
-	
-	/**
-	 * Returns the checked JRE or <code>null</code> if none.
-	 * 
-	 * @return the checked JRE or <code>null</code> if none
-	 */
-	public IVMInstall getCheckedJRE() {
-		Object[] objects = runtimesTableViewer.getCheckedElements();
-		if (objects.length == 0) {
-			return null;
-		}
-		return (IVMInstall)objects[0];
-	}
-	
-	/**
-	 * Persist table settings into the give dialog store, prefixed
-	 * with the given key.
-	 * 
-	 * @param settings dialog store
-	 * @param qualifier key qualifier
-	 */
-	public void saveColumnSettings(IDialogSettings settings, String qualifier) {
-        int columnCount = runtimesTable.getColumnCount();
-		for (int i = 0; i < columnCount; i++) {
-			settings.put(qualifier + ".columnWidth" + i, runtimesTable.getColumn(i).getWidth());	 //$NON-NLS-1$
-		}
-		settings.put(qualifier + ".sortColumn", fSortColumn); //$NON-NLS-1$
-	}
-	
-	/**
-	 * Restore table settings from the given dialog store using the
-	 * given key.
-	 * 
-	 * @param settings dialog settings store
-	 * @param qualifier key to restore settings from
-	 */
-	public void restoreColumnSettings(IDialogSettings settings, String qualifier) {
-		runtimesTableViewer.getTable().layout(true);
-        restoreColumnWidths(settings, qualifier);
-		try {
-			fSortColumn = settings.getInt(qualifier + ".sortColumn"); //$NON-NLS-1$
-		} catch (NumberFormatException e) {
-			fSortColumn = 1;
-		}
-		switch (fSortColumn) {
-			case 1:
-				sortByName();
-				break;
-			case 2:
-				sortByLocation();
-				break;
-			case 3:
-				sortByType();
-				break;
-		}
-	}
-	
-	private void restoreColumnWidths(IDialogSettings settings, String qualifier) {
-        int columnCount = runtimesTable.getColumnCount();
-        for (int i = 0; i < columnCount; i++) {
-            int width = -1;
-            try {
-                width = settings.getInt(qualifier + ".columnWidth" + i); 
-            } catch (NumberFormatException e) {}
-            
-            if ((width <= 0) || (i == runtimesTable.getColumnCount() - 1)) {
-                runtimesTable.getColumn(i).pack();
-            } else {
-                runtimesTable.getColumn(i).setWidth(width);
-            }
-        }
-	}
-	
-	protected void fillWithWorkspaceForgeRuntimes() {
-		List standins = new ArrayList();
-		IVMInstallType[] types = JavaRuntime.getVMInstallTypes();
-		for (int i = 0; i < types.length; i++) {
-			IVMInstallType type = types[i];
-			IVMInstall[] installs = type.getVMInstalls();
-			for (int j = 0; j < installs.length; j++) {
-				IVMInstall install = installs[j];
-				standins.add(new VMStandin(install));
-			}
-		}
-		setJREs((IVMInstall[])standins.toArray(new IVMInstall[standins.size()]));	
-	}
-		
-}



More information about the jbosstools-commits mailing list