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.RenameIdentifierInfo;
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>
34 public class RenameIdentifierPage extends UserInputWizardPage {
36 private static final String DS_KEY = RenameIdentifierPage.class.getName();
37 private static final String DS_UPDATE_BUNDLE = "UPDATE_BUNDLE"; //$NON-NLS-1$
38 private static final String DS_ALL_PROJECTS = "ALL_PROJECTS"; //$NON-NLS-1$
40 private final RenameIdentifierInfo info;
42 private IDialogSettings dialogSettings;
43 private Text txtNewName;
44 private Button cbUpdateBundle;
45 private Button cbAllProjects;
48 public RenameIdentifierPage( final RenameIdentifierInfo info ) {
49 super( RenameIdentifierPage.class.getName() );
55 // interface methods of UserInputWizardPage
56 ///////////////////////////////////////////
58 public void createControl( final Composite parent ) {
59 Composite composite = createRootComposite( parent );
60 setControl( composite );
62 createLblNewName( composite );
63 createTxtNewName( composite );
64 createCbUpdateBundle( composite );
65 createCbAllProjects( composite );
71 // UI creation methods
72 //////////////////////
74 private Composite createRootComposite( final Composite parent ) {
75 Composite result = new Composite( parent, SWT.NONE );
76 GridLayout gridLayout = new GridLayout( 2, false );
77 gridLayout.marginWidth = 10;
78 gridLayout.marginHeight = 10;
79 result.setLayout( gridLayout );
80 initializeDialogUnits( result );
81 Dialog.applyDialogFont( result );
85 private void createLblNewName( final Composite composite ) {
86 Label lblNewName = new Label( composite, SWT.NONE );
87 lblNewName.setText( UITexts.renamePropertyInputPage_lblNewName );
90 private void createTxtNewName(Composite composite) {
91 txtNewName = new Text( composite, SWT.BORDER );
92 txtNewName.setText( info.getOldName() );
93 txtNewName.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
94 txtNewName.selectAll();
95 txtNewName.addKeyListener( new KeyAdapter() {
96 public void keyReleased( final KeyEvent e ) {
97 info.setNewName( txtNewName.getText() );
103 private void createCbUpdateBundle( final Composite composite ) {
104 String texts = UITexts.renamePropertyInputPage_cbUpdateBundle;
105 cbUpdateBundle = createCheckbox( composite, texts );
106 cbUpdateBundle.addSelectionListener( new SelectionAdapter() {
107 public void widgetSelected( final SelectionEvent event ) {
108 boolean selected = cbUpdateBundle.getSelection();
109 dialogSettings.put( DS_UPDATE_BUNDLE, selected );
110 info.setUpdateProject( selected );
113 initUpdateBundleOption();
116 private void createCbAllProjects( final Composite composite ) {
117 String text = UITexts.renamePropertyInputPage_cbAllProjects;
118 cbAllProjects = createCheckbox( composite, text );
119 cbAllProjects.addSelectionListener( new SelectionAdapter() {
120 public void widgetSelected( final SelectionEvent event ) {
121 boolean selected = cbAllProjects.getSelection();
122 dialogSettings.put( DS_ALL_PROJECTS, selected );
123 info.setAllProjects( selected );
124 // for demonstration purposes, we enforce the preview for refactorings
125 // that span the entire workspace
126 getRefactoringWizard().setForcePreviewReview( selected );
129 initAllProjectsOption();
132 private Button createCheckbox( final Composite composite,
133 final String text ) {
134 Button result = new Button( composite, SWT.CHECK );
135 result.setText( text );
137 GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
138 gridData.horizontalSpan = 2;
139 result.setLayoutData( gridData );
148 private void initDialogSettings() {
149 IDialogSettings ds = PHPeclipsePlugin.getDefault().getDialogSettings();
150 dialogSettings = ds.getSection( DS_KEY );
151 if( dialogSettings == null ) {
152 dialogSettings = ds.addNewSection( DS_KEY );
153 // init default values
154 dialogSettings.put( DS_UPDATE_BUNDLE, true );
155 dialogSettings.put( DS_ALL_PROJECTS, false );
159 private void validate() {
160 String txt = txtNewName.getText();
161 setPageComplete( txt.length() > 0 && !txt.equals( info.getOldName() ) );
164 private void initUpdateBundleOption() {
165 boolean updateRefs = dialogSettings.getBoolean( DS_UPDATE_BUNDLE );
166 cbUpdateBundle.setSelection( updateRefs );
167 info.setUpdateProject( updateRefs );
170 private void initAllProjectsOption() {
171 boolean allProjects = dialogSettings.getBoolean( DS_ALL_PROJECTS );
172 cbAllProjects.setSelection( allProjects );
173 info.setAllProjects( allProjects );