1 // Copyright (c) 2005 by Leif Frenzel. All rights reserved.
2 // See http://leiffrenzel.de
3 package net.sourceforge.phpdt.ltk.ui.wizards;
5 import net.sourceforge.phpdt.ltk.core.RenamePropertyInfo;
6 import net.sourceforge.phpdt.ltk.ui.UITexts;
7 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
9 import org.eclipse.jface.dialogs.Dialog;
10 import org.eclipse.jface.dialogs.IDialogSettings;
11 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
12 import org.eclipse.swt.SWT;
13 import org.eclipse.swt.events.KeyAdapter;
14 import org.eclipse.swt.events.KeyEvent;
15 import org.eclipse.swt.events.SelectionAdapter;
16 import org.eclipse.swt.events.SelectionEvent;
17 import org.eclipse.swt.layout.GridData;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Label;
22 import org.eclipse.swt.widgets.Text;
25 /** <p>the input page for the Rename Property refactoring, where users can
26 * control the effects of the refactoring; to be shown in the wizard.</p>
28 * <p>We let the user enter the new name for the property, and we let her
29 * decide whether other property files in the bundle should be affected, and
30 * whether the operation is supposed to span the entire workspace or only
31 * the current project.</p>
33 * @author Leif Frenzel
35 public class RenamePropertyInputPage extends UserInputWizardPage {
37 private static final String DS_KEY = RenamePropertyInputPage.class.getName();
38 private static final String DS_UPDATE_BUNDLE = "UPDATE_BUNDLE"; //$NON-NLS-1$
39 private static final String DS_ALL_PROJECTS = "ALL_PROJECTS"; //$NON-NLS-1$
41 private final RenamePropertyInfo info;
43 private IDialogSettings dialogSettings;
44 private Text txtNewName;
45 private Button cbUpdateBundle;
46 private Button cbAllProjects;
49 public RenamePropertyInputPage( final RenamePropertyInfo info ) {
50 super( RenamePropertyInputPage.class.getName() );
56 // interface methods of UserInputWizardPage
57 ///////////////////////////////////////////
59 public void createControl( final Composite parent ) {
60 Composite composite = createRootComposite( parent );
61 setControl( composite );
63 createLblNewName( composite );
64 createTxtNewName( composite );
65 createCbUpdateBundle( composite );
66 createCbAllProjects( composite );
72 // UI creation methods
73 //////////////////////
75 private Composite createRootComposite( final Composite parent ) {
76 Composite result = new Composite( parent, SWT.NONE );
77 GridLayout gridLayout = new GridLayout( 2, false );
78 gridLayout.marginWidth = 10;
79 gridLayout.marginHeight = 10;
80 result.setLayout( gridLayout );
81 initializeDialogUnits( result );
82 Dialog.applyDialogFont( result );
86 private void createLblNewName( final Composite composite ) {
87 Label lblNewName = new Label( composite, SWT.NONE );
88 lblNewName.setText( UITexts.renamePropertyInputPage_lblNewName );
91 private void createTxtNewName(Composite composite) {
92 txtNewName = new Text( composite, SWT.BORDER );
93 txtNewName.setText( info.getOldName() );
94 txtNewName.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
95 txtNewName.selectAll();
96 txtNewName.addKeyListener( new KeyAdapter() {
97 public void keyReleased( final KeyEvent e ) {
98 info.setNewName( txtNewName.getText() );
104 private void createCbUpdateBundle( final Composite composite ) {
105 String texts = UITexts.renamePropertyInputPage_cbUpdateBundle;
106 cbUpdateBundle = createCheckbox( composite, texts );
107 cbUpdateBundle.addSelectionListener( new SelectionAdapter() {
108 public void widgetSelected( final SelectionEvent event ) {
109 boolean selected = cbUpdateBundle.getSelection();
110 dialogSettings.put( DS_UPDATE_BUNDLE, selected );
111 info.setUpdateBundle( selected );
114 initUpdateBundleOption();
117 private void createCbAllProjects( final Composite composite ) {
118 String text = UITexts.renamePropertyInputPage_cbAllProjects;
119 cbAllProjects = createCheckbox( composite, text );
120 cbAllProjects.addSelectionListener( new SelectionAdapter() {
121 public void widgetSelected( final SelectionEvent event ) {
122 boolean selected = cbAllProjects.getSelection();
123 dialogSettings.put( DS_ALL_PROJECTS, selected );
124 info.setAllProjects( selected );
125 // for demonstration purposes, we enforce the preview for refactorings
126 // that span the entire workspace
127 getRefactoringWizard().setForcePreviewReview( selected );
130 initAllProjectsOption();
133 private Button createCheckbox( final Composite composite,
134 final String text ) {
135 Button result = new Button( composite, SWT.CHECK );
136 result.setText( text );
138 GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
139 gridData.horizontalSpan = 2;
140 result.setLayoutData( gridData );
149 private void initDialogSettings() {
150 IDialogSettings ds = PHPeclipsePlugin.getDefault().getDialogSettings();
151 dialogSettings = ds.getSection( DS_KEY );
152 if( dialogSettings == null ) {
153 dialogSettings = ds.addNewSection( DS_KEY );
154 // init default values
155 dialogSettings.put( DS_UPDATE_BUNDLE, true );
156 dialogSettings.put( DS_ALL_PROJECTS, false );
160 private void validate() {
161 String txt = txtNewName.getText();
162 setPageComplete( txt.length() > 0 && !txt.equals( info.getOldName() ) );
165 private void initUpdateBundleOption() {
166 boolean updateRefs = dialogSettings.getBoolean( DS_UPDATE_BUNDLE );
167 cbUpdateBundle.setSelection( updateRefs );
168 info.setUpdateBundle( updateRefs );
171 private void initAllProjectsOption() {
172 boolean allProjects = dialogSettings.getBoolean( DS_ALL_PROJECTS );
173 cbAllProjects.setSelection( allProjects );
174 info.setAllProjects( allProjects );