Search in sources :

Example 1 with StatusInfo

use of org.erlide.ui.util.StatusInfo in project erlide_eclipse by erlang.

the class DirectorySelectUtil method chooseLocation.

public static IContainer chooseLocation(final String dialogTitle, final String labelText, final IProject project2, final String outputLocation, final Shell shell) {
    final IWorkspaceRoot root = project2.getWorkspace().getRoot();
    final Class<?>[] acceptedClasses = new Class[] { IProject.class, IFolder.class };
    final IProject[] allProjects = root.getProjects();
    final List<IProject> rejectedElements = new ArrayList<>(allProjects.length);
    for (final IProject allProject : allProjects) {
        if (!allProject.equals(project2)) {
            rejectedElements.add(allProject);
        }
    }
    final ViewerFilter filter = new TypedViewerFilter(acceptedClasses, rejectedElements.toArray());
    final ILabelProvider lp = new WorkbenchLabelProvider();
    final ITreeContentProvider cp = new WorkbenchContentProvider();
    IResource initSelection = null;
    if (outputLocation != null) {
        initSelection = root.findMember(outputLocation);
    }
    final FolderSelectionDialog dialog = new FolderSelectionDialog(shell, lp, cp);
    dialog.setTitle(dialogTitle);
    final ISelectionStatusValidator validator = new ISelectionStatusValidator() {

        ISelectionStatusValidator myValidator = new TypedElementSelectionValidator(acceptedClasses, false);

        @Override
        public IStatus validate(final Object[] selection) {
            final IStatus typedStatus = myValidator.validate(selection);
            if (!typedStatus.isOK()) {
                return typedStatus;
            }
            if (selection[0] instanceof IFolder) {
                // }
                return new StatusInfo();
            }
            return new StatusInfo(IStatus.ERROR, "");
        }
    };
    dialog.setValidator(validator);
    dialog.setMessage(labelText);
    dialog.addFilter(filter);
    dialog.setInput(root);
    dialog.setInitialSelection(initSelection);
    dialog.setComparator(new ResourceComparator(ResourceComparator.NAME));
    if (dialog.open() == Window.OK) {
        return (IContainer) dialog.getFirstResult();
    }
    return null;
}
Also used : ITreeContentProvider(org.eclipse.jface.viewers.ITreeContentProvider) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) IStatus(org.eclipse.core.runtime.IStatus) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TypedViewerFilter(org.erlide.ui.util.TypedViewerFilter) ArrayList(java.util.ArrayList) FolderSelectionDialog(org.erlide.ui.util.FolderSelectionDialog) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TypedElementSelectionValidator(org.erlide.ui.util.TypedElementSelectionValidator) IProject(org.eclipse.core.resources.IProject) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) StatusInfo(org.erlide.ui.util.StatusInfo) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) IContainer(org.eclipse.core.resources.IContainer) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder) TypedViewerFilter(org.erlide.ui.util.TypedViewerFilter)

Example 2 with StatusInfo

use of org.erlide.ui.util.StatusInfo in project erlide_eclipse by erlang.

the class ProjectSelectionDialog method doSelectionChanged.

void doSelectionChanged(final Object[] objects) {
    if (objects.length != 1) {
        // $NON-NLS-1$
        updateStatus(new StatusInfo(IStatus.ERROR, ""));
        setSelectionResult(null);
    } else {
        updateStatus(new StatusInfo());
        setSelectionResult(objects);
    }
}
Also used : StatusInfo(org.erlide.ui.util.StatusInfo)

Example 3 with StatusInfo

use of org.erlide.ui.util.StatusInfo in project erlide_eclipse by erlang.

the class AddRuntimeDialog method validateLocation.

protected IStatus validateLocation() {
    final StatusInfo status = new StatusInfo();
    final String loc = fOtpHome.getText();
    if (loc == null || loc.trim().isEmpty()) {
        status.setInfo("Enter the installation's location");
    } else {
        final File f = new File(loc);
        if (!f.exists()) {
            status.setError("Location doesn't exist");
        } else if (!f.isDirectory()) {
            status.setError("Location isn't a directory");
        } else if (!RuntimeInfo.validateLocation(loc)) {
            status.setError("Location is not a valid OTP home");
        }
    }
    return status;
}
Also used : StatusInfo(org.erlide.ui.util.StatusInfo) File(java.io.File)

Example 4 with StatusInfo

use of org.erlide.ui.util.StatusInfo in project erlide_eclipse by erlang.

the class CodeAssistPreferencePage method validateCommaSeparatedCharacters.

private IStatus validateCommaSeparatedCharacters(final String text) {
    final StatusInfo status = new StatusInfo();
    status.setOK();
    if (text.length() > 1) {
        final String[] chars = text.split(",");
        for (final String c : chars) {
            if (c.trim().length() != 1) {
                status.setError("Trigger keys should be a list of comma-separated characters");
                break;
            }
        }
    }
    return status;
}
Also used : StatusInfo(org.erlide.ui.util.StatusInfo)

Example 5 with StatusInfo

use of org.erlide.ui.util.StatusInfo in project erlide_eclipse by erlang.

the class AddRuntimeDialog method validateName.

protected IStatus validateName() {
    final StatusInfo status = new StatusInfo();
    final String name = fName.getText();
    if (name == null || name.trim().isEmpty()) {
        // $NON-NLS-1$
        status.setError("Enter the runtime's name");
    } else if (fRequestor.isDuplicateName(name) && (fEditedRuntime == null || !name.equals(fEditedRuntime.getName()))) {
        // $NON-NLS-1$
        status.setError("The name is already used");
    } else {
        final IStatus s = ResourcesPlugin.getWorkspace().validateName(name, IResource.FILE);
        if (!s.isOK()) {
            status.setError(MessageFormat.format("Name is invalid: %s", (Object[]) new String[] { s.getMessage() }));
        }
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) StatusInfo(org.erlide.ui.util.StatusInfo)

Aggregations

StatusInfo (org.erlide.ui.util.StatusInfo)5 IStatus (org.eclipse.core.runtime.IStatus)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 IContainer (org.eclipse.core.resources.IContainer)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 ILabelProvider (org.eclipse.jface.viewers.ILabelProvider)1 ITreeContentProvider (org.eclipse.jface.viewers.ITreeContentProvider)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 ISelectionStatusValidator (org.eclipse.ui.dialogs.ISelectionStatusValidator)1 WorkbenchContentProvider (org.eclipse.ui.model.WorkbenchContentProvider)1 WorkbenchLabelProvider (org.eclipse.ui.model.WorkbenchLabelProvider)1 ResourceComparator (org.eclipse.ui.views.navigator.ResourceComparator)1 FolderSelectionDialog (org.erlide.ui.util.FolderSelectionDialog)1 TypedElementSelectionValidator (org.erlide.ui.util.TypedElementSelectionValidator)1 TypedViewerFilter (org.erlide.ui.util.TypedViewerFilter)1