1515
1616import static org .eclipse .tm4e .core .internal .utils .NullSafetyHelper .lateNonNull ;
1717
18+ import java .util .List ;
1819import java .util .stream .Collectors ;
1920
2021import org .eclipse .core .runtime .content .IContentType ;
3435import org .eclipse .tm4e .core .grammar .IGrammar ;
3536import org .eclipse .tm4e .registry .IGrammarDefinition ;
3637import org .eclipse .tm4e .registry .IGrammarRegistryManager ;
38+ import org .eclipse .tm4e .registry .ITMScope ;
3739import org .eclipse .tm4e .registry .TMEclipseRegistryPlugin ;
3840import org .eclipse .tm4e .ui .TMUIPlugin ;
3941import org .eclipse .tm4e .ui .internal .TMUIMessages ;
@@ -69,6 +71,7 @@ public final class GrammarPreferencePage extends AbstractPreferencePage {
6971 private GrammarInfoWidget grammarInfoWidget = lateNonNull ();
7072 private TableWithControlsWidget <IContentType > contentTypesWidget = lateNonNull ();
7173 private ThemeAssociationsWidget themeAssociationsWidget = lateNonNull ();
74+ private TableWithControlsWidget <ITMScope > injectionsWidget = lateNonNull ();
7275
7376 private TMViewer grammarPreview = lateNonNull ();
7477
@@ -194,8 +197,8 @@ private void createGrammarDetailsView(final Composite parent) {
194197
195198 createGeneralTab (folder );
196199 createContentTypeTab (folder );
197- createThemeTab (folder );
198200 createInjectionTab (folder );
201+ createThemeTab (folder );
199202 }
200203
201204 /**
@@ -250,7 +253,47 @@ protected void createColumns() {
250253 };
251254 }
252255 };
253- contentTypesWidget .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
256+ contentTypesWidget .setLayoutData (new GridData (GridData .FILL_BOTH ));
257+
258+ tab .setControl (parent );
259+ }
260+
261+ /**
262+ * Create "Injection" tab
263+ */
264+ private void createInjectionTab (final TabFolder folder ) {
265+ final var tab = new TabItem (folder , SWT .NONE );
266+ tab .setText (TMUIMessages .GrammarPreferencePage_tab_injection_text );
267+
268+ final var parent = new Composite (folder , SWT .NONE );
269+ parent .setLayout (new GridLayout ());
270+ parent .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
271+
272+ injectionsWidget = new TableWithControlsWidget <>(parent , TMUIMessages .GrammarInjectionsWidget_description , false ) {
273+
274+ @ Override
275+ protected TableWidget <ITMScope > createTable (final Composite parent ) {
276+ return new TableWidget <>(parent , false ) {
277+ {
278+ getTable ().setHeaderVisible (false );
279+ }
280+
281+ @ Override
282+ protected void createColumns () {
283+ createColumn ("" , 100 , 0 );
284+ }
285+
286+ @ Override
287+ protected @ Nullable String getColumnText (final ITMScope injection , final int columnIndex ) {
288+ return switch (columnIndex ) {
289+ case 0 -> injection .getQualifiedName ();
290+ default -> null ;
291+ };
292+ }
293+ };
294+ }
295+ };
296+ injectionsWidget .setLayoutData (new GridData (GridData .FILL_BOTH ));
254297
255298 tab .setControl (parent );
256299 }
@@ -286,26 +329,11 @@ private void setPreviewTheme(final String themeId) {
286329 }
287330 }
288331
289- /**
290- * Create "Injection" tab
291- */
292- private void createInjectionTab (final TabFolder folder ) {
293- final var tab = new TabItem (folder , SWT .NONE );
294- tab .setText (TMUIMessages .GrammarPreferencePage_tab_injection_text );
295-
296- final var parent = new Composite (folder , SWT .NONE );
297- parent .setLayout (new GridLayout ());
298- parent .setLayoutData (new GridData (GridData .FILL_HORIZONTAL ));
299-
300- // TODO: manage UI injection
301-
302- tab .setControl (parent );
303- }
304-
305332 private void selectGrammar (final IGrammarDefinition definition ) {
306333 fillGeneralTab (definition );
307334 fillContentTypeTab (definition );
308335 fillThemeTab (definition );
336+ fillInjectionsTab (definition );
309337 preview (definition , themeAssociationsWidget .getTable ().getFirstSelectedElement ());
310338 }
311339
@@ -319,6 +347,15 @@ private void fillContentTypeTab(final IGrammarDefinition definition) {
319347 contentTypesWidget .getTable ().setInput (grammarManager .getContentTypesForScope (definition .getScope ()));
320348 }
321349
350+ private void fillInjectionsTab (final IGrammarDefinition definition ) {
351+ final var contributedInjections = grammarManager .getInjections (definition .getScope ());
352+ if (contributedInjections != null ) {
353+ injectionsWidget .getTable ().setInput (contributedInjections .stream ().map (ITMScope ::parse ).toArray ());
354+ } else {
355+ injectionsWidget .getTable ().setInput (List .of ());
356+ }
357+ }
358+
322359 private void fillThemeTab (final IGrammarDefinition definition ) {
323360 final TableWidget <IThemeAssociation > themeAssociationsTable = themeAssociationsWidget .getTable ();
324361 final IThemeAssociation selectedAssociation = themeAssociationsTable .getFirstSelectedElement ();
0 commit comments