use of de.catma.indexer.IndexedProject in project catma by forTEXT.
the class TaggerView method initComponents.
private void initComponents() {
setSizeFull();
VerticalLayout taggerPanel = new VerticalLayout();
taggerPanel.setSizeFull();
taggerPanel.setSpacing(true);
taggerPanel.setMargin(new MarginInfo(true, true, true, false));
boolean isRtl = sourceDocument == null ? false : sourceDocument.getSourceContentHandler().getSourceDocumentInfo().getIndexInfoSet().isRightToLeftWriting();
pager = new Pager(taggerID, approxMaxLineLength, maxPageLengthInLines, isRtl);
tagger = new Tagger(taggerID, pager, this, project);
// $NON-NLS-1$
tagger.addStyleName("tagger");
// $NON-NLS-1$
tagger.setWidth("100%");
taggerPanel.addComponent(tagger);
taggerPanel.setExpandRatio(tagger, 1.0f);
HorizontalLayout actionPanel = new HorizontalLayout();
actionPanel.setSpacing(false);
taggerPanel.addComponent(actionPanel);
pagerComponent = new PagerComponent(pager, new PageChangeListener() {
public void pageChanged(int number) {
tagger.setPage(number);
}
});
actionPanel.addComponent(pagerComponent);
linesPerPageSlider = new Slider(1, 100, 0);
// $NON-NLS-1$
linesPerPageSlider.setWidth("100px");
actionPanel.addComponent(linesPerPageSlider);
cbTraceSelection = new IconButton(VaadinIcons.TWIN_COL_SELECT);
// state
cbTraceSelection.setData(false);
cbTraceSelection.setDescription("Allow multiple discontinuous selections");
actionPanel.addComponent(cbTraceSelection);
btClearSearchHighlights = new IconButton(VaadinIcons.ERASER);
btClearSearchHighlights.setDescription("Clear all search highlights");
actionPanel.addComponent(btClearSearchHighlights);
cbAutoShowComments = new IconButton(VaadinIcons.COMMENT);
cbAutoShowComments.setDescription("Toggle live Comments");
// state
cbAutoShowComments.setData(true);
actionPanel.addComponent(cbAutoShowComments);
btAnalyze = new Button("Analyze");
// $NON-NLS-1$
btAnalyze.addStyleName("primary-button");
btAnalyze.setEnabled(project instanceof IndexedProject);
actionPanel.addComponent(btAnalyze);
rightSplitPanel = new VerticalSplitPanel();
rightSplitPanel.setSizeFull();
kwicPanel = new KwicPanel(eventBus, project, KwicProvider.buildKwicProviderByDocumentIdCache(project));
kwicPanel.setExpandResource(VaadinIcons.CLOSE);
kwicPanel.setCompressResource(VaadinIcons.CLOSE);
rightSplitPanel.addComponent(kwicPanel);
hideKwicPanel();
annotationPanel = new AnnotationPanel(project, userMarkupCollectionManager, selectedAnnotationId -> tagger.setTagInstanceSelected(selectedAnnotationId), collection -> handleCollectionValueChange(collection), tag -> tagger.addTagInstanceWith(tag), () -> sourceDocument, eventBus);
rightSplitPanel.addComponent(annotationPanel);
splitPanel = new TaggerSplitPanel();
splitPanel.addComponent(taggerPanel);
splitPanel.addComponent(rightSplitPanel);
splitPanel.setSplitPosition(initialSplitterPositionInPixels, Unit.PIXELS);
// $NON-NLS-1$
splitPanel.addStyleName("catma-tab-spacing");
SplitterPositionChangedListener listener = new SplitterPositionChangedListener() {
@Override
public void positionChanged(SplitterPositionChangedEvent event) {
float width = event.getPosition();
// TODO: if it is PERCENTAGE, work out the splitter position in pixels
if (event.getPositionUnit() != Unit.PIXELS) {
// $NON-NLS-1$
String message = "Must use PIXELS Unit for split position";
errorHandler.showAndLogError(message, new IllegalArgumentException(message));
}
int approxMaxLineLength = getApproximateMaxLineLengthForSplitterPanel(width);
List<ClientTagInstance> absoluteTagInstances = pager.getAbsoluteTagInstances();
Page currentPage = null;
if (pager.hasPages()) {
currentPage = pager.getCurrentPage();
}
pager.setApproxMaxLineLength(approxMaxLineLength);
if (pager.hasPages()) {
// recalculate pages
try {
pager.setText(sourceDocument.getContent(), comments);
int previousPageNumber = pager.getPageNumberFor(currentPage.getPageStart());
tagger.setPage(previousPageNumber);
tagger.setTagInstancesVisible(absoluteTagInstances, true);
pagerComponent.setPage(previousPageNumber);
} catch (IOException e) {
// $NON-NLS-1$
errorHandler.showAndLogError("Error showing the Document!", e);
}
}
}
};
splitPanel.addListener(SplitterPositionChangedEvent.class, listener, SplitterPositionChangedListener.positionChangedMethod);
resourcePanel = new AnnotateResourcePanel(project, sourceDocument, eventBus);
drawer = new SliderPanelBuilder(resourcePanel).mode(SliderMode.LEFT).expanded(sourceDocument == null).build();
addComponent(drawer);
addComponent(splitPanel);
setExpandRatio(splitPanel, 1.0f);
}
use of de.catma.indexer.IndexedProject in project catma by forTEXT.
the class TaggerView method analyzeDocument.
public void analyzeDocument() {
Corpus corpus = new Corpus();
corpus.addSourceDocument(sourceDocument);
for (AnnotationCollection umc : userMarkupCollectionManager.getUserMarkupCollections()) {
AnnotationCollectionReference userMarkupCollRef = sourceDocument.getUserMarkupCollectionReference(umc.getId());
if (userMarkupCollRef != null) {
corpus.addUserMarkupCollectionReference(userMarkupCollRef);
}
}
if (project instanceof IndexedProject) {
eventBus.post(new RouteToAnalyzeEvent((IndexedProject) project, corpus));
}
}
use of de.catma.indexer.IndexedProject in project catma by forTEXT.
the class TaggerView method initData.
private void initData(final AfterDocumentLoadedOperation afterDocumentLoadedOperation) {
if (sourceDocument != null) {
// loading of the Document is done in an extra step,
// because of a client side rendering racing condition which prevents the first page to be displayed
final UI ui = UI.getCurrent();
((CatmaApplication) ui).submit("Load Document", new DefaultProgressCallable<Void>() {
@Override
public Void call() throws Exception {
ui.accessSynchronously(() -> {
try {
linesPerPageSlider.setEnabled(true);
btAnalyze.setEnabled(project instanceof IndexedProject);
pagerComponent.setEnabled(true);
TaggerView.this.comments.clear();
TaggerView.this.comments.addAll(TaggerView.this.project.getComments(sourceDocument.getUuid()));
tagger.setText(sourceDocument.getContent(), TaggerView.this.comments);
totalLineCount = pager.getTotalLineCount();
try {
linesPerPageSlider.setValue((100.0 / totalLineCount) * maxPageLengthInLines);
} catch (ValueOutOfBoundsException toBeIgnored) {
}
List<AnnotationCollectionReference> collectionReferences = resourcePanel.getSelectedAnnotationCollectionReferences();
userMarkupCollectionManager.clear();
for (AnnotationCollectionReference collectionRef : collectionReferences) {
AnnotationCollection collection = project.getUserMarkupCollection(collectionRef);
userMarkupCollectionManager.add(collection);
}
Collection<TagsetDefinition> tagsets = new HashSet<>(resourcePanel.getSelectedTagsets());
annotationPanel.setData(sourceDocument, tagsets, new ArrayList<>(userMarkupCollectionManager.getUserMarkupCollections()));
if (taggerContextMenu != null) {
taggerContextMenu.setTagsets(tagsets);
}
if (afterDocumentLoadedOperation != null) {
afterDocumentLoadedOperation.afterDocumentLoaded(TaggerView.this);
}
ui.push();
} catch (IOException e) {
errorHandler.showAndLogError("Error showing the Document!", e);
}
});
return null;
}
}, new ExecutionListener<Void>() {
@Override
public void done(Void result) {
/*noop*/
}
@Override
public void error(Throwable t) {
errorHandler.showAndLogError("Error showing the Document!", t);
}
});
} else {
linesPerPageSlider.setEnabled(false);
btAnalyze.setEnabled(false);
pagerComponent.setEnabled(false);
}
}
use of de.catma.indexer.IndexedProject in project catma by forTEXT.
the class ProjectView method handleAnalyzeResources.
private void handleAnalyzeResources(MenuBar.MenuItem menuItem, TreeGrid<Resource> resourceGrid) {
if (resourceGrid.getSelectedItems().isEmpty()) {
Notification.show("Info", "Please select something first!", Type.HUMANIZED_MESSAGE);
} else {
Corpus corpus = new Corpus();
for (Resource resource : resourceGrid.getSelectedItems()) {
try {
if (resource.getClass().equals(DocumentResource.class)) {
DocumentResource docResource = (DocumentResource) resource;
corpus.addSourceDocument(docResource.getDocument());
} else {
CollectionResource collResource = (CollectionResource) resource;
corpus.addUserMarkupCollectionReference(collResource.getCollectionReference());
DocumentResource docParent = (DocumentResource) resourceGrid.getTreeData().getParent(collResource);
if (!corpus.getSourceDocuments().contains(docParent.getDocument())) {
corpus.addSourceDocument(docParent.getDocument());
}
}
} catch (Exception e) {
errorHandler.showAndLogError("Error adding resource to analyzer module " + resource, e);
}
}
eventBus.post(new RouteToAnalyzeEvent((IndexedProject) project, corpus));
}
}
Aggregations