9a536cecc0bd1de9569a9f8c6356ec8b8a81b5e5
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / ltk / ui / wizards / RenameLocalVariablePage.java
1 // Copyright (c) 2005 by Leif Frenzel. All rights reserved.
2 // See http://leiffrenzel.de
3 package net.sourceforge.phpdt.ltk.ui.wizards;
4
5 import net.sourceforge.phpdt.ltk.core.RenameIdentifierInfo;
6 import net.sourceforge.phpdt.ltk.ui.UITexts;
7 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
8
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;
21
22
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>
25   *
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>
30   *
31   */
32 public class RenameLocalVariablePage extends UserInputWizardPage {
33
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$
37
38   private final RenameIdentifierInfo info;
39
40   private IDialogSettings dialogSettings;
41   private Text txtNewName;
42
43
44   public RenameLocalVariablePage( final RenameIdentifierInfo info ) {
45     super( RenameLocalVariablePage.class.getName() );
46     this.info = info;
47     initDialogSettings();
48   }
49
50
51   // interface methods of UserInputWizardPage
52   ///////////////////////////////////////////
53
54   public void createControl( final Composite parent ) {
55     Composite composite = createRootComposite( parent );
56     setControl( composite );
57
58     createLblNewName( composite );
59     createTxtNewName( composite );
60     createCbUpdateBundle( composite );
61     createCbAllProjects( composite );
62
63     validate();
64   }
65
66
67   // UI creation methods
68   //////////////////////
69
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 );
78     return result;
79   }
80
81   private void createLblNewName( final Composite composite ) {
82     Label lblNewName = new Label( composite, SWT.NONE );
83     lblNewName.setText( UITexts.renamePropertyInputPage_lblNewName );
84   }
85
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() );
94         validate();
95       }
96     } );
97   }
98
99   private void createCbUpdateBundle( final Composite composite ) {
100     String texts = UITexts.renamePropertyInputPage_cbUpdateBundle;
101     initUpdateBundleOption();
102   }
103
104   private void createCbAllProjects( final Composite composite ) {
105     String text = UITexts.renamePropertyInputPage_cbAllProjects;
106     initAllProjectsOption();
107   }
108
109   private Button createCheckbox( final Composite composite,
110                                  final String text ) {
111     Button result = new Button( composite, SWT.CHECK );
112     result.setText( text );
113
114     GridData gridData = new GridData( GridData.FILL_HORIZONTAL );
115     gridData.horizontalSpan = 2;
116     result.setLayoutData( gridData );
117
118     return result;
119   }
120
121
122   // helping methods
123   //////////////////
124
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 );
133     }
134   }
135
136   private void validate() {
137     String txt = txtNewName.getText();
138     setPageComplete( txt.length() > 0 && !txt.equals( info.getOldName() ) );
139   }
140
141   private void initUpdateBundleOption() {
142 //    boolean updateRefs = dialogSettings.getBoolean( DS_UPDATE_BUNDLE );
143 //    cbUpdateBundle.setSelection( updateRefs );
144 //    info.setUpdateProject( updateRefs );
145   }
146
147   private void initAllProjectsOption() {
148 //    boolean allProjects = dialogSettings.getBoolean( DS_ALL_PROJECTS );
149 //    cbAllProjects.setSelection( allProjects );
150 //    info.setAllProjects( allProjects );
151   }
152 }