001: /**
002: *
003: */package gui.wizards;
004:
005: import org.eclipse.core.runtime.IStatus;
006: import org.eclipse.jdt.core.JavaConventions;
007: import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
008: import org.eclipse.jface.dialogs.Dialog;
009: import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
010: import org.eclipse.swt.SWT;
011: import org.eclipse.swt.events.KeyAdapter;
012: import org.eclipse.swt.events.KeyEvent;
013: import org.eclipse.swt.layout.GridData;
014: import org.eclipse.swt.layout.GridLayout;
015: import org.eclipse.swt.widgets.Composite;
016: import org.eclipse.swt.widgets.Label;
017: import org.eclipse.swt.widgets.Text;
018:
019: import core.ModelInfo;
020:
021: /** <p>the input page for the Rename Type refactoring, where users can
022: * control the effects of the refactoring; to be shown in the wizard.</p>
023: *
024: * <p>We let the user enter the new name for the property, and we let her
025: * decide whether other property files in the bundle should be affected, and
026: * whether the operation is supposed to span the entire workspace or only
027: * the current project.</p>
028: *
029: * @author sh
030: */
031: public class RenameImplementationInputPage extends UserInputWizardPage {
032:
033: private static final String DS_KEY = RenameImplementationInputPage.class
034: .getName();
035:
036: private final ModelInfo info;
037:
038: private Text txtImplementation;
039:
040: public RenameImplementationInputPage(final ModelInfo info) {
041: super (RenameTypeInputPage.class.getName());
042: this .info = info;
043: }
044:
045: /**
046: * interface methods of UserInputWizardPage
047: */
048: public void createControl(final Composite parent) {
049: Composite composite = createRootComposite(parent);
050: setControl(composite);
051:
052: createLblImplementation(composite);
053: createTxtVarName(composite);
054:
055: validate();
056: }
057:
058: /**
059: * UI creation method
060: */
061: private Composite createRootComposite(final Composite parent) {
062: Composite result = new Composite(parent, SWT.NONE);
063: GridLayout gridLayout = new GridLayout(2, false);
064: gridLayout.marginWidth = 10;
065: gridLayout.marginHeight = 10;
066: result.setLayout(gridLayout);
067: initializeDialogUnits(result);
068: Dialog.applyDialogFont(result);
069: return result;
070: }
071:
072: /**
073: * UI creation method
074: */
075: private void createLblImplementation(final Composite composite) {
076: Label lblNewName = new Label(composite, SWT.NONE);
077: lblNewName.setText("Implementation");
078: }
079:
080: /**
081: * UI creation method
082: */
083: private void createTxtVarName(Composite composite) {
084: txtImplementation = new Text(composite, SWT.BORDER);
085: txtImplementation.setText(info.getOldImplementation());
086: txtImplementation.setLayoutData(new GridData(
087: GridData.FILL_HORIZONTAL));
088: txtImplementation.selectAll();
089: txtImplementation.addKeyListener(new KeyAdapter() {
090: public void keyReleased(final KeyEvent e) {
091: info.setNewImplementation(txtImplementation.getText());
092: validate();
093: }
094: });
095: }
096:
097: /**
098: * helper method
099: */
100: private void validate() {
101: String implementationTxt = txtImplementation.getText();
102: IStatus status = JavaConventions.validatePackageName(
103: implementationTxt, CompilerOptions.VERSION_1_3,
104: CompilerOptions.VERSION_1_3);
105:
106: if (status.isOK()) {
107: setPageComplete(true);
108: setMessage(null);
109: } else if (status.ERROR == IStatus.ERROR) {
110: setPageComplete(false);
111: setMessage(status.getMessage());
112: }
113: }
114: }
|