Java Code Examples for org.eclipse.jface.dialogs.InputDialog#OK

The following examples show how to use org.eclipse.jface.dialogs.InputDialog#OK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyItemListEditor.java    From http4e with Apache License 2.0 6 votes vote down vote up
protected String getNewInputObject(){
   String returnvalue = null;
   ProxyInputDialog inputDialog = new ProxyInputDialog(getShell());
   if (inputDialog.open() == InputDialog.OK) {
      // check for valid Input
      try {
         String name = inputDialog.getName();
         String host = inputDialog.getHost();
         String port = inputDialog.getPort();

         String inputText = name + "," + host + "," + port;

         // parse String for empty fields
         ProxyItem.createFromString(inputText);

         returnvalue = inputText;
      } catch (Exception e) {
         MessageDialog.openError(getShell(), "Wrong entry", "None of the fields must be left blank");
      }
   }
   return returnvalue;
}
 
Example 2
Source File: CreateTermHandler.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
	if (selection == null || !(selection instanceof IStructuredSelection)) {
		return null;
	}
	IStructuredSelection currentSelection = (IStructuredSelection) selection;
	if (currentSelection.size() == 1) {
		Term term = (Term) currentSelection.getFirstElement();	
		CreateTermDialog dialog = new CreateTermDialog(null, term.getName());
		dialog.setBlockOnOpen(true);
		if (dialog.open() == InputDialog.OK) {
			TermCreator.create(dialog.getTermName(), term, dialog.getTermPosition());							
		}
	}	
	return null;
}
 
Example 3
Source File: RenameTermHandler.java    From slr-toolkit with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {			
	ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
	if (selection == null || !(selection instanceof IStructuredSelection)) {
		return null;
	}
	IStructuredSelection currentSelection = (IStructuredSelection) selection;
	if (currentSelection.size() == 1) {
		Term term = (Term) currentSelection.getFirstElement();	
		InputDialog dialog = new InputDialog(
				null,
				"Rename Term", 
				"Rename Term: " + term.getName() + " to:",
				term.getName(),
				null);
		dialog.setBlockOnOpen(true);
		if (dialog.open() == InputDialog.OK) {
			TermRenamer.rename(term, dialog.getValue());
		}
	}		
	return null;
}
 
Example 4
Source File: DjangoMakeMigrations.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IAction action) {
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.trim().length() == 0) {
                return "Name cannot be empty";
            }
            return null;
        }
    };
    InputDialog d = new InputDialog(EditorUtils.getShell(), "App name",
            "Name of the django app to makemigrations on", "",
            validator);

    int retCode = d.open();
    if (retCode == InputDialog.OK) {
        createApp(d.getValue().trim());
    }
}
 
Example 5
Source File: DjangoCreateApp.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(IAction action) {
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.trim().length() == 0) {
                return "Name cannot be empty";
            }
            return null;
        }
    };
    InputDialog d = new InputDialog(EditorUtils.getShell(), "App name", "Name of the django app to be created", "",
            validator);

    int retCode = d.open();
    if (retCode == InputDialog.OK) {
        createApp(d.getValue().trim());
    }
}
 
Example 6
Source File: SSLEditor.java    From http4e with Apache License 2.0 5 votes vote down vote up
protected String getNewInputObject(){
   String returnvalue = null;
   SSLInputDialog inputDialog = new SSLInputDialog(getShell());
   if (inputDialog.open() == InputDialog.OK) {
      // check for valid Input
      try {
         returnvalue = inputDialog.getName();
      } catch (Exception e) {
         MessageDialog.openError(getShell(), "Wrong entry", "Wrong entry");
      }
   }
   return returnvalue;
}
 
Example 7
Source File: SaveAsTemplateAction.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a window for entering the template name, checks the user's input and
 * proceeds to save the template. 
 */
public void run(IAction action) {
    
    IFile file = ((FileEditorInput)editor.getEditorInput()).getFile();
    String fullname = file.getFullPath().toString();
    
    // create dialog
    InputQueryDialog dialog = new InputQueryDialog(editor.getEditorSite().getShell(),
            TexlipsePlugin.getResourceString("templateSaveDialogTitle"),
            TexlipsePlugin.getResourceString("templateSaveDialogMessage").replaceAll("%s", fullname),
            file.getName().substring(0,file.getName().lastIndexOf('.')),
            new IInputValidator() {
        public String isValid(String newText) {
            if (newText != null && newText.length() > 0) {
                return null; // no error
            }
            return TexlipsePlugin.getResourceString("templateSaveErrorFileName");
        }});
    
    if (dialog.open() == InputDialog.OK) {
        String newName = dialog.getInput();
        
        // check existing
        boolean reallySave = true;
        if (ProjectTemplateManager.templateExists(newName)) {
            reallySave = MessageDialog.openConfirm(editor.getSite().getShell(),
                    TexlipsePlugin.getResourceString("templateSaveOverwriteTitle"),
                    TexlipsePlugin.getResourceString("templateSaveOverwriteText").replaceAll("%s", newName));
        }
        
        if (reallySave) {
            ProjectTemplateManager.saveProjectTemplate(file, newName);
        }
    }
}
 
Example 8
Source File: DFSActionImpl.java    From RDFS with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new sub-folder into an existing directory
 * 
 * @param selection
 */
private void mkdir(IStructuredSelection selection) {
  List<DFSFolder> folders = filterSelection(DFSFolder.class, selection);
  if (folders.size() >= 1) {
    DFSFolder folder = folders.get(0);
    InputDialog dialog =
        new InputDialog(Display.getCurrent().getActiveShell(),
            "Create subfolder", "Enter the name of the subfolder", "",
            null);
    if (dialog.open() == InputDialog.OK)
      folder.mkdir(dialog.getValue());
  }
}
 
Example 9
Source File: AbstractPyCreateClassOrMethodOrField.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@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);
    }
}
 
Example 10
Source File: AbstractInterpreterEditor.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private void renameSelection() {
    int index = getSelectionIndex();
    if (index >= 0) {
        TreeItem curr = treeWithInterpreters.getItem(index);

        final String initialName = getNameFromTreeItem(curr);
        InputDialog d = new InputDialog(this.getShell(), "New name",
                "Please specify the new name of the interpreter.", initialName, new IInputValidator() {
                    @Override
                    public String isValid(String newText) {
                        if (newText == null || newText.trim().equals("")) {
                            return "Please specify a non-empty name.";
                        }
                        newText = newText.trim();
                        if (newText.equals(initialName)) {
                            return null;
                        }
                        return InterpreterConfigHelpers.getDuplicatedMessageError(
                                newText, null, nameToInfo);
                    }
                });

        int retCode = d.open();
        if (retCode == InputDialog.OK) {
            String newName = d.getValue().trim();
            if (!newName.equals(initialName)) {
                IInterpreterInfo info = this.nameToInfo.get(initialName);
                info.setName(newName);
                curr.setText(0, newName);
                this.nameToInfo.remove(initialName);
                this.nameToInfo.put(newName, info);
                this.exeOrJarOfInterpretersToRestore.add(info.getExecutableOrJar());
            }
        }
    }
}
 
Example 11
Source File: SelectExistingOrCreateNewDialog.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent e) {
    Object source = e.getSource();
    if (source == btAdd) {
        InputDialog dialog = new InputDialog(getShell(), "Add custom command to list",
                "Add custom command to list", "", new IInputValidator() {

                    @Override
                    public String isValid(String newText) {
                        if (newText.trim().length() == 0) {
                            return "Command not entered.";
                        }
                        if (input.contains(newText)) {
                            return "Command already entered.";
                        }
                        return null;
                    }
                });
        int open = dialog.open();
        if (open == InputDialog.OK) {
            String value = dialog.getValue();
            input.add(value);
            saveCurrentCommands(value); //Save it.
            updateGui();
        }
    } else if (source == btRemove) {
        removeSelection();

    }
}
 
Example 12
Source File: PyConvertSpaceToTab.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Currently returns an int of the Preferences' Tab Width.
 * @param textEditor 
 * 
 * @return Tab width in preferences
 */
protected static String getTabSpace(ITextEditor textEditor) {
    class NumberValidator implements IInputValidator {

        /*
         * @see IInputValidator#isValid(String)
         */
        @Override
        public String isValid(String input) {

            if (input == null || input.length() == 0) {
                return " ";
            }

            try {
                int i = Integer.parseInt(input);
                if (i <= 0) {
                    return "Must be more than 0.";
                }

            } catch (NumberFormatException x) {
                return x.getMessage();
            }

            return null;
        }
    }

    InputDialog inputDialog = new InputDialog(EditorUtils.getShell(), "Tab length",
            "How many spaces should be considered for each tab?", ""
                    + DefaultIndentPrefs.get(textEditor).getTabWidth(),
            new NumberValidator());

    if (inputDialog.open() != InputDialog.OK) {
        return null;
    }

    int tabWidth = Integer.parseInt(inputDialog.getValue());
    return new FastStringBuffer(tabWidth).appendN(' ', tabWidth).toString();
}
 
Example 13
Source File: PyCodeCoverageView.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run() {
    InputDialog d = new InputDialog(EditorUtils.getShell(), "Enter number of columns",
            "Enter the number of columns to be used for the name.", ""
                    + PyCoveragePreferences.getNameNumberOfColumns(),
            new IInputValidator() {

                @Override
                public String isValid(String newText) {
                    if (newText.trim().length() == 0) {
                        return "Please enter a number > 5";
                    }
                    try {
                        int i = Integer.parseInt(newText);
                        if (i < 6) {
                            return "Please enter a number > 5";
                        }
                        if (i > 256) {
                            return "Please enter a number <= 256";
                        }
                    } catch (NumberFormatException e) {
                        return "Please enter a number > 5";
                    }
                    return null;
                }
            });
    int retCode = d.open();
    if (retCode == InputDialog.OK) {
        PyCoveragePreferences.setNameNumberOfColumns(Integer.parseInt(d.getValue()));
        onSelectedFileInTree(lastSelectedFile);
    }

}
 
Example 14
Source File: NoteListComposite.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(){
	InputDialog input = new InputDialog(getShell(), "Notiz", "Notiz erfassen", "", null);
	if (input.open() == InputDialog.OK) {
		if (input.getValue() != null && !input.getValue().isEmpty()) {
			adapter.addNote(input.getValue());
			dataList.add(input.getValue());
			natTableWrapper.getNatTable().refresh();
		}
	}
}
 
Example 15
Source File: DFSActionImpl.java    From hadoop-gpu with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new sub-folder into an existing directory
 * 
 * @param selection
 */
private void mkdir(IStructuredSelection selection) {
  List<DFSFolder> folders = filterSelection(DFSFolder.class, selection);
  if (folders.size() >= 1) {
    DFSFolder folder = folders.get(0);
    InputDialog dialog =
        new InputDialog(Display.getCurrent().getActiveShell(),
            "Create subfolder", "Enter the name of the subfolder", "",
            null);
    if (dialog.open() == InputDialog.OK)
      folder.mkdir(dialog.getValue());
  }
}
 
Example 16
Source File: PySearchInOpenDocumentsAction.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void run() {
    IDialogSettings settings = TextEditorPlugin.getDefault().getDialogSettings();
    IDialogSettings s = settings.getSection("org.eclipse.ui.texteditor.FindReplaceDialog");
    boolean caseSensitive = false;
    boolean wholeWord = false;
    boolean isRegEx = false;
    if (s != null) {
        caseSensitive = s.getBoolean("casesensitive"); //$NON-NLS-1$
        wholeWord = s.getBoolean("wholeword"); //$NON-NLS-1$
        isRegEx = s.getBoolean("isRegEx"); //$NON-NLS-1$
    }

    String searchText = "";
    if (parameters != null) {
        searchText = StringUtils.join(" ", parameters);
    }
    if (searchText.length() == 0) {
        PySelection ps = PySelectionFromEditor.createPySelectionFromEditor(edit);
        try {
            searchText = ps.getSelectedText();
        } catch (BadLocationException e) {
            searchText = "";
        }
    }
    IStatusLineManager statusLineManager = edit.getStatusLineManager();
    if (searchText.length() == 0) {
        InputDialog d = new InputDialog(EditorUtils.getShell(), "Text to search", "Enter text to search.", "",
                null);

        int retCode = d.open();
        if (retCode == InputDialog.OK) {
            searchText = d.getValue();
        }
    }

    if (searchText.length() >= 0) {
        if (wholeWord && !isRegEx && isWord(searchText)) {
            isRegEx = true;
            searchText = "\\b" + searchText + "\\b";
        }

        FindInOpenDocuments.findInOpenDocuments(searchText, caseSensitive, wholeWord, isRegEx, statusLineManager);
    }
}