Commit 680845ef authored by thomas's avatar thomas
Browse files

[22205] rework findings table visible code selection and expand groups

parent 6946e819
Pipeline #22225 passed with stages
in 4 minutes and 26 seconds
......@@ -4,19 +4,25 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ITableFontProvider;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.ToolBar;
import ch.elexis.core.findings.ICoding;
import ch.elexis.core.findings.ui.util.FindingsUiUtil;
public class VisibleCodingsSelectionDialog extends TitleAreaDialog {
......@@ -26,6 +32,8 @@ public class VisibleCodingsSelectionDialog extends TitleAreaDialog {
private List<ICoding> selected;
private Font boldFont;
public VisibleCodingsSelectionDialog(Shell parentShell, List<ICoding> available){
super(parentShell);
this.available = available;
......@@ -44,18 +52,32 @@ public class VisibleCodingsSelectionDialog extends TitleAreaDialog {
protected Control createDialogArea(Composite parent){
Composite ret = new Composite(parent, SWT.NONE);
ret.setLayoutData(new GridData(GridData.FILL_BOTH));
ret.setLayout(new FillLayout());
ret.setLayout(new GridLayout());
Table table = new Table(ret, SWT.MULTI | SWT.CHECK);
viewer = new CheckboxTableViewer(table);
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setLabelProvider(new LabelProvider() {
ToolBarManager mgr = new ToolBarManager();
mgr.add(new Action("Gruppen selektieren") {
@Override
public String getText(Object element){
ICoding iCoding = (ICoding) element;
return iCoding != null ? iCoding.getDisplay() + " (" + iCoding.getCode() + ")" : "";
public void run(){
List<ICoding> groups = available.stream()
.filter(c -> FindingsUiUtil.isCodingForGroup(c))
.collect(Collectors.toList());
viewer.setAllChecked(false);
for (ICoding iCoding : groups) {
viewer.setChecked(iCoding, true);
}
selected = groups;
}
});
ToolBar toolbar = mgr.createControl(ret);
toolbar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
Table table = new Table(ret, SWT.MULTI | SWT.CHECK);
table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
boldFont = createBoldFont(table.getFont());
viewer = new CheckboxTableViewer(table);
viewer.setContentProvider(ArrayContentProvider.getInstance());
viewer.setLabelProvider(new LabelProvider());
viewer.setInput(available);
for (ICoding iCoding : selected) {
......@@ -79,4 +101,30 @@ public class VisibleCodingsSelectionDialog extends TitleAreaDialog {
public List<ICoding> getSelected(){
return selected;
}
private Font createBoldFont(Font baseFont){
FontData fd = baseFont.getFontData()[0];
Font font =
new Font(baseFont.getDevice(), fd.getName(), fd.getHeight(), fd.getStyle() | SWT.BOLD);
return font;
}
private class LabelProvider extends org.eclipse.jface.viewers.LabelProvider
implements ITableFontProvider {
@Override
public String getText(Object element){
ICoding iCoding = (ICoding) element;
return iCoding != null ? iCoding.getDisplay() + " (" + iCoding.getCode() + ")" : "";
}
@Override
public Font getFont(Object element, int columnIndex){
if (FindingsUiUtil.isCodingForGroup((ICoding) element)) {
return boldFont;
}
return null;
}
}
}
......@@ -11,6 +11,7 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.emf.common.util.EList;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ToolBarManager;
import org.eclipse.jface.dialogs.MessageDialog;
......@@ -33,10 +34,14 @@ import ch.elexis.core.findings.IObservation.ObservationType;
import ch.elexis.core.findings.IProcedureRequest;
import ch.elexis.core.findings.ObservationComponent;
import ch.elexis.core.findings.codes.CodingSystem;
import ch.elexis.core.findings.templates.model.FindingsTemplate;
import ch.elexis.core.findings.templates.model.InputData;
import ch.elexis.core.findings.templates.model.InputDataGroup;
import ch.elexis.core.findings.ui.action.DateAction;
import ch.elexis.core.findings.ui.composites.CompositeGroup;
import ch.elexis.core.findings.ui.composites.ICompositeSaveable;
import ch.elexis.core.findings.ui.services.CodingServiceComponent;
import ch.elexis.core.findings.ui.services.FindingsTemplateServiceComponent;
import ch.elexis.core.findings.util.commands.FindingDeleteCommand;
import ch.elexis.core.findings.util.commands.ILockingProvider;
import ch.elexis.core.lock.types.LockResponse;
......@@ -337,4 +342,45 @@ public class FindingsUiUtil {
}
return null;
}
public static boolean isCodingForGroup(ICoding c){
Optional<FindingsTemplate> template =
FindingsTemplateServiceComponent.getService().getFindingsTemplate(c);
if (template.isPresent()) {
return template.get().getInputData() instanceof InputDataGroup;
}
return false;
}
public static List<ICoding> getCodesOfGroup(ICoding iCoding){
Optional<FindingsTemplate> template =
FindingsTemplateServiceComponent.getService().getFindingsTemplate(iCoding);
if (template.isPresent()) {
List<ICoding> ret = new ArrayList<>();
InputData inputData = template.get().getInputData();
if (inputData instanceof InputDataGroup) {
ret.addAll(getCodesOfGroup((InputDataGroup) inputData));
} else {
ret.add(iCoding);
}
return ret;
}
return Collections.emptyList();
}
private static List<ICoding> getCodesOfGroup(InputDataGroup inputData){
List<ICoding> ret = new ArrayList<>();
EList<FindingsTemplate> subTemplates = inputData.getFindingsTemplates();
for (FindingsTemplate findingsTemplate : subTemplates) {
if (findingsTemplate.getInputData() instanceof InputDataGroup) {
ret.addAll(getCodesOfGroup((InputDataGroup) findingsTemplate.getInputData()));
} else {
CodingServiceComponent.getService()
.getCode(CodingSystem.ELEXIS_LOCAL_CODESYSTEM.getSystem(),
findingsTemplate.getTitle())
.ifPresent(c -> ret.add(c));
}
}
return ret;
}
}
package ch.elexis.core.findings.ui.views;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
......@@ -229,6 +230,9 @@ public class FindingsViewDynamic extends ViewPart implements IActivationListener
private void updateCodingsSelection(StructuredSelection selection){
@SuppressWarnings("unchecked")
List<ICoding> shownCodings = (List<ICoding>) selection.toList();
// convert groups to contents
shownCodings = expandGroups(shownCodings);
shownCodings.sort(new Comparator<ICoding>() {
@Override
......@@ -246,6 +250,23 @@ public class FindingsViewDynamic extends ViewPart implements IActivationListener
natTable.refresh(true);
}
private List<ICoding> expandGroups(List<ICoding> codings){
List<ICoding> ret = new ArrayList<>();
for (ICoding iCoding : codings) {
if (FindingsUiUtil.isCodingForGroup(iCoding)) {
List<ICoding> codesOfGroup = FindingsUiUtil.getCodesOfGroup(iCoding);
for (ICoding codeOfGroup : codesOfGroup) {
if (!ret.contains(codeOfGroup)) {
ret.add(codeOfGroup);
}
}
} else {
ret.add(iCoding);
}
}
return ret;
}
public void refresh(){
dataProvider.reload(ElexisEventDispatcher.getSelectedPatient());
natTable.refresh();
......
Supports Markdown
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