Search in sources :

Example 96 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project eclipse.platform.ui by eclipse-platform.

the class RenameResourceAction method queryNewResourceName.

/**
 * Return the new name to be given to the target resource.
 *
 * @return java.lang.String
 * @param resource
 *            the resource to query status on
 */
protected String queryNewResourceName(final IResource resource) {
    final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
    final IPath prefix = resource.getFullPath().removeLastSegments(1);
    IInputValidator validator = string -> {
        if (resource.getName().equals(string)) {
            return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
        }
        IStatus status = workspace.validateName(string, resource.getType());
        if (!status.isOK()) {
            return status.getMessage();
        }
        if (workspace.getRoot().exists(prefix.append(string))) {
            return IDEWorkbenchMessages.RenameResourceAction_nameExists;
        }
        return null;
    };
    InputDialog dialog = new InputDialog(getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle, IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
    dialog.setBlockOnOpen(true);
    int result = dialog.open();
    if (result == Window.OK)
        return dialog.getValue();
    return null;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IShellProvider(org.eclipse.jface.window.IShellProvider) CoreException(org.eclipse.core.runtime.CoreException) FocusEvent(org.eclipse.swt.events.FocusEvent) IPreferencesService(org.eclipse.core.runtime.preferences.IPreferencesService) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Point(org.eclipse.swt.graphics.Point) TreeEditor(org.eclipse.swt.custom.TreeEditor) WorkspaceUndoUtil(org.eclipse.ui.ide.undo.WorkspaceUndoUtil) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IStatus(org.eclipse.core.runtime.IStatus) IWorkspace(org.eclipse.core.resources.IWorkspace) IPath(org.eclipse.core.runtime.IPath) IWorkbenchPreferenceConstants(org.eclipse.ui.IWorkbenchPreferenceConstants) IDEWorkbenchPlugin(org.eclipse.ui.internal.ide.IDEWorkbenchPlugin) Composite(org.eclipse.swt.widgets.Composite) IIDEHelpContextIds(org.eclipse.ui.internal.ide.IIDEHelpContextIds) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) IDEWorkbenchMessages(org.eclipse.ui.internal.ide.IDEWorkbenchMessages) LTKLauncher(org.eclipse.ui.internal.ide.actions.LTKLauncher) PlatformUI(org.eclipse.ui.PlatformUI) Status(org.eclipse.core.runtime.Status) ExecutionException(org.eclipse.core.commands.ExecutionException) TreeItem(org.eclipse.swt.widgets.TreeItem) List(java.util.List) Window(org.eclipse.jface.window.Window) MoveResourcesOperation(org.eclipse.ui.ide.undo.MoveResourcesOperation) Tree(org.eclipse.swt.widgets.Tree) IResource(org.eclipse.core.resources.IResource) IInputValidator(org.eclipse.jface.dialogs.IInputValidator) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) SWT(org.eclipse.swt.SWT) Platform(org.eclipse.core.runtime.Platform) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) FocusAdapter(org.eclipse.swt.events.FocusAdapter) ResourceAttributes(org.eclipse.core.resources.ResourceAttributes) Control(org.eclipse.swt.widgets.Control) IStatus(org.eclipse.core.runtime.IStatus) InputDialog(org.eclipse.jface.dialogs.InputDialog) IPath(org.eclipse.core.runtime.IPath) IWorkspace(org.eclipse.core.resources.IWorkspace) Point(org.eclipse.swt.graphics.Point) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 97 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project jbosstools-hibernate by jbosstools.

the class NameValidator method renameLaunchConfiguration.

public boolean renameLaunchConfiguration(ILaunchConfiguration launchConfiguration) {
    Shell mParentShell = null;
    IInputValidator inputValidator = new NameValidator();
    InputDialog d = new InputDialog(mParentShell, HibernateConsoleMessages.RenameAction_dialog_title, HibernateConsoleMessages.RenameAction_dialog_message, launchConfiguration.getName(), inputValidator);
    if (d.open() == Window.OK) {
        try {
            ILaunchConfigurationWorkingCopy wc = launchConfiguration.getWorkingCopy();
            wc.rename(d.getValue());
            wc.doSave();
            return true;
        } catch (CoreException e) {
            HibernateConsolePlugin.getDefault().showError(mParentShell, HibernateConsoleMessages.RenameAction_error_title, e);
        }
    }
    return false;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) InputDialog(org.eclipse.jface.dialogs.InputDialog) CoreException(org.eclipse.core.runtime.CoreException) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 98 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project org.eclipse.rap by eclipse-rap.

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 99 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project org.eclipse.rap by eclipse-rap.

the class DialogExamplePage method showInputDialog.

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

        public String isValid(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 dialog = new InputDialog(getShell(), title, mesg, def, val) {

        @Override
        public boolean close() {
            boolean result = super.close();
            int returnCode = getReturnCode();
            String resultText = "Result: " + getReturnCodeText(returnCode);
            if (returnCode == Window.OK) {
                resultText += ", value: " + getValue();
            }
            showResult(resultText);
            return result;
        }
    };
    dialog.setBlockOnOpen(false);
    dialog.open();
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) IInputValidator(org.eclipse.jface.dialogs.IInputValidator)

Example 100 with IInputValidator

use of org.eclipse.jface.dialogs.IInputValidator in project jbosstools-server by jbosstools.

the class ArchivesActionProvider method createFolder.

/*
	 * Methods below are called from the standard actions,
	 * the implementations of the action, where the action does its work etc
	 */
private void createFolder() {
    IInputValidator validator = new IInputValidator() {

        public String isValid(String newText) {
            IArchiveNode selected = getSelectedNode(site);
            boolean folderExists = false;
            IArchiveNode[] folders = selected.getChildren(IArchiveNode.TYPE_ARCHIVE_FOLDER);
            for (int i = 0; i < folders.length; i++) {
                IArchiveFolder folder = (IArchiveFolder) folders[i];
                if (folder.getName().equals(newText)) {
                    folderExists = true;
                    break;
                }
            }
            if (folderExists) {
                return NLS.bind(ArchivesUIMessages.ProjectPackagesView_createFolderDialog_warnFolderExists, newText);
            }
            if ("".equals(newText)) {
                // $NON-NLS-1$
                return ArchivesUIMessages.ProjectPackagesView_createFolderDialog_blank;
            }
            return null;
        }
    };
    InputDialog dialog = new InputDialog(getShell(), ArchivesUIMessages.ProjectPackagesView_createFolderDialog_title, ArchivesUIMessages.ProjectPackagesView_createFolderDialog_message, "", // $NON-NLS-1$
    validator);
    int response = dialog.open();
    if (response == Dialog.OK) {
        // $NON-NLS-1$
        String[] folderPaths = dialog.getValue().split("[\\\\/]");
        IArchiveNode selected = getSelectedNode(site);
        IArchiveFolder current = null;
        IArchiveFolder temp = null;
        for (int i = folderPaths.length - 1; i >= 0; i--) {
            temp = ArchivesCore.getInstance().getNodeFactory().createFolder();
            temp.setName(folderPaths[i]);
            if (current == null)
                current = temp;
            else {
                temp.addChild(current);
                current = temp;
            }
        }
        selected.addChild(current);
        new SaveArchivesJob(selected.getProjectPath()).schedule();
    }
}
Also used : SaveArchivesJob(org.jboss.ide.eclipse.archives.core.build.SaveArchivesJob) InputDialog(org.eclipse.jface.dialogs.InputDialog) IArchiveNode(org.jboss.ide.eclipse.archives.core.model.IArchiveNode) IArchiveFolder(org.jboss.ide.eclipse.archives.core.model.IArchiveFolder) 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