Search in sources :

Example 1 with IValidator

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

the class ComboInputPage method createControl.

@Override
public void createControl(final Composite parent) {
    composite = new Composite(parent, SWT.NONE);
    inputLabel = new Label(composite, SWT.LEFT);
    inputLabel.setText(labelText);
    // GridData gridData = new GridData();
    // gridData.horizontalAlignment = GridData.FILL;
    // gridData.horizontalSpan = 2;
    // inputLabel.setLayoutData(gridData);
    selectionList = new Combo(composite, SWT.DROP_DOWN);
    for (final String s : moduleNames) {
        selectionList.add(s);
    }
    // gridData = new GridData();
    // gridData.horizontalAlignment = GridData.FILL;
    // gridData.horizontalSpan = 2;
    // selectionList.setLayoutData(gridData);
    // GridLayout layout = new GridLayout();
    final RowLayout layout = new RowLayout();
    layout.spacing = 5;
    layout.center = true;
    composite.setLayout(layout);
    setControl(composite);
    selectionList.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
        }

        @Override
        @SuppressWarnings("synthetic-access")
        public void widgetSelected(final SelectionEvent e) {
            ((SimpleOneStepWranglerRefactoring) getRefactoring()).setUserInput(selectionList.getText());
            setPageComplete(true);
        }
    });
    final IValidator validator = new AtomValidator();
    selectionList.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(final ModifyEvent e) {
            if (validator.isValid(selectionList.getText())) {
                ((SimpleWranglerRefactoring) getRefactoring()).setUserInput(selectionList.getText());
                setErrorMessage(null);
                setPageComplete(true);
            } else {
                setPageComplete(false);
                setErrorMessage("Module name must be a a valid atom!");
            }
        }
    });
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IValidator(org.erlide.wrangler.refactoring.ui.validator.IValidator) RowLayout(org.eclipse.swt.layout.RowLayout) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener) AtomValidator(org.erlide.wrangler.refactoring.ui.validator.AtomValidator)

Example 2 with IValidator

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

the class RecordDataInputPage method isInputValid.

@Override
protected boolean isInputValid() {
    final IValidator theValidator = new AtomValidator();
    boolean valid = theValidator.isValid(recordName.getText());
    final List<String> fn = new ArrayList<>();
    for (final Text t : fieldNames) {
        valid = valid && theValidator.isValid(t.getText());
        fn.add(t.getText());
        if (!valid) {
            break;
        }
    }
    if (valid) {
        refactoring.setRecordData(recordName.getText(), fn);
        setErrorMessage(null);
        setPageComplete(true);
    } else {
        setPageComplete(false);
        setErrorMessage("Please provide valid record name, and field names!");
    }
    return valid;
}
Also used : IValidator(org.erlide.wrangler.refactoring.ui.validator.IValidator) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) AtomValidator(org.erlide.wrangler.refactoring.ui.validator.AtomValidator)

Example 3 with IValidator

use of org.erlide.wrangler.refactoring.ui.validator.IValidator 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

IValidator (org.erlide.wrangler.refactoring.ui.validator.IValidator)3 AtomValidator (org.erlide.wrangler.refactoring.ui.validator.AtomValidator)2 ArrayList (java.util.ArrayList)1 IInputValidator (org.eclipse.jface.dialogs.IInputValidator)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 ModuleNameValidator (org.erlide.wrangler.refactoring.ui.validator.ModuleNameValidator)1