001: package org.eclipse.pde.internal.ui.refactoring;
002:
003: import org.eclipse.jface.dialogs.Dialog;
004: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
005: import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
006: import org.eclipse.pde.internal.core.util.IdUtil;
007: import org.eclipse.pde.internal.ui.PDEUIMessages;
008: import org.eclipse.swt.SWT;
009: import org.eclipse.swt.events.ModifyEvent;
010: import org.eclipse.swt.events.ModifyListener;
011: import org.eclipse.swt.events.SelectionAdapter;
012: import org.eclipse.swt.events.SelectionEvent;
013: import org.eclipse.swt.layout.GridData;
014: import org.eclipse.swt.layout.GridLayout;
015: import org.eclipse.swt.widgets.Button;
016: import org.eclipse.swt.widgets.Composite;
017: import org.eclipse.swt.widgets.Label;
018: import org.eclipse.swt.widgets.Text;
019:
020: /*******************************************************************************
021: * Copyright (c) 2007 IBM Corporation and others.
022: * All rights reserved. This program and the accompanying materials
023: * are made available under the terms of the Eclipse Public License v1.0
024: * which accompanies this distribution, and is available at
025: * http://www.eclipse.org/legal/epl-v10.html
026: *
027: * Contributors:
028: * IBM Corporation - initial API and implementation
029: *******************************************************************************/
030: public class RenamePluginWizardPage extends UserInputWizardPage {
031:
032: private Text fNewId;
033: private Button fUpdateReferences;
034: private Button fRenameProject;
035: private RenamePluginInfo fInfo;
036:
037: private static final String RENAME_PROJECT = "renameProject"; //$NON-NLS-1$
038:
039: protected RenamePluginWizardPage(RenamePluginInfo info) {
040: super ("RenamePluginWizardPage"); //$NON-NLS-1$
041: fInfo = info;
042: }
043:
044: public void createControl(Composite parent) {
045: Composite composite = new Composite(parent, SWT.NONE);
046: composite.setLayout(new GridLayout(2, false));
047: Dialog.applyDialogFont(composite);
048:
049: createNewID(composite);
050: createRenameProject(composite);
051: createUpdateReferences(composite);
052:
053: setPageComplete(false);
054: setControl(composite);
055: }
056:
057: private void createNewID(Composite composite) {
058: Label label = new Label(composite, SWT.NONE);
059: label.setText(PDEUIMessages.RenamePluginWizardPage_newId);
060:
061: fNewId = new Text(composite, SWT.BORDER);
062: fNewId.setText(fInfo.getCurrentID());
063: fNewId.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
064: fNewId.addModifyListener(new ModifyListener() {
065: public void modifyText(ModifyEvent e) {
066: fInfo.setNewID(fNewId.getText());
067: validatePage();
068: }
069: });
070: }
071:
072: private void createRenameProject(Composite composite) {
073: fRenameProject = new Button(composite, SWT.CHECK);
074: fRenameProject
075: .setText(PDEUIMessages.RenamePluginWizardPage_renameProject);
076: fRenameProject.setLayoutData(new GridData(GridData.BEGINNING,
077: GridData.CENTER, true, false, 2, 1));
078: fRenameProject.addSelectionListener(new SelectionAdapter() {
079: public void widgetSelected(SelectionEvent e) {
080: fInfo.setRenameProject(fRenameProject.getSelection());
081: }
082: });
083: boolean checked = getRefactoringSettings().getBoolean(
084: RENAME_PROJECT);
085: fRenameProject.setSelection(checked);
086: fInfo.setRenameProject(checked);
087: }
088:
089: private void createUpdateReferences(Composite composite) {
090: fUpdateReferences = new Button(composite, SWT.CHECK);
091: fUpdateReferences
092: .setText(PDEUIMessages.RenamePluginWizardPage_updateReferences);
093: fUpdateReferences
094: .setLayoutData(new GridData(GridData.BEGINNING,
095: GridData.CENTER, true, false, 2, 1));
096: fUpdateReferences.addSelectionListener(new SelectionAdapter() {
097: public void widgetSelected(SelectionEvent e) {
098: fInfo.setUpdateReferences(fUpdateReferences
099: .getSelection());
100: }
101: });
102: fUpdateReferences.setSelection(true);
103: }
104:
105: public void dispose() {
106: getRefactoringSettings().put(RENAME_PROJECT,
107: fRenameProject.getSelection());
108: }
109:
110: protected void validatePage() {
111: String text = fNewId.getText();
112: String errorMessage = null;
113: if (text.length() == 0)
114: errorMessage = PDEUIMessages.RenamePluginWizardPage_idNotSet;
115: else if (!IdUtil.isValidCompositeID(text))
116: errorMessage = PDEUIMessages.RenamePluginWizardPage_invalidId;
117: if (errorMessage == null && text.equals(fInfo.getCurrentID()))
118: setPageComplete(false);
119: else
120: setPageComplete(errorMessage == null ? new RefactoringStatus()
121: : RefactoringStatus
122: .createFatalErrorStatus(errorMessage));
123: }
124:
125: }
|