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

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

Introduction

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

Prototype

public Image getImage() 

Source Link

Document

Get the image shown in this control decoration.

Usage

From source file:com.xored.af.ui.forms.parts.ControlDecorationUpdater.java

License:Open Source License

private synchronized void runUpdates() {
    final long startTime = System.currentTimeMillis();

    final Map<ControlDecoration, Update> updatesCopy = new HashMap<ControlDecoration, Update>(updates);
    updates.clear();/*from w ww. j  a v  a2s  .  com*/

    final int size = updatesCopy.size();
    int changes = 0;

    for (final Map.Entry<ControlDecoration, Update> entry : updatesCopy.entrySet()) {
        final ControlDecoration decoration = entry.getKey();
        // decoration itself may be already disposed, and also its control
        // may be disposed separately because of non-atomicity of disposal
        if (decoration.getControl() != null && !decoration.getControl().isDisposed()) {
            final Update update = entry.getValue();
            boolean changed = false;
            if (!equals(decoration.getImage(), update.image)) {
                decoration.setImage(update.image);
                changed = true;
            }
            if (!equals(decoration.getDescriptionText(), update.text)) {
                decoration.setDescriptionText(update.text);
                changed = true;
            }
            if (!equals(decoration.getControl().getBackground(), update.controlBg)) {
                decoration.getControl().setBackground(update.controlBg);
                changed = true;
            }
            if (changed) {
                changes++;
            }
        }
    }

    if (DEBUG) {
        AfUiPlugin.getDefault().info("Updated " + changes + " decorations in " + size + " requests in "
                + (System.currentTimeMillis() - startTime) + " millis");
    }
}

From source file:net.sf.eclipsensis.wizard.util.NSISWizardDialogUtil.java

License:Open Source License

/**
 * @param control/*from w ww. j  a v a  2s .  c o m*/
 */
public static void decorate(Control control) {
    ControlDecoration controlDecoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP, null);
    control.setData(CONTROL_DECORATION, controlDecoration);
    updateDecoration(control, control.isEnabled());
    if (controlDecoration.getImage() != null) {
        ((GridData) control.getLayoutData()).horizontalIndent += controlDecoration.getImage().getBounds().width;
    }
}

From source file:org.bonitasoft.studio.contract.ui.property.FieldDecoratorProviderTest.java

License:Open Source License

@Test
public void should_createControlDecorator_attach_a_ControlDecorator_to_a_Control() throws Exception {
    final ControlDecoration decorator = fieldDecoratorProvider.createControlDecorator(
            realmWithDisplay.createComposite(), "a description", FieldDecorationRegistry.DEC_CONTENT_PROPOSAL,
            SWT.RIGHT);/*from  w  w w .j a v  a 2  s  .  c  o m*/
    assertThat(decorator.getDescriptionText()).isEqualTo("a description");
    assertThat(decorator.getImage()).isNotNull();
}

From source file:org.eclipse.dltk.ui.wizards.ControlDecorationManager.java

License:Open Source License

public void show(Control control, IStatus status) {
    ControlDecoration decoration = decorations.get(control);
    if (decoration == null) {
        decoration = new ControlDecoration(control, SWT.LEFT | SWT.TOP);
        decorations.put(control, decoration);
    }/*  www .  ja  va 2 s.co m*/
    final Image image = getImageFor(status);
    if (decoration.getImage() != image) {
        final Composite parent = control.getParent();
        if (parent.getLayout() instanceof GridLayout) {
            final GridLayout layout = (GridLayout) parent.getLayout();
            if (image.getBounds().width > layout.horizontalSpacing) {
                layout.horizontalSpacing = image.getBounds().width;
                parent.layout();
            }
        }
        decoration.setImage(image);
    }
    decoration.setDescriptionText(status.getMessage());
    decoration.show();
}

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

License:Open Source License

/**
 * /*from  w  ww  .j  av a2 s.  c om*/
 * {@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.ptp.internal.rdt.editor.preferences.HeaderFooterContentProposalAdapter.java

License:Open Source License

/**
 * The constructor/*from  www .  ja  v a2  s  . com*/
 * @param text   the text field to add content assist 
 */
public HeaderFooterContentProposalAdapter(Text text) {
    super(text, new TextContentAdapter(), new HeaderFooterProposalProvider(), getTrigger(), "<".toCharArray());
    setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);
    setAutoActivationDelay(0);

    // add a "light bulb" to indicate that content assist is available
    ControlDecoration dec = new ControlDecoration(text, SWT.LEFT | SWT.TOP);
    FieldDecoration contentassistDecoration = FieldDecorationRegistry.getDefault()
            .getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    dec.setImage(contentassistDecoration.getImage());
    dec.setDescriptionText(contentassistDecoration.getDescription());
    dec.setShowOnlyOnFocus(true);

    // ensure that there is enough room for the "light bulb"
    Composite parent = text.getParent();
    GridLayout layout = (GridLayout) parent.getLayout();
    layout.horizontalSpacing = Math.max(layout.horizontalSpacing, dec.getImage().getBounds().width);
    layout.marginLeft = Math.max(layout.marginWidth, dec.getImage().getBounds().width) - layout.marginWidth;
}

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

License:Open Source License

/**
 * Tests the <i>private</i> method {@code createErrorDecoration}.
 * /*  ww w  . ja v a2s .  c  om*/
 * @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.wst.sse.sieditor.test.ui.v2.newtypedialog.NewTypeDialogTest.java

License:Open Source License

/**
 * Test method for//from  w  w w .j  a  v  a2 s.c  om
 * {@link org.eclipse.wst.sse.sieditor.ui.v2.newtypedialog.NewTypeDialog#createNameComposite(org.eclipse.swt.widgets.Composite)}
 * .
 */
@Test
public final void testCreateNameComposite() {
    setUpCreateAndOpenMock();
    dialogExposed.createAndOpen();
    final Composite dialogArea = (Composite) dialogExposed.getShell().getChildren()[0];
    final Composite dialogContent = (Composite) dialogArea.getChildren()[0];
    final Control control = dialogContent.getChildren()[1];
    assertTrue(control instanceof Composite);
    final Composite nameComposite = (Composite) control;
    final Control[] children = nameComposite.getChildren();
    assertEquals(2, children.length);
    assertTrue(children[0] instanceof Label);
    assertEquals(Messages.NewTypeDialog_label_name, ((Label) children[0]).getText());
    assertTrue(children[1] instanceof Text);
    assertEquals(DEFAULT_NAME, ((Text) children[1]).getText());
    final ControlDecoration decoration = dialogExposed.getDecoration();
    assertEquals(decoration.getControl(), children[1]);
    assertEquals(FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR)
            .getImage(), decoration.getImage());

    dialogExposed.buttonPressed(Dialog.CANCEL);
}