1 11 package org.eclipse.team.internal.ccvs.ui.wizards; 12 13 14 import org.eclipse.jface.dialogs.Dialog; 15 import org.eclipse.jface.resource.ImageDescriptor; 16 import org.eclipse.jface.viewers.*; 17 import org.eclipse.osgi.util.TextProcessor; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.widgets.*; 21 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation; 22 import org.eclipse.team.internal.ccvs.ui.*; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.model.*; 25 26 31 public class RepositorySelectionPage extends CVSWizardPage { 32 33 private class DecoratingRepoLabelProvider extends WorkbenchLabelProvider { 34 protected String decorateText(String input, Object element) { 35 return TextProcessor.process(input, ":@/"); } 38 } 39 40 41 private TableViewer table; 42 private Button useExistingRepo; 43 private Button useNewRepo; 44 45 private ICVSRepositoryLocation result; 46 47 String extendedDescription; 48 49 56 public RepositorySelectionPage(String pageName, String title, ImageDescriptor titleImage) { 57 super(pageName, title, titleImage); 58 } 59 protected TableViewer createTable(Composite parent, int span) { 60 Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION); 61 GridData data = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL); 62 data.horizontalSpan = span; 63 data.widthHint = 200; 64 table.setLayoutData(data); 65 TableLayout layout = new TableLayout(); 66 layout.addColumnData(new ColumnWeightData(100, true)); 67 table.setLayout(layout); 68 TableColumn col = new TableColumn(table, SWT.NONE); 69 col.setResizable(true); 70 71 return new TableViewer(table); 72 } 73 78 public void createControl(Composite parent) { 79 Composite composite = createComposite(parent, 1, false); 80 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARING_SELECT_REPOSITORY_PAGE); 82 if (extendedDescription == null) { 83 extendedDescription = CVSUIMessages.RepositorySelectionPage_description; 84 } 85 createWrappingLabel(composite, extendedDescription, 0 , 1 ); 86 87 useNewRepo = createRadioButton(composite, CVSUIMessages.RepositorySelectionPage_useNew, 1); 88 89 useExistingRepo = createRadioButton(composite, CVSUIMessages.RepositorySelectionPage_useExisting, 1); 90 table = createTable(composite, 1); 91 table.setContentProvider(new WorkbenchContentProvider()); 92 table.setLabelProvider(new DecoratingRepoLabelProvider()); 93 table.addDoubleClickListener(new IDoubleClickListener() { 94 public void doubleClick(DoubleClickEvent event) { 95 getContainer().showPage(getNextPage()); 96 } 97 }); 98 99 setControl(composite); 100 101 initializeValues(); 102 Dialog.applyDialogFont(parent); 103 104 table.addSelectionChangedListener(new ISelectionChangedListener() { 105 public void selectionChanged(SelectionChangedEvent event) { 106 result = (ICVSRepositoryLocation)((IStructuredSelection)table.getSelection()).getFirstElement(); 107 setPageComplete(true); 108 } 109 }); 110 111 useExistingRepo.addListener(SWT.Selection, new Listener() { 112 public void handleEvent(Event event) { 113 if (useNewRepo.getSelection()) { 114 table.getTable().setEnabled(false); 115 result = null; 116 } else { 117 table.getTable().setEnabled(true); 118 result = (ICVSRepositoryLocation)((IStructuredSelection)table.getSelection()).getFirstElement(); 119 } 120 setPageComplete(true); 121 } 122 }); 123 } 124 127 private void initializeValues() { 128 ICVSRepositoryLocation[] locations = CVSUIPlugin.getPlugin().getRepositoryManager().getKnownRepositoryLocations(); 129 AdaptableList input = new AdaptableList(locations); 130 table.setInput(input); 131 if (locations.length == 0) { 132 useNewRepo.setSelection(true); 133 useExistingRepo.setSelection(false); 134 table.getTable().setEnabled(false); 135 } else { 136 useNewRepo.setSelection(false); 137 useExistingRepo.setSelection(true); 138 table.getTable().setEnabled(true); 139 result = locations[0]; 140 table.setSelection(new StructuredSelection(result)); 141 } 142 setPageComplete(true); 143 } 144 145 public ICVSRepositoryLocation getLocation() { 146 return result; 147 } 148 public void setVisible(boolean visible) { 149 super.setVisible(visible); 150 if (visible) { 151 useExistingRepo.setFocus(); 152 } 153 } 154 155 public void setExtendedDescription(String extendedDescription) { 156 this.extendedDescription = extendedDescription; 157 } 158 } 159 | Popular Tags |