1 11 package org.eclipse.ltk.internal.ui.refactoring.history; 12 13 import org.eclipse.core.runtime.Assert; 14 15 import org.eclipse.ltk.core.refactoring.RefactoringDescriptorProxy; 16 import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; 17 18 import org.eclipse.ltk.internal.ui.refactoring.RefactoringPluginImages; 19 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages; 20 import org.eclipse.ltk.internal.ui.refactoring.util.PixelConverter; 21 import org.eclipse.ltk.internal.ui.refactoring.util.SWTUtil; 22 23 import org.eclipse.swt.SWT; 24 import org.eclipse.swt.custom.ViewForm; 25 import org.eclipse.swt.events.DisposeEvent; 26 import org.eclipse.swt.events.DisposeListener; 27 import org.eclipse.swt.events.SelectionAdapter; 28 import org.eclipse.swt.events.SelectionEvent; 29 import org.eclipse.swt.layout.GridData; 30 import org.eclipse.swt.layout.GridLayout; 31 import org.eclipse.swt.widgets.Button; 32 import org.eclipse.swt.widgets.Composite; 33 import org.eclipse.swt.widgets.ToolBar; 34 35 import org.eclipse.jface.action.Action; 36 import org.eclipse.jface.action.IAction; 37 import org.eclipse.jface.action.Separator; 38 import org.eclipse.jface.action.ToolBarManager; 39 import org.eclipse.jface.viewers.IContentProvider; 40 import org.eclipse.jface.viewers.TreeViewer; 41 42 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryContentProvider; 43 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration; 44 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryLabelProvider; 45 46 55 public class BrowseRefactoringHistoryControl extends RefactoringHistoryControl { 56 57 58 private static final RefactoringDescriptorProxy[] EMPTY_DESCRIPTORS= {}; 59 60 61 private static final String TOOLBAR_SORT_GROUP= "group.sort"; 63 64 private Button fDeselectAllButton= null; 65 66 67 private Button fSelectAllButton= null; 68 69 70 private final IAction fSortProjects= new Action(RefactoringUIMessages.BrowseRefactoringHistoryControl_sort_project, IAction.AS_RADIO_BUTTON) { 71 72 public final void run() { 73 final BrowseRefactoringHistoryContentProvider provider= (BrowseRefactoringHistoryContentProvider) fHistoryViewer.getContentProvider(); 74 provider.setSortProjects(true); 75 fHistoryViewer.setSorter(fViewerSorter); 76 fHistoryViewer.refresh(false); 77 setExpandedState(); 78 reconcileCheckState(); 79 fSortProjects.setChecked(true); 80 fSortTimestamps.setChecked(false); 81 } 82 }; 83 84 85 private final IAction fSortTimestamps= new Action(RefactoringUIMessages.BrowseRefactoringHistoryControl_sort_date, IAction.AS_RADIO_BUTTON) { 86 87 public final void run() { 88 final BrowseRefactoringHistoryContentProvider provider= (BrowseRefactoringHistoryContentProvider) fHistoryViewer.getContentProvider(); 89 provider.setSortProjects(false); 90 fHistoryViewer.setSorter(null); 91 fHistoryViewer.refresh(false); 92 setExpandedState(); 93 reconcileCheckState(); 94 fSortTimestamps.setChecked(true); 95 fSortProjects.setChecked(false); 96 } 97 }; 98 99 100 private ToolBarManager fToolBarManager= null; 101 102 103 private final BrowseRefactoringHistoryViewerSorter fViewerSorter= new BrowseRefactoringHistoryViewerSorter(); 104 105 113 public BrowseRefactoringHistoryControl(final Composite parent, final RefactoringHistoryControlConfiguration configuration) { 114 super(parent, configuration); 115 116 addDisposeListener(new DisposeListener() { 117 118 public final void widgetDisposed(final DisposeEvent event) { 119 if (fToolBarManager != null) { 120 fToolBarManager.removeAll(); 121 fToolBarManager.dispose(); 122 fToolBarManager= null; 123 } 124 } 125 }); 126 } 127 128 131 protected void createBottomButtonBar(final Composite parent) { 132 Assert.isNotNull(parent); 133 final Composite composite= new Composite(parent, SWT.NONE); 134 final GridLayout layout= new GridLayout(2, false); 135 layout.marginWidth= 0; 136 layout.marginHeight= 0; 137 layout.marginTop= 5; 138 composite.setLayout(layout); 139 140 final GridData data= new GridData(); 141 data.grabExcessHorizontalSpace= true; 142 data.grabExcessVerticalSpace= false; 143 data.horizontalAlignment= SWT.FILL; 144 data.verticalAlignment= SWT.TOP; 145 composite.setLayoutData(data); 146 147 createSelectAllButton(composite); 148 createDeselectAllButton(composite); 149 } 150 151 154 public void createControl() { 155 super.createControl(); 156 final GridData data= new GridData(); 157 data.grabExcessHorizontalSpace= true; 158 data.heightHint= new PixelConverter(this).convertHeightInCharsToPixels(22); 159 data.horizontalAlignment= SWT.FILL; 160 data.verticalAlignment= SWT.FILL; 161 setLayoutData(data); 162 } 163 164 170 protected void createDeselectAllButton(final Composite parent) { 171 Assert.isNotNull(parent); 172 fDeselectAllButton= new Button(parent, SWT.NONE); 173 fDeselectAllButton.setEnabled(false); 174 fDeselectAllButton.setText(RefactoringUIMessages.SelectRefactoringHistoryControl_deselect_all_label); 175 final GridData data= new GridData(); 176 data.horizontalAlignment= GridData.END; 177 data.verticalAlignment= GridData.BEGINNING; 178 data.widthHint= SWTUtil.getButtonWidthHint(fDeselectAllButton); 179 fDeselectAllButton.setLayoutData(data); 180 181 fDeselectAllButton.addSelectionListener(new SelectionAdapter() { 182 183 public final void widgetSelected(final SelectionEvent event) { 184 handleDeselectAll(); 185 } 186 }); 187 } 188 189 192 protected TreeViewer createHistoryViewer(final Composite parent) { 193 Assert.isNotNull(parent); 194 TreeViewer viewer= null; 195 if (fControlConfiguration.isCheckableViewer()) 196 viewer= new RefactoringHistoryTreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); 197 else 198 viewer= new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); 199 return viewer; 200 } 201 202 208 protected void createSelectAllButton(final Composite parent) { 209 Assert.isNotNull(parent); 210 fSelectAllButton= new Button(parent, SWT.NONE); 211 fSelectAllButton.setEnabled(false); 212 fSelectAllButton.setText(RefactoringUIMessages.SelectRefactoringHistoryControl_select_all_label); 213 final GridData data= new GridData(); 214 data.horizontalAlignment= GridData.END; 215 data.grabExcessHorizontalSpace= true; 216 data.verticalAlignment= GridData.BEGINNING; 217 data.widthHint= SWTUtil.getButtonWidthHint(fSelectAllButton); 218 fSelectAllButton.setLayoutData(data); 219 220 fSelectAllButton.addSelectionListener(new SelectionAdapter() { 221 222 public final void widgetSelected(final SelectionEvent event) { 223 handleSelectAll(); 224 } 225 }); 226 } 227 228 231 protected void createToolBar(final ViewForm parent) { 232 final ToolBarManager manager= getToolBarManager(); 233 if (manager != null) { 234 manager.removeAll(); 235 manager.add(new Separator(TOOLBAR_SORT_GROUP)); 236 fSortProjects.setText(RefactoringUIMessages.BrowseRefactoringHistoryControl_sort_project); 237 fSortProjects.setToolTipText(RefactoringUIMessages.BrowseRefactoringHistoryControl_sort_project); 238 fSortProjects.setDescription(RefactoringUIMessages.BrowseRefactoringHistoryControl_sort_project_description); 239 fSortProjects.setImageDescriptor(RefactoringPluginImages.DESC_ELCL_SORT_PROJECT); 240 fSortProjects.setDisabledImageDescriptor(RefactoringPluginImages.DESC_DLCL_SORT_PROJECT); 241 fSortTimestamps.setText(RefactoringUIMessages.BrowseRefactoringHistoryControl_sort_date); 242 fSortTimestamps.setToolTipText(RefactoringUIMessages.BrowseRefactoringHistoryControl_sort_date); 243 fSortTimestamps.setDescription(RefactoringUIMessages.BrowseRefactoringHistoryControl_sort_date_description); 244 fSortTimestamps.setImageDescriptor(RefactoringPluginImages.DESC_ELCL_SORT_DATE); 245 fSortTimestamps.setDisabledImageDescriptor(RefactoringPluginImages.DESC_DLCL_SORT_DATE); 246 manager.appendToGroup(TOOLBAR_SORT_GROUP, fSortProjects); 247 manager.appendToGroup(TOOLBAR_SORT_GROUP, fSortTimestamps); 248 manager.update(true); 249 } 250 } 251 252 255 protected int getContainerColumns() { 256 return 1; 257 } 258 259 262 protected RefactoringHistoryContentProvider getContentProvider() { 263 return new BrowseRefactoringHistoryContentProvider(fControlConfiguration); 264 } 265 266 271 public Button getDeselectAllButton() { 272 return fDeselectAllButton; 273 } 274 275 278 protected RefactoringHistoryLabelProvider getLabelProvider() { 279 return new BrowseRefactoringHistoryLabelProvider(fControlConfiguration); 280 } 281 282 287 public Button getSelectAllButton() { 288 return fSelectAllButton; 289 } 290 291 296 protected ToolBarManager getToolBarManager() { 297 if (fToolBarManager == null) { 298 final ToolBar toolbar= new ToolBar(fHistoryPane, SWT.FLAT); 299 fHistoryPane.setTopCenter(toolbar); 300 fToolBarManager= new ToolBarManager(toolbar); 301 } 302 return fToolBarManager; 303 } 304 305 308 protected void handleCheckStateChanged() { 309 super.handleCheckStateChanged(); 310 final RefactoringHistory history= getInput(); 311 if (history != null) { 312 final int checked= getCheckedDescriptors().length; 313 final int total= history.getDescriptors().length; 314 if (fSelectAllButton != null) 315 fSelectAllButton.setEnabled(checked < total); 316 if (fDeselectAllButton != null) 317 fDeselectAllButton.setEnabled(checked > 0); 318 } 319 } 320 321 324 protected void handleDeselectAll() { 325 setCheckedDescriptors(EMPTY_DESCRIPTORS); 326 } 327 328 331 protected void handleSelectAll() { 332 final RefactoringHistory history= getInput(); 333 if (history != null) 334 setCheckedDescriptors(history.getDescriptors()); 335 } 336 337 343 public boolean isSortByDate() { 344 return !isSortByProjects(); 345 } 346 347 353 public boolean isSortByProjects() { 354 final IContentProvider provider= fHistoryViewer.getContentProvider(); 355 if (provider instanceof BrowseRefactoringHistoryContentProvider) { 356 final BrowseRefactoringHistoryContentProvider extended= (BrowseRefactoringHistoryContentProvider) provider; 357 return extended.isSortProjects(); 358 } 359 return false; 360 } 361 362 365 public void setInput(final RefactoringHistory history) { 366 super.setInput(history); 367 if (fDeselectAllButton != null) 368 fDeselectAllButton.setEnabled(false); 369 if (fSelectAllButton != null) 370 fSelectAllButton.setEnabled(history != null && !history.isEmpty()); 371 } 372 373 376 public void sortByDate() { 377 fSortTimestamps.run(); 378 } 379 380 383 public void sortByProjects() { 384 fSortProjects.run(); 385 } 386 } | Popular Tags |