1 11 package org.eclipse.team.internal.ccvs.ui.repo; 12 13 import java.util.Arrays ; 14 15 import org.eclipse.core.runtime.IAdaptable; 16 import org.eclipse.jface.dialogs.Dialog; 17 import org.eclipse.jface.dialogs.IDialogSettings; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.jface.util.IPropertyChangeListener; 20 import org.eclipse.jface.util.PropertyChangeEvent; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.layout.GridLayout; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource; 25 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 26 import org.eclipse.team.internal.ccvs.ui.*; 27 import org.eclipse.team.internal.ccvs.ui.model.RemoteContentProvider; 28 import org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage; 29 import org.eclipse.ui.IWorkingSet; 30 import org.eclipse.ui.PlatformUI; 31 import org.eclipse.ui.model.IWorkbenchAdapter; 32 import org.eclipse.ui.model.WorkbenchLabelProvider; 33 34 38 public class RefreshRemoteProjectSelectionPage extends CVSWizardPage { 39 40 private ICVSRemoteResource[] rootFolders; 41 private ListSelectionArea listArea; 42 private WorkingSetSelectionArea workingSetArea; 43 private IWorkingSet workingSet; 44 private IDialogSettings settings; 45 46 49 private class InputElement implements IWorkbenchAdapter, IAdaptable { 50 public Object [] getChildren(Object o) { 51 return rootFolders; 52 } 53 public ImageDescriptor getImageDescriptor(Object object) { 54 return null; 55 } 56 public String getLabel(Object o) { 57 return null; 58 } 59 public Object getParent(Object o) { 60 return null; 61 } 62 public Object getAdapter(Class adapter) { 63 if (adapter == IWorkbenchAdapter.class) return this; 64 return null; 65 } 66 } 67 68 75 public RefreshRemoteProjectSelectionPage( 76 String pageName, 77 String title, 78 ImageDescriptor titleImage, 79 String description, 80 IDialogSettings settings, 81 ICVSRepositoryLocation root, 82 ICVSRemoteResource[] rootFolders) { 83 super(pageName, title, titleImage, description); 84 this.settings = settings; 85 this.rootFolders = rootFolders; 86 } 87 88 91 public void createControl(Composite parent) { 92 93 final Composite composite = new Composite(parent, SWT.NONE); 94 composite.setLayout(new GridLayout(1, false)); 95 96 setControl(composite); 97 98 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.REFRESH_REMOTE_PROJECT_SELECTION_PAGE); 100 101 listArea = new ListSelectionArea( 102 new InputElement(), 103 new RemoteContentProvider(), 104 new WorkbenchLabelProvider(), 105 CVSUIMessages.RefreshRemoteProjectSelectionPage_selectRemoteProjects); 106 listArea.createArea(composite); 107 108 listArea.addPropertyChangeListener(new IPropertyChangeListener() { 109 public void propertyChange(PropertyChangeEvent event) { 110 updateEnablement(); 111 } 112 }); 113 listArea.getViewer().setComparator(new RepositoryComparator()); 114 115 workingSetArea = new WorkingSetSelectionArea(getShell(), CVSUIMessages.RefreshRemoteProjectSelectionPage_noWorkingSet, CVSUIMessages.RefreshRemoteProjectSelectionPage_workingSet, settings); setWorkingSet(workingSet); 117 workingSetArea.addPropertyChangeListener(new IPropertyChangeListener() { 118 public void propertyChange(PropertyChangeEvent event) { 119 workingSet = (IWorkingSet)event.getNewValue(); 120 handleWorkingSetChange(); 121 } 122 }); 123 workingSetArea.createArea(composite); 124 Dialog.applyDialogFont(parent); 125 } 126 127 136 public void setWorkingSet(IWorkingSet workingSet) { 137 this.workingSet = workingSet; 138 139 if (workingSetArea != null) { 140 workingSetArea.setWorkingSet(workingSet); 141 } 142 } 143 144 private void handleWorkingSetChange() { 145 if (workingSet != null) { 146 listArea.getViewer().setAllChecked(false); 148 RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager(); 149 ICVSRemoteResource[] resources = manager.filterResources(workingSet, rootFolders); 150 for (int i = 0; i < resources.length; i++) { 151 ICVSRemoteResource resource = resources[i]; 152 listArea.getViewer().setChecked(resource, true); 153 } 154 } 155 } 156 157 private void updateEnablement() { 158 boolean atLeastOne = listArea.getViewer().getCheckedElements().length > 0; 159 setPageComplete(atLeastOne); 160 } 161 162 166 public ICVSRemoteResource[] getSelectedRemoteProject() { 167 Object [] checked = listArea.getViewer().getCheckedElements(); 168 return (ICVSRemoteResource[]) Arrays.asList(checked).toArray(new ICVSRemoteResource[checked.length]); 169 } 170 } 171 | Popular Tags |