Search in sources :

Example 1 with ModuleNameValidator

use of org.erlide.wrangler.refactoring.ui.validator.ModuleNameValidator in project erlide_eclipse by erlang.

the class AddRefacHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Add user-defined refactoring", "Please type callback module name!", "", new IInputValidator() {

        public IValidator internalV = new ModuleNameValidator();

        @Override
        public String isValid(final String newText) {
            if (internalV.isValid(newText)) {
                return null;
            }
            return "Please type a correct module name!";
        }
    });
    dialog.open();
    if (dialog.getReturnCode() == Window.CANCEL) {
        return null;
    }
    final String callbackModule = dialog.getValue();
    final RefacType type = checkType(callbackModule);
    if (type == null) {
        showErrorMesg("Callback module must implement either " + "gen_refac or gen_composite_refac behaviour");
        return null;
    }
    if (!addAndLoad(callbackModule, type)) {
        showErrorMesg("Can not load callback module");
        return null;
    }
    if (type.equals(RefacType.ELEMENTARY)) {
        UserRefactoringsManager.getInstance().addMyElementary(callbackModule);
    } else {
        UserRefactoringsManager.getInstance().addMyComposite(callbackModule);
    }
    MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Add user-defined refactoring", "Success!");
    return null;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) ModuleNameValidator(org.erlide.wrangler.refactoring.ui.validator.ModuleNameValidator) IValidator(org.erlide.wrangler.refactoring.ui.validator.IValidator) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 IValidator (org.erlide.wrangler.refactoring.ui.validator.IValidator)1 ModuleNameValidator (org.erlide.wrangler.refactoring.ui.validator.ModuleNameValidator)1