Search in sources :

Example 91 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project OpenTCS-4 by touchmii.

the class DialogsTab method showInputDialog.

private void showInputDialog() {
    final IInputValidator val = new IInputValidator() {

        @Override
        public String isValid(final String newText) {
            String result = null;
            if (newText.length() < 5) {
                result = "Input text too short!";
            }
            return result;
        }
    };
    String title = "Input Dialog";
    String mesg = "Enter at least five characters";
    String def = "default text";
    final InputDialog dlg;
    dlg = new InputDialog(getShell(), title, mesg, def, val);
    int returnCode = dlg.open();
    String resultText = "Result: " + getReturnCodeText(returnCode);
    if (returnCode == Window.OK) {
        resultText += ", value: " + dlg.getValue();
    }
    inputDlgResLabel.setText(resultText);
    inputDlgResLabel.pack();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 92 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project Pydev by fabioz.

the class CopyFilesAndFoldersOperation method getNewNameFor.

/**
 * Returns a new name for a copy of the resource at the given path in the
 * given workspace.
 *
 * @param originalName
 *            the full path of the resource
 * @param workspace
 *            the workspace
 * @return the new full path for the copy, or <code>null</code> if the
 *         resource should not be copied
 */
private IPath getNewNameFor(final IPath originalName, final IWorkspace workspace) {
    final IResource resource = workspace.getRoot().findMember(originalName);
    final IPath prefix = resource.getFullPath().removeLastSegments(1);
    // $NON-NLS-1$
    final String[] returnValue = { "" };
    messageShell.getDisplay().syncExec(new Runnable() {

        @Override
        public void run() {
            IInputValidator validator = new IInputValidator() {

                @Override
                public String isValid(String string) {
                    if (resource.getName().equals(string)) {
                        return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_nameMustBeDifferent;
                    }
                    IStatus status = workspace.validateName(string, resource.getType());
                    if (!status.isOK()) {
                        return status.getMessage();
                    }
                    if (workspace.getRoot().exists(prefix.append(string))) {
                        return IDEWorkbenchMessages.CopyFilesAndFoldersOperation_nameExists;
                    }
                    return null;
                }
            };
            InputDialog dialog = new InputDialog(messageShell, IDEWorkbenchMessages.CopyFilesAndFoldersOperation_inputDialogTitle, NLS.bind(IDEWorkbenchMessages.CopyFilesAndFoldersOperation_inputDialogMessage, resource.getName()), getAutoNewNameFor(originalName, workspace).lastSegment().toString(), validator);
            dialog.setBlockOnOpen(true);
            dialog.open();
            if (dialog.getReturnCode() == Window.CANCEL) {
                returnValue[0] = null;
            } else {
                returnValue[0] = dialog.getValue();
            }
        }
    });
    if (returnValue[0] == null) {
        throw new OperationCanceledException();
    }
    return prefix.append(returnValue[0]);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) InputDialog(org.eclipse.jface.dialogs.InputDialog) IPath(org.eclipse.core.runtime.IPath) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IResource(org.eclipse.core.resources.IResource) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 93 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project Pydev by fabioz.

the class AbstractPyCreateClassOrMethodOrField method execute.

@Override
public void execute(RefactoringInfo refactoringInfo, int locationStrategy) {
    try {
        String creationStr = this.getCreationStr();
        final String asTitle = StringUtils.getWithFirstUpper(creationStr);
        PySelection pySelection = refactoringInfo.getPySelection();
        Tuple<String, Integer> currToken = pySelection.getCurrToken();
        String actTok = currToken.o1;
        List<String> parametersAfterCall = null;
        if (actTok.length() == 0) {
            InputDialog dialog = new InputDialog(EditorUtils.getShell(), asTitle + " name", "Please enter the name of the " + asTitle + " to be created.", "", new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText.length() == 0) {
                        return "The " + asTitle + " name may not be empty";
                    }
                    if (StringUtils.containsWhitespace(newText)) {
                        return "The " + asTitle + " name may not contain whitespaces.";
                    }
                    return null;
                }
            });
            if (dialog.open() != InputDialog.OK) {
                return;
            }
            actTok = dialog.getValue();
        } else {
            parametersAfterCall = pySelection.getParametersAfterCall(currToken.o2 + actTok.length());
        }
        execute(refactoringInfo, actTok, parametersAfterCall, locationStrategy);
    } catch (BadLocationException e) {
        Log.log(e);
    }
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) PySelection(org.python.pydev.core.docutils.PySelection) BadLocationException(org.eclipse.jface.text.BadLocationException) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 94 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project tdq-studio-se by Talend.

the class TOPRepositoryService method getInputDialog.

/**
 * Comment method "getInputDialog".
 *
 * @param get input dialog
 * @return inputDialog
 */
@Override
public InputDialog getInputDialog(final Item newItem) {
    Shell parentShell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    // $NON-NLS-1$
    String dialogTitle = DefaultMessagesImpl.getString("TOPRepositoryService.InputDialog.Title");
    // $NON-NLS-1$
    String dialogMessage = DefaultMessagesImpl.getString("TOPRepositoryService.InputDialog.Message");
    final InputDialog inputDialog = new InputDialog(parentShell, dialogTitle, dialogMessage, newItem.getProperty().getLabel() + DateUtils.formatTimeStamp(DateUtils.PATTERN_6, System.currentTimeMillis()), new IInputValidator() {

        @Override
        public String isValid(String newText) {
            String returnStr = null;
            Item item = newItem;
            ERepositoryObjectType type = ERepositoryObjectType.getItemType(item);
            // String pattern = RepositoryConstants.getPattern(type);
            // $NON-NLS-1$
            String pattern = "[_A-Za-z0-9-][a-zA-Z0-9\\\\.\\\\-_(), ]*";
            boolean matches = Pattern.matches(pattern, newText);
            boolean nameAvailable = false;
            try {
                List<IRepositoryViewObject> listExistingObjects = ProxyRepositoryFactory.getInstance().getAll(type, true, false);
                nameAvailable = ProxyRepositoryFactory.getInstance().isNameAvailable(item, newText, listExistingObjects);
            } catch (PersistenceException e) {
                log.error(e, e);
                return e.getMessage();
            }
            if (!matches) {
                returnStr = DefaultMessagesImpl.getString(// $NON-NLS-1$
                "TOPRepositoryService.InputDialog.ErrorMessage1");
            } else if (!nameAvailable) {
                returnStr = DefaultMessagesImpl.getString(// $NON-NLS-1$
                "TOPRepositoryService.InputDialog.ErrorMessage2");
            }
            return returnStr;
        }
    });
    return inputDialog;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Shell(org.eclipse.swt.widgets.Shell) InputDialog(org.eclipse.jface.dialogs.InputDialog) PersistenceException(org.talend.commons.exception.PersistenceException) ArrayList(java.util.ArrayList) List(java.util.List) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 95 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project subclipse by subclipse.

the class CopyAction method execute.

protected void execute(IAction action) throws InvocationTargetException, InterruptedException {
    final IResource[] resources = getSelectedResources();
    final IProject project = resources[0].getProject();
    ContainerSelectionDialog dialog = new ContainerSelectionDialog(getShell(), project, false, // $NON-NLS-1$
    Policy.bind("CopyAction.selectionLabel"));
    if (dialog.open() == ContainerSelectionDialog.CANCEL)
        return;
    Object[] result = dialog.getResult();
    if (result == null || result.length == 0)
        return;
    final Path path = (Path) result[0];
    IProject selectedProject;
    File target = null;
    if (path.segmentCount() == 1) {
        selectedProject = ResourcesPlugin.getWorkspace().getRoot().getProject(path.toString());
        target = selectedProject.getLocation().toFile();
    } else {
        IFile targetFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
        selectedProject = targetFile.getProject();
        target = targetFile.getLocation().toFile();
    }
    final IProject targetProject = selectedProject;
    final File destPath = target;
    BusyIndicator.showWhile(Display.getCurrent(), new Runnable() {

        public void run() {
            ISVNClientAdapter client = null;
            ISVNRepositoryLocation repository = null;
            try {
                ISVNLocalResource svnTargetResource = SVNWorkspaceRoot.getSVNResourceFor(targetProject);
                for (int i = 0; i < resources.length; i++) {
                    final IResource resource = resources[i];
                    if (client == null) {
                        repository = SVNWorkspaceRoot.getSVNResourceFor(resources[i]).getRepository();
                        client = repository.getSVNClient();
                    }
                    File checkFile = new File(destPath.getPath() + File.separator + resource.getName());
                    File srcPath = new File(resource.getLocation().toString());
                    File newDestPath = new File(destPath.getPath() + File.separator + resource.getName());
                    if (checkFile.exists()) {
                        IInputValidator inputValidator = new IInputValidator() {

                            public String isValid(String newText) {
                                if (newText.equals(resource.getName()))
                                    // $NON-NLS-1$
                                    return Policy.bind("CopyAction.nameConflictSame");
                                return null;
                            }
                        };
                        InputDialog inputDialog = new InputDialog(getShell(), Policy.bind("CopyAction.nameConflictTitle"), Policy.bind("CopyAction.nameConflictMessage", resource.getName()), "Copy of " + resource.getName(), // $NON-NLS-1$
                        inputValidator);
                        if (inputDialog.open() == InputDialog.CANCEL)
                            return;
                        String newName = inputDialog.getValue();
                        if (newName == null || newName.trim().length() == 0)
                            return;
                        newDestPath = new File(destPath.getPath() + File.separator + newName);
                    }
                    ISVNLocalResource svnResource = SVNWorkspaceRoot.getSVNResourceFor(resource);
                    boolean sameRepository = svnTargetResource != null && svnTargetResource.getRepository() != null && svnTargetResource.getRepository().getLocation().equals(svnResource.getRepository().getLocation());
                    if (sameRepository)
                        client.copy(srcPath, newDestPath);
                    else
                        client.doExport(srcPath, newDestPath, true);
                    SVNUIPlugin.getPlugin().getRepositoryManager().resourceCreated(null, null);
                }
                targetProject.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
            } catch (Exception e) {
                MessageDialog.openError(getShell(), Policy.bind("CopyAction.copy"), // $NON-NLS-1$
                e.getMessage());
            } finally {
                if (repository != null) {
                    repository.returnSVNClient(client);
                }
            }
        }
    });
}
Also used : Path(org.eclipse.core.runtime.Path) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) InputDialog(org.eclipse.jface.dialogs.InputDialog) ISVNLocalResource(org.tigris.subversion.subclipse.core.ISVNLocalResource) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) ISVNRepositoryLocation(org.tigris.subversion.subclipse.core.ISVNRepositoryLocation) ContainerSelectionDialog(org.eclipse.ui.dialogs.ContainerSelectionDialog) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) ISVNClientAdapter(org.tigris.subversion.svnclientadapter.ISVNClientAdapter) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Aggregations

IInputValidator (org.eclipse.jface.dialogs.IInputValidator)101 InputDialog (org.eclipse.jface.dialogs.InputDialog)88 Composite (org.eclipse.swt.widgets.Composite)20 IStatus (org.eclipse.core.runtime.IStatus)16 SelectionEvent (org.eclipse.swt.events.SelectionEvent)13 ArrayList (java.util.ArrayList)12 Button (org.eclipse.swt.widgets.Button)12 GridData (org.eclipse.swt.layout.GridData)11 GridLayout (org.eclipse.swt.layout.GridLayout)10 FacetsListInputDialog (com.amalto.workbench.dialogs.FacetsListInputDialog)9 List (java.util.List)8 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)8 Label (org.eclipse.swt.widgets.Label)8 SelectionListener (org.eclipse.swt.events.SelectionListener)7 Control (org.eclipse.swt.widgets.Control)7 Display (org.eclipse.swt.widgets.Display)7 IResource (org.eclipse.core.resources.IResource)6 CoreException (org.eclipse.core.runtime.CoreException)6 Window (org.eclipse.jface.window.Window)6 Event (org.eclipse.swt.widgets.Event)6