org.eclipse.jface.dialogs.InputDialog Java Examples

The following examples show how to use org.eclipse.jface.dialogs.InputDialog. 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: DialogHelpers.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static Integer openAskInt(String title, String message, int initial) {
    Shell shell = EditorUtils.getShell();
    String initialValue = "" + initial;
    IInputValidator validator = new IInputValidator() {

        @Override
        public String isValid(String newText) {
            if (newText.length() == 0) {
                return "At least 1 char must be provided.";
            }
            try {
                Integer.parseInt(newText);
            } catch (Exception e) {
                return "A number is required.";
            }
            return null;
        }
    };
    InputDialog dialog = new InputDialog(shell, title, message, initialValue, validator);
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
        return Integer.parseInt(dialog.getValue());
    }
    return null;
}
 
Example #2
Source File: AddStringEntryAction.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void run(){
	InputDialog inputDialog = new InputDialog(UiDesk.getTopShell(), "Hinzufügen",
		"Bitte geben Sie die Bezeichnung an", null, null);
	int retVal = inputDialog.open();
	if (retVal != Dialog.OK) {
		return;
	}
	String value = inputDialog.getValue();
	
	if (targetCollection != null) {
		targetCollection.add(value);
		structuredViewer.setInput(targetCollection);
	} else {
		Object input = structuredViewer.getInput();
		if (input instanceof Collection) {
			((Collection<String>) input).add(value);
			structuredViewer.refresh();
		}
		super.run();
	}
}
 
Example #3
Source File: ModelEditor.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void doSaveAs() {
	InputDialog diag = new InputDialog(UI.shell(), M.SaveAs, M.SaveAs,
			model.name + " - Copy", (name) -> {
				if (Strings.nullOrEmpty(name))
					return M.NameCannotBeEmpty;
				if (Strings.nullOrEqual(name, model.name))
					return M.NameShouldBeDifferent;
				return null;
			});
	if (diag.open() != Window.OK)
		return;
	String newName = diag.getValue();
	try {
		T clone = (T) model.clone();
		clone.name = newName;
		clone = dao.insert(clone);
		App.openEditor(clone);
		Navigator.refresh();
	} catch (Exception e) {
		log.error("failed to save " + model + " as " + newName, e);
	}
}
 
Example #4
Source File: DbCopyAction.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	if (config == null) {
		IDatabaseConfiguration conf = Database.getActiveConfiguration();
		if (!(conf instanceof DerbyConfiguration))
			return;
		config = (DerbyConfiguration) conf;
	}
	InputDialog dialog = new InputDialog(UI.shell(),
			M.Copy,
			M.PleaseEnterAName,
			config.getName(), null);
	if (dialog.open() != Window.OK)
		return;
	String newName = dialog.getValue();
	if (!DbUtils.isValidName(newName) || Database.getConfigurations()
			.nameExists(newName.trim())) {
		MsgBox.error(M.NewDatabase_InvalidName);
		return;
	}
	App.runInUI("Copy database", () -> doCopy(newName));
}
 
Example #5
Source File: DbRenameAction.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	if (config == null) {
		IDatabaseConfiguration conf = Database.getActiveConfiguration();
		if (!(conf instanceof DerbyConfiguration))
			return;
		config = (DerbyConfiguration) conf;
	}
	InputDialog dialog = new InputDialog(UI.shell(),
			M.Rename,
			M.PleaseEnterANewName,
			config.getName(), null);
	if (dialog.open() != Window.OK)
		return;
	String newName = dialog.getValue();
	if (!DbUtils.isValidName(newName) || Database.getConfigurations()
			.nameExists(newName.trim())) {
		MsgBox.error(M.DatabaseRenameError);
		return;
	}
	doRename(newName);
}
 
Example #6
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 #7
Source File: SdkToolsControl.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
private String editGroupName(String initialName, final Set<String> usedNames) {
    InputDialog dlg = new InputDialog(getShell(), Messages.SdkToolsControl_NewGroupName, 
            Messages.SdkToolsControl_EnterGroupName+':', initialName, 
            new IInputValidator() 
    {
        @Override
        public String isValid(String newText) {
            newText = newText.trim();
            if (newText.isEmpty()) {
                return Messages.SdkToolsControl_NameIsEmpty;
            } else if (usedNames.contains(newText)) {
                return Messages.SdkToolsControl_NameIsUsed;
            }
            return null;
        }
    });
    if (dlg.open() == Window.OK) {
        return dlg.getValue().trim();
    }
    return null;
}
 
Example #8
Source File: RenameResourceAction.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
	final IInputValidator validator = string -> {
		if (resource.getName().equals(string)) {
			return IDEWorkbenchMessages.RenameResourceAction_nameMustBeDifferent;
		}
		final 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;
	};

	final InputDialog dialog =
			new InputDialog(WorkbenchHelper.getShell(), IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
					IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
	dialog.setBlockOnOpen(true);
	final int result = dialog.open();
	if (result == Window.OK) { return dialog.getValue(); }
	return null;
}
 
Example #9
Source File: VGroupEditPart.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
/**
	 * {@inheritDoc}
	 */
	@Override
	public void performRequestOpen() {
		VGroup group = (VGroup) this.getModel();
		ERDiagram diagram = this.getDiagram();

//		VGroup copyGroup = group.clone();

		InputDialog dialog = new InputDialog(
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
				"�O���[�v���ύX", "�O���[�v�����͂��ĉ������B", group.getName(), null);

		if (dialog.open() == IDialogConstants.OK_ID) {
			CompoundCommand command = new CompoundCommand();
			command.add(new ChangeVGroupNameCommand(diagram, group, dialog.getValue()));
			this.executeCommand(command.unwrap());
		}
	}
 
Example #10
Source File: ChangeVirtualDiagramNameAction.java    From erflute with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Event event) {
    final ERDiagram diagram = getDiagram();
    final List<?> selectedEditParts = getTreeViewer().getSelectedEditParts();
    final EditPart editPart = (EditPart) selectedEditParts.get(0);
    final Object model = editPart.getModel();
    if (model instanceof ERVirtualDiagram) {
        final ERVirtualDiagram vdiagram = (ERVirtualDiagram) model;
        final InputVirtualDiagramNameValidator validator = new InputVirtualDiagramNameValidator(diagram, vdiagram.getName());
        final InputDialog dialog = new InputDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Rename",
                "Input new name", vdiagram.getName(), validator);
        if (dialog.open() == IDialogConstants.OK_ID) {
            final ChangeVirtualDiagramNameCommand command = new ChangeVirtualDiagramNameCommand(vdiagram, dialog.getValue());
            execute(command);
        }
    }
}
 
Example #11
Source File: FallPlaneRechnung.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
public Object execute(ExecutionEvent arg0) throws ExecutionException{
	InputDialog dlg =
		new InputDialog(UiDesk.getTopShell(), Messages.FallPlaneRechnung_PlanBillingHeading,
			Messages.FallPlaneRechnung_PlanBillingAfterDays, "30", new IInputValidator() { //$NON-NLS-1$
			
				public String isValid(String newText){
					if (newText.matches("[0-9]*")) { //$NON-NLS-1$
						return null;
					}
					return Messages.FallPlaneRechnung_PlanBillingPleaseEnterPositiveInteger;
				}
			});
	if (dlg.open() == Dialog.OK) {
		return dlg.getValue();
	}
	return null;
}
 
Example #12
Source File: NewNameQueries.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static INewNameQuery createStaticQuery(final IInputValidator validator, final String message, final String initial, final Shell shell){
	return new INewNameQuery(){
		public String getNewName() throws OperationCanceledException {
			InputDialog dialog= new InputDialog(shell, ReorgMessages.ReorgQueries_nameConflictMessage, message, initial, validator) {
				/* (non-Javadoc)
				 * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
				 */
				@Override
				protected Control createDialogArea(Composite parent) {
					Control area= super.createDialogArea(parent);
					TextFieldNavigationHandler.install(getText());
					return area;
				}
			};
			if (dialog.open() == Window.CANCEL)
				throw new OperationCanceledException();
			return dialog.getValue();
		}
	};
}
 
Example #13
Source File: ERModelAddAction.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
@Override
	public void execute(Event event) throws Exception {
		ERDiagram diagram = this.getDiagram();

		Settings settings = (Settings) diagram.getDiagramContents()
				.getSettings().clone();

		InputDialog dialog = new InputDialog(
				PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
				"�_�C�A�O�����쐬", "�_�C�A�O����������͂��ĉ������B", "", null);
		if (dialog.open() == IDialogConstants.OK_ID) {
			AddERModelCommand command = new AddERModelCommand(diagram, dialog.getValue());
			this.execute(command);
		}
		
//		CategoryManageDialog dialog = new CategoryManageDialog(PlatformUI
//				.getWorkbench().getActiveWorkbenchWindow().getShell(),
//				settings, diagram);
//
//		if (dialog.open() == IDialogConstants.OK_ID) {
//			ChangeSettingsCommand command = new ChangeSettingsCommand(diagram,
//					settings);
//			this.execute(command);
//		}
	}
 
Example #14
Source File: ZoomInputAction.java    From JDeodorant with MIT License 6 votes vote down vote up
public void run() {  

		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();  
		String dialogBoxTitle = "Custom Zoom";  
		String message = "Enter Zoom Value (in percent): ";  
		String initialValue = "";
		
		
		InputDialog dialog = new InputDialog(shell, dialogBoxTitle, message, initialValue, new ZoomValueValidator() );
		if(dialog.open() == Window.OK){
			String value = dialog.getValue();
			if(value != null && (root != null || root2!= null)){
				if(isFreeform)
				this.root.setScale(Double.parseDouble(value)/100);
				else
					this.root2.setScale(Double.parseDouble(value)/100);
			}
		}
	}
 
Example #15
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 #16
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 #17
Source File: LevelPropertyDialog.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void handleDefaultValueEditEvent( )
{
	InputDialog dialog = new InputDialog(this.getShell( ), DEFAULTVALUE_EDIT_TITLE, DEFAULTVALUE_EDIT_LABEL, DEUtil.resolveNull( input.getDefaultValue( )), null);
	if(dialog.open( ) == Window.OK){
		String value = dialog.getValue( );
		try
		{
			if(value==null || value.trim( ).length( ) == 0)
				input.setDefaultValue( null );
			else input.setDefaultValue( value.trim( ) );
			defaultValueViewer.refresh( );
		}
		catch ( SemanticException e )
		{
			ExceptionHandler.handle( e );
		}
	}
}
 
Example #18
Source File: CubeGroupContent.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @deprecated
 */
private InputDialog createInputDialog( ReportElementHandle handle,
		String title, String message )
{
	InputDialog inputDialog = new InputDialog( getShell( ),
			title,
			message,
			handle.getName( ),
			null ) {

		public int open( )
		{

			return super.open( );
		}
	};
	inputDialog.create( );
	return inputDialog;
}
 
Example #19
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 #20
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 #21
Source File: ExportElementToLibraryAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void doRename( )
{

	if ( selectedObj instanceof DesignElementHandle
			|| selectedObj instanceof EmbeddedImageHandle )
	{
		initOriginalName( );
		InputDialog inputDialog = new InputDialog( UIUtil.getDefaultShell( ),
				Messages.getString( "ExportElementToLibraryAction.DialogTitle" ), //$NON-NLS-1$
				Messages.getString( "ExportElementToLibraryAction.DialogMessage" ), //$NON-NLS-1$
				originalName,
				null );
		inputDialog.create( );
		clickOK = false;
		if ( inputDialog.open( ) == Window.OK )
		{
			saveChanges( inputDialog.getValue( ).trim( ) );
			clickOK = true;
		}
	}
}
 
Example #22
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 #23
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 #24
Source File: PyRenameResourceAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Return the new name to be given to the target resource.
 *
 * @return java.lang.String
 * @param resource the resource to query status on
 *
 * Fix from platform: was not checking return from dialog.open
 */
@Override
protected String queryNewResourceName(final IResource resource) {
    final IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace();
    final IPath prefix = resource.getFullPath().removeLastSegments(1);
    IInputValidator validator = new IInputValidator() {
        @Override
        public String isValid(String 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(shell, IDEWorkbenchMessages.RenameResourceAction_inputDialogTitle,
            IDEWorkbenchMessages.RenameResourceAction_inputDialogMessage, resource.getName(), validator);
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
        return dialog.getValue();
    } else {
        return null;
    }
}
 
Example #25
Source File: PySetupCustomFilters.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IAction action) {
    final Display display = Display.getDefault();
    display.syncExec(new Runnable() {

        @Override
        public void run() {

            //ask the filters to the user
            IInputValidator validator = null;

            IPreferenceStore prefs = PydevPlugin.getDefault().getPreferenceStore();
            InputDialog dialog = new InputDialog(display.getActiveShell(), "Custom Filters",

            "Enter the filters (separated by comma. E.g.: \"__init__.py, *.xyz\").\n" + "\n"
                    + "Note 1: Only * and ? may be used for custom matching.\n" + "\n"
                    + "Note 2: it'll only take effect if the 'Pydev: Hide custom specified filters'\n"
                    + "is active in the menu: customize view > filters.",

            prefs.getString(CUSTOM_FILTERS_PREFERENCE_NAME), validator);

            dialog.setBlockOnOpen(true);
            dialog.open();
            if (dialog.getReturnCode() == Window.OK) {
                //update the preferences and refresh the viewer (when we update the preferences, the 
                //filter that uses this will promptly update its values -- just before the refresh).
                prefs.setValue(CUSTOM_FILTERS_PREFERENCE_NAME, dialog.getValue());
                PydevPackageExplorer p = (PydevPackageExplorer) view;
                p.getCommonViewer().refresh();
            }
        }
    });
}
 
Example #26
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 #27
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 #28
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 #29
Source File: TokenDialog.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private Integer open() {
	Display.getDefault().syncExec(() -> {
		InputDialog dialog = new InputDialog(UI.shell(), M.EnterYourAuthenticatorToken,
				M.PleaseEnterYourAuthenticatorTokenToProceed, null, TokenDialog::checkValid);
		if (dialog.open() != IDialogConstants.OK_ID)
			return;
		token = Integer.parseInt(dialog.getValue());
	});
	return token;
}
 
Example #30
Source File: RenameAction.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public void run() {

	// for parameters, open another dialog
	if (element instanceof ModelElement) {
		var d = ((ModelElement) element).getContent();
		if (d.type == ModelType.PARAMETER) {
			var param = new ParameterDao(Database.get())
					.getForId(d.id);
			RenameParameterDialog.open(param);
			return;
		}
	}

	var name = element instanceof CategoryElement
			? ((CategoryElement) element).getContent().name
			: ((ModelElement) element).getContent().name;

	var dialog = new InputDialog(UI.shell(), M.Rename,
			M.PleaseEnterANewName, name, null);
	if (dialog.open() != Window.OK)
		return;
	var newName = dialog.getValue();
	if (newName == null || newName.trim().isEmpty()) {
		MsgBox.error(M.NameCannotBeEmpty);
		return;
	}
	if (element instanceof CategoryElement) {
		doUpdate(((CategoryElement) element).getContent(), newName);
	} else {
		doUpdate(((ModelElement) element).getContent(), newName);
	}
}