Source:
<code>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 <START> DRepresentationDescriptor).map(obj -> (DRepresentationDescriptor) obj) <END> .collect(Collectors.toSet()); if (!repToDelete.isEmpty()) { DeleteRepresentationAction deleteRepresentationAction = new DeleteRepresentationAction(repToDelete); deleteRepresentationAction.run(); } } theTreeViewer.refresh(); } }); }</code><technical_language>written DRepresentationDescriptor.class::cast</technical_language>

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(); } }); }