@Override public Options getOptions(DocumentOperationInput operationInput) throws DocumentOperationException { Options options = new Options(GoToDocumentsOperation.class); options.addLabel("Unique IDs (URNs), one per line:", false, true); String defaultString = ""; for (AnnotatedPluginDocument annotatedPluginDocument : operationInput.getInputDocumentsArray()) { defaultString += annotatedPluginDocument.getURN() + "\n"; } options .addMultipleLineStringOption(URNS_OPTION_NAME, "", defaultString, 5, false) .setValue(defaultString); return options; }
@Override public void performOperation( AnnotatedPluginDocument[] annotatedDocuments, ProgressListener progressListener, Options options, SequenceSelection sequenceSelection, OperationCallback callback) throws DocumentOperationException { try { String[] urnStrings = options.getValueAsString(URNS_OPTION_NAME).split("\n"); List<URN> validUrns = new ArrayList<URN>(); List<String> brokenUrns = new ArrayList<String>(); List<URN> missingUrns = new ArrayList<URN>(); for (String urnString : urnStrings) { try { String trimmedString = urnString.trim(); if (trimmedString.isEmpty()) { continue; } URN urn = new URN(trimmedString); if (DocumentUtilities.getDocumentByURN(urn) == null) { missingUrns.add(urn); continue; } validUrns.add(urn); } catch (MalformedURNException e) { brokenUrns.add(urnString); } } if (!brokenUrns.isEmpty()) { if (!Dialogs.showContinueCancelDialog( "Some of the URNs you entered are invalid. They will be ignored:\n\n" + StringUtilities.join("\n", brokenUrns), "Invalid URNs", null, Dialogs.DialogIcon.INFORMATION)) { return; } } if (!missingUrns.isEmpty()) { if (!Dialogs.showContinueCancelDialog( "Some of the URNs you entered cannot be found. They will be ignored:\n\n" + StringUtilities.join("\n", missingUrns), "Missing URNs", null, Dialogs.DialogIcon.INFORMATION)) { return; } } DocumentUtilities.selectDocuments(validUrns); } finally { progressListener.setProgress(1.0); } }