KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > ui > refactoring > RefactoringWizardDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
29  * A dialog to host refactoring wizards.
30  */

31 public class RefactoringWizardDialog extends WizardDialog {
32
33     private static final String JavaDoc DIALOG_SETTINGS= "RefactoringWizard"; //$NON-NLS-1$
34
private static final String JavaDoc WIDTH= "width"; //$NON-NLS-1$
35
private static final String JavaDoc HEIGHT= "height"; //$NON-NLS-1$
36

37     private IDialogSettings fSettings;
38     
39     /*
40      * note: this field must not be initialized - setter is called in the call to super
41      * and java initializes fields 'after' the call to super is made. So initializing
42      * would override setting.
43      */

44     private boolean fMakeNextButtonDefault;
45
46     /**
47      * Creates a new refactoring wizard dialog with the given wizard.
48      *
49      * @param parent the parent shell
50      * @param wizard the refactoring wizard
51      */

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 JavaDoc 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 JavaDoc e) {
76             }
77         }
78         setMinimumPageSize(width, height);
79     }
80     
81     /**
82      * {@inheritDoc}
83      */

84     protected void configureShell(Shell newShell) {
85         super.configureShell(newShell);
86         getRefactoringWizard().getRefactoring().setValidationContext(newShell);
87     }
88     
89     /**
90      * {@inheritDoc}
91      */

92     protected void cancelPressed() {
93         storeCurrentSize();
94         super.cancelPressed();
95     }
96     
97     /*
98      * @see WizardDialog#finishPressed()
99      */

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     /*
114      * @see IWizardContainer#updateButtons()
115      */

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     /* usually called in the IWizard#setContainer(IWizardContainer) method
128      */

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