@Override public Object execute(ExecutionEvent event) throws ExecutionException { ISelection selection = HandlerUtil.getCurrentSelectionChecked(event); if (!selection.isEmpty()) { IStructuredSelection sSelection = (IStructuredSelection) selection; boolean confirmed = MessageDialog.openConfirm( HandlerUtil.getActiveShell(event), "Confirm Delete", "Please confirm that you wish to delete this metadata."); if (!confirmed) return null; MetsProjectNature mpn = MetsProjectNature.getNatureForMetsObject((EObject) sSelection.getFirstElement()); HashSet<SmLinkType> del = new HashSet<SmLinkType>(); Iterator it = sSelection.iterator(); while (it.hasNext()) { Object sel = it.next(); if (sel instanceof SmLinkType) { del.add((SmLinkType) sel); } } Command c = RemoveCommand.create( mpn.getEditingDomain(), mpn.getMets().getStructLink(), MetsPackage.eINSTANCE.getStructLinkType_SmLink(), del); mpn.getCommandStack().execute(c); } return null; }
/* * (non-Javadoc) * * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang. Object) */ @Override public Object[] getChildren(Object parent) { // log.debug("getChildren: {}", parent.toString()); try { if (parent instanceof IFile) { IFile f = (IFile) parent; if (IResourceConstants.CROSSWALK_EXTENSION.equals(f.getFileExtension())) { Map<Integer, MetadataCompartment> results = new HashMap<Integer, MetadataCompartment>(); IProject p = f.getProject(); MetsProjectNature n = (MetsProjectNature) p.getNature(MetsProjectNature.NATURE_ID); Collection<MdSecType> mdSecs = METSUtils.getAllMdSecTypes(n.getMets()); for (MdSecType mdSec : mdSecs) { if (f.getName().equals(mdSec.getGROUPID())) { // crosswalk record IDs end in underscore and row number String row = mdSec.getID().substring(mdSec.getID().lastIndexOf("_") + 1); Integer r = Integer.valueOf(Integer.parseInt(row)); MetadataCompartment mc = null; if (results.get(Integer.valueOf(r)) == null) { mc = new MetadataCompartment(); mc.row = r.intValue(); results.put(r, mc); } else { mc = results.get(r); } mc.metadataSections.add(mdSec); } } return results.values().toArray(); } } else if (parent instanceof MetadataCompartment) { MetadataCompartment mc = (MetadataCompartment) parent; return mc.metadataSections.toArray(); } } catch (CoreException e) { throw new Error(e); } return EMPTY_ARRAY; }