1 11 12 package org.eclipse.ltk.internal.ui.refactoring; 13 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.graphics.Point; 16 import org.eclipse.swt.widgets.Button; 17 import org.eclipse.swt.widgets.Control; 18 import org.eclipse.swt.widgets.Shell; 19 20 import org.eclipse.jface.dialogs.DialogSettings; 21 import org.eclipse.jface.dialogs.IDialogConstants; 22 import org.eclipse.jface.dialogs.IDialogSettings; 23 import org.eclipse.jface.wizard.IWizardPage; 24 import org.eclipse.jface.wizard.WizardDialog; 25 26 import org.eclipse.ltk.ui.refactoring.RefactoringWizard; 27 28 31 public class RefactoringWizardDialog extends WizardDialog { 32 33 private static final String DIALOG_SETTINGS= "RefactoringWizard"; private static final String WIDTH= "width"; private static final String HEIGHT= "height"; 37 private IDialogSettings fSettings; 38 39 44 private boolean fMakeNextButtonDefault; 45 46 52 public RefactoringWizardDialog(Shell parent, RefactoringWizard wizard) { 53 super(parent, wizard); 54 setShellStyle(getShellStyle() | SWT.RESIZE | SWT.MAX); 55 IDialogSettings settings= wizard.getDialogSettings(); 56 if (settings == null) { 57 settings= RefactoringUIPlugin.getDefault().getDialogSettings(); 58 wizard.setDialogSettings(settings); 59 } 60 61 int width= 600; 62 int height= 400; 63 64 String settingsSectionId= DIALOG_SETTINGS + '.'+ wizard.getRefactoring().getName(); 65 fSettings= settings.getSection(settingsSectionId); 66 if (fSettings == null) { 67 fSettings= new DialogSettings(settingsSectionId); 68 settings.addSection(fSettings); 69 fSettings.put(WIDTH, width); 70 fSettings.put(HEIGHT, height); 71 } else { 72 try { 73 width= fSettings.getInt(WIDTH); 74 height= fSettings.getInt(HEIGHT); 75 } catch (NumberFormatException e) { 76 } 77 } 78 setMinimumPageSize(width, height); 79 } 80 81 84 protected void configureShell(Shell newShell) { 85 super.configureShell(newShell); 86 getRefactoringWizard().getRefactoring().setValidationContext(newShell); 87 } 88 89 92 protected void cancelPressed() { 93 storeCurrentSize(); 94 super.cancelPressed(); 95 } 96 97 100 protected void finishPressed() { 101 storeCurrentSize(); 102 super.finishPressed(); 103 } 104 105 private void storeCurrentSize() { 106 IWizardPage page= getCurrentPage(); 107 Control control= page.getControl().getParent(); 108 Point size = control.getSize(); 109 fSettings.put(WIDTH, size.x); 110 fSettings.put(HEIGHT, size.y); 111 } 112 113 116 public void updateButtons() { 117 super.updateButtons(); 118 if (! fMakeNextButtonDefault) 119 return; 120 if (getShell() == null) 121 return; 122 Button next= getButton(IDialogConstants.NEXT_ID); 123 if (next.isEnabled()) 124 getShell().setDefaultButton(next); 125 } 126 127 129 public void makeNextButtonDefault() { 130 fMakeNextButtonDefault= true; 131 } 132 133 public Button getCancelButton() { 134 return getButton(IDialogConstants.CANCEL_ID); 135 } 136 137 private RefactoringWizard getRefactoringWizard() { 138 return (RefactoringWizard)getWizard(); 139 } 140 } 141 | Popular Tags |