Example usage for org.eclipse.jface.preference PreferencePage setErrorMessage

List of usage examples for org.eclipse.jface.preference PreferencePage setErrorMessage

Introduction

In this page you can find the example usage for org.eclipse.jface.preference PreferencePage setErrorMessage.

Prototype

@Override
    public void setErrorMessage(String newMessage) 

Source Link

Usage

From source file:org.eclipse.buckminster.p4.ui.prefs.ClientPane.java

License:Open Source License

public void init() {
    Composite clientFields = new Composite(this, SWT.NONE);
    clientFields.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;// www. j  a va  2 s . co  m
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    clientFields.setLayout(layout);
    m_clientName = UiUtils.createLabeledText(clientFields, Messages.name, SWT.READ_ONLY, s_tooltipRefresh);
    m_clientName.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));

    m_localRoot = UiUtils.createLabeledText(clientFields, Messages.local_root_with_colon, SWT.NONE,
            s_tooltipRefresh);
    m_localRoot.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            boolean valid = true;
            String errMsg = null;
            String dirName = ((Text) e.getSource()).getText().trim();
            if (dirName.length() > 0) {
                File file = new File(dirName);
                valid = file.exists();
                if (!valid && !dirName.contains("${")) //$NON-NLS-1$
                    errMsg = dirName + Messages._does_not_exist;
            }

            PreferencePage prefPage = getPreferencePage();
            prefPage.setValid(errMsg == null);
            prefPage.setErrorMessage(errMsg);
        }
    });
    m_browse = new Button(clientFields, SWT.PUSH);
    m_browse.setText(Messages.browse_with_dots);
    m_browse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent event) {
            browseButtonPressed();
        }
    });

    m_defaultClient = new Button(clientFields, SWT.CHECK);
    m_defaultClient.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false, 3, 1));
    m_defaultClient.setText(Messages.this_is_the_default_client);
    m_defaultClient.setEnabled(false);
    this.createListContents(Messages.depot_mappings);

    Composite depotMappingFields = new Composite(this, SWT.NONE);
    depotMappingFields.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
    layout = new GridLayout(2, false);
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    depotMappingFields.setLayout(layout);

    m_depotMappingName = UiUtils.createLabeledText(depotMappingFields, Messages.name, SWT.READ_ONLY, null);
    m_depotPattern = UiUtils.createLabeledText(depotMappingFields, Messages.depot_pattern_with_colon, SWT.NONE,
            new ModifyListener() {
                public void modifyText(ModifyEvent ev) {
                    String errMsg = null;
                    String lpe = ((Text) ev.getSource()).getText().trim();
                    if (lpe.length() > 0) {
                        try {
                            Pattern.compile(lpe);
                        } catch (PatternSyntaxException e) {
                            errMsg = e.getMessage();
                        }
                    }
                    PreferencePage prefPage = getPreferencePage();
                    prefPage.setValid(errMsg == null);
                    prefPage.setErrorMessage(errMsg);
                }
            });

    m_depotPattern.setToolTipText(
            Messages.a_regular_expression_used_when_creating_a_client_root_relative_path_that_will_be_used_for_component_materialization_based_on_the_full_depot_path_of_a_component);

    m_localReplacement = UiUtils.createLabeledText(depotMappingFields, Messages.local_replacement_with_colon,
            SWT.NONE, null);
    m_localReplacement.setToolTipText(
            Messages.the_replacement_string_used_when_creating_the_client_root_relative_path_that_will_be_used_for_component_materialization_based_on_the_full_depot_path_of_a_component);
}