1 11 package org.eclipse.team.internal.ccvs.ui.subscriber; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.jface.dialogs.IDialogConstants; 15 import org.eclipse.jface.viewers.*; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.events.*; 18 import org.eclipse.swt.layout.GridData; 19 import org.eclipse.swt.layout.GridLayout; 20 import org.eclipse.swt.widgets.*; 21 import org.eclipse.team.core.synchronize.*; 22 import org.eclipse.team.internal.ccvs.ui.AdaptableResourceList; 23 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; 24 import org.eclipse.team.internal.ui.dialogs.DetailsDialog; 25 import org.eclipse.ui.model.WorkbenchContentProvider; 26 import org.eclipse.ui.model.WorkbenchLabelProvider; 27 28 32 public abstract class SyncInfoSetDetailsDialog extends DetailsDialog { 33 34 private static final int WIDTH_HINT = 350; 35 private final static int SELECTION_HEIGHT_HINT = 100; 36 37 private CheckboxTableViewer listViewer; 38 39 private SyncInfoSet syncSet; 40 private Object [] selectedResources; 41 42 public SyncInfoSetDetailsDialog(Shell parentShell, String dialogTitle, SyncInfoSet syncSet) { 43 super(parentShell, dialogTitle); 44 this.syncSet = syncSet; 45 } 46 47 50 protected Composite createDropDownDialogArea(Composite parent) { 51 Composite composite = createComposite(parent); 52 53 addResourcesArea(composite); 54 55 58 return composite; 59 } 60 61 64 private void addResourcesArea(Composite composite) { 65 68 listViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER); 69 GridData data = new GridData(GridData.FILL_BOTH); 70 data.heightHint = SELECTION_HEIGHT_HINT; 71 data.widthHint = WIDTH_HINT; 72 listViewer.getTable().setLayoutData(data); 73 74 listViewer.setLabelProvider(new WorkbenchLabelProvider() { 76 protected String decorateText(String input, Object element) { 77 if (element instanceof IResource) 78 return ((IResource)element).getFullPath().toString(); 79 else 80 return input; 81 } 82 }); 83 listViewer.setContentProvider(new WorkbenchContentProvider()); 84 setViewerInput(); 85 listViewer.addSelectionChangedListener(new ISelectionChangedListener() { 86 public void selectionChanged(SelectionChangedEvent event) { 87 selectedResources = listViewer.getCheckedElements(); 88 } 89 }); 90 91 addSelectionButtons(composite); 92 93 } 94 95 99 private void addSelectionButtons(Composite composite) { 100 101 Composite buttonComposite = new Composite(composite, SWT.RIGHT); 102 GridLayout layout = new GridLayout(); 103 layout.numColumns = 2; 104 buttonComposite.setLayout(layout); 105 GridData data = 106 new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL); 107 data.grabExcessHorizontalSpace = true; 108 composite.setData(data); 109 110 Button selectButton = createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, CVSUIMessages.ReleaseCommentDialog_selectAll, false); 111 SelectionListener listener = new SelectionAdapter() { 112 public void widgetSelected(SelectionEvent e) { 113 listViewer.setAllChecked(true); 114 selectedResources = null; 115 } 116 }; 117 selectButton.addSelectionListener(listener); 118 119 Button deselectButton = createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, CVSUIMessages.ReleaseCommentDialog_deselectAll, false); 120 listener = new SelectionAdapter() { 121 public void widgetSelected(SelectionEvent e) { 122 listViewer.setAllChecked(false); 123 selectedResources = new Object [0]; 124 125 } 126 }; 127 deselectButton.addSelectionListener(listener); 128 } 129 130 protected void setViewerInput() { 131 if (listViewer == null || listViewer.getControl().isDisposed()) return; 132 listViewer.setInput(new AdaptableResourceList(getAllResources())); 133 if (selectedResources == null) { 134 listViewer.setAllChecked(true); 135 } else { 136 listViewer.setCheckedElements(selectedResources); 137 } 138 } 139 140 143 protected IResource[] getAllResources() { 144 return syncSet.getResources(); 145 } 146 147 151 protected void updateEnablements() { 152 } 153 154 157 public SyncInfoSet getSyncSet() { 158 return syncSet; 159 } 160 161 164 protected void buttonPressed(int id) { 165 if (id == IDialogConstants.OK_ID) { 166 filterSyncSet(); 167 } 168 super.buttonPressed(id); 169 } 170 171 protected void filterSyncSet() { 172 if (selectedResources != null) { 174 getSyncSet().selectNodes(new FastSyncInfoFilter() { 175 public boolean select(SyncInfo info) { 176 IResource local = info.getLocal(); 177 for (int i = 0; i < selectedResources.length; i++) { 178 if (local.equals(selectedResources[i])) return true; 179 } 180 return false; 181 } 182 }); 183 } 184 } 185 } 186 | Popular Tags |