Bug 30888 IndexOutOfBoundsException in CodeTemplateBlock
latest on 0204 i pressed the edit button (nothing was selected in the tree) java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.RangeCheck(ArrayList.java:508) at java.util.ArrayList.get(ArrayList.java:320) at org.eclipse.jdt.internal.ui.preferences.CodeTemplateBlock.doButtonPressed (CodeTemplateBlock.java:317) at org.eclipse.jdt.internal.ui.preferences.CodeTemplateBlock$CodeTemplateAdapter.cu stomButtonPressed(CodeTemplateBlock.java:65) at org.eclipse.jdt.internal.ui.wizards.dialogfields.TreeListDialogField.buttonPress ed(TreeListDialogField.java:165) at org.eclipse.jdt.internal.ui.wizards.dialogfields.TreeListDialogField.doButtonSel ected(TreeListDialogField.java:380) at org.eclipse.jdt.internal.ui.wizards.dialogfields.TreeListDialogField.access$2 (TreeListDialogField.java:376) at org.eclipse.jdt.internal.ui.wizards.dialogfields.TreeListDialogField$2.widgetSel ected(TreeListDialogField.java:343) at org.eclipse.swt.widgets.TypedListener.handleEvent (TypedListener.java:87) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:77) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:836) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1692) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1410) at org.eclipse.jface.window.Window.runEventLoop(Window.java:561) at org.eclipse.jface.window.Window.open(Window.java:541) at org.eclipse.ui.internal.OpenPreferencesAction.run (OpenPreferencesAction.java:47) at org.eclipse.jface.action.Action.runWithEvent(Action.java:804) at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection (ActionContributionItem.java:450) at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent (ActionContributionItem.java:398) at org.eclipse.jface.action.ActionContributionItem.access$0 (ActionContributionItem.java:392) at org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent (ActionContributionItem.java:72) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:77) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:836) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:1692) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1410) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1240) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1223) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:845) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:462) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.eclipse.core.launcher.Main.basicRun(Main.java:247) at org.eclipse.core.launcher.Main.run(Main.java:703) at org.eclipse.core.launcher.Main.main(Main.java:539)
org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/preferences/CodeTemplateBlock.java
Template newTemplate= new Template(template);
		EditTemplateDialog dialog= new EditTemplateDialog(getShell(), newTemplate, true, false, new String[0]);
		if (dialog.open() == EditTemplateDialog.OK) {
			
			template.setDescription(newTemplate.getDescription());
			template.setPattern(newTemplate.getPattern());
			fCodeTemplateTree.refresh(template);
			fCodeTemplateTree.selectElements(new StructuredSelection(template));
		}
	}
		
	private void import_() {
		FileDialog dialog= new FileDialog(getShell());
		dialog.setText(PreferencesMessages.getString("CodeTemplateBlock.import.title")); 
		dialog.setFilterExtensions(new String[] {PreferencesMessages.getString("CodeTemplateBlock.import.extension")}); 
		String path= dialog.open();
		if (path != null) {
			try {
				fTemplates.addFromFile(new File(path), false);
			} catch (CoreException e) {			
				openReadErrorDialog(e);
			}
			fCodeTemplateTree.refresh();
		}
	}
	
	private void exportAll() {
		export(fTemplates);	
	}
	private void export(List selected) {