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 RenameLocalVariablePage extends UserInputWizardPage {
36 private static final String DS_KEY = RenameLocalVariablePage.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;
46 public RenameLocalVariablePage( final RenameIdentifierInfo info ) {
47 super( RenameLocalVariablePage.class.getName() );
53 // interface methods of UserInputWizardPage
54 ///////////////////////////////////////////
56 public void createControl( final Composite parent ) {
57 Composite composite = createRootComposite( parent );
58 setControl( composite );
60 createLblNewName( composite );
61 createTxtNewName( composite );
62 createCbUpdateBundle( composite );
63 createCbAllProjects( composite );
69 // UI creation methods
70 //////////////////////
72 private Composite createRootComposite( final Composite parent ) {
73 Composite result = new Composite( parent, SWT.NONE );
74 GridLayout gridLayout = new GridLayout( 2, false );
75 gridLayout.marginWidth = 10;
76 gridLayout.marginHeight = 10;
77 result.setLayout( gridLayout );
78 initializeDialogUnits( result );
79 Dialog.applyDialogFont( result );
83 private void createLblNewName( final Composite composite ) {
84 Label lblNewName = new Label( composite, SWT.NONE );
85 lblNewName.setText( UITexts.renamePropertyInputPage_lblNewName );
88 private void createTxtNewName(Composite composite) {
89 txtNewName = new Text( composite, SWT.BORDER );
90 txtNewName.setText( info.getOldName() );
91 txtNewName.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
92 txtNewName.selectAll();
93 txtNewName.addKeyListener( new KeyAdapter() {
94 public void keyReleased( final KeyEvent e ) {
95 info.setNewName( txtNewName.getText() );
101 private void createCbUpdateBundle( final Composite composite ) {
102 String texts = UITexts.renamePropertyInputPage_cbUpdateBundle;
103 initUpdateBundleOption();
106 private void createCbAllProjects( final Composite composite ) {
107 String text = UITexts.renamePropertyInputPage_cbAllProjects;
108 initAllProjectsOption();
111 private Button createCheckbox( final Composite composite,
112 final String text ) {
113 Button result = new Button( composite, SWT.CHECK );
114 result.setText( text );
116 GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
117 gridData.horizontalSpan = 2;
118 result.setLayoutData( gridData );
127 private void initDialogSettings() {
128 IDialogSettings ds = PHPeclipsePlugin.getDefault().getDialogSettings();
129 dialogSettings = ds.getSection( DS_KEY );
130 if( dialogSettings == null ) {
131 dialogSettings = ds.addNewSection( DS_KEY );
132 // init default values
133 dialogSettings.put( DS_UPDATE_BUNDLE, true );
134 dialogSettings.put( DS_ALL_PROJECTS, false );
138 private void validate() {
139 String txt = txtNewName.getText();
140 setPageComplete( txt.length() > 0 && !txt.equals( info.getOldName() ) );
143 private void initUpdateBundleOption() {
144 // boolean updateRefs = dialogSettings.getBoolean( DS_UPDATE_BUNDLE );
145 // cbUpdateBundle.setSelection( updateRefs );
146 // info.setUpdateProject( updateRefs );
149 private void initAllProjectsOption() {
150 // boolean allProjects = dialogSettings.getBoolean( DS_ALL_PROJECTS );
151 // cbAllProjects.setSelection( allProjects );
152 // info.setAllProjects( allProjects );