/** * Adds a new environment variable to the table. */ protected void handleEnvAddButtonSelected() { MultipleInputDialog dialog = new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_22); dialog.addTextField(NAME_LABEL, null, false); dialog.addVariablesField(VALUE_LABEL, null, true); if (dialog.open() != Window.OK) { return; } String name = dialog.getStringValue(NAME_LABEL); String value = dialog.getStringValue(VALUE_LABEL); if (name != null && value != null && name.length() > 0 && value.length() >0) { addVariable(new EnvironmentVariable(name.trim(), value.trim())); updateAppendReplace(); } }
/** * Attempts to add the given variable. Returns whether the variable * was added or not (as when the user answers not to overwrite an * existing variable). * @param variable the variable to add * @return whether the variable was added */ protected boolean addVariable(EnvironmentVariable variable) { String name= variable.getName(); TableItem[] items = environmentTable.getTable().getItems(); for (int i = 0; i < items.length; i++) { EnvironmentVariable existingVariable = (EnvironmentVariable) items[i].getData(); if (existingVariable.getName().equals(name)) { boolean overWrite = MessageDialog.openQuestion(getShell(), LaunchConfigurationsMessages.EnvironmentTab_12, MessageFormat.format(LaunchConfigurationsMessages.EnvironmentTab_13, new Object[] { name })); // if (!overWrite) { return false; } environmentTable.remove(existingVariable); break; } } environmentTable.add(variable); updateLaunchConfigurationDialog(); return true; }
MultipleInputDialog dialog= new MultipleInputDialog(getShell(), LaunchConfigurationsMessages.EnvironmentTab_11); dialog.addTextField(NAME_LABEL, originalName, false); if(value != null && value.indexOf(System.getProperty("line.separator")) > -1) { //$NON-NLS-1$
/** * Displays a dialog that allows user to select native environment variables * to add to the table. */ private void handleEnvSelectButtonSelected() { //get Environment Variables from the OS Map<String, EnvironmentVariable> envVariables = getNativeEnvironment(); //get Environment Variables from the table TableItem[] items = environmentTable.getTable().getItems(); for (int i = 0; i < items.length; i++) { EnvironmentVariable var = (EnvironmentVariable) items[i].getData(); envVariables.remove(var.getName()); } NativeEnvironmentSelectionDialog dialog = new NativeEnvironmentSelectionDialog(getShell(), envVariables); dialog.setTitle(LaunchConfigurationsMessages.EnvironmentTab_20); int button = dialog.open(); if (button == Window.OK) { Object[] selected = dialog.getResult(); for (int i = 0; i < selected.length; i++) { environmentTable.add(selected[i]); } } updateAppendReplace(); updateLaunchConfigurationDialog(); }