1 11 package org.eclipse.jdt.internal.ui.wizards.buildpaths; 12 13 import java.util.Arrays ; 14 15 import org.eclipse.swt.SWT; 16 import org.eclipse.swt.widgets.Composite; 17 18 import org.eclipse.jface.dialogs.Dialog; 19 import org.eclipse.jface.dialogs.IDialogSettings; 20 import org.eclipse.jface.viewers.ArrayContentProvider; 21 import org.eclipse.jface.viewers.DoubleClickEvent; 22 import org.eclipse.jface.viewers.IDoubleClickListener; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.ISelectionChangedListener; 25 import org.eclipse.jface.viewers.LabelProvider; 26 import org.eclipse.jface.viewers.ListViewer; 27 import org.eclipse.jface.viewers.SelectionChangedEvent; 28 import org.eclipse.jface.viewers.ViewerComparator; 29 import org.eclipse.jface.wizard.WizardPage; 30 31 import org.eclipse.ui.PlatformUI; 32 33 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 34 import org.eclipse.jdt.internal.ui.JavaPlugin; 35 import org.eclipse.jdt.internal.ui.JavaPluginImages; 36 import org.eclipse.jdt.internal.ui.util.SelectionUtil; 37 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 38 39 41 public class ClasspathContainerSelectionPage extends WizardPage { 42 43 private static final String DIALOGSTORE_SECTION= "ClasspathContainerSelectionPage"; private static final String DIALOGSTORE_CONTAINER_IDX= "index"; 46 47 private static class ClasspathContainerLabelProvider extends LabelProvider { 48 public String getText(Object element) { 49 return ((ClasspathContainerDescriptor) element).getName(); 50 } 51 } 52 53 private ListViewer fListViewer; 54 private ClasspathContainerDescriptor[] fContainers; 55 private IDialogSettings fDialogSettings; 56 57 61 protected ClasspathContainerSelectionPage(ClasspathContainerDescriptor[] containerPages) { 62 super("ClasspathContainerWizardPage"); setTitle(NewWizardMessages.ClasspathContainerSelectionPage_title); 64 setDescription(NewWizardMessages.ClasspathContainerSelectionPage_description); 65 setImageDescriptor(JavaPluginImages.DESC_WIZBAN_ADD_LIBRARY); 66 67 fContainers= containerPages; 68 69 IDialogSettings settings= JavaPlugin.getDefault().getDialogSettings(); 70 fDialogSettings= settings.getSection(DIALOGSTORE_SECTION); 71 if (fDialogSettings == null) { 72 fDialogSettings= settings.addNewSection(DIALOGSTORE_SECTION); 73 fDialogSettings.put(DIALOGSTORE_CONTAINER_IDX, 0); 74 } 75 validatePage(); 76 } 77 78 81 public void createControl(Composite parent) { 82 fListViewer= new ListViewer(parent, SWT.SINGLE | SWT.BORDER); 83 fListViewer.setLabelProvider(new ClasspathContainerLabelProvider()); 84 fListViewer.setContentProvider(new ArrayContentProvider()); 85 fListViewer.setComparator(new ViewerComparator()); 86 fListViewer.setInput(Arrays.asList(fContainers)); 87 fListViewer.addSelectionChangedListener(new ISelectionChangedListener() { 88 public void selectionChanged(SelectionChangedEvent event) { 89 validatePage(); 90 } 91 }); 92 fListViewer.addDoubleClickListener(new IDoubleClickListener() { 93 public void doubleClick(DoubleClickEvent event) { 94 doDoubleClick(); 95 } 96 }); 97 98 int selectionIndex= fDialogSettings.getInt(DIALOGSTORE_CONTAINER_IDX); 99 if (selectionIndex >= fContainers.length) { 100 selectionIndex= 0; 101 } 102 fListViewer.getList().select(selectionIndex); 103 validatePage(); 104 setControl(fListViewer.getList()); 105 Dialog.applyDialogFont(fListViewer.getList()); 106 107 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJavaHelpContextIds.BP_SELECT_CLASSPATH_CONTAINER); 108 } 109 110 113 private void validatePage() { 114 setPageComplete(getSelected() != null); 115 } 116 117 118 public ClasspathContainerDescriptor getSelected() { 119 if (fListViewer != null) { 120 ISelection selection= fListViewer.getSelection(); 121 return (ClasspathContainerDescriptor) SelectionUtil.getSingleElement(selection); 122 } 123 return null; 124 } 125 126 public ClasspathContainerDescriptor[] getContainers() { 127 return fContainers; 128 } 129 130 protected void doDoubleClick() { 131 if (canFlipToNextPage()) { 132 getContainer().showPage(getNextPage()); 133 } 134 } 135 136 139 public boolean canFlipToNextPage() { 140 return isPageComplete(); } 142 143 146 public void setVisible(boolean visible) { 147 if (!visible && fListViewer != null) { 148 fDialogSettings.put(DIALOGSTORE_CONTAINER_IDX, fListViewer.getList().getSelectionIndex()); 149 } 150 super.setVisible(visible); 151 } 152 153 } 154 | Popular Tags |