Search in sources :

Example 1 with DefaultEObjectLabelProvider

use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.

the class DefaultEObjectLabelProviderTest method testSimple.

@Test
public void testSimple() throws Exception {
    final List<String> calls = new ArrayList<String>();
    @SuppressWarnings("unused") DefaultEObjectLabelProvider lp = new DefaultEObjectLabelProvider(null) {

        {
            setImageHelper(new IImageHelper.NullImageHelper());
        }

        public String text(String object) {
            return object;
        }

        public String text(Integer object) {
            return object.toString();
        }

        public String image(String obj) {
            calls.add(obj);
            return null;
        }

        public String image(Integer obj) {
            calls.add(obj.toString());
            return null;
        }
    };
    assertEquals("foo", lp.getText("foo"));
    assertEquals("89", lp.getText(new Integer(89)));
    assertTrue(calls.isEmpty());
    lp.getImage(true);
    assertTrue(calls.isEmpty());
    lp.getImage("String");
    assertTrue(calls.contains("String"));
    lp.getImage(new Integer(45));
    assertTrue(calls.contains("45"));
    assertTrue(calls.size() == 2);
}
Also used : DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) ArrayList(java.util.ArrayList) StyledString(org.eclipse.jface.viewers.StyledString) IImageHelper(org.eclipse.xtext.ui.IImageHelper) Test(org.junit.Test)

Example 2 with DefaultEObjectLabelProvider

use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.

the class DefaultEObjectLabelProviderTest method testErrorHandling.

@Test
public void testErrorHandling() throws Exception {
    final List<Object> calls = new ArrayList<Object>();
    @SuppressWarnings("unused") DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider() {

        {
            setImageHelper(new IImageHelper.NullImageHelper());
        }

        public String text(String object) {
            throw new NullPointerException();
        }

        public String text(Integer object) {
            throw new IllegalArgumentException();
        }

        public String image(String obj) {
            throw new NullPointerException();
        }

        public String image(Integer obj) {
            throw new IllegalArgumentException();
        }

        @Override
        protected String getDefaultText() {
            return DEFAULT_TEXT;
        }

        @Override
        protected Object handleImageError(Object[] params, Throwable e) {
            calls.add(params[0]);
            return super.handleImageError(params, e);
        }

        @Override
        protected Object handleTextError(Object[] params, Throwable e) {
            calls.add(params[0]);
            return super.handleTextError(params, e);
        }
    };
    assertEquals(DEFAULT_TEXT, defaultLabelProvider.getText("foo"));
    assertEquals(1, calls.size());
    try {
        assertEquals("89", defaultLabelProvider.getText(new Integer(89)));
        fail();
    } catch (RuntimeException e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    assertEquals(2, calls.size());
    assertNull(defaultLabelProvider.getImage("String"));
    assertEquals(3, calls.size());
    try {
        defaultLabelProvider.getImage(new Integer(45));
        fail();
    } catch (RuntimeException e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    assertEquals(4, calls.size());
}
Also used : DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) ArrayList(java.util.ArrayList) StyledString(org.eclipse.jface.viewers.StyledString) IImageHelper(org.eclipse.xtext.ui.IImageHelper) Test(org.junit.Test)

Example 3 with DefaultEObjectLabelProvider

use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.

the class DefaultEObjectLabelProviderTest method testGetTextCharSequence.

@Test
public void testGetTextCharSequence() throws Exception {
    DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider() {

        @SuppressWarnings("unused")
        public Object text(ParserRule parserRule) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append(parserRule.getName());
            return _builder;
        }
    };
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    parserRule.setName("testCreateStyledString");
    String styledText = defaultLabelProvider.getText(parserRule);
    assertEquals("testCreateStyledString", styledText);
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) StyledString(org.eclipse.jface.viewers.StyledString) Test(org.junit.Test)

Example 4 with DefaultEObjectLabelProvider

use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.

the class DefaultEObjectLabelProviderTest method testGetStyledTextFallbackText.

@Test
public void testGetStyledTextFallbackText() throws Exception {
    DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider();
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    parserRule.setName("testCreateStyledString");
    StyledString styledText = defaultLabelProvider.getStyledText(parserRule);
    assertEquals("testCreateStyledString", styledText.getString());
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) StyledString(org.eclipse.jface.viewers.StyledString) Test(org.junit.Test)

Example 5 with DefaultEObjectLabelProvider

use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.

the class DefaultEObjectLabelProviderTest method testGetTextWithExistingStyledStringLabel.

@Test
public void testGetTextWithExistingStyledStringLabel() throws Exception {
    DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider() {

        @SuppressWarnings("unused")
        public StyledString text(ParserRule parserRule) {
            return new StyledString(parserRule.getName());
        }
    };
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    parserRule.setName("testGetTextWithStyledStringLabel");
    assertEquals("testGetTextWithStyledStringLabel", defaultLabelProvider.getText(parserRule));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) StyledString(org.eclipse.jface.viewers.StyledString) Test(org.junit.Test)

Aggregations

DefaultEObjectLabelProvider (org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider)10 Test (org.junit.Test)9 StyledString (org.eclipse.jface.viewers.StyledString)8 ParserRule (org.eclipse.xtext.ParserRule)6 ArrayList (java.util.ArrayList)2 DefaultLocationInFileProvider (org.eclipse.xtext.resource.DefaultLocationInFileProvider)2 IImageHelper (org.eclipse.xtext.ui.IImageHelper)2 DefaultOutlineTreeProvider (org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider)2 Injector (com.google.inject.Injector)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 ISetup (org.eclipse.xtext.ISetup)1 XtextResource (org.eclipse.xtext.resource.XtextResource)1 IXtextDocument (org.eclipse.xtext.ui.editor.model.IXtextDocument)1 IOutlineNode (org.eclipse.xtext.ui.editor.outline.IOutlineNode)1 TextRegion (org.eclipse.xtext.util.TextRegion)1 IUnitOfWork (org.eclipse.xtext.util.concurrent.IUnitOfWork)1