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;
26 * the input page for the Rename Property refactoring, where users can control
27 * the effects of the refactoring; to be shown in the wizard.
31 * We let the user enter the new name for the property, and we let her decide
32 * whether other property files in the bundle should be affected, and whether
33 * the operation is supposed to span the entire workspace or only the current
38 public class RenameIdentifierPage extends UserInputWizardPage {
40 private static final String DS_KEY = RenameIdentifierPage.class.getName();
42 private static final String DS_UPDATE_BUNDLE = "UPDATE_BUNDLE"; //$NON-NLS-1$
44 private static final String DS_ALL_PROJECTS = "ALL_PROJECTS"; //$NON-NLS-1$
46 private final RenameIdentifierInfo info;
48 private IDialogSettings dialogSettings;
50 private Text txtNewName;
52 private Button cbUpdateBundle;
54 private Button cbAllProjects;
56 public RenameIdentifierPage(final RenameIdentifierInfo info) {
57 super(RenameIdentifierPage.class.getName());
62 // interface methods of UserInputWizardPage
63 // /////////////////////////////////////////
65 public void createControl(final Composite parent) {
66 Composite composite = createRootComposite(parent);
67 setControl(composite);
69 createLblNewName(composite);
70 createTxtNewName(composite);
71 createCbUpdateBundle(composite);
72 createCbAllProjects(composite);
77 // UI creation methods
78 // ////////////////////
80 private Composite createRootComposite(final Composite parent) {
81 Composite result = new Composite(parent, SWT.NONE);
82 GridLayout gridLayout = new GridLayout(2, false);
83 gridLayout.marginWidth = 10;
84 gridLayout.marginHeight = 10;
85 result.setLayout(gridLayout);
86 initializeDialogUnits(result);
87 Dialog.applyDialogFont(result);
91 private void createLblNewName(final Composite composite) {
92 Label lblNewName = new Label(composite, SWT.NONE);
93 lblNewName.setText(UITexts.renamePropertyInputPage_lblNewName);
96 private void createTxtNewName(Composite composite) {
97 txtNewName = new Text(composite, SWT.BORDER);
98 txtNewName.setText(info.getOldName());
99 txtNewName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
100 txtNewName.selectAll();
101 txtNewName.addKeyListener(new KeyAdapter() {
102 public void keyReleased(final KeyEvent e) {
103 info.setNewName(txtNewName.getText());
109 private void createCbUpdateBundle(final Composite composite) {
110 String texts = UITexts.renamePropertyInputPage_cbUpdateBundle;
111 cbUpdateBundle = createCheckbox(composite, texts);
112 cbUpdateBundle.addSelectionListener(new SelectionAdapter() {
113 public void widgetSelected(final SelectionEvent event) {
114 boolean selected = cbUpdateBundle.getSelection();
115 dialogSettings.put(DS_UPDATE_BUNDLE, selected);
116 info.setUpdateProject(selected);
119 initUpdateBundleOption();
122 private void createCbAllProjects(final Composite composite) {
123 String text = UITexts.renamePropertyInputPage_cbAllProjects;
124 cbAllProjects = createCheckbox(composite, text);
125 cbAllProjects.addSelectionListener(new SelectionAdapter() {
126 public void widgetSelected(final SelectionEvent event) {
127 boolean selected = cbAllProjects.getSelection();
128 dialogSettings.put(DS_ALL_PROJECTS, selected);
129 info.setAllProjects(selected);
130 // for demonstration purposes, we enforce the preview for
132 // that span the entire workspace
133 getRefactoringWizard().setForcePreviewReview(selected);
136 initAllProjectsOption();
139 private Button createCheckbox(final Composite composite, final String text) {
140 Button result = new Button(composite, SWT.CHECK);
141 result.setText(text);
143 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
144 gridData.horizontalSpan = 2;
145 result.setLayoutData(gridData);
153 private void initDialogSettings() {
154 IDialogSettings ds = PHPeclipsePlugin.getDefault().getDialogSettings();
155 dialogSettings = ds.getSection(DS_KEY);
156 if (dialogSettings == null) {
157 dialogSettings = ds.addNewSection(DS_KEY);
158 // init default values
159 dialogSettings.put(DS_UPDATE_BUNDLE, true);
160 dialogSettings.put(DS_ALL_PROJECTS, false);
164 private void validate() {
165 String txt = txtNewName.getText();
166 setPageComplete(txt.length() > 0 && !txt.equals(info.getOldName()));
169 private void initUpdateBundleOption() {
170 boolean updateRefs = dialogSettings.getBoolean(DS_UPDATE_BUNDLE);
171 cbUpdateBundle.setSelection(updateRefs);
172 info.setUpdateProject(updateRefs);
175 private void initAllProjectsOption() {
176 boolean allProjects = dialogSettings.getBoolean(DS_ALL_PROJECTS);
177 cbAllProjects.setSelection(allProjects);
178 info.setAllProjects(allProjects);