1 11 package org.eclipse.team.internal.ccvs.ui.wizards; 12 13 import org.eclipse.jface.dialogs.IDialogSettings; 14 import org.eclipse.jface.wizard.Wizard; 15 import org.eclipse.jface.wizard.WizardDialog; 16 import org.eclipse.swt.graphics.Point; 17 import org.eclipse.swt.graphics.Rectangle; 18 import org.eclipse.swt.widgets.Shell; 19 20 23 public class ResizableWizard extends Wizard { 24 25 private final int DEFAULT_WIDTH; 26 private final int DEFAULT_HEIGHT; 27 28 private static final String BOUNDS_HEIGHT_KEY = "width"; private static final String BOUNDS_WIDTH_KEY = "height"; 31 final String fSectionName; 32 33 public ResizableWizard(String sectionName, IDialogSettings settings) { 34 this(sectionName, settings, 300, 400); 35 } 36 37 protected ResizableWizard(String sectionName, IDialogSettings settings, int defaultWidth, int defaultHeight) { 38 DEFAULT_WIDTH= defaultWidth; 39 DEFAULT_HEIGHT= defaultHeight; 40 fSectionName= sectionName; 41 setDialogSettings(settings); 42 } 43 44 protected static int open(Shell shell, ResizableWizard wizard) { 45 final WizardDialog dialog= new WizardDialog(shell, wizard); 46 dialog.setMinimumPageSize(wizard.loadSize()); 47 return dialog.open(); 48 } 49 50 public void saveSize() { 51 final Rectangle bounds= getContainer().getCurrentPage().getControl().getParent().getClientArea(); 52 final IDialogSettings settings= getDialogSettings(); 53 if (settings == null) 54 return; 55 56 IDialogSettings section= settings.getSection(fSectionName); 57 if (section == null) 58 section= settings.addNewSection(fSectionName); 59 60 section.put(BOUNDS_WIDTH_KEY, bounds.width); 61 section.put(BOUNDS_HEIGHT_KEY, bounds.height); 62 } 63 64 public Point loadSize() { 65 final Point size= new Point(DEFAULT_WIDTH, DEFAULT_HEIGHT); 66 67 final IDialogSettings settings= getDialogSettings(); 68 if (settings == null) 69 return size; 70 71 final IDialogSettings section= settings.getSection(fSectionName); 72 if (section == null) 73 return size; 74 75 try { 76 size.x= section.getInt(BOUNDS_WIDTH_KEY); 77 size.y= section.getInt(BOUNDS_HEIGHT_KEY); 78 } catch (NumberFormatException e) { 79 } 80 return size; 81 } 82 83 84 public boolean performFinish() { 85 saveSize(); 86 return true; 87 } 88 } 89 | Popular Tags |