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.history.RefactoringHistory; 16 17 import org.eclipse.ltk.internal.ui.refactoring.RefactoringUIMessages; 18 import org.eclipse.ltk.internal.ui.refactoring.util.PixelConverter; 19 import org.eclipse.ltk.internal.ui.refactoring.util.SWTUtil; 20 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.layout.GridLayout; 24 import org.eclipse.swt.widgets.Button; 25 import org.eclipse.swt.widgets.Composite; 26 27 import org.eclipse.jface.dialogs.IDialogConstants; 28 import org.eclipse.jface.viewers.IStructuredSelection; 29 import org.eclipse.jface.viewers.TreeViewer; 30 31 import org.eclipse.ltk.ui.refactoring.history.RefactoringHistoryControlConfiguration; 32 33 39 public class ShowRefactoringHistoryControl extends SortableRefactoringHistoryControl { 40 41 42 private Button fDeleteAllButton= null; 43 44 45 private Button fDeleteButton= null; 46 47 48 private Button fEditButton= null; 49 50 58 public ShowRefactoringHistoryControl(final Composite parent, final RefactoringHistoryControlConfiguration configuration) { 59 super(parent, configuration); 60 } 61 62 65 protected void createBottomButtonBar(final Composite parent) { 66 } 68 69 72 public void createControl() { 73 super.createControl(); 74 final GridData data= new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL); 75 data.heightHint= new PixelConverter(this).convertHeightInCharsToPixels(24); 76 setLayoutData(data); 77 } 78 79 85 protected void createDeleteAllButton(final Composite parent) { 86 Assert.isNotNull(parent); 87 fDeleteAllButton= new Button(parent, SWT.NONE); 88 fDeleteAllButton.setEnabled(false); 89 fDeleteAllButton.setText(RefactoringUIMessages.ShowRefactoringHistoryControl_delete_all_label); 90 final GridData data= new GridData(); 91 data.horizontalAlignment= GridData.FILL; 92 data.grabExcessHorizontalSpace= true; 93 data.verticalAlignment= GridData.BEGINNING; 94 data.widthHint= SWTUtil.getButtonWidthHint(fDeleteAllButton); 95 fDeleteAllButton.setLayoutData(data); 96 } 97 98 106 protected void createDeleteButton(final Composite parent, final int alignment) { 107 Assert.isNotNull(parent); 108 fDeleteButton= new Button(parent, SWT.NONE); 109 fDeleteButton.setEnabled(false); 110 fDeleteButton.setText(RefactoringUIMessages.ShowRefactoringHistoryControl_delete_label); 111 final GridData data= new GridData(); 112 data.horizontalAlignment= alignment; 113 data.grabExcessHorizontalSpace= true; 114 data.verticalAlignment= GridData.BEGINNING; 115 data.widthHint= SWTUtil.getButtonWidthHint(fDeleteButton); 116 fDeleteButton.setLayoutData(data); 117 } 118 119 125 protected void createEditButton(final Composite parent) { 126 Assert.isNotNull(parent); 127 fEditButton= new Button(parent, SWT.NONE); 128 fEditButton.setEnabled(false); 129 fEditButton.setText(RefactoringUIMessages.ShowRefactoringHistoryControl_edit_label); 130 final GridData data= new GridData(); 131 data.verticalIndent= new PixelConverter(parent).convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 132 data.horizontalAlignment= GridData.FILL; 133 data.grabExcessHorizontalSpace= true; 134 data.verticalAlignment= GridData.BEGINNING; 135 data.widthHint= SWTUtil.getButtonWidthHint(fEditButton); 136 fEditButton.setLayoutData(data); 137 } 138 139 142 protected TreeViewer createHistoryViewer(final Composite parent) { 143 Assert.isNotNull(parent); 144 if (fControlConfiguration.isCheckableViewer()) 145 return new RefactoringHistoryTreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); 146 else 147 return new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI); 148 } 149 150 153 protected void createRightButtonBar(final Composite parent) { 154 Assert.isNotNull(parent); 155 final Composite composite= new Composite(parent, SWT.NONE); 156 final GridLayout layout= new GridLayout(1, false); 157 composite.setLayout(layout); 158 159 final GridData data= new GridData(); 160 data.grabExcessHorizontalSpace= false; 161 data.grabExcessVerticalSpace= true; 162 data.horizontalAlignment= SWT.FILL; 163 data.verticalAlignment= SWT.TOP; 164 composite.setLayoutData(data); 165 166 createDeleteButton(composite, GridData.FILL); 167 createDeleteAllButton(composite); 168 createEditButton(composite); 169 } 170 171 174 protected void createSelectionLabel(final Composite parent) { 175 } 177 178 181 protected int getContainerColumns() { 182 return 2; 183 } 184 185 190 public Button getDeleteAllButton() { 191 return fDeleteAllButton; 192 } 193 194 199 public Button getDeleteButton() { 200 return fDeleteButton; 201 } 202 203 206 protected int getDetailColumns() { 207 return 1; 208 } 209 210 215 public Button getEditButton() { 216 return fEditButton; 217 } 218 219 222 protected void handleCheckStateChanged() { 223 super.handleCheckStateChanged(); 224 if (fDeleteButton != null) 225 fDeleteButton.setEnabled(getCheckedDescriptors().length > 0); 226 } 227 228 231 protected void handleSelectionChanged(final IStructuredSelection selection) { 232 super.handleSelectionChanged(selection); 233 if (fEditButton != null) 234 fEditButton.setEnabled(getSelectedDescriptors().length == 1); 235 if (fDeleteButton != null) 236 fDeleteButton.setEnabled(getCheckedDescriptors().length > 0); 237 } 238 239 242 public void setInput(final RefactoringHistory history) { 243 super.setInput(history); 244 if (fDeleteAllButton != null) 245 fDeleteAllButton.setEnabled(history != null && !history.isEmpty()); 246 if (fDeleteButton != null) 247 fDeleteButton.setEnabled(false); 248 if (fEditButton != null) 249 fEditButton.setEnabled(false); 250 } 251 } 252 | Popular Tags |