use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class ProjectView method initResourceContent.
/**
* initialize the resource part
* @return
*/
private Component initResourceContent() {
HorizontalFlexLayout resourceContent = new HorizontalFlexLayout();
documentGrid = TreeGridFactory.createDefaultTreeGrid();
documentGrid.addStyleNames(// $NON-NLS-1$
"flat-undecorated-icon-buttonrenderer");
documentGrid.setHeaderVisible(false);
documentGrid.setRowHeight(45);
documentGrid.addColumn(resource -> resource.getIcon(), new HtmlRenderer()).setWidth(100);
Function<Resource, String> buildNameFunction = (resource) -> {
StringBuilder sb = new StringBuilder().append(// $NON-NLS-1$
"<div class='documentsgrid__doc'> ").append(// $NON-NLS-1$
"<div class='documentsgrid__doc__title'> ").append(resource.getName()).append(// $NON-NLS-1$
"</div>");
if (resource.hasDetail()) {
sb.append(// $NON-NLS-1$
"<span class='documentsgrid__doc__author'> ").append(resource.getDetail()).append(// $NON-NLS-1$
"</span>");
}
// $NON-NLS-1$
sb.append("</div>");
return sb.toString();
};
documentGrid.addColumn(resource -> buildNameFunction.apply(resource), new HtmlRenderer()).setCaption("Name").setId(DocumentGridColumn.NAME.name()).setWidth(300);
documentGrid.addColumn(res -> res.getPermissionIcon(), new HtmlRenderer()).setCaption("Permission").setExpandRatio(1);
Label documentsAnnotations = new Label("Documents & Annotations");
documentGridComponent = new ActionGridComponent<TreeGrid<Resource>>(documentsAnnotations, documentGrid);
// $NON-NLS-1$
documentGridComponent.addStyleName("project-view-action-grid");
resourceContent.addComponent(documentGridComponent);
tagsetGrid = new Grid<>();
tagsetGrid.setHeaderVisible(false);
// $NON-NLS-1$
tagsetGrid.setWidth("400px");
tagsetGrid.addColumn(tagset -> VaadinIcons.TAGS.getHtml(), new HtmlRenderer()).setWidth(100);
tagsetGrid.addColumn(tagset -> tagset.getName()).setId(TagsetGridColumn.NAME.name()).setCaption("Name").setWidth(300);
Label tagsetsAnnotations = new Label("Tagsets");
tagsetGridComponent = new ActionGridComponent<Grid<TagsetDefinition>>(tagsetsAnnotations, tagsetGrid);
// $NON-NLS-1$
tagsetGridComponent.addStyleName("project-view-action-grid");
resourceContent.addComponent(tagsetGridComponent);
return resourceContent;
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class ChangeImportActionDialog method addContent.
@Override
protected void addContent(ComponentContainer content) {
HorizontalLayout choicePanel = new HorizontalLayout();
ListDataProvider<TagsetDefinition> tagsetGridDataProvider = new ListDataProvider<TagsetDefinition>(tagsets);
this.tagsetGrid = new Grid<>("Available Tagsets", tagsetGridDataProvider);
this.tagsetGrid.setHeight("200px");
tagsetGrid.addColumn(tagset -> tagset.getName()).setCaption("Name");
this.tagsetNameInput = new TextField("Enter the name of the new Tagset");
this.choices = new RadioButtonGroup<String>("Your choices are");
this.choices.setItems(choice1, choice2, choice3);
this.choices.addValueChangeListener(event -> {
choicePanel.removeAllComponents();
if (event.getValue().equals(choice1)) {
choicePanel.addComponent(this.tagsetNameInput);
} else if (event.getValue().equals(choice2)) {
choicePanel.addComponent(this.tagsetGrid);
}
});
content.addComponent(this.choices);
content.addComponent(choicePanel);
if (content instanceof AbstractOrderedLayout) {
((AbstractOrderedLayout) content).setComponentAlignment(choices, Alignment.TOP_CENTER);
((AbstractOrderedLayout) content).setComponentAlignment(choicePanel, Alignment.TOP_CENTER);
}
this.choices.setValue(choice2);
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class ImportIntrinsicMarkupStep method enter.
@Override
public void enter(boolean back) {
if (back) {
return;
}
contentPanel.setEnabled(false);
progressBar.setVisible(true);
progressBar.setIndeterminate(true);
@SuppressWarnings("unchecked") final ArrayList<UploadFile> files = new ArrayList<UploadFile>(((Collection<UploadFile>) wizardContext.get(DocumentWizard.WizardContextKey.UPLOAD_FILE_LIST)).stream().filter(uploadFile -> uploadFile.getMimetype().equals(FileType.XML2.getMimeType())).collect(Collectors.toList()));
final TagManager tagmanager = new TagManager(new TagLibrary());
BackgroundServiceProvider backgroundServiceProvider = (BackgroundServiceProvider) UI.getCurrent();
backgroundServiceProvider.submit("inspecting-intrinsic-markup", new DefaultProgressCallable<List<UploadFile>>() {
@Override
public List<UploadFile> call() throws Exception {
IDGenerator idGenerator = new IDGenerator();
for (UploadFile uploadFile : files) {
XML2ContentHandler contentHandler = new XML2ContentHandler();
SourceDocument doc = new SourceDocument(uploadFile.getUuid(), contentHandler);
SourceDocumentInfo documentInfo = new SourceDocumentInfo();
TechInfoSet techInfoSet = new TechInfoSet();
techInfoSet.setURI(uploadFile.getTempFilename());
documentInfo.setTechInfoSet(techInfoSet);
contentHandler.setSourceDocumentInfo(documentInfo);
XmlMarkupCollectionSerializationHandler handler = new XmlMarkupCollectionSerializationHandler(tagmanager, contentHandler, project.getUser().getIdentifier());
try (FileInputStream fis = new FileInputStream(new File(uploadFile.getTempFilename()))) {
AnnotationCollection collection = handler.deserialize(doc, idGenerator.generateCollectionId(), fis);
uploadFile.setIntrinsicMarkupCollection(collection);
}
}
return files;
}
}, new ExecutionListener<List<UploadFile>>() {
@Override
public void done(List<UploadFile> result) {
contentPanel.setEnabled(true);
progressBar.setVisible(false);
progressBar.setIndeterminate(false);
fileList.clear();
fileList.addAll(result);
fileDataProvider.refreshAll();
tagsetImportList.clear();
String defaultIntrinsicXMLElmentsName = "Default Intrinsic XML Elements";
for (TagsetDefinition tagset : tagmanager.getTagLibrary()) {
if (!tagset.isEmpty()) {
TagsetDefinition targetTagset = project.getTagManager().getTagLibrary().getTagsetDefinition(tagset.getUuid());
boolean inProject = false;
if (targetTagset == null) {
targetTagset = tagset;
} else {
inProject = true;
}
String namespace = tagset.getName() == null ? "none" : tagset.getName();
if (tagset.getName() == null) {
tagset.setName(defaultIntrinsicXMLElmentsName);
}
TagsetImport tagsetImport = new TagsetImport(namespace, tagset, targetTagset, inProject ? TagsetImportState.WILL_BE_MERGED : TagsetImportState.WILL_BE_CREATED);
tagsetImportList.add(tagsetImport);
}
}
tagsetDataProvider.refreshAll();
wizardContext.put(DocumentWizard.WizardContextKey.TAGSET_IMPORT_LIST, tagsetImportList);
if (stepChangeListener != null) {
stepChangeListener.stepChanged(ImportIntrinsicMarkupStep.this);
}
}
@Override
public void error(Throwable t) {
Logger.getLogger(ImportIntrinsicMarkupStep.class.getName()).log(Level.SEVERE, "Error inspecting files", t);
String errorMsg = t.getMessage();
if ((errorMsg == null) || (errorMsg.trim().isEmpty())) {
errorMsg = "";
}
Notification.show("Error", String.format("Error inspecting the contents! " + "\n The underlying error message was:\n%1$s", errorMsg), Type.ERROR_MESSAGE);
}
});
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class TagsetXMLExportStreamSource method getStream.
@Override
public InputStream getStream() {
final UI ui = UI.getCurrent();
Set<TagsetDefinition> tagsets = tagsetsSupplier.get();
Project project = projectSupplier.get();
if (tagsets != null && !tagsets.isEmpty()) {
TeiDocumentFactory teiDocumentFactory = new TeiDocumentFactory();
try {
final TeiDocument teiDocument = teiDocumentFactory.createEmptyDocument(null);
final TeiTagLibrarySerializer teiTagSerializer = new TeiTagLibrarySerializer(teiDocument);
final TagManager tagManager = new TagManager(new TagLibrary());
tagsets.forEach(tagset -> tagManager.addTagsetDefinition(tagset));
final ContentInfoSet contentInfoSet = new ContentInfoSet(project.getUser().toString(), project.getDescription(), project.getUser().toString(), project.getName());
teiDocument.getTeiHeader().setValues(contentInfoSet);
teiTagSerializer.serialize(tagManager.getTagLibrary());
File tempFile = File.createTempFile(new IDGenerator().generate() + "_TagLibrary_Export", "xml");
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
teiDocument.printXmlDocument(fos);
}
return new FileInputStream(tempFile);
} catch (Exception e) {
((ErrorHandler) ui).showAndLogError("Error exporting Tagsets to XML!", e);
}
}
return null;
}
use of de.catma.tag.TagsetDefinition in project catma by forTEXT.
the class TagResourcePanel method initComponents.
private void initComponents() {
setWidth("400px");
setHeight("100%");
Label tagsetLabel = new Label("Tagsets");
tagsetGrid = new Grid<>();
tagsetGrid.addStyleNames("resource-grid", "flat-undecorated-icon-buttonrenderer", "no-focused-before-border");
tagsetGrid.setSelectionMode(SelectionMode.MULTI);
tagsetGrid.setSizeFull();
tagsetGrid.addColumn(tagset -> tagset.getName()).setCaption("Name").setWidth(150);
tagsetGrid.addColumn(tagset -> project.hasPermission(project.getRoleForTagset(tagset.getUuid()), RBACPermission.TAGSET_WRITE) ? VaadinIcons.UNLOCK.getHtml() : VaadinIcons.LOCK.getHtml(), new HtmlRenderer()).setWidth(50);
tagsetGrid.addColumn(tagset -> VaadinIcons.TAGS.getHtml(), new HtmlRenderer()).setExpandRatio(1);
tagsetActionGridComponent = new ActionGridComponent<Grid<TagsetDefinition>>(tagsetLabel, tagsetGrid);
tagsetActionGridComponent.setSelectionModeFixed(SelectionMode.MULTI);
tagsetActionGridComponent.getActionGridBar().setMargin(new MarginInfo(false, false, false, true));
addComponent(tagsetActionGridComponent);
}
Aggregations