Search in sources :

Example 6 with DefaultEObjectLabelProvider

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

the class DefaultEObjectLabelProviderTest method testGetNullSafeDefaultText.

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

        @SuppressWarnings("unused")
        public StyledString text(ParserRule parserRule) {
            return new StyledString(parserRule.getName());
        }

        @Override
        protected String getDefaultText() {
            return DEFAULT_TEXT;
        }
    };
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    StyledString styledText = defaultLabelProvider.getStyledText(parserRule);
    assertEquals(DEFAULT_TEXT, 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 7 with DefaultEObjectLabelProvider

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

the class DefaultEObjectLabelProviderTest method testGetStyledTextWithExistingTextLabel.

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

        @SuppressWarnings("unused")
        public String text(ParserRule parserRule) {
            return parserRule.getName();
        }
    };
    ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
    parserRule.setName("testCreateStyledStringWithTextLabel");
    StyledString styledText = defaultLabelProvider.getStyledText(parserRule);
    assertEquals("testCreateStyledStringWithTextLabel", 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 8 with DefaultEObjectLabelProvider

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

the class DefaultEObjectLabelProviderTest method testGetStyledText.

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

        @SuppressWarnings("unused")
        public Object text(ParserRule parserRule) {
            return new StyledString(parserRule.getName());
        }
    };
    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 9 with DefaultEObjectLabelProvider

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

the class OutlineTreeProviderTest method testNoNames.

@Test
public void testNoNames() throws Exception {
    final DefaultOutlineTreeProvider noNamesTreeProvider = new DefaultOutlineTreeProvider(new DefaultEObjectLabelProvider(), new DefaultLocationInFileProvider()) {

        @Override
        protected Object _text(Object modelElement) {
            return null;
        }
    };
    final String modelAsText = "element1 { element11 {}} element2 {}";
    IXtextDocument document = createXtextDocument(modelAsText);
    final IOutlineNode rootNode = noNamesTreeProvider.createRoot(document);
    document.readOnly(new IUnitOfWork.Void<XtextResource>() {

        @Override
        public void process(XtextResource state) throws Exception {
            noNamesTreeProvider.createChildren(rootNode, state.getContents().get(0));
            assertEquals(1, rootNode.getChildren().size());
            IOutlineNode modelNode = rootNode.getChildren().get(0);
            assertEquals(state.getURI().trimFileExtension().lastSegment(), modelNode.getText());
            assertTrue(modelNode.hasChildren());
            assertEquals(1, modelNode.getChildren().size());
            IOutlineNode element1 = modelNode.getChildren().get(0);
            assertEquals("<unnamed>", element1.getText().toString());
            assertEquals(new TextRegion(0, 8), element1.getSignificantTextRegion());
            assertEquals(new TextRegion(0, 24), element1.getFullTextRegion());
            assertEquals(modelNode, element1.getParent());
            // node does not know that its children will be skipped
            assertTrue(element1.hasChildren());
            assertTrue(element1.getChildren().isEmpty());
        }
    });
}
Also used : DefaultLocationInFileProvider(org.eclipse.xtext.resource.DefaultLocationInFileProvider) DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) TextRegion(org.eclipse.xtext.util.TextRegion) XtextResource(org.eclipse.xtext.resource.XtextResource) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) DefaultOutlineTreeProvider(org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider) IOutlineNode(org.eclipse.xtext.ui.editor.outline.IOutlineNode) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Test(org.junit.Test)

Example 10 with DefaultEObjectLabelProvider

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

the class OutlineTreeProviderTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    final Injector injector = TestsActivator.getInstance().getInjector("org.eclipse.xtext.ui.tests.editor.outline.OutlineTestLanguage");
    with(new ISetup() {

        @Override
        public Injector createInjectorAndDoEMFRegistration() {
            return injector;
        }
    });
    treeProvider = new DefaultOutlineTreeProvider(new DefaultEObjectLabelProvider(), new DefaultLocationInFileProvider());
}
Also used : DefaultLocationInFileProvider(org.eclipse.xtext.resource.DefaultLocationInFileProvider) DefaultEObjectLabelProvider(org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider) Injector(com.google.inject.Injector) DefaultOutlineTreeProvider(org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider) ISetup(org.eclipse.xtext.ISetup)

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