/**
*
*/
package gui.wizards;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.jdt.core.JavaConventions;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.ltk.ui.refactoring.UserInputWizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import core.ModelInfo;
/** <p>the input page for the Rename Type refactoring, where users can
* control the effects of the refactoring; to be shown in the wizard.</p>
*
* <p>We let the user enter the new name for the property, and we let her
* decide whether other property files in the bundle should be affected, and
* whether the operation is supposed to span the entire workspace or only
* the current project.</p>
*
* @author sh
*/
public class RenameImplementationInputPage extends UserInputWizardPage {
private static final String DS_KEY = RenameImplementationInputPage.class.getName();
private final ModelInfo info;
private Text txtImplementation;
public RenameImplementationInputPage(final ModelInfo info) {
super(RenameTypeInputPage.class.getName());
this.info = info;
}
/**
* interface methods of UserInputWizardPage
*/
public void createControl(final Composite parent) {
Composite composite = createRootComposite(parent);
setControl(composite);
createLblImplementation(composite);
createTxtVarName(composite);
validate();
}
/**
* UI creation method
*/
private Composite createRootComposite(final Composite parent) {
Composite result = new Composite(parent, SWT.NONE);
GridLayout gridLayout = new GridLayout(2, false);
gridLayout.marginWidth = 10;
gridLayout.marginHeight = 10;
result.setLayout(gridLayout);
initializeDialogUnits(result);
Dialog.applyDialogFont(result);
return result;
}
/**
* UI creation method
*/
private void createLblImplementation(final Composite composite) {
Label lblNewName = new Label(composite, SWT.NONE);
lblNewName.setText("Implementation");
}
/**
* UI creation method
*/
private void createTxtVarName(Composite composite) {
txtImplementation = new Text(composite, SWT.BORDER);
txtImplementation.setText(info.getOldImplementation());
txtImplementation.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
txtImplementation.selectAll();
txtImplementation.addKeyListener(new KeyAdapter() {
public void keyReleased(final KeyEvent e) {
info.setNewImplementation(txtImplementation.getText());
validate();
}
});
}
/**
* helper method
*/
private void validate() {
String implementationTxt = txtImplementation.getText();
IStatus status = JavaConventions.validatePackageName(implementationTxt, CompilerOptions.VERSION_1_3,CompilerOptions.VERSION_1_3);
if (status.isOK()) {
setPageComplete(true);
setMessage(null);
}
else if (status.ERROR == IStatus.ERROR){
setPageComplete(false);
setMessage(status.getMessage());
}
}
}
|