KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > refactoring > RenamePluginWizardPage


1 package org.eclipse.pde.internal.ui.refactoring;
2
3 import org.eclipse.jface.dialogs.Dialog;
4 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
5 import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
6 import org.eclipse.pde.internal.core.util.IdUtil;
7 import org.eclipse.pde.internal.ui.PDEUIMessages;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.events.ModifyEvent;
10 import org.eclipse.swt.events.ModifyListener;
11 import org.eclipse.swt.events.SelectionAdapter;
12 import org.eclipse.swt.events.SelectionEvent;
13 import org.eclipse.swt.layout.GridData;
14 import org.eclipse.swt.layout.GridLayout;
15 import org.eclipse.swt.widgets.Button;
16 import org.eclipse.swt.widgets.Composite;
17 import org.eclipse.swt.widgets.Label;
18 import org.eclipse.swt.widgets.Text;
19
20 /*******************************************************************************
21  * Copyright (c) 2007 IBM Corporation and others.
22  * All rights reserved. This program and the accompanying materials
23  * are made available under the terms of the Eclipse Public License v1.0
24  * which accompanies this distribution, and is available at
25  * http://www.eclipse.org/legal/epl-v10.html
26  *
27  * Contributors:
28  * IBM Corporation - initial API and implementation
29  *******************************************************************************/

30 public class RenamePluginWizardPage extends UserInputWizardPage {
31     
32     private Text fNewId;
33     private Button fUpdateReferences;
34     private Button fRenameProject;
35     private RenamePluginInfo fInfo;
36     
37     private static final String JavaDoc RENAME_PROJECT = "renameProject"; //$NON-NLS-1$
38

39     protected RenamePluginWizardPage(RenamePluginInfo info) {
40         super("RenamePluginWizardPage"); //$NON-NLS-1$
41
fInfo = info;
42     }
43
44     public void createControl(Composite parent) {
45         Composite composite = new Composite(parent, SWT.NONE);
46         composite.setLayout(new GridLayout(2, false));
47         Dialog.applyDialogFont(composite);
48         
49         createNewID(composite);
50         createRenameProject(composite);
51         createUpdateReferences(composite);
52         
53         setPageComplete(false);
54         setControl(composite);
55     }
56     
57     private void createNewID(Composite composite) {
58         Label label = new Label(composite, SWT.NONE);
59         label.setText(PDEUIMessages.RenamePluginWizardPage_newId);
60         
61         fNewId = new Text(composite, SWT.BORDER);
62         fNewId.setText(fInfo.getCurrentID());
63         fNewId.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
64         fNewId.addModifyListener(new ModifyListener() {
65             public void modifyText(ModifyEvent e) {
66                 fInfo.setNewID(fNewId.getText());
67                 validatePage();
68             }
69         });
70     }
71     
72     private void createRenameProject(Composite composite) {
73         fRenameProject = new Button(composite, SWT.CHECK);
74         fRenameProject.setText(PDEUIMessages.RenamePluginWizardPage_renameProject);
75         fRenameProject.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false, 2, 1));
76         fRenameProject.addSelectionListener(new SelectionAdapter() {
77             public void widgetSelected(SelectionEvent e) {
78                 fInfo.setRenameProject(fRenameProject.getSelection());
79             }
80         });
81         boolean checked = getRefactoringSettings().getBoolean(RENAME_PROJECT);
82         fRenameProject.setSelection(checked);
83         fInfo.setRenameProject(checked);
84     }
85     
86     private void createUpdateReferences(Composite composite) {
87         fUpdateReferences = new Button(composite, SWT.CHECK);
88         fUpdateReferences.setText(PDEUIMessages.RenamePluginWizardPage_updateReferences);
89         fUpdateReferences.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false, 2, 1));
90         fUpdateReferences.addSelectionListener(new SelectionAdapter() {
91             public void widgetSelected(SelectionEvent e) {
92                 fInfo.setUpdateReferences(fUpdateReferences.getSelection());
93             }
94         });
95         fUpdateReferences.setSelection(true);
96     }
97     
98     public void dispose() {
99         getRefactoringSettings().put(RENAME_PROJECT, fRenameProject.getSelection());
100     }
101     
102     protected void validatePage() {
103         String JavaDoc text = fNewId.getText();
104         String JavaDoc errorMessage = null;
105         if (text.length() == 0)
106             errorMessage = PDEUIMessages.RenamePluginWizardPage_idNotSet;
107         else if (!IdUtil.isValidCompositeID(text))
108             errorMessage = PDEUIMessages.RenamePluginWizardPage_invalidId;
109         if (errorMessage == null && text.equals(fInfo.getCurrentID()))
110             setPageComplete(false);
111         else
112             setPageComplete(errorMessage == null ? new RefactoringStatus() : RefactoringStatus.createFatalErrorStatus(errorMessage));
113     }
114
115 }
116
Popular Tags