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;
8 import net.sourceforge.phpeclipse.ui.WebUI;
10 import org.eclipse.jface.dialogs.Dialog;
11 import org.eclipse.jface.dialogs.IDialogSettings;
12 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
13 import org.eclipse.swt.SWT;
14 import org.eclipse.swt.events.KeyAdapter;
15 import org.eclipse.swt.events.KeyEvent;
16 import org.eclipse.swt.events.SelectionAdapter;
17 import org.eclipse.swt.events.SelectionEvent;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.Button;
21 import org.eclipse.swt.widgets.Composite;
22 import org.eclipse.swt.widgets.Label;
23 import org.eclipse.swt.widgets.Text;
27 * the input page for the Rename Property refactoring, where users can control
28 * the effects of the refactoring; to be shown in the wizard.
32 * We let the user enter the new name for the property, and we let her decide
33 * whether other property files in the bundle should be affected, and whether
34 * the operation is supposed to span the entire workspace or only the current
39 public class RenameIdentifierPage extends UserInputWizardPage {
41 private static final String DS_KEY = RenameIdentifierPage.class.getName();
43 private static final String DS_UPDATE_BUNDLE = "UPDATE_BUNDLE"; //$NON-NLS-1$
45 private static final String DS_ALL_PROJECTS = "ALL_PROJECTS"; //$NON-NLS-1$
47 private final RenameIdentifierInfo info;
49 private IDialogSettings dialogSettings;
51 private Text txtNewName;
53 private Button cbUpdateBundle;
55 private Button cbAllProjects;
57 public RenameIdentifierPage(final RenameIdentifierInfo info) {
58 super(RenameIdentifierPage.class.getName());
63 // interface methods of UserInputWizardPage
64 // /////////////////////////////////////////
66 public void createControl(final Composite parent) {
67 Composite composite = createRootComposite(parent);
68 setControl(composite);
70 createLblNewName(composite);
71 createTxtNewName(composite);
72 createCbUpdateBundle(composite);
73 createCbAllProjects(composite);
78 // UI creation methods
79 // ////////////////////
81 private Composite createRootComposite(final Composite parent) {
82 Composite result = new Composite(parent, SWT.NONE);
83 GridLayout gridLayout = new GridLayout(2, false);
84 gridLayout.marginWidth = 10;
85 gridLayout.marginHeight = 10;
86 result.setLayout(gridLayout);
87 initializeDialogUnits(result);
88 Dialog.applyDialogFont(result);
92 private void createLblNewName(final Composite composite) {
93 Label lblNewName = new Label(composite, SWT.NONE);
94 lblNewName.setText(UITexts.renamePropertyInputPage_lblNewName);
97 private void createTxtNewName(Composite composite) {
98 txtNewName = new Text(composite, SWT.BORDER);
99 txtNewName.setText(info.getOldName());
100 txtNewName.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
101 txtNewName.selectAll();
102 txtNewName.addKeyListener(new KeyAdapter() {
103 public void keyReleased(final KeyEvent e) {
104 info.setNewName(txtNewName.getText());
110 private void createCbUpdateBundle(final Composite composite) {
111 String texts = UITexts.renamePropertyInputPage_cbUpdateBundle;
112 cbUpdateBundle = createCheckbox(composite, texts);
113 cbUpdateBundle.addSelectionListener(new SelectionAdapter() {
114 public void widgetSelected(final SelectionEvent event) {
115 boolean selected = cbUpdateBundle.getSelection();
116 dialogSettings.put(DS_UPDATE_BUNDLE, selected);
117 info.setUpdateProject(selected);
120 initUpdateBundleOption();
123 private void createCbAllProjects(final Composite composite) {
124 String text = UITexts.renamePropertyInputPage_cbAllProjects;
125 cbAllProjects = createCheckbox(composite, text);
126 cbAllProjects.addSelectionListener(new SelectionAdapter() {
127 public void widgetSelected(final SelectionEvent event) {
128 boolean selected = cbAllProjects.getSelection();
129 dialogSettings.put(DS_ALL_PROJECTS, selected);
130 info.setAllProjects(selected);
131 // for demonstration purposes, we enforce the preview for
133 // that span the entire workspace
134 getRefactoringWizard().setForcePreviewReview(selected);
137 initAllProjectsOption();
140 private Button createCheckbox(final Composite composite, final String text) {
141 Button result = new Button(composite, SWT.CHECK);
142 result.setText(text);
144 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
145 gridData.horizontalSpan = 2;
146 result.setLayoutData(gridData);
154 private void initDialogSettings() {
155 IDialogSettings ds = WebUI.getDefault().getDialogSettings();
156 dialogSettings = ds.getSection(DS_KEY);
157 if (dialogSettings == null) {
158 dialogSettings = ds.addNewSection(DS_KEY);
159 // init default values
160 dialogSettings.put(DS_UPDATE_BUNDLE, true);
161 dialogSettings.put(DS_ALL_PROJECTS, false);
165 private void validate() {
166 String txt = txtNewName.getText();
167 setPageComplete(txt.length() > 0 && !txt.equals(info.getOldName()));
170 private void initUpdateBundleOption() {
171 boolean updateRefs = dialogSettings.getBoolean(DS_UPDATE_BUNDLE);
172 cbUpdateBundle.setSelection(updateRefs);
173 info.setUpdateProject(updateRefs);
176 private void initAllProjectsOption() {
177 boolean allProjects = dialogSettings.getBoolean(DS_ALL_PROJECTS);
178 cbAllProjects.setSelection(allProjects);
179 info.setAllProjects(allProjects);