Source:
<code>public Object execute(ExecutionEvent event) throws ExecutionException { if (HandlerUtil.getActivePartChecked(event) instanceof ViewPart) { ViewPart view = (ViewPart) HandlerUtil.getActivePartChecked(event); IWorkbenchPartSite myIWorkbenchPartSite = view.getSite(); ISelectionProvider selectionProvider = myIWorkbenchPartSite.getSelectionProvider(); if (selectionProvider != null && selectionProvider.getSelection() instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) selectionProvider.getSelection(); List<String> names = new LinkedList<String>(); List<Artifact> artifacts = new LinkedList<Artifact>(); ArtifactClipboard clipboard = new ArtifactClipboard(view.getSite().getId()); Iterator<?> iterator = selection.iterator(); Object selectionObject = null; while (iterator.hasNext()) { Object object = iterator.next(); if (object instanceof IAdaptable) { selectionObject = ((IAdaptable) object).getAdapter(Branch.class); if (selectionObject == null) { selectionObject = ((IAdaptable) object).getAdapter(Artifact.class); } } else if (object instanceof Match) { selectionObject = ((Match) object).getElement(); } if (selectionObject instanceof IOseeBranch) { names.add(((IOseeBranch) selectionObject).getName()); } else if (selectionObject instanceof Artifact) { Artifact artifact = (Artifact) selectionObject; names.add(artifact.getName()); artifacts.add(artifact); } } if (!names.isEmpty() && artifacts.isEmpty()) { clipboard.setTextToClipboard(names); } else if (!names.isEmpty() && !artifacts.isEmpty()) { try { clipboard.setArtifactsToClipboard(ServiceUtil.getAccessPolicy(), artifacts); } catch (OseeCoreException ex) { clipboard.dispose(); throw new ExecutionException(ex.getLocalizedMessage()); } } clipboard.dispose(); <START> } <END> } return null; }</code><technical_language>want consider wrapping code creation of clipboard in a try { // Code } finally { clipboard.dispose; } block, dispose clipboard if is exception selection processing</technical_language>

Target:
public Object execute(ExecutionEvent event) throws ExecutionException { if (HandlerUtil.getActivePartChecked(event) instanceof ViewPart) { ViewPart view = (ViewPart) HandlerUtil.getActivePartChecked(event); IWorkbenchPartSite myIWorkbenchPartSite = view.getSite(); ISelectionProvider selectionProvider = myIWorkbenchPartSite.getSelectionProvider(); if (selectionProvider != null && selectionProvider.getSelection() instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) selectionProvider.getSelection(); List<String> names = new LinkedList<String>(); List<Artifact> artifacts = new LinkedList<Artifact>(); ArtifactClipboard clipboard = new ArtifactClipboard(view.getSite().getId()); Iterator<?> iterator = selection.iterator(); Object selectionObject = null; try { while (iterator.hasNext()) { Object object = iterator.next(); if (object instanceof IAdaptable) { selectionObject = ((IAdaptable) object).getAdapter(Branch.class); if (selectionObject == null) { selectionObject = ((IAdaptable) object).getAdapter(Artifact.class); } } else if (object instanceof Match) { selectionObject = ((Match) object).getElement(); } if (selectionObject instanceof IOseeBranch) { names.add(((IOseeBranch) selectionObject).getName()); } else if (selectionObject instanceof Artifact) { Artifact artifact = (Artifact) selectionObject; names.add(artifact.getName()); artifacts.add(artifact); } } if (!names.isEmpty() && artifacts.isEmpty()) { clipboard.setTextToClipboard(names); } else if (!names.isEmpty() && !artifacts.isEmpty()) { try { clipboard.setArtifactsToClipboard(ServiceUtil.getAccessPolicy(), artifacts); } catch (OseeCoreException ex) { clipboard.dispose(); throw new ExecutionException(ex.getLocalizedMessage()); } } } finally { clipboard.dispose(); } } } return null; }