Commit 390c4f41 authored by Thomas Huster's avatar Thomas Huster

[17265] updated favorites ui and code block ui

parent b31a3138
Pipeline #12213 passed with stages
in 4 minutes and 36 seconds
......@@ -3,17 +3,20 @@ package ch.elexis.data;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.elexis.core.constants.StringConstants;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.events.ElexisEvent;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.events.ElexisEventListenerImpl;
import ch.elexis.core.data.service.StoreToStringServiceHolder;
import ch.elexis.core.jdt.Nullable;
import ch.elexis.core.data.interfaces.IPersistentObject;
import ch.elexis.core.model.ICodeElementBlock;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.services.IStoreToStringService;
public class VerrechenbarFavorites {
......@@ -29,7 +32,7 @@ public class VerrechenbarFavorites {
favorites = null;
};
};
static {
ElexisEventDispatcher.getInstance().addListeners(eeli_pat);
}
......@@ -69,25 +72,22 @@ public class VerrechenbarFavorites {
}
CoreHub.userCfg.set(USER_CFG_FAVORITES, sb.toString());
CoreHub.userCfg.flush();
ElexisEventDispatcher.reload(Favorite.class);
}
/**
* Add or remove the object to or from the {@link Favorite}s of the user. The
* {@link IStoreToStringService} must be able to create a store to string from the object.
*
* @param billable
* @param val
* toggle element as favorite of the user
* @since 3.1
*/
public static void setFavorite(IPersistentObject po, boolean val){
Favorite fav = VerrechenbarFavorites.isFavorite(po);
public static void setFavorite(Object object, boolean val){
Favorite fav = VerrechenbarFavorites.isFavorite(object);
if (val) {
if (fav != null)
return;
String storeToString;
if (po instanceof Leistungsblock) {
storeToString =
Leistungsblock.class.getName() + StringConstants.DOUBLECOLON + po.getId();
} else {
storeToString = po.storeToString();
}
String storeToString = StoreToStringServiceHolder.getStoreToString(object);
VerrechenbarFavorites.getFavorites().add(new Favorite(storeToString, "", 0));
} else {
if (fav == null)
......@@ -100,19 +100,14 @@ public class VerrechenbarFavorites {
}
/**
* Test if the object is a {@link Favorite} of the user.
*
* @return the {@link Favorite} if a favorite {@link VerrechenbarAdapter} of this user, else
* null
* @param billable
* @return
*/
public static Favorite isFavorite(IPersistentObject po){
public static Favorite isFavorite(Object object){
for (Favorite favorite : getFavorites()) {
String comparator = "";
if (po instanceof Leistungsblock) {
comparator =
Leistungsblock.class.getName() + StringConstants.DOUBLECOLON + po.getId();
} else {
comparator = po.storeToString();
}
String comparator = StoreToStringServiceHolder.getStoreToString(object);
if (comparator.equalsIgnoreCase(favorite.storeToString)) {
return favorite;
}
......@@ -142,8 +137,6 @@ public class VerrechenbarFavorites {
String macroString;
int order;
private PersistentObjectFactory pof = new PersistentObjectFactory();
public Favorite(String storeToString, String macroString, int order){
this.storeToString = storeToString;
this.macroString = macroString;
......@@ -165,17 +158,17 @@ public class VerrechenbarFavorites {
public String getMacroString(){
if (storeToString.startsWith(Leistungsblock.class.getName())) {
Leistungsblock po = (Leistungsblock) getPersistentObject();
return (po != null) ? po.getMacro() : macroString;
ICodeElementBlock block = (ICodeElementBlock) getObject().orElse(null);
return (block != null) ? block.getMacro() : macroString;
}
return macroString;
}
public void setMacroString(String macroString){
if (storeToString.startsWith(Leistungsblock.class.getName())) {
Leistungsblock po = (Leistungsblock) getPersistentObject();
if (po != null) {
po.setMacro(macroString);
ICodeElementBlock block = (ICodeElementBlock) getObject().orElse(null);
if (block != null) {
block.setMacro(macroString);
} else {
log.warn("Could not set macroString " + macroString
+ " to Leistungsblock as po is null.");
......@@ -193,11 +186,13 @@ public class VerrechenbarFavorites {
}
/**
* @return the {@link IPersistentObject} as resolved via {@link #storeToString},
* <code>null</code> if erroneous
* Get the {@link Identifiable} referenced by this {@link Favorite} using an
* {@link IStoreToStringService}.
*
* @return
*/
public @Nullable IPersistentObject getPersistentObject(){
return pof.createFromString(storeToString);
public Optional<Identifiable> getObject(){
return StoreToStringServiceHolder.get().loadFromString(storeToString);
}
}
}
......@@ -2,35 +2,50 @@ package ch.elexis.core.ui.actions;
import org.eclipse.jface.action.Action;
import ch.elexis.core.model.IBillable;
import ch.elexis.core.model.ICodeElementBlock;
import ch.elexis.core.ui.icons.Images;
import ch.elexis.data.Leistungsblock;
import ch.elexis.data.PersistentObject;
import ch.elexis.data.VerrechenbarAdapter;
import ch.elexis.data.VerrechenbarFavorites;
import ch.elexis.data.VerrechenbarFavorites.Favorite;
public class ToggleVerrechenbarFavoriteAction extends Action {
private PersistentObject currentSelection;
private IBillable currentBillable;
private ICodeElementBlock currentBlock;
@Override
public void run(){
Favorite favorite = VerrechenbarFavorites.isFavorite(currentSelection);
VerrechenbarFavorites.setFavorite(currentSelection, favorite == null);
if (currentBillable != null) {
Favorite favorite = VerrechenbarFavorites.isFavorite(currentBillable);
VerrechenbarFavorites.setFavorite(currentBillable, favorite == null);
} else if (currentBlock != null) {
Favorite favorite = VerrechenbarFavorites.isFavorite(currentBlock);
VerrechenbarFavorites.setFavorite(currentBlock, favorite == null);
}
}
public void updateSelection(Object object){
if (object instanceof VerrechenbarAdapter || object instanceof Leistungsblock) {
if (object instanceof IBillable) {
setEnabled(true);
currentBillable = (IBillable) object;
Favorite favorite = VerrechenbarFavorites.isFavorite(currentBillable);
setText((favorite != null) ? Messages.ToggleVerrechenbarFavoriteAction_DeFavorize
: Messages.ToggleVerrechenbarFavoriteAction_Favorize);
setImageDescriptor((favorite != null) ? Images.IMG_STAR.getImageDescriptor()
: Images.IMG_STAR_EMPTY.getImageDescriptor());
} else if (object instanceof ICodeElementBlock) {
setEnabled(true);
currentSelection = (PersistentObject) object;
Favorite favorite = VerrechenbarFavorites.isFavorite(currentSelection);
currentBlock = (ICodeElementBlock) object;
Favorite favorite = VerrechenbarFavorites.isFavorite(currentBlock);
setText((favorite != null) ? Messages.ToggleVerrechenbarFavoriteAction_DeFavorize
: Messages.ToggleVerrechenbarFavoriteAction_Favorize);
setImageDescriptor((favorite != null) ? Images.IMG_STAR.getImageDescriptor()
: Images.IMG_STAR_EMPTY.getImageDescriptor());
} else {
setEnabled(false);
currentSelection = null;
currentBillable = null;
currentBlock = null;
}
}
}
......@@ -7,10 +7,15 @@ import org.eclipse.swt.widgets.Display;
import ch.elexis.core.constants.StringConstants;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.interfaces.ICodeElement;
import ch.elexis.core.data.interfaces.IDiagnose;
import ch.elexis.core.data.interfaces.IVerrechenbar;
import ch.elexis.core.data.interfaces.events.MessageEvent;
import ch.elexis.core.model.IBillable;
import ch.elexis.core.model.IBilled;
import ch.elexis.core.model.ICodeElement;
import ch.elexis.core.model.ICodeElementBlock;
import ch.elexis.core.model.IDiagnosis;
import ch.elexis.core.model.IEncounter;
import ch.elexis.core.services.holder.BillingServiceHolder;
import ch.elexis.core.services.holder.CoreModelServiceHolder;
import ch.elexis.core.ui.util.IKonsMakro;
import ch.elexis.data.Konsultation;
import ch.elexis.data.Leistungsblock;
......@@ -25,37 +30,43 @@ public class BlockMakro implements IKonsMakro {
List<Leistungsblock> macros = Leistungsblock.findMacrosValidForCurrentMandator(makro);
if ((macros != null) && (macros.size() > 0) && (actKons != null)) {
Leistungsblock lb = macros.get(0);
addBlock(actKons, lb);
addBlock(actKons, CoreModelServiceHolder.get().load(lb.getId(), ICodeElementBlock.class)
.orElse(null));
return StringConstants.EMPTY;
}
return null;
}
public void addBlock(Konsultation kons, Leistungsblock block){
List<ICodeElement> elements = block.getElements();
for (ICodeElement ice : elements) {
if (ice instanceof IVerrechenbar) {
Result<IVerrechenbar> res = kons.addLeistung((IVerrechenbar) ice);
if (!res.isOK()) {
MessageEvent.fireError("Error", res.toString());
public void addBlock(Konsultation actKons, ICodeElementBlock elementBlock){
IEncounter encounter = CoreModelServiceHolder.get().load(actKons.getId(), IEncounter.class).orElse(null);
if (elementBlock != null && encounter != null) {
List<ch.elexis.core.model.ICodeElement> elements = elementBlock.getElements();
for (ICodeElement ice : elements) {
if (ice instanceof IBillable) {
Result<IBilled> res =
BillingServiceHolder.get().bill((IBillable) ice, encounter, 1.0);
if (!res.isOK()) {
MessageEvent.fireError("Error", res.toString());
}
} else if (ice instanceof IDiagnosis) {
encounter.addDiagnosis((IDiagnosis) ice);
CoreModelServiceHolder.get().save(encounter);
}
} else if (ice instanceof IDiagnose) {
kons.addDiagnose((IDiagnose) ice);
}
}
java.util.List<ICodeElement> diff = block.getDiffToReferences(elements);
if (!diff.isEmpty()) {
StringBuilder sb = new StringBuilder();
diff.forEach(r -> {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append(r);
});
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warnung",
"Warnung folgende Leistungen konnten im aktuellen Kontext (Fall, Konsultation, Gesetz) nicht verrechnet werden.\n"
+ sb.toString());
java.util.List<ICodeElement> diff = elementBlock.getDiffToReferences(elements);
if (!diff.isEmpty()) {
StringBuilder sb = new StringBuilder();
diff.forEach(r -> {
if (sb.length() > 0) {
sb.append("\n");
}
sb.append(r);
});
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warnung",
"Warnung folgende Leistungen konnten im aktuellen Kontext (Fall, Konsultation, Gesetz) nicht verrechnet werden.\n"
+ sb.toString());
}
}
}
}
package ch.elexis.core.ui.text;
import java.util.Optional;
import ch.elexis.core.constants.StringConstants;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.interfaces.IVerrechenbar;
import ch.elexis.core.data.interfaces.events.MessageEvent;
import ch.elexis.core.model.IBillable;
import ch.elexis.core.model.IBilled;
import ch.elexis.core.model.ICodeElementBlock;
import ch.elexis.core.model.IEncounter;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.services.holder.BillingServiceHolder;
import ch.elexis.core.services.holder.CoreModelServiceHolder;
import ch.elexis.core.ui.util.IKonsMakro;
import ch.elexis.data.Konsultation;
import ch.elexis.data.Leistungsblock;
import ch.elexis.data.VerrechenbarFavorites;
import ch.elexis.data.VerrechenbarFavorites.Favorite;
import ch.rgw.tools.Result;
......@@ -18,19 +25,22 @@ public class FavoritenKonsMakro implements IKonsMakro {
Konsultation actKons = (Konsultation) ElexisEventDispatcher.getSelected(Konsultation.class);
Favorite fav = VerrechenbarFavorites.findFavoritByMacroForCurrentUser(macro);
if (fav != null) {
if (fav.getPersistentObject() instanceof IVerrechenbar) {
Result<IVerrechenbar> res =
actKons.addLeistung((IVerrechenbar) fav.getPersistentObject());
if (!res.isOK()) {
MessageEvent.fireError("Error", res.toString());
}
else {
IEncounter encounter = CoreModelServiceHolder.get().load(actKons.getId(), IEncounter.class).orElse(null);
Optional<Identifiable> favObj = fav.getObject();
if (favObj.isPresent()) {
if (favObj.get() instanceof ICodeElementBlock) {
BlockMakro blockMacro = new BlockMakro();
blockMacro.addBlock(actKons, (ICodeElementBlock) favObj.get());
return StringConstants.EMPTY;
} else if (favObj.get() instanceof IBillable) {
Result<IBilled> res =
BillingServiceHolder.get().bill((IBillable) favObj.get(), encounter, 1.0);
if (!res.isOK()) {
MessageEvent.fireError("Error", res.toString());
} else {
return StringConstants.EMPTY;
}
}
} else if (fav.getPersistentObject() instanceof Leistungsblock) {
BlockMakro blockMacro = new BlockMakro();
blockMacro.addBlock(actKons, (Leistungsblock) fav.getPersistentObject());
return StringConstants.EMPTY;
}
}
return null;
......
package ch.elexis.core.ui.views;
import java.util.Optional;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.layout.TableColumnLayout;
......@@ -39,17 +41,19 @@ import org.eclipse.swt.widgets.TableItem;
import ch.elexis.core.constants.Preferences;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.interfaces.ICodeElement;
import ch.elexis.core.data.interfaces.IPersistentObject;
import ch.elexis.core.data.events.ElexisEvent;
import ch.elexis.core.data.events.ElexisEventDispatcher;
import ch.elexis.core.data.service.StoreToStringServiceHolder;
import ch.elexis.core.model.ICodeElement;
import ch.elexis.core.model.ICodeElementBlock;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.ui.UiDesk;
import ch.elexis.core.ui.actions.CodeSelectorHandler;
import ch.elexis.core.ui.actions.ICodeSelectorTarget;
import ch.elexis.core.ui.actions.Messages;
import ch.elexis.core.ui.events.ElexisUiEventListenerImpl;
import ch.elexis.core.ui.icons.ImageSize;
import ch.elexis.core.ui.icons.Images;
import ch.elexis.core.ui.util.PersistentObjectDragSource;
import ch.elexis.data.Leistungsblock;
import ch.elexis.data.PersistentObject;
import ch.elexis.data.VerrechenbarFavorites;
import ch.elexis.data.VerrechenbarFavorites.Favorite;
......@@ -60,6 +64,14 @@ public class FavoritenComposite extends Composite {
TextTransfer.getInstance()
};
private ElexisUiEventListenerImpl reloadListener =
new ElexisUiEventListenerImpl(Favorite.class, ElexisEvent.EVENT_RELOAD) {
@Override
public void runInUi(ElexisEvent ev){
update();
}
};
/**
* Create the composite.
*
......@@ -99,13 +111,13 @@ public class FavoritenComposite extends Composite {
TableItem item = (TableItem) event.item;
Favorite fav = (Favorite) item.getData();
IPersistentObject cfs = fav.getPersistentObject();
Optional<Identifiable> cfs = fav.getObject();
String simpleName = "?";
String label = "?";
if (cfs != null) {
simpleName = cfs.getClass().getSimpleName();
label = cfs.getLabel();
if (cfs.isPresent()) {
simpleName = cfs.get().getClass().getSimpleName();
label = cfs.get().getLabel();
}
/* center column 1 vertically */
......@@ -143,14 +155,17 @@ public class FavoritenComposite extends Composite {
StructuredSelection ss = (StructuredSelection) tv.getSelection();
if (!ss.isEmpty()) {
Favorite fav = (Favorite) ss.getFirstElement();
IPersistentObject po = fav.getPersistentObject();
if (po instanceof Leistungsblock) {
Leistungsblock lb = (Leistungsblock) po;
for (ICodeElement iCodeElement : lb.getElements()) {
target.codeSelected((PersistentObject) iCodeElement);
Optional<Identifiable> po = fav.getObject();
if (po.isPresent()) {
if (po.get() instanceof ICodeElementBlock) {
ICodeElementBlock lb = (ICodeElementBlock) po.get();
for (ch.elexis.core.model.ICodeElement iCodeElement : lb
.getElements()) {
target.codeSelected(iCodeElement);
}
} else {
target.codeSelected(po.get());
}
} else {
target.codeSelected((PersistentObject) po);
}
}
}
......@@ -206,7 +221,7 @@ public class FavoritenComposite extends Composite {
public void run(){
StructuredSelection selection = (StructuredSelection) tv.getSelection();
Favorite fav = (Favorite) selection.getFirstElement();
VerrechenbarFavorites.setFavorite(fav.getPersistentObject(), false);
VerrechenbarFavorites.setFavorite(fav.getObject(), false);
tv.refresh();
}
});
......@@ -223,39 +238,43 @@ public class FavoritenComposite extends Composite {
event.data = null;
} else {
Favorite fav = (Favorite) ss.getFirstElement();
if (fav.getPersistentObject() instanceof Leistungsblock) {
Leistungsblock lb = (Leistungsblock) fav.getPersistentObject();
if (lb != null) {
event.data = lb.storeToString();
}
} else {
event.data = fav.getStoreToString();
Optional<Identifiable> favObj = fav.getObject();
if (favObj.isPresent()) {
event.data = StoreToStringServiceHolder.getStoreToString(favObj.get());
}
}
}
public void dragStart(final DragSourceEvent event){
StructuredSelection ss = (StructuredSelection) tv.getSelection();
if (ss.isEmpty()) {
PersistentObjectDragSource.setDraggedObject(null);
event.doit = false;
} else {
Favorite fav = (Favorite) ss.getFirstElement();
if (fav.getPersistentObject() instanceof Leistungsblock) {
Leistungsblock lb = (Leistungsblock) fav.getPersistentObject();
PersistentObjectDragSource.setDraggedObject(lb);
} else {
PersistentObjectDragSource
.setDraggedObject((PersistentObject) fav.getPersistentObject());
}
event.doit = true;
}
// TODO ...
// StructuredSelection ss = (StructuredSelection) tv.getSelection();
// if (ss.isEmpty()) {
// PersistentObjectDragSource.setDraggedObject(null);
// event.doit = false;
// } else {
// Favorite fav = (Favorite) ss.getFirstElement();
// if (fav.getPersistentObject() instanceof Leistungsblock) {
// Leistungsblock lb = (Leistungsblock) fav.getPersistentObject();
// PersistentObjectDragSource.setDraggedObject(lb);
// } else {
// PersistentObjectDragSource
// .setDraggedObject((PersistentObject) fav.getPersistentObject());
// }
// event.doit = true;
// }
}
});
tv.setContentProvider(new ArrayContentProvider());
tv.setLabelProvider(new ColorizedLabelProvider());
tv.setInput(VerrechenbarFavorites.getFavorites());
ElexisEventDispatcher.getInstance().addListeners(reloadListener);
}
@Override
public void dispose(){
ElexisEventDispatcher.getInstance().removeListeners(reloadListener);
}
@Override
......@@ -279,11 +298,11 @@ public class FavoritenComposite extends Composite {
@Override
public Color getBackground(Object element){
Favorite fav = (Favorite) element;
ICodeElement v = (ICodeElement) fav.getPersistentObject();
if (v == null) {
Optional<Identifiable> v = fav.getObject();
if (!v.isPresent()) {
return null;
}
String codeSystemName = v.getCodeSystemName();
String codeSystemName = ((ICodeElement) v.get()).getCodeSystemName();
if (codeSystemName == null) {
return null;
}
......
......@@ -54,7 +54,6 @@ import org.slf4j.LoggerFactory;
import ch.elexis.core.common.ElexisEventTopics;
import ch.elexis.core.data.activator.CoreHub;
import ch.elexis.core.data.util.NoPoUtil;
import ch.elexis.core.model.ICodeElementBlock;
import ch.elexis.core.model.Identifiable;
import ch.elexis.core.model.builder.ICodeElementBlockBuilder;
......@@ -101,7 +100,7 @@ public class BlockSelector extends CodeSelectorFactory {
if (firstElement instanceof BlockTreeViewerItem) {
selected = ((BlockTreeViewerItem) firstElement).getBlock();
}
tvfa.updateSelection(NoPoUtil.loadAsPersistentObject((Identifiable) selected));
tvfa.updateSelection((Identifiable) selected);
ContextServiceHolder.get().getRootContext().setTyped(selected);
}
};
......
......@@ -7,7 +7,6 @@ import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import ch.elexis.core.data.util.NoPoUtil;
import ch.elexis.core.model.ICodeElementBlock;
import ch.elexis.core.ui.icons.Images;
import ch.elexis.data.VerrechenbarFavorites;
......@@ -69,8 +68,7 @@ public class BlockTreeViewerItem {
public Image getImage(Object element){
if (element instanceof BlockTreeViewerItem) {
BlockTreeViewerItem item = (BlockTreeViewerItem) element;
Favorite fav = VerrechenbarFavorites
.isFavorite(NoPoUtil.loadAsPersistentObject(item.getBlock()));
Favorite fav = VerrechenbarFavorites.isFavorite(item.getBlock());
if (fav != null)
return Images.IMG_STAR.getImage();
}
......
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