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.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Button;
18 import org.eclipse.swt.widgets.Composite;
19 import org.eclipse.swt.widgets.Label;
20 import org.eclipse.swt.widgets.Text;
23 /** <p>the input page for the Rename Property refactoring, where users can
24 * control the effects of the refactoring; to be shown in the wizard.</p>
26 * <p>We let the user enter the new name for the property, and we let her
27 * decide whether other property files in the bundle should be affected, and
28 * whether the operation is supposed to span the entire workspace or only
29 * the current project.</p>
32 public class RenameLocalVariablePage extends UserInputWizardPage {
34 private static final String DS_KEY = RenameLocalVariablePage.class.getName();
35 private static final String DS_UPDATE_BUNDLE = "UPDATE_BUNDLE"; //$NON-NLS-1$
36 private static final String DS_ALL_PROJECTS = "ALL_PROJECTS"; //$NON-NLS-1$
38 private final RenameIdentifierInfo info;
40 private IDialogSettings dialogSettings;
41 private Text txtNewName;
44 public RenameLocalVariablePage( final RenameIdentifierInfo info ) {
45 super( RenameLocalVariablePage.class.getName() );
51 // interface methods of UserInputWizardPage
52 ///////////////////////////////////////////
54 public void createControl( final Composite parent ) {
55 Composite composite = createRootComposite( parent );
56 setControl( composite );
58 createLblNewName( composite );
59 createTxtNewName( composite );
60 createCbUpdateBundle( composite );
61 createCbAllProjects( composite );
67 // UI creation methods
68 //////////////////////
70 private Composite createRootComposite( final Composite parent ) {
71 Composite result = new Composite( parent, SWT.NONE );
72 GridLayout gridLayout = new GridLayout( 2, false );
73 gridLayout.marginWidth = 10;
74 gridLayout.marginHeight = 10;
75 result.setLayout( gridLayout );
76 initializeDialogUnits( result );
77 Dialog.applyDialogFont( result );
81 private void createLblNewName( final Composite composite ) {
82 Label lblNewName = new Label( composite, SWT.NONE );
83 lblNewName.setText( UITexts.renamePropertyInputPage_lblNewName );
86 private void createTxtNewName(Composite composite) {
87 txtNewName = new Text( composite, SWT.BORDER );
88 txtNewName.setText( info.getOldName() );
89 txtNewName.setLayoutData( new GridData( GridData.FILL_HORIZONTAL ) );
90 txtNewName.selectAll();
91 txtNewName.addKeyListener( new KeyAdapter() {
92 public void keyReleased( final KeyEvent e ) {
93 info.setNewName( txtNewName.getText() );
99 private void createCbUpdateBundle( final Composite composite ) {
100 String texts = UITexts.renamePropertyInputPage_cbUpdateBundle;
101 initUpdateBundleOption();
104 private void createCbAllProjects( final Composite composite ) {
105 String text = UITexts.renamePropertyInputPage_cbAllProjects;
106 initAllProjectsOption();
109 private Button createCheckbox( final Composite composite,
110 final String text ) {
111 Button result = new Button( composite, SWT.CHECK );
112 result.setText( text );
114 GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
115 gridData.horizontalSpan = 2;
116 result.setLayoutData( gridData );
125 private void initDialogSettings() {
126 IDialogSettings ds = PHPeclipsePlugin.getDefault().getDialogSettings();
127 dialogSettings = ds.getSection( DS_KEY );
128 if( dialogSettings == null ) {
129 dialogSettings = ds.addNewSection( DS_KEY );
130 // init default values
131 dialogSettings.put( DS_UPDATE_BUNDLE, true );
132 dialogSettings.put( DS_ALL_PROJECTS, false );
136 private void validate() {
137 String txt = txtNewName.getText();
138 setPageComplete( txt.length() > 0 && !txt.equals( info.getOldName() ) );
141 private void initUpdateBundleOption() {
142 // boolean updateRefs = dialogSettings.getBoolean( DS_UPDATE_BUNDLE );
143 // cbUpdateBundle.setSelection( updateRefs );
144 // info.setUpdateProject( updateRefs );
147 private void initAllProjectsOption() {
148 // boolean allProjects = dialogSettings.getBoolean( DS_ALL_PROJECTS );
149 // cbAllProjects.setSelection( allProjects );
150 // info.setAllProjects( allProjects );