1 11 package org.eclipse.team.internal.ccvs.ui; 12 13 import java.util.Arrays ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.jface.dialogs.IDialogConstants; 18 import org.eclipse.jface.viewers.*; 19 import org.eclipse.osgi.util.NLS; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.events.*; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.layout.GridLayout; 24 import org.eclipse.swt.widgets.*; 25 import org.eclipse.team.internal.ui.dialogs.DetailsDialog; 26 import org.eclipse.ui.model.WorkbenchContentProvider; 27 import org.eclipse.ui.model.WorkbenchLabelProvider; 28 29 34 public class AddToVersionControlDialog extends DetailsDialog { 35 36 private static final int WIDTH_HINT = 350; 37 private final static int SELECTION_HEIGHT_HINT = 100; 38 39 private IResource[] unaddedResources; 40 private Object [] resourcesToAdd; 41 42 private CheckboxTableViewer listViewer; 43 47 public AddToVersionControlDialog(Shell parentShell, IResource[] unaddedResources) { 48 super(parentShell, CVSUIMessages.AddToVersionControlDialog_title); 49 this.unaddedResources = unaddedResources; 50 } 51 52 55 protected void createMainDialogArea(Composite parent) { 56 Composite composite = new Composite(parent, SWT.NULL); 57 composite.setLayout(new GridLayout()); 58 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 59 60 if (unaddedResources.length==1) { 62 createWrappingLabel(composite, NLS.bind(CVSUIMessages.AddToVersionControlDialog_thereIsAnUnaddedResource, new String [] { new Integer (unaddedResources.length).toString() })); 63 } else { 64 createWrappingLabel(composite, NLS.bind(CVSUIMessages.AddToVersionControlDialog_thereAreUnaddedResources, new String [] { new Integer (unaddedResources.length).toString() })); 65 } 66 } 67 68 71 protected String getHelpContextId() { 72 return IHelpContextIds.ADD_TO_VERSION_CONTROL_DIALOG; 73 } 74 75 78 protected Composite createDropDownDialogArea(Composite parent) { 79 Composite composite = new Composite(parent, SWT.NONE); 81 GridLayout layout = new GridLayout(); 82 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 83 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 84 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 85 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 86 composite.setLayout(layout); 87 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 88 89 addUnaddedResourcesArea(composite); 90 91 return composite; 92 } 93 94 private void addUnaddedResourcesArea(Composite composite) { 95 96 createWrappingLabel(composite, CVSUIMessages.ReleaseCommentDialog_unaddedResources); 98 99 listViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER); 101 GridData data = new GridData(GridData.FILL_BOTH); 102 data.heightHint = SELECTION_HEIGHT_HINT; 103 data.widthHint = WIDTH_HINT; 104 listViewer.getTable().setLayoutData(data); 105 106 listViewer.setLabelProvider(new WorkbenchLabelProvider() { 108 protected String decorateText(String input, Object element) { 109 if (element instanceof IResource) 110 return ((IResource)element).getFullPath().toString(); 111 else 112 return input; 113 } 114 }); 115 listViewer.setContentProvider(new WorkbenchContentProvider()); 116 listViewer.setInput(new AdaptableResourceList(unaddedResources)); 117 if (resourcesToAdd == null) { 118 listViewer.setAllChecked(true); 119 } else { 120 listViewer.setCheckedElements(resourcesToAdd); 121 } 122 listViewer.addSelectionChangedListener(new ISelectionChangedListener() { 123 public void selectionChanged(SelectionChangedEvent event) { 124 resourcesToAdd = listViewer.getCheckedElements(); 125 } 126 }); 127 128 addSelectionButtons(composite); 129 } 130 131 135 private void addSelectionButtons(Composite composite) { 136 137 Composite buttonComposite = new Composite(composite, SWT.RIGHT); 138 GridLayout layout = new GridLayout(); 139 layout.numColumns = 2; 140 buttonComposite.setLayout(layout); 141 GridData data = 142 new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL); 143 data.grabExcessHorizontalSpace = true; 144 composite.setData(data); 145 146 Button selectButton = createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, CVSUIMessages.ReleaseCommentDialog_selectAll, false); 147 SelectionListener listener = new SelectionAdapter() { 148 public void widgetSelected(SelectionEvent e) { 149 listViewer.setAllChecked(true); 150 resourcesToAdd = null; 151 } 152 }; 153 selectButton.addSelectionListener(listener); 154 155 Button deselectButton = createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, CVSUIMessages.ReleaseCommentDialog_deselectAll, false); 156 listener = new SelectionAdapter() { 157 public void widgetSelected(SelectionEvent e) { 158 listViewer.setAllChecked(false); 159 resourcesToAdd = new Object [0]; 160 161 } 162 }; 163 deselectButton.addSelectionListener(listener); 164 } 165 166 169 protected void updateEnablements() { 170 } 171 172 176 public IResource[] getResourcesToAdd() { 177 if (resourcesToAdd == null) { 178 return unaddedResources; 179 } else { 180 List result = Arrays.asList(resourcesToAdd); 181 return (IResource[]) result.toArray(new IResource[result.size()]); 182 } 183 } 184 185 188 protected void createButtonsForButtonBar(Composite parent) { 189 createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true); 190 createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true); 191 super.createButtonsForButtonBar(parent); 192 } 193 194 197 protected boolean includeOkButton() { 198 return false; 199 } 200 203 protected void buttonPressed(int id) { 204 if(id == IDialogConstants.YES_ID || id == IDialogConstants.NO_ID) { 207 setReturnCode(id); 208 close(); 209 } else { 210 super.buttonPressed(id); 211 } 212 } 213 } 214 | Popular Tags |