Commit 9d9ae9a7 authored by slogic-sa's avatar slogic-sa Committed by Thomas Huster

[17697] Dokumente View, flache Ansicht (#386)

parent 1a5abcea
Pipeline #12552 passed with stages
in 4 minutes and 58 seconds
......@@ -25,6 +25,7 @@ Import-Package: ch.elexis.admin,
ch.elexis.core.ui.services,
ch.elexis.core.ui.util,
ch.elexis.data,
ch.rgw.io,
ch.rgw.tools,
org.apache.commons.io;version="2.4.0",
org.eclipse.e4.core.commands,
......
......@@ -10,6 +10,7 @@ command.name.5 = Local Edit Done Dokument
command.name.6 = Local Edit Overview Dokument
command.name.7 = Send As Mail
command.name.8 = Senden
command.name.9 = Flache Ansicht
command.label = Bearbeiten
command.label.0 = L\u00F6schen
command.label.1 = Start edit local document
......@@ -22,4 +23,5 @@ command.label.6 = Das Dokument in eine Datei exportieren
command.label.7 = Offene lokale Dokumente
command.tooltip = Offene lokale Dokumente
command.label.8 = Versenden
command.label.9 = Als E-Mail
\ No newline at end of file
command.label.9 = Als E-Mail
command.label.10= Flache Ansicht
\ No newline at end of file
......@@ -10,6 +10,7 @@ command.name.5 = Local Edit Done Dokument
command.name.6 = Local Edit Overview Dokument
command.name.7 = Send As Mail
command.name.8 = Senden
command.name.9 = Flache Ansicht
command.label = Bearbeiten
command.label.0 = L\u00F6schen
command.label.1 = ffnen
......@@ -22,4 +23,5 @@ command.label.6 = Das Dokument in eine Datei exportieren
command.label.7 = Offene lokale Dokumente
command.tooltip = Offene lokale Dokumente
command.label.8 = Versenden
command.label.9 = als E-Mail
\ No newline at end of file
command.label.9 = als E-Mail
command.label.10= Flache Ansicht
\ No newline at end of file
......@@ -62,6 +62,11 @@
id="ch.elexis.core.ui.documents.send"
name="%command.name.8">
</command>
<command
defaultHandler="ch.elexis.core.ui.documents.handler.FlatViewHandler"
id="ch.elexis.core.ui.documents.commandFlatView"
name="%command.name.9">
</command>
</extension>
<extension
point="org.eclipse.ui.menus">
......@@ -206,6 +211,12 @@
label="%command.label.8"
style="pulldown">
</command>
<command
commandId="ch.elexis.core.ui.documents.commandFlatView"
icon="icon://IMG_FILTER"
label="%command.label.10"
style="toggle">
</command>
</menuContribution>
<menuContribution
allPopups="false"
......
package ch.elexis.core.ui.documents.handler;
import java.util.Map;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.IElementUpdater;
import org.eclipse.ui.menus.UIElement;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.ui.documents.views.DocumentsView;
public class FlatViewHandler extends AbstractHandler implements IElementUpdater {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException{
IViewPart viewPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.findView(DocumentsView.ID);
if (viewPart instanceof DocumentsView) {
((DocumentsView) viewPart)
.switchFlatView(!CoreHub.userCfg.get(DocumentsView.SETTING_FLAT_VIEW, false));
}
return null;
}
@Override
public void updateElement(UIElement element, Map parameters){
boolean bFlat = CoreHub.userCfg.get(DocumentsView.SETTING_FLAT_VIEW, false);
element.setChecked(bFlat);
}
}
......@@ -81,6 +81,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.elexis.core.common.ElexisEventTopics;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.documents.FilterCategory;
import ch.elexis.core.exceptions.ElexisException;
......@@ -105,6 +106,10 @@ import ch.rgw.tools.TimeTool;
*/
public class DocumentsView extends ViewPart {
public static final String ID = "ch.elexis.core.ui.documents.views.DocumentsView";
public static final String SETTING_FLAT_VIEW = "documentsView/flatView";
private static Logger logger = LoggerFactory.getLogger(DocumentsView.class);
private TreeViewer viewer;
......@@ -122,6 +127,7 @@ public class DocumentsView extends ViewPart {
private DocumentsViewerComparator ovComparator;
private Action doubleClickAction;
private boolean bFlat = false;
@Inject
void activePatient(@Optional IPatient patient){
......@@ -258,7 +264,8 @@ public class DocumentsView extends ViewPart {
}
public void updateElement(IDocument iDocument){
if (iDocument != null) {
// also called after category creation - that call will be ignored
if (iDocument != null && !"text/category".equals(iDocument.getMimeType())) {
removeFromCategories(iDocument);
FilterCategory filterCategory = new FilterCategory(iDocument.getCategory());
List<IDocument> categoryDocuments = documentsMap.get(filterCategory);
......@@ -287,17 +294,6 @@ public class DocumentsView extends ViewPart {
}
}
public void createElement(IDocument iDocument){
FilterCategory filterCategory = new FilterCategory(iDocument.getCategory());
List<IDocument> iDocuments = documentsMap.get(filterCategory);
if (iDocuments == null) {
iDocuments = new ArrayList<>();
}
iDocuments.add(iDocument);
documentsMap.put(filterCategory, iDocuments);
viewer.refresh(true);
}
private void loadElementsByCategory(String patientId, ICategory iCategory){
if (!(iCategory instanceof FilterCategory) || documentsMap.get(iCategory) == null) {
List<IDocument> iDocuments = DocumentStoreServiceHolder.getService()
......@@ -313,6 +309,19 @@ public class DocumentsView extends ViewPart {
public void dispose(){}
public Object[] getElements(Object parent){
Object[] categories = getFilteredCategories();
if (bFlat) {
// single category - load its children
if (categories.length == 1) {
return getChildren(categories[0]);
} else {
return documentsMap.values().stream().flatMap(e -> e.stream()).toArray();
}
}
return categories;
}
private Object[] getFilteredCategories(){
if (selectedFilter.isAll()) {
List<ICategory> keys = new ArrayList<>(documentsMap.keySet());
return keys.toArray();
......@@ -325,7 +334,8 @@ public class DocumentsView extends ViewPart {
}
public Object[] getChildren(Object parentElement){
if (parentElement instanceof ICategory && documentsMap.containsKey(parentElement)) {
if (parentElement instanceof ICategory
&& documentsMap.containsKey(parentElement)) {
return documentsMap.get(parentElement).toArray();
} else {
return new Object[0];
......@@ -362,7 +372,7 @@ public class DocumentsView extends ViewPart {
case 1:
return dh.getStatus().getName().substring(0, 1);
case 2:
return "";
return bFlat ? dh.getCategory().getName() : "";
case 3:
return new TimeTool(dh.getLastchanged()).toString(TimeTool.FULL_GER);
case 4:
......@@ -451,6 +461,8 @@ public class DocumentsView extends ViewPart {
DocumentsFilterBarComposite filterBarComposite = addFilterBar(parent);
bFlat = CoreHub.userCfg.get(SETTING_FLAT_VIEW, false);
viewer.setContentProvider(
new ViewContentProvider().selectFilterCategory(filterBarComposite.getSelection()));
viewer.setLabelProvider(new ViewLabelProvider());
......@@ -669,6 +681,7 @@ public class DocumentsView extends ViewPart {
SelectionAdapter selectionAdapter = new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e){
ovComparator.setBFlat(bFlat);
ovComparator.setColumn(index);
viewer.getTree().setSortDirection(ovComparator.getDirection());
viewer.getTree().setSortColumn(column);
......@@ -796,4 +809,12 @@ public class DocumentsView extends ViewPart {
}
});
}
public void switchFlatView(boolean bFlat){
this.bFlat = bFlat;
if (viewer != null) {
CoreHub.userCfg.set(SETTING_FLAT_VIEW, bFlat);
viewer.refresh();
}
}
}
\ No newline at end of file
package ch.elexis.core.ui.documents.views;
import java.util.Objects;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
......@@ -20,6 +22,7 @@ public class DocumentsViewerComparator extends ViewerComparator {
private int propertyIndex;
private int direction = DESCENDING;
private int catDirection;
private boolean bFlat;
public DocumentsViewerComparator(){
this.propertyIndex = 0;
......@@ -37,7 +40,7 @@ public class DocumentsViewerComparator extends ViewerComparator {
direction = DESCENDING;
}
if (column == 1) {
if (column == 2) {
catDirection = direction;
}
}
......@@ -66,32 +69,37 @@ public class DocumentsViewerComparator extends ViewerComparator {
switch (propertyIndex) {
case 1:
rc = cat1.compareTo(cat2);
if (bFlat || cat1.equals(cat2)) {
rc = dh1.getStatus().getName().compareTo(dh2.getStatus().getName());
} else {
compareCategories = true;
}
break;
case 2:
if (cat1.equals(cat2)) {
rc = dh1.getStatus().getName().compareTo(dh2.getStatus().getName());
if (bFlat) {
rc = cat1.compareToIgnoreCase(cat2);
} else {
compareCategories = true;
}
break;
case 3:
if (cat1.equals(cat2)) {
if (bFlat || cat1.equals(cat2)) {
rc = dh1.getLastchanged().compareTo(dh2.getLastchanged());
} else {
compareCategories = true;
}
break;
case 4:
if (cat1.equals(cat2)) {
rc = dh1.getCreated().compareTo(dh2.getCreated());
if (bFlat || cat1.equals(cat2)) {
rc = dh1.getTitle().compareToIgnoreCase(dh2.getTitle());
} else {
compareCategories = true;
}
break;
case 5:
if (cat1.equals(cat2)) {
rc = dh1.getTitle().toLowerCase().compareTo(dh2.getTitle().toLowerCase());
if (bFlat || cat1.equals(cat2)) {
rc = Objects.toString(dh1.getKeywords(), "")
.compareToIgnoreCase(Objects.toString(dh2.getKeywords(), ""));
} else {
compareCategories = true;
}
......@@ -103,8 +111,8 @@ public class DocumentsViewerComparator extends ViewerComparator {
// If not in category column and values were not from same category
if (compareCategories) {
rc = cat1.compareTo(cat2);
if (!bFlat && compareCategories) {
rc = cat1.compareToIgnoreCase(cat2);
if (catDirection == DESCENDING) {
rc = -rc;
}
......@@ -137,4 +145,8 @@ public class DocumentsViewerComparator extends ViewerComparator {
public int getPropertyIndex(){
return propertyIndex;
}
public void setBFlat(boolean bFlat){
this.bFlat = bFlat;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment