Source:
private void createModelExplorerButton(Composite parent, final TreeViewer theTreeViewer) { Composite subComposite = toolkit.createComposite(parent, SWT.NONE); subComposite.setLayout(GridLayoutFactory.fillDefaults().margins(0, 0).create()); subComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); Composite buttonsComposite = toolkit.createComposite(subComposite, SWT.NONE); FillLayout buttonsLayout = new FillLayout(SWT.BEGINNING); buttonsLayout.spacing = 5; buttonsComposite.setLayout(buttonsLayout); addButton(buttonsComposite, Messages.UI_SessionEditor_new_semantic_model_action_label, () -> { createAndRegisterNewSemanticModel(); }); addButton(buttonsComposite, Messages.UI_SessionEditor_models_button_newSemanticModel, () -> { AddModelDependencyAction addModelDependencyAction = new AddModelDependencyAction(session); addModelDependencyAction.run(); }); removeSemanticModelOrRepresentationButton = addButton(buttonsComposite, Messages.UI_SessionEditor_models_button_removeSemanticModel, () -> { if (theTreeViewer != null) { final IStructuredSelection selection = (IStructuredSelection) theTreeViewer.getSelection(); Collection<?> selectedObjects = selection.toList(); if (!selectedObjects.isEmpty()) { Collection<Resource> semanticResources = getSemanticResources(selectedObjects); if (!semanticResources.isEmpty()) { RemoveSemanticResourceAction removeSemanticResourceAction = new RemoveSemanticResourceAction(semanticResources, session); removeSemanticResourceAction.run(); } Set<DRepresentationDescriptor> repToDelete = selectedObjects.stream().filter(obj -> obj instanceof DRepresentationDescriptor).map(obj -> (DRepresentationDescriptor) obj) .collect(Collectors.toSet()); if (!repToDelete.isEmpty()) { DeleteRepresentationAction deleteRepresentationAction = new DeleteRepresentationAction(repToDelete); deleteRepresentationAction.run(); } } theTreeViewer.refresh(); } }); }

Target:
private void createModelExplorerButton(Composite parent, final TreeViewer theTreeViewer) { Composite subComposite = toolkit.createComposite(parent, SWT.NONE); subComposite.setLayout(GridLayoutFactory.fillDefaults().margins(0, 0).create()); subComposite.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); Composite buttonsComposite = toolkit.createComposite(subComposite, SWT.NONE); FillLayout buttonsLayout = new FillLayout(SWT.BEGINNING); buttonsLayout.spacing = 5; buttonsComposite.setLayout(buttonsLayout); addButton(buttonsComposite, Messages.UI_SessionEditor_new_semantic_model_action_label, () -> { createAndRegisterNewSemanticModel(); }); addButton(buttonsComposite, Messages.UI_SessionEditor_models_button_newSemanticModel, () -> { AddModelDependencyAction addModelDependencyAction = new AddModelDependencyAction(session, false); addModelDependencyAction.run(); }); removeSemanticModelOrRepresentationButton = addButton(buttonsComposite, Messages.UI_SessionEditor_models_button_removeSemanticModel, () -> { if (theTreeViewer != null) { final IStructuredSelection selection = (IStructuredSelection) theTreeViewer.getSelection(); Collection<?> selectedObjects = selection.toList(); if (!selectedObjects.isEmpty()) { Collection<Resource> semanticResources = getSemanticResources(selectedObjects); if (!semanticResources.isEmpty()) { RemoveSemanticResourceAction removeSemanticResourceAction = new RemoveSemanticResourceAction(semanticResources, session); removeSemanticResourceAction.run(); } Set<DRepresentationDescriptor> repToDelete = selectedObjects.stream().filter(DRepresentationDescriptor.class::isInstance).map(DRepresentationDescriptor.class::cast) .collect(Collectors.toSet()); if (!repToDelete.isEmpty()) { DeleteRepresentationAction deleteRepresentationAction = new DeleteRepresentationAction(repToDelete); deleteRepresentationAction.run(); } } theTreeViewer.refresh(); } }); }