Java Code Examples for org.eclipse.jface.dialogs.InputDialog#getValue()

The following examples show how to use org.eclipse.jface.dialogs.InputDialog#getValue() . 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: 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 2
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 3
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 4
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 5
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 6
Source File: GroupPage.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void run() {
	String m = M.PleaseEnterAName;
	InputDialog dialog = new InputDialog(getSite().getShell(), m, m,
			"", null);
	int code = dialog.open();
	if (code == Window.OK) {
		String name = dialog.getValue();
		ProcessGrouping group = new ProcessGrouping();
		group.name = name;
		groups.add(group);
		groupViewer.add(group);
		resultSection.update();
		updateViewers();
	}
}
 
Example 7
Source File: VirtualDiagramAddAction.java    From erflute with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(Event event) throws Exception {
    final ERDiagram diagram = getDiagram();
    final Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    final String dialogTitle = "New Virtual Diagram";
    final String dialogMessage = "Input name for new Virtual Diagram";
    final InputVirtualDiagramNameValidator validator = new InputVirtualDiagramNameValidator(diagram, null);
    final InputDialog dialog = new InputDialog(shell, dialogTitle, dialogMessage, "", validator);
    if (dialog.open() == IDialogConstants.OK_ID) {
        final AddVirtualDiagramCommand addCommand = new AddVirtualDiagramCommand(diagram, dialog.getValue());
        execute(addCommand);
        final OpenERModelCommand openCommand = new OpenERModelCommand(diagram, diagram.getCurrentVirtualDiagram());
        execute(openCommand);
    }
}
 
Example 8
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 9
Source File: WakaTime.java    From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void promptForApiKey(IWorkbenchWindow window) {
    String apiKey = ConfigFile.get("settings", "api_key");
    InputDialog dialog = new InputDialog(window.getShell(),
        "WakaTime API Key", "Please enter your api key from http://wakatime.com/settings#apikey", apiKey, null);
    if (dialog.open() == IStatus.OK) {
      apiKey = dialog.getValue();
      ConfigFile.set("settings", "api_key", apiKey);
    }
}
 
Example 10
Source File: StringListFieldEditor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected String getNewInputObject(){
	InputDialog id =
		new InputDialog(Hub.plugin.getWorkbench().getActiveWorkbenchWindow().getShell(), title,
			message, StringTool.leer, null); //$NON-NLS-1$
	id.open();
	return id.getValue();
}
 
Example 11
Source File: DialogHelpers.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public static String openInputRequest(String title, String message, Shell shell, IInputValidator validator) {
    if (shell == null) {
        shell = EditorUtils.getShell();
    }
    String initialValue = "";
    InputDialog dialog = new InputDialog(shell, title, message, initialValue, validator);
    dialog.setBlockOnOpen(true);
    if (dialog.open() == Window.OK) {
        return dialog.getValue();
    }
    return null;
}
 
Example 12
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 13
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 14
Source File: CloneModelHandlerDelegate.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
public Object execute(ExecutionEvent event) throws ExecutionException {
	final TLCSpec spec = ToolboxHandle.getCurrentSpec().getAdapter(TLCSpec.class);
	
	Model model = null;
	/*
	 * First try to get the model from the parameters. It is an optional
	 * parameter, so it may not have been set.
	 */
	final String paramModelName = (String) event.getParameter(PARAM_MODEL_NAME);
	final String paramForeignModelName = (String) event.getParameter(PARAM_FOREIGN_FULLY_QUALIFIED_MODEL_NAME);
	final boolean isForeignClone = (paramForeignModelName != null);
	if (paramModelName != null) {
		// The name is given which means the user clicked the main menu
		// instead of the spec explorer. Under the constraint that only ever
		// a single spec can be open, lookup the current spec to eventually
		// get the corresponding model.
		model = spec.getModel(paramModelName);
	} else if (isForeignClone) {
		model = TLCModelFactory.getByName(paramForeignModelName);
	} else {
		/*
		 * No parameter try to get it from active navigator if any
		 */
		final ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
		if (selection != null && selection instanceof IStructuredSelection) {
			// model
			model = (Model) ((IStructuredSelection) selection).getFirstElement();
		}
	}

	if (model != null) {
		final InputDialog dialog = new InputDialog(UIHelper.getShellProvider().getShell(), "Clone model...",
				"Please input the new name of the model", spec.getModelNameSuggestion(model), new ModelNameValidator(spec));
		dialog.setBlockOnOpen(true);
		if (dialog.open() == Window.OK) {
			final String chosenName = dialog.getValue();

			if (isForeignClone) {
				if (model.copyIntoForeignSpec(spec, chosenName) == null) {
					throw new ExecutionException("Failed to copy with name " + chosenName
													+ " from model " + model.getName() + " in spec " + model.getSpec().getName());
				}
			} else {
				if (model.copy(chosenName) == null) {
					throw new ExecutionException("Failed to copy with name " + chosenName + " from model " + model.getName());
				}
			}

			// Open the previously created model
			final Map<String, String> parameters = new HashMap<String, String>();
			parameters.put(OpenModelHandler.PARAM_MODEL_NAME, chosenName);
			UIHelper.runCommand(OpenModelHandler.COMMAND_ID, parameters);
		}
	}
	return null;
}
 
Example 15
Source File: ParameterNamePrefixListEditor.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected String getNewInputObject() {
    InputDialog d = new InputDialog(getShell(), "Type doctag generation", "Enter a parameter prefix", null, null);
    d.open();
    return d.getValue();
}
 
Example 16
Source File: TreeWithAddRemove.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public void addItemWithDialog(InputDialog dialog) {
    dialog.open();
    String value = dialog.getValue();
    addTreeItem(value);
}
 
Example 17
Source File: InvoiceCorrectionView.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
private boolean changeQuantityDialog(LeistungDTO leistungDTO){
	String p = Integer.toString(leistungDTO.getCount());
	InputDialog dlg =
		new InputDialog(UiDesk.getTopShell(), Messages.VerrechnungsDisplay_changeNumberCaption, //$NON-NLS-1$
			Messages.VerrechnungsDisplay_changeNumberBody, //$NON-NLS-1$
			p, null);
	if (dlg.open() == Dialog.OK) {
		try {
			String val = dlg.getValue();
			if (!StringTool.isNothing(val)) {
				int changeAnzahl;
				double secondaryScaleFactor = 1.0;
				String text = leistungDTO.getIVerrechenbar().getText();
				
				if (val.indexOf(StringConstants.SLASH) > 0) {
					changeAnzahl = 1;
					String[] frac = val.split(StringConstants.SLASH);
					secondaryScaleFactor =
						Double.parseDouble(frac[0]) / Double.parseDouble(frac[1]);
					text = leistungDTO.getIVerrechenbar().getText() + " (" + val //$NON-NLS-1$
						+ Messages.VerrechnungsDisplay_Orininalpackungen;
				} else if (val.indexOf('.') > 0) {
					changeAnzahl = 1;
					secondaryScaleFactor = Double.parseDouble(val);
					text = leistungDTO.getIVerrechenbar().getText() + " ("
						+ Double.toString(secondaryScaleFactor) + ")";
				} else {
					changeAnzahl = Integer.parseInt(dlg.getValue());
				}
				
				leistungDTO.setCount(changeAnzahl);
				leistungDTO.setScale2(secondaryScaleFactor);
				return true;
			}
		} catch (NumberFormatException ne) {
			log.error("quantity changing", ne);
			SWTHelper.showError(Messages.VerrechnungsDisplay_invalidEntryCaption, //$NON-NLS-1$
				Messages.VerrechnungsDisplay_invalidEntryBody); //$NON-NLS-1$
		}
	}
	
	return false;
}
 
Example 18
Source File: VerrechnungsDisplay.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
private void changeQuantityDialog(String p, IBilled billed){
	InputDialog dlg =
		new InputDialog(UiDesk.getTopShell(), Messages.VerrechnungsDisplay_changeNumberCaption, //$NON-NLS-1$
			Messages.VerrechnungsDisplay_changeNumberBody, //$NON-NLS-1$
			p, null);
	if (dlg.open() == Dialog.OK) {
		try {
			String val = dlg.getValue();
			if (!StringTool.isNothing(val)) {
				double changeAnzahl;
				IBillable billable = billed.getBillable();
				String text = billable.getText();
				if (val.indexOf(StringConstants.SLASH) > 0) {
					String[] frac = val.split(StringConstants.SLASH);
					changeAnzahl =
						Double.parseDouble(frac[0]) / Double.parseDouble(frac[1]);
					text = billed.getText() + " (" + val //$NON-NLS-1$
						+ Messages.VerrechnungsDisplay_Orininalpackungen;
				} else if (val.indexOf('.') > 0) {
					changeAnzahl =  Double.parseDouble(val);
				} else {
					changeAnzahl = Integer.parseInt(dlg.getValue());
				}
				
				if (!(changeAnzahl % 1 == 0) && billed.isChangedPrice()) {
					MessageDialog.openInformation(UiDesk.getTopShell(), "Info",
						"Wenn der Preis bereits geƤndert wurde, darf die Anzahl nur ganzzahlig sein.");
					return;
				}
				double diff = changeAnzahl - billed.getAmount();
				Result<?> result =
					BillingServiceHolder.get().bill(billable, actEncounter, diff);
				if(!result.isOK()) {
					ResultDialog.show(result);
					return;
				}
				billed.setText(text);
				CoreModelServiceHolder.get().save(billed);
				viewer.update(billed, null);
			}
		} catch (NumberFormatException ne) {
			SWTHelper.showError(Messages.VerrechnungsDisplay_invalidEntryCaption, //$NON-NLS-1$
				Messages.VerrechnungsDisplay_invalidEntryBody); //$NON-NLS-1$
		}
	}
}
 
Example 19
Source File: NewFolderAction.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns the new name to be given to the target resource.
 * 
 * @param container
 *            the container to query status on
 * @return the new name to be given to the target resource.
 */
private String queryNewResourceName( final File container )
{
	final IWorkspace workspace = ResourcesPlugin.getWorkspace( );

	IInputValidator validator = new IInputValidator( ) {

		/*
		 * (non-Javadoc)
		 * 
		 * @see org.eclipse.jface.dialogs.IInputValidator#isValid(java.lang.String)
		 */
		public String isValid( String string )
		{
			if ( string == null || string.length( ) <= 0 )
			{
				return Messages.getString( "NewFolderAction.emptyName" ); //$NON-NLS-1$
			}

			File newPath = new File( container, string );

			if ( newPath.exists( ) )
			{
				return Messages.getString( "NewFolderAction.nameExists" ); //$NON-NLS-1$
			}

			IStatus status = workspace.validateName( newPath.getName( ),
					IResource.FOLDER );

			if ( !status.isOK( ) )
			{
				return status.getMessage( );
			}
			return null;
		}
	};

	InputDialog dialog = new InputDialog( getShell( ),
			Messages.getString( "NewFolderAction.inputDialogTitle" ), //$NON-NLS-1$
			Messages.getString( "NewFolderAction.inputDialogMessage" ), //$NON-NLS-1$
			"", //$NON-NLS-1$
			validator );

	dialog.setBlockOnOpen( true );
	int result = dialog.open( );
	if ( result == Window.OK )
	{
		return dialog.getValue( );
	}
	return null;
}
 
Example 20
Source File: MainWindow.java    From arx with Apache License 2.0 3 votes vote down vote up
/**
 * Shows an input dialog.
 *
 * @param shell
 * @param header
 * @param text
 * @param initial
 * @param validator
 * @return
 */
public String showInputDialog(final Shell shell, final String header, final String text, final String initial, final IInputValidator validator) {
    final InputDialog dlg = new InputDialog(shell, header, text, initial, validator);
    if (dlg.open() == Window.OK) {
        return dlg.getValue();
    } else {
        return null;
    }
}