Example usage for org.eclipse.jface.fieldassist ControlDecoration getMarginWidth

List of usage examples for org.eclipse.jface.fieldassist ControlDecoration getMarginWidth

Introduction

In this page you can find the example usage for org.eclipse.jface.fieldassist ControlDecoration getMarginWidth.

Prototype

public int getMarginWidth() 

Source Link

Document

Get the margin width in pixels that should be used between the decorator and the horizontal edge of the control.

Usage

From source file:org.eclipse.jubula.launch.ui.tab.AutLaunchConfigurationTab.java

License:Open Source License

/**
 * //  w  w w  .j  a  v  a 2 s .  c o  m
 * {@inheritDoc}
 */
public void createControl(Composite parent) {
    Image infoImage = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION).getImage();
    Composite composite = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(composite);
    composite.setLayout(new GridLayout(2, false));

    m_autIdLabel = new Label(composite, SWT.NONE);
    m_autIdLabel.setText(Messages.AutLaunchConfigurationTab_AutIdTextField_label);

    m_autIdText = new Text(composite, SWT.BORDER);

    ControlDecoration autIdLabelDecoration = new ControlDecoration(m_autIdText, SWT.LEFT | SWT.TOP);
    autIdLabelDecoration.setDescriptionText(Messages.AutLaunchConfigurationTab_AutIdTextField_info);
    autIdLabelDecoration.setImage(infoImage);
    autIdLabelDecoration.setMarginWidth(2);
    autIdLabelDecoration.setShowOnlyOnFocus(false);

    GridDataFactory.fillDefaults().grab(true, false)
            .indent(autIdLabelDecoration.getImage().getBounds().x + (autIdLabelDecoration.getMarginWidth() * 2),
                    0)
            .applyTo(m_autIdText);

    m_autIdText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            setDirty(true);
            updateLaunchConfigurationDialog();
        }
    });

    setControl(composite);
}

From source file:org.eclipse.riena.ui.ridgets.swt.MarkerSupportTest.java

License:Open Source License

/**
 * Tests the <i>private</i> method {@code createErrorDecoration}.
 * /*from  ww  w .  ja v  a2s  .  c o m*/
 * @throws Exception
 *             handled by JUnit
 */
public void testCreateErrorDecoration() throws Exception {
    final RienaDefaultLnf originalLnf = LnfManager.getLnf();
    final DefaultRealm realm = new DefaultRealm();
    try {
        final Text text = new Text(shell, SWT.NONE);
        final ITextRidget ridget = new TextRidget();
        ridget.setUIControl(text);
        MarkerSupport support = new MarkerSupport(ridget, null);

        LnfManager.setLnf(new MyLnf());
        ControlDecoration deco = ReflectionUtils.invokeHidden(support, "createErrorDecoration", text);
        assertEquals(100, deco.getMarginWidth());
        assertNotNull(deco.getImage());

        LnfManager.setLnf(new MyNonsenseLnf());
        deco = ReflectionUtils.invokeHidden(support, "createErrorDecoration", text);
        assertEquals(1, deco.getMarginWidth());
        assertNotNull(deco.getImage());

        support = null;
        SwtUtilities.dispose(text);
    } finally {
        LnfManager.setLnf(originalLnf);
        realm.dispose();
    }
}

From source file:org.eclipse.team.internal.ccvs.ui.wizards.ConfigurationWizardMainPage.java

License:Open Source License

/**
 * Creates the UI part of the page.//from   w  ww.j  a  v  a  2 s  .  co  m
 * 
 * @param parent  the parent of the created widgets
 */
public void createControl(Composite parent) {
    Composite composite = createComposite(parent, 2, false);
    // set F1 help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.SHARING_NEW_REPOSITORY_PAGE);

    Listener listener = new Listener() {
        public void handleEvent(Event event) {
            if (location != null) {
                oldLocation = location;
                location = null;
            }
            if (event.widget == hostCombo) {
                String hostText = hostCombo.getText();
                if (hostText.length() > 0 && hostText.charAt(0) == ':') {
                    try {
                        CVSRepositoryLocation newLocation = CVSRepositoryLocation.fromString(hostText);
                        connectionMethodCombo.setText(newLocation.getMethod().getName());
                        repositoryPathCombo.setText(newLocation.getRootDirectory());
                        int port = newLocation.getPort();
                        if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT) {
                            useDefaultPort.setSelection(true);
                            useCustomPort.setSelection(false);
                        } else {
                            useCustomPort.setSelection(true);
                            useDefaultPort.setSelection(false);
                            portText.setText(String.valueOf(port));
                        }

                        userCombo.setText(newLocation.getUsername());
                        //passwordText.setText(newLocation.xxx);
                        hostCombo.setText(newLocation.getHost());
                    } catch (CVSException e) {
                        CVSUIPlugin.log(e);
                    }
                }
            }
            updateWidgetEnablements();
        }
    };

    Group g = createGroup(composite, CVSUIMessages.ConfigurationWizardMainPage_Location_1);

    // Host name
    createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_host);
    hostCombo = createEditableCombo(g);
    ControlDecoration decoration = new ControlDecoration(hostCombo, SWT.TOP | SWT.LEFT);
    FieldDecoration infoDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION);
    decoration.setImage(infoDecoration.getImage());
    decoration.setDescriptionText(CVSUIMessages.ConfigurationWizardMainPage_8);
    decoration.setShowOnlyOnFocus(true);

    ((GridLayout) g.getLayout()).horizontalSpacing = decoration.getMarginWidth()
            + infoDecoration.getImage().getBounds().width;

    hostCombo.addListener(SWT.Selection, listener);
    hostCombo.addListener(SWT.Modify, listener);

    // Repository Path
    createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_repositoryPath);
    repositoryPathCombo = createEditableCombo(g);
    repositoryPathCombo.addListener(SWT.Selection, listener);
    repositoryPathCombo.addListener(SWT.Modify, listener);

    g = createGroup(composite, CVSUIMessages.ConfigurationWizardMainPage_Authentication_2);

    // User name
    createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_userName);
    userCombo = createEditableCombo(g);
    userCombo.addListener(SWT.Selection, listener);
    userCombo.addListener(SWT.Modify, listener);

    // Password
    createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_password);
    passwordText = createPasswordField(g);
    passwordText.addListener(SWT.Modify, listener);

    g = createGroup(composite, CVSUIMessages.ConfigurationWizardMainPage_Connection_3);

    // Connection type
    createLabel(g, CVSUIMessages.ConfigurationWizardMainPage_connection);
    connectionMethodCombo = createCombo(g);
    connectionMethodCombo.addListener(SWT.Selection, listener);

    // Port number
    // create a composite to ensure the radio buttons come in the correct order
    Composite portGroup = new Composite(g, SWT.NONE);
    GridData data = new GridData();
    data.horizontalSpan = 2;
    portGroup.setLayoutData(data);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    portGroup.setLayout(layout);
    useDefaultPort = createRadioButton(portGroup, CVSUIMessages.ConfigurationWizardMainPage_useDefaultPort, 2);
    useCustomPort = createRadioButton(portGroup, CVSUIMessages.ConfigurationWizardMainPage_usePort, 1);
    useCustomPort.addListener(SWT.Selection, listener);
    portText = createTextField(portGroup);
    portText.addListener(SWT.Modify, listener);

    // create a composite to ensure the validate button is in its own tab group
    if (showValidate) {
        Composite validateButtonTabGroup = new Composite(composite, SWT.NONE);
        data = new GridData();
        data.horizontalSpan = 2;
        validateButtonTabGroup.setLayoutData(data);
        validateButtonTabGroup.setLayout(new FillLayout());

        validateButton = new Button(validateButtonTabGroup, SWT.CHECK);
        validateButton.setText(CVSUIMessages.ConfigurationWizardAutoconnectPage_validate);
        validateButton.addListener(SWT.Selection, new Listener() {
            public void handleEvent(Event e) {
                validate = validateButton.getSelection();
            }
        });
    }

    allowCachingButton = new Button(composite, SWT.CHECK);
    allowCachingButton.setText(CVSUIMessages.UserValidationDialog_6);
    data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    data.horizontalSpan = 2;
    allowCachingButton.setLayoutData(data);
    allowCachingButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            allowCaching = allowCachingButton.getSelection();
        }
    });

    Link link = SWTUtils.createPreferenceLink(getShell(), composite,
            CVSUIMessages.ConfigurationWizardMainPage_9, CVSUIMessages.ConfigurationWizardMainPage_10);
    data = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    data.horizontalSpan = 2;
    link.setLayoutData(data);

    SWTUtils.createPreferenceLink(getShell(), composite, "org.eclipse.team.cvs.ui.ExtMethodPreferencePage", //$NON-NLS-1$
            new String[] { "org.eclipse.team.cvs.ui.cvs", //$NON-NLS-1$
                    "org.eclipse.team.cvs.ui.ExtMethodPreferencePage", //$NON-NLS-1$
                    "org.eclipse.jsch.ui.SSHPreferences", //$NON-NLS-1$
                    "org.eclipse.ui.net.NetPreferences" }, //$NON-NLS-1$
            CVSUIMessages.ConfigurationWizardMainPage_7);

    initializeValues();
    updateWidgetEnablements();
    hostCombo.setFocus();

    setControl(composite);
    Dialog.applyDialogFont(parent);
}