Example usage for org.apache.commons.lang StringUtils defaultString

List of usage examples for org.apache.commons.lang StringUtils defaultString

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultString.

Prototype

public static String defaultString(String str) 

Source Link

Document

Returns either the passed in String, or if the String is null, an empty String ("").

Usage

From source file:org.eclipse.jubula.client.ui.rcp.properties.ProjectGeneralPropertyPage.java

/**
 * Creates the textfield for the project description.
 * /*from   w w  w .  j a va 2s .c o  m*/
 * @param parent
 *            The parent composite.
 */
private void createProjectDescrField(Composite parent) {
    Composite leftComposite = createComposite(parent, NUM_COLUMNS_1, GridData.BEGINNING, false);
    Composite rightComposite = createComposite(parent, NUM_COLUMNS_1, GridData.FILL, true);
    createLabel(leftComposite, Messages.ProjectPropertyPageProjectDescr);
    m_projectDescriptionTextField = new Text(rightComposite, SWT.BORDER);
    m_projectDescriptionTextField.setText(StringUtils.defaultString(getProject().getComment()));
    GridData textGridData = new GridData();
    textGridData.grabExcessHorizontalSpace = true;
    textGridData.horizontalAlignment = GridData.FILL;
    LayoutUtil.addToolTipAndMaxWidth(textGridData, m_projectDescriptionTextField);
    m_projectDescriptionTextField.setLayoutData(textGridData);
    LayoutUtil.setMaxChar(m_projectDescriptionTextField, IPersistentObject.MAX_STRING_LENGTH);
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.AutConfigComponent.java

/**
 * Populates GUI for the basic configuration section.
 * //from  w w w .j  a va2  s.  c o m
 * @param data Map representing the data to use for population.
 */
protected void populateBasicArea(Map<String, String> data) {
    fillServerCombo();
    if (!isDataNew(data)) {
        m_serverCombo
                .select(m_serverCombo.indexOf(StringUtils.defaultString(data.get(AutConfigConstants.SERVER))));
        m_autConfigNameTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.CONFIG_NAME),
                NLS.bind(Messages.AUTConfigComponentDefaultAUTConfigName,
                        new String[] { m_autName, m_serverCombo.getText() })));
        m_autIdTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.AUT_ID)));
        m_autWorkingDirectoryTextField
                .setText(StringUtils.defaultString(data.get(AutConfigConstants.WORKING_DIR)));
    } else {
        // set some default values
        m_serverCombo.select(m_serverCombo.indexOf(StringUtils.defaultString(Constants.LOCALHOST1)));

        m_autConfigNameTextField.setText(NLS.bind(Messages.AUTConfigComponentDefaultAUTConfigName,
                new String[] { m_autName, m_serverCombo.getText() }));
    }
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.AutConfigComponent.java

/**
 * Maps the given value to the given key for the AUT Configuration. If
 * the given key already has a value mapped to it, this value will be 
 * overwritten./* w w w .  j  a va 2s  . c  om*/
 *  
 * Updates the enablement of all fields based on the new status of 
 * the AUT Configuration. Subclasses should extend this method to update the
 * fields that they define.
 * 
 * @param key The key for the mapping.
 * @param value The value for the mapping.
 * @return <code>true</code> if the configuration was changed as a result 
 *         of this method call (i.e. if <code>value</code> was <em>not</em>
 *         already mapped to <code>key</code>). Otherwise 
 *         <code>false</code>. Note that there is no need to update fields
 *         if the mapping has not changed.
 */
protected boolean putConfigValue(String key, String value) {

    String previousValue = StringUtils.defaultString(getAutConfig().put(key, value));
    boolean wasEmpty = previousValue.length() == 0;
    boolean isEmpty = StringUtils.defaultString(value).length() == 0;
    boolean areBothEmpty = wasEmpty && isEmpty;

    if (isEmpty) {
        getAutConfig().remove(key);
    }

    return (!m_isinitialized && !areBothEmpty) || !value.equals(previousValue);
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.HtmlAutConfigComponent.java

/**
 * {@inheritDoc}/*w  w w.  j a va2  s.  com*/
 */
protected void populateBasicArea(Map<String, String> data) {
    super.populateBasicArea(data);

    String browser = data.get(AutConfigConstants.BROWSER);
    if (browser == null) {
        browser = Browser.InternetExplorer.toString();
    }
    m_browserCombo.setSelectedObject(Browser.valueOf(browser));

    if (!isDataNew(data)) {
        m_autUrlTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.AUT_URL)));
    }
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.HtmlAutConfigComponent.java

/**
 * {@inheritDoc}//from w  w  w  .ja v a  2  s.com
 */
protected void populateAdvancedArea(Map<String, String> data) {
    if (!isDataNew(data)) {
        m_browserTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.BROWSER_PATH)));
        String selection = data.get(AutConfigConstants.SINGLE_WINDOW_MODE);
        boolean selected = false;
        if (StringUtils.isEmpty(selection)) {
            selected = true;
        } else {
            selected = Boolean.parseBoolean(selection);
        }
        m_singleWindowCheckBox.setSelection(selected);
    } else {
        m_singleWindowCheckBox.setSelection(true);
    }

}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.JavaAutConfigComponent.java

/**
 * {@inheritDoc}/*w ww.java2s  .  c o m*/
 */
protected boolean putConfigValue(String key, String value) {
    boolean hasChanged = super.putConfigValue(key, value);

    if (hasChanged) {

        for (Control field : getJavaRelatedFields()) {
            field.setEnabled(true);
        }

        boolean enableJarField = StringUtils.defaultString(getConfigValue(AutConfigConstants.CLASSNAME))
                .length() == 0;
        m_jarTextField.setEnabled(enableJarField);
        m_jarButton.setEnabled(enableJarField && (checkLocalhostServer() || isRemoteRequest()));

        m_classNameTextField.setEnabled(
                StringUtils.defaultString(getConfigValue(AutConfigConstants.JAR_FILE)).length() == 0);

        String exe = getConfigValue(AutConfigConstants.EXECUTABLE);
        boolean isEmpty = exe == null || exe.length() == 0;
        for (Control field : getJavaRelatedFields()) {
            field.setEnabled(isEmpty && field.isEnabled());
        }
        if (!isEmpty) {
            m_classPathListField.setSelection(-1);
            checkClasspathButtons();
        }

        String classname = getConfigValue(AutConfigConstants.CLASSNAME);
        String jar = getConfigValue(AutConfigConstants.JAR_FILE);
        boolean isClassnameEmpty = classname == null || classname.length() == 0;
        boolean isJarEmpty = jar == null || jar.length() == 0;
        boolean enableExe = isJarEmpty && isClassnameEmpty;
        m_execTextField.setEnabled(enableExe);
        m_execButton.setEnabled(enableExe && (checkLocalhostServer() || isRemoteRequest()));

    }

    return hasChanged;
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.JavaAutConfigComponent.java

/** 
 * The action of the JAR name field.//w ww  .ja v  a 2s. com
 * @return <code>null</code> if the new value is valid. Otherwise, returns
 *         a status parameter indicating the cause of the problem.
 */
DialogStatusParameter modifyJarFieldAction() {

    DialogStatusParameter error = null;
    boolean isEmpty = m_jarTextField.getText().length() == 0;
    if (isValid(m_jarTextField, true) && !isEmpty) {
        if (checkLocalhostServer()) {
            String filename = m_jarTextField.getText();
            File file = new File(filename);
            String workingDir = StringUtils.defaultString(getConfigValue(AutConfigConstants.WORKING_DIR));
            if (!file.isAbsolute() && workingDir.length() != 0) {

                filename = workingDir + "/" + filename; //$NON-NLS-1$
                file = new File(filename);
            }
            try {
                if (!file.exists()) {
                    error = createWarningStatus(
                            NLS.bind(Messages.AUTConfigComponentFileNotFound, file.getCanonicalPath()));
                } else {
                    JarFile jarFile = new JarFile(file);
                    Manifest jarManifest = jarFile.getManifest();
                    if (jarManifest == null) {
                        // no manifest for JAR
                        error = createErrorStatus(Messages.AUTConfigComponentNoManifest);
                    } else if (jarManifest.getMainAttributes().getValue(MAIN_CLASS) == null) {

                        // no main class defined in JAR manifest
                        error = createErrorStatus(Messages.AUTConfigComponentNoMainClass);
                    }
                }
            } catch (ZipException ze) {
                // given file is not a jar file
                error = createErrorStatus(NLS.bind(Messages.AUTConfigComponentFileNotJar, filename));
            } catch (IOException e) {
                // could not find jar file
                error = createWarningStatus(NLS.bind(Messages.AUTConfigComponentFileNotFound, filename));
            }
        }
    } else if (!isEmpty) {
        error = createErrorStatus(Messages.AUTConfigComponentWrongJAR);
    }

    putConfigValue(AutConfigConstants.JAR_FILE, m_jarTextField.getText());

    return error;
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.JavaAutConfigComponent.java

/**
 * Populates GUI for the advanced configuration section, and Displays the
 * current Values of the Activation_METHOD and monitoring agents in the 
 * ComboBoxes/*  w ww . j  ava 2 s .  c o m*/
 * @param data map representing the data to use for population.
 */

protected void populateExpertArea(Map<String, String> data) {

    m_activationMethodCombo
            .setSelectedObject(ActivationMethod.getEnum(data.get(AutConfigConstants.ACTIVATION_METHOD)));

    String monitoringAgentId = data.get(AutConfigConstants.MONITORING_AGENT_ID);
    if (StringUtils.isEmpty(monitoringAgentId)) {
        m_monitoringCombo.deselectAll();
    } else {
        m_monitoringCombo.setSelectedObject(monitoringAgentId);
        if (m_monitoringCombo.getSelectedObject() == null) {
            // additional handling for missing Monitoring extension
            ArrayList<String> values = new ArrayList<String>(m_monitoringCombo.getValues());
            ArrayList<String> displayValues = new ArrayList<String>(
                    Arrays.asList(m_monitoringCombo.getItems()));
            values.add(0, monitoringAgentId);
            values.remove(null);
            displayValues.add(0, monitoringAgentId);
            displayValues.remove(StringUtils.EMPTY);

            m_monitoringCombo.setItems(values, displayValues);
            m_monitoringCombo.setSelectedObject(monitoringAgentId);
        }
    }

    if (!isDataNew(data)) {
        m_autJreParamTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.JRE_PARAMETER)));
        m_envTextArea.setText(StringUtils.defaultString(data.get(AutConfigConstants.ENVIRONMENT)));
    }

}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.JavaAutConfigComponent.java

/**
 * Populates GUI for the advanced configuration section.
 * /*from w w w  .  ja  v  a 2 s . co  m*/
 * @param data Map representing the data to use for population.
 */
protected void populateAdvancedArea(Map<String, String> data) {
    // class name
    m_classNameTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.CLASSNAME)));

    // class path
    initDataClassPath(StringUtils.defaultString(data.get(AutConfigConstants.CLASSPATH)));

    // aut arguments
    m_autArgsTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.AUT_ARGUMENTS)));
    // JRE
    String jreDirectory = StringUtils.defaultString(getConfigValue(AutConfigConstants.JRE_BINARY));
    if (isConfigNew()) {
        jreDirectory = getDefaultJreBin();
        modifyJREFieldAction();
    }
    m_autJreTextField.setText(jreDirectory);
}

From source file:org.eclipse.jubula.client.ui.rcp.widgets.autconfig.JavaAutConfigComponent.java

/**
 * Populates GUI for the basic configuration section.
 * //from w  w w  .  j a  v a 2s  .c  om
 * @param data Map representing the data to use for population.
 */
protected void populateBasicArea(Map<String, String> data) {

    super.populateBasicArea(data);

    if (!isDataNew(data)) {
        getServerCombo().select(
                getServerCombo().indexOf(StringUtils.defaultString(data.get(AutConfigConstants.SERVER))));
        m_jarTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.JAR_FILE)));
        m_execTextField.setText(StringUtils.defaultString(data.get(AutConfigConstants.EXECUTABLE)));

    }

}