use of de.catma.util.Pair 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.util.Pair in project catma by forTEXT.
the class TagSelectionPanel method initListeners.
private void initListeners() {
tagChangedListener = new PropertyChangeListener() {
@SuppressWarnings("unchecked")
@Override
public void propertyChange(PropertyChangeEvent evt) {
Object newValue = evt.getNewValue();
Object oldValue = evt.getOldValue();
if (oldValue == null) {
// created
Pair<TagsetDefinition, TagDefinition> value = (Pair<TagsetDefinition, TagDefinition>) newValue;
TagsetDefinition tagset = value.getFirst();
TagDefinition tag = value.getSecond();
if (tag.getParentUuid().isEmpty()) {
TagsetTreeItem tagsetItem = new TagsetDataItem(tagset);
tagsetData.addItem(tagsetItem, new TagDataItem(tag));
tagsetGrid.expand(tagsetItem);
} else {
TagDefinition parentTag = project.getTagManager().getTagLibrary().getTagDefinition(tag.getParentUuid());
TagsetTreeItem parentTagItem = new TagDataItem(parentTag);
tagsetData.addItem(parentTagItem, new TagDataItem(tag));
tagsetGrid.expand(parentTagItem);
}
tagsetDataProvider.refreshAll();
} else if (newValue == null) {
// removed
Pair<TagsetDefinition, TagDefinition> deleted = (Pair<TagsetDefinition, TagDefinition>) oldValue;
TagDefinition deletedTag = deleted.getSecond();
tagsetData.removeItem(new TagDataItem(deletedTag));
tagsetDataProvider.refreshAll();
} else {
// update
TagDefinition tag = (TagDefinition) newValue;
TagsetDefinition tagset = (TagsetDefinition) oldValue;
TagsetTreeItem tagsetItem = new TagsetDataItem(tagset);
tagsetData.removeItem(new TagDataItem(tag));
TagDataItem tagDataItem = new TagDataItem(tag);
tagDataItem.setPropertiesExpanded(true);
tagsetData.addItem(tagsetItem, tagDataItem);
// TODO: sort
tagsetDataProvider.refreshAll();
}
}
};
project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagDefinitionChanged, tagChangedListener);
this.tagsetChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
handleTagsetChange(evt);
}
};
project.getTagManager().addPropertyChangeListener(TagManagerEvent.tagsetDefinitionChanged, tagsetChangeListener);
}
use of de.catma.util.Pair in project catma by forTEXT.
the class CorpusImportDialog method handleOkPressed.
@Override
protected void handleOkPressed() {
if (corporaGrid.getSelectedItems().isEmpty()) {
Notification.show("Info", "Please select a Corpus from the list first!", Type.HUMANIZED_MESSAGE);
} else {
final CorpusImportMetadata corpusMetadata = corporaGrid.getSelectedItems().iterator().next();
BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
progressBar.setCaption("Loading Corpus " + corpusMetadata);
backgroundServiceProvider.submit("load-corpus", new DefaultProgressCallable<Pair<File, List<CorpusImportDocumentMetadata>>>() {
@Override
public Pair<File, List<CorpusImportDocumentMetadata>> call() throws Exception {
File corpusFile = getCorpusFile(corpusMetadata);
return new Pair<>(corpusFile, null);
}
}, new ExecutionListener<Pair<File, List<CorpusImportDocumentMetadata>>>() {
@Override
public void done(Pair<File, List<CorpusImportDocumentMetadata>> result) {
try {
List<CorpusImportDocumentMetadata> documentMetadataList = getDocumentMetadata(corpusMetadata);
result.setSecond(documentMetadataList);
progressBar.setVisible(false);
CorpusImportDialog.this.result = result;
CorpusImportDialog.super.handleOkPressed();
} catch (Exception e) {
progressBar.setVisible(false);
Notification.show("Error", String.format("Error retrieving Document metadata! " + "\n The underlying error message was:\n%2$s", e.getMessage()), Type.ERROR_MESSAGE);
handleCancelPressed();
}
}
@Override
public void error(Throwable t) {
Logger.getLogger(ProjectView.class.getName()).log(Level.SEVERE, String.format("Error loading CATMA 5 Corpus %1$s!", corpusMetadata.toString()), t);
String errorMsg = t.getMessage();
if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
errorMsg = "";
}
progressBar.setVisible(false);
Notification.show("Error", String.format("Error listing CATMA 5 Corpus %1$s! " + "\n The underlying error message was:\n%2$s", corpusMetadata.toString(), errorMsg), Type.ERROR_MESSAGE);
handleCancelPressed();
}
});
}
}
use of de.catma.util.Pair in project catma by forTEXT.
the class AddParenttagDialog method getResult.
@Override
protected Pair<TagsetDefinition, TagDefinition> getResult() {
TagDefinition tag = new TagDefinition(idGenerator.generate(), tfName.getValue(), null, cbTagsets.getValue().getUuid());
tag.addSystemPropertyDefinition(new PropertyDefinition(idGenerator.generate(PropertyDefinition.SystemPropertyName.catma_displaycolor.name()), PropertyDefinition.SystemPropertyName.catma_displaycolor.name(), Collections.singletonList(String.valueOf(colorPicker.getValue().getRGB()))));
for (PropertyDefinition propertyDefinition : propertyDefDataProvider.getItems()) {
tag.addUserDefinedPropertyDefinition(propertyDefinition);
}
return new Pair<>(cbTagsets.getValue(), tag);
}
use of de.catma.util.Pair in project catma by forTEXT.
the class GitlabManagerPrivileged method acquireImpersonationToken.
@Override
public Pair<GitUser, String> acquireImpersonationToken(String identifier, String provider, String email, String name) throws IOException {
User user = this.acquireUser(identifier, provider, email, name);
UserApi customUserApi = this.privilegedGitLabApi.getUserApi();
try {
List<PersonalAccessToken> impersonationTokens = customUserApi.getImpersonationTokens(user.getId(), ImpersonationState.ACTIVE);
// revoke the default token if it exists actively
for (PersonalAccessToken token : impersonationTokens) {
if (token.getName().equals(GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME)) {
privilegedGitLabApi.getUserApi().revokeImpersonationToken(user.getId(), token.getId());
break;
}
}
} catch (GitLabApiException e) {
throw new IOException("Failed to revoke existing impersonation token", e);
}
String impersonationToken = this.createImpersonationToken(user.getId(), GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME);
if (impersonationToken == null) {
String errorMessage = String.format("Failed to acquire impersonation token for CATMA with identifier `%s`. " + "The creation of the token the associated GitLab user ID `%s` failed, no " + "active impersonation token called `%s` can be found!", identifier, user.getId(), GITLAB_DEFAULT_IMPERSONATION_TOKEN_NAME);
throw new IOException(errorMessage);
}
Pair<GitUser, String> retVal = new Pair<>(new GitUser(user), impersonationToken);
return retVal;
}
Aggregations