use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.
the class KwicPanel method handleAnnotateSelectedRequest.
private void handleAnnotateSelectedRequest(EventBus eventBus) {
final Set<QueryResultRow> selectedRows = kwicGrid.getSelectedItems();
if (selectedRows.isEmpty()) {
Notification.show("Info", "Please select one or more rows to annotate!", Type.HUMANIZED_MESSAGE);
return;
}
Set<String> documentIds = kwicDataProvider.getItems().stream().map(row -> row.getSourceDocumentId()).collect(Collectors.toSet());
WizardContext wizardContext = new WizardContext();
wizardContext.put(AnnotationWizardContextKey.DOCUMENTIDS, documentIds);
AnnotationWizard wizard = new AnnotationWizard(eventBus, project, wizardContext, new SaveCancelListener<WizardContext>() {
@Override
public void savePressed(WizardContext result) {
try {
annotateSelection(selectedRows, result);
} catch (Exception e) {
((ErrorHandler) UI.getCurrent()).showAndLogError("error annotating selected rows", e);
}
}
});
wizard.show();
}
use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.
the class ProjectView method importCollection.
private void importCollection() {
Set<SourceDocument> selectedDocuments = getSelectedDocuments();
if (selectedDocuments.size() != 1) {
Notification.show("Info", "Please select the corresponding Document first!", Type.HUMANIZED_MESSAGE);
} else {
final SourceDocument document = selectedDocuments.iterator().next();
GenericUploadDialog uploadDialog = new GenericUploadDialog(String.format("Upload a Collection for %1$s:", document.toString()), new SaveCancelListener<byte[]>() {
public void savePressed(byte[] result) {
InputStream is = new ByteArrayInputStream(result);
try {
if (BOMFilterInputStream.hasBOM(result)) {
is = new BOMFilterInputStream(is, // $NON-NLS-1$
Charset.forName("UTF-8"));
}
Pair<AnnotationCollection, List<TagsetDefinitionImportStatus>> loadResult = project.loadAnnotationCollection(is, document);
List<TagsetDefinitionImportStatus> tagsetDefinitionImportStatusList = loadResult.getSecond();
final AnnotationCollection annotationCollection = loadResult.getFirst();
CollectionImportDialog tagsetImportDialog = new CollectionImportDialog(tagsetDefinitionImportStatusList, new SaveCancelListener<List<TagsetDefinitionImportStatus>>() {
@Override
public void savePressed(List<TagsetDefinitionImportStatus> result) {
try {
project.importCollection(result, annotationCollection);
} catch (IOException e) {
((CatmaApplication) UI.getCurrent()).showAndLogError("Error importing Tagsets", e);
}
}
});
tagsetImportDialog.show();
} catch (IOException e) {
((CatmaApplication) UI.getCurrent()).showAndLogError("Error loading external Tagsets", e);
} finally {
CloseSafe.close(is);
}
}
});
uploadDialog.show();
}
}
use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.
the class AnnotationPanel method handleAddSubtagRequest.
private void handleAddSubtagRequest() {
final List<TagDefinition> parentTags = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList());
for (TagDefinition parentTag : parentTags) {
if (!project.hasPermission(project.getRoleForTagset(parentTag.getTagsetDefinitionUuid()), RBACPermission.TAGSET_WRITE)) {
Notification.show("Info", String.format("You do not have the permission to make changes to the Tagset of Tag %1$s, " + "Please contact the Project maintainer!", parentTag.getName()), Type.HUMANIZED_MESSAGE);
return;
}
}
if (!parentTags.isEmpty()) {
AddSubtagDialog addTagDialog = new AddSubtagDialog(new SaveCancelListener<TagDefinition>() {
public void savePressed(TagDefinition result) {
for (TagDefinition parent : parentTags) {
TagsetDefinition tagset = project.getTagManager().getTagLibrary().getTagsetDefinition(parent);
TagDefinition tag = new TagDefinition(result);
tag.setUuid(idGenerator.generate());
tag.setParentUuid(parent.getUuid());
tag.setTagsetDefinitionUuid(tagset.getUuid());
project.getTagManager().addTagDefinition(tagset, tag);
}
}
});
addTagDialog.show();
} else {
Notification.show("Info", "Please select at least one parent Tag!", Type.HUMANIZED_MESSAGE);
}
}
use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.
the class AnnotationPanel method handleAddTagRequest.
private void handleAddTagRequest() {
final Optional<TagsetDefinition> selectedTagset = tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagsetDataItem).findFirst().map(tagsetTreeItem -> ((TagsetDataItem) tagsetTreeItem).getTagset());
if (selectedTagset.isPresent() && !project.hasPermission(project.getRoleForTagset(selectedTagset.get().getUuid()), RBACPermission.TAGSET_WRITE)) {
Notification.show("Info", String.format("You do not have the permission to make changes to Tagset %1$s, " + "Please contact the Project maintainer!", selectedTagset.get().getName()), Type.HUMANIZED_MESSAGE);
return;
}
if (tagsets.isEmpty()) {
if (project.isAuthorizedOnProject(RBACPermission.TAGSET_CREATE_OR_UPLOAD)) {
Notification.show("Info", "You do not have any Tagsets to add Tags to yet, please create a Tagset first!", Type.HUMANIZED_MESSAGE);
} else {
Notification.show("Info", "You do not have any Tagsets to add Tags to yet, please contact the Project maintainer!", Type.HUMANIZED_MESSAGE);
}
return;
}
List<TagsetDefinition> editableTagsets = tagsets.stream().filter(tagset -> project.hasPermission(project.getRoleForTagset(tagset.getUuid()), RBACPermission.TAGSET_WRITE)).collect(Collectors.toList());
if (editableTagsets.isEmpty()) {
Notification.show("Info", "You do not have the permission to make changes to any of the available Tagsets! " + "Please contact the Project maintainer for changes!", Type.HUMANIZED_MESSAGE);
return;
}
AddParenttagDialog addTagDialog = new AddParenttagDialog(editableTagsets, selectedTagset, new SaveCancelListener<Pair<TagsetDefinition, TagDefinition>>() {
@Override
public void savePressed(Pair<TagsetDefinition, TagDefinition> result) {
project.getTagManager().addTagDefinition(result.getFirst(), result.getSecond());
}
});
addTagDialog.show();
}
use of de.catma.ui.dialog.SaveCancelListener in project catma by forTEXT.
the class AnnotationPanel method handleAddPropertyRequest.
private void handleAddPropertyRequest() {
final List<TagDefinition> targetTags = new ArrayList<>();
if (tagsetGrid.getSelectedItems().size() == 1) {
TagsetTreeItem selectedItem = tagsetGrid.getSelectedItems().iterator().next();
while (!(selectedItem instanceof TagDataItem) && (selectedItem != null)) {
selectedItem = tagsetData.getParent(selectedItem);
}
if (selectedItem != null) {
targetTags.add(((TagDataItem) selectedItem).getTag());
}
} else {
targetTags.addAll(tagsetGrid.getSelectedItems().stream().filter(tagsetTreeItem -> tagsetTreeItem instanceof TagDataItem).map(tagsetTreeItem -> ((TagDataItem) tagsetTreeItem).getTag()).collect(Collectors.toList()));
}
if (targetTags.isEmpty()) {
Notification.show("Info", "Please select one ore more Tags first!", Type.TRAY_NOTIFICATION);
} else {
for (TagDefinition targetTag : targetTags) {
if (!project.hasPermission(project.getRoleForTagset(targetTag.getTagsetDefinitionUuid()), RBACPermission.TAGSET_WRITE)) {
Notification.show("Info", String.format("You do not have the permission to make changes to the Tagset of Tag %1$s, " + "Please contact the Project maintainer!", targetTag.getName()), Type.HUMANIZED_MESSAGE);
return;
}
}
Multimap<String, PropertyDefinition> propertiesByName = ArrayListMultimap.create();
for (TagDefinition tag : targetTags) {
for (PropertyDefinition propertyDef : tag.getUserDefinedPropertyDefinitions()) {
if (!propertiesByName.containsKey(propertyDef.getName()) || propertiesByName.get(propertyDef.getName()).iterator().next().getPossibleValueList().equals(propertyDef.getPossibleValueList())) {
propertiesByName.put(propertyDef.getName(), propertyDef);
}
}
}
List<PropertyDefinition> commonProperties = propertiesByName.asMap().entrySet().stream().filter(entry -> entry.getValue().size() == targetTags.size()).map(entry -> new PropertyDefinition(entry.getValue().iterator().next())).collect(Collectors.toList());
// just a single tag's properties or is it a bulk(>1) edit?
final boolean bulkEdit = targetTags.size() > 1;
AddEditPropertyDialog addPropertyDialog = new AddEditPropertyDialog(bulkEdit, commonProperties, new SaveCancelListener<List<PropertyDefinition>>() {
@Override
public void savePressed(List<PropertyDefinition> result) {
if (bulkEdit) {
handleBulkEditProperties(result, commonProperties, targetTags);
} else {
handleSingleEditProperties(result, targetTags.iterator().next());
}
}
});
addPropertyDialog.show();
}
}
Aggregations