1 11 package org.eclipse.team.internal.ui.dialogs; 12 13 import org.eclipse.jface.dialogs.*; 14 import org.eclipse.jface.dialogs.Dialog; 15 import org.eclipse.jface.resource.JFaceResources; 16 import org.eclipse.swt.SWT; 17 import org.eclipse.swt.graphics.Image; 18 import org.eclipse.swt.graphics.Point; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.*; 22 import org.eclipse.ui.PlatformUI; 23 24 27 abstract public class DetailsDialog extends TrayDialog { 28 31 private Button detailsButton; 32 33 36 private Button okButton; 37 38 41 private String title; 42 43 46 private Label errorMessageLabel; 47 48 51 private Composite detailsComposite; 52 53 56 private boolean detailsCreated = false; 57 58 61 private String imageKey = null; 62 63 72 public DetailsDialog(Shell parentShell, String dialogTitle) { 73 super(parentShell); 74 this.title = dialogTitle; 75 initializeStyle(); 76 } 77 78 protected void initializeStyle() { 79 setShellStyle(SWT.DIALOG_TRIM | SWT.RESIZE | SWT.APPLICATION_MODAL); 80 } 81 82 90 protected void buttonPressed(int id) { 91 if (id == IDialogConstants.DETAILS_ID) { toggleDetailsArea(); 93 } else { 94 super.buttonPressed(id); 95 } 96 } 97 98 101 protected void configureShell(Shell shell) { 102 super.configureShell(shell); 103 shell.setText(title); 104 String helpContextId = getHelpContextId(); 105 if (helpContextId != null) { 106 PlatformUI.getWorkbench().getHelpSystem().setHelp(shell, helpContextId); 107 } 108 } 109 110 113 protected void createButtonsForButtonBar(Composite parent) { 114 if(includeOkButton()) { 116 okButton = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true); 117 } 118 if (includeCancelButton()) { 119 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); 120 } 121 if(includeDetailsButton()) { 122 detailsButton = createButton(parent, IDialogConstants.DETAILS_ID, getDetailsButtonLabelShow(), false); 123 } 124 updateEnablements(); 125 } 126 127 protected String getDetailsButtonLabelShow() { 128 return IDialogConstants.SHOW_DETAILS_LABEL; 129 } 130 131 protected String getDetailsButtonLabelHide() { 132 return IDialogConstants.HIDE_DETAILS_LABEL; 133 } 134 135 140 final protected Control createDialogArea(Composite parent) { 141 142 applyDialogFont(parent); 143 initializeDialogUnits(parent); 144 145 Composite composite = (Composite)super.createDialogArea(parent); 147 if (!isMainGrabVertical()) { 148 composite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); 149 } 150 151 String helpContextId = getHelpContextId(); 152 if (helpContextId != null) { 153 PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, helpContextId); 154 } 155 156 String key = getImageKey(); 158 Image image = null; 159 if (key != null) { 160 image = JFaceResources.getImageRegistry().get(key); 161 } 162 if (image != null) { 163 Composite top = new Composite(composite, SWT.NONE); 165 GridLayout layout = new GridLayout(); 166 layout.marginHeight = 0; 167 layout.marginWidth = 0; 168 layout.verticalSpacing = 0; 169 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 170 layout.numColumns = 2; 171 top.setLayout(layout); 172 top.setLayoutData(new GridData(GridData.FILL_BOTH)); 173 174 Label label = new Label(top, 0); 176 image.setBackground(label.getBackground()); 177 label.setImage(image); 178 label.setLayoutData(new GridData( 179 GridData.HORIZONTAL_ALIGN_CENTER | 180 GridData.VERTICAL_ALIGN_BEGINNING)); 181 182 Composite right = new Composite(top, SWT.NONE); 184 layout = new GridLayout(); 185 layout.marginHeight = 0; 186 layout.marginWidth = 0; 187 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 188 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 189 right.setLayout(layout); 190 right.setLayoutData(new GridData(GridData.FILL_BOTH)); 191 createMainDialogArea(right); 192 } else { 193 createMainDialogArea(composite); 194 } 195 196 if(includeErrorMessage()) { 197 errorMessageLabel = new Label(composite, SWT.NONE); 198 errorMessageLabel.setLayoutData(new GridData( 199 GridData.GRAB_HORIZONTAL | 200 GridData.HORIZONTAL_ALIGN_FILL)); 201 errorMessageLabel.setForeground(getShell().getDisplay().getSystemColor(SWT.COLOR_RED)); 202 } 203 204 Dialog.applyDialogFont(parent); 205 return composite; 206 } 207 208 214 protected String getHelpContextId() { 215 return null; 216 } 217 218 225 protected boolean isMainGrabVertical() { 226 return true; 227 } 228 229 234 abstract protected void createMainDialogArea(Composite parent); 235 236 242 abstract protected Composite createDropDownDialogArea(Composite parent); 243 244 248 private void toggleDetailsArea() { 249 Point windowSize = getShell().getSize(); 250 Point oldSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT); 251 252 if (detailsCreated) { 253 detailsComposite.dispose(); 254 detailsCreated = false; 255 detailsButton.setText(getDetailsButtonLabelShow()); 256 } else { 257 detailsComposite = createDropDownDialogArea((Composite)getContents()); 258 detailsCreated = true; 259 detailsButton.setText(getDetailsButtonLabelHide()); 260 } 261 Dialog.applyDialogFont(getContents()); 262 Point newSize = getContents().computeSize(SWT.DEFAULT, SWT.DEFAULT); 263 264 getShell().setSize(new Point(windowSize.x, windowSize.y + (newSize.y - oldSize.y))); 265 } 266 267 final protected void setErrorMessage(String error) { 268 if(errorMessageLabel != null) { 269 if(error == null || error.length() == 0) { 270 errorMessageLabel.setText(""); } else { 272 errorMessageLabel.setText(error); 273 } 274 errorMessageLabel.update(); 275 } 276 } 277 278 final protected void setPageComplete(boolean complete) { 279 if(okButton != null ) { 280 okButton.setEnabled(complete); 281 } 282 } 283 284 abstract protected void updateEnablements(); 285 286 protected boolean includeCancelButton() { 287 return true; 288 } 289 290 protected boolean includeOkButton() { 291 return true; 292 } 293 294 298 protected String getImageKey() { 299 return imageKey; 300 } 301 302 303 307 protected void setImageKey(String imageKey) { 308 this.imageKey = imageKey; 309 } 310 311 protected Label createWrappingLabel(Composite parent, String text) { 312 Label label = new Label(parent, SWT.LEFT | SWT.WRAP); 313 label.setText(text); 314 GridData data = new GridData(); 315 data.horizontalSpan = 1; 316 data.horizontalAlignment = GridData.FILL; 317 data.horizontalIndent = 0; 318 data.grabExcessHorizontalSpace = true; 319 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH); 320 label.setLayoutData(data); 321 label.setFont(parent.getFont()); 322 return label; 323 } 324 325 protected Composite createComposite(Composite parent) { 326 Composite composite = new Composite(parent, SWT.NONE); 327 GridLayout layout = new GridLayout(); 328 composite.setLayout(layout); 329 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 330 composite.setFont(parent.getFont()); 331 return composite; 332 } 333 334 protected boolean isDetailsVisible() { 335 return detailsCreated; 336 } 337 338 protected boolean includeErrorMessage() { 339 return true; 340 } 341 342 protected boolean includeDetailsButton() { 343 return true; 344 } 345 } 346 | Popular Tags |