Skip to content

Commit

Permalink
Filter für Lehrgänge View Update (#233)
Browse files Browse the repository at this point in the history
* Filter für Lehrgänge View

* Umstellung auf DBIterator

* While performanter
  • Loading branch information
JohannMaierhofer authored Jun 15, 2024
1 parent 4227384 commit ed2acba
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 176 deletions.
178 changes: 19 additions & 159 deletions src/de/jost_net/JVerein/gui/control/LehrgangControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
package de.jost_net.JVerein.gui.control;

import java.rmi.RemoteException;
import java.text.ParseException;
import java.util.Date;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

Expand All @@ -34,8 +32,6 @@
import de.jost_net.JVerein.util.JVDateFormatTTMMJJJJ;
import de.willuhn.datasource.pseudo.PseudoIterator;
import de.willuhn.datasource.rmi.DBIterator;
import de.willuhn.datasource.rmi.ObjectNotFoundException;
import de.willuhn.jameica.gui.AbstractControl;
import de.willuhn.jameica.gui.AbstractView;
import de.willuhn.jameica.gui.GUI;
import de.willuhn.jameica.gui.Part;
Expand All @@ -51,7 +47,7 @@
import de.willuhn.logging.Logger;
import de.willuhn.util.ApplicationException;

public class LehrgangControl extends AbstractControl
public class LehrgangControl extends FilterControl
{

private TablePart lehrgaengeList;
Expand All @@ -68,15 +64,6 @@ public class LehrgangControl extends AbstractControl

private Lehrgang lehrg = null;

// Elemente für die Auswertung

private SelectInput suchlehrgangsart = null;

private DateInput datumvon = null;

private DateInput datumbis = null;

private Settings settings = null;

public LehrgangControl(AbstractView view)
{
Expand Down Expand Up @@ -181,81 +168,6 @@ public Input getErgebnis() throws RemoteException
return ergebnis;
}

public SelectInput getSuchLehrgangsart() throws RemoteException
{
if (suchlehrgangsart != null)
{
return suchlehrgangsart;
}
DBIterator<Lehrgangsart> it = Einstellungen.getDBService()
.createList(Lehrgangsart.class);
it.setOrder("order by bezeichnung");
Lehrgangsart letztesuche = null;
try
{
letztesuche = (Lehrgangsart) Einstellungen.getDBService().createObject(
Lehrgangsart.class, settings.getString("suchlehrgangsart", null));
}
catch (ObjectNotFoundException e)
{
//
}
suchlehrgangsart = new SelectInput(it != null ? PseudoIterator.asList(it) : null, letztesuche);
suchlehrgangsart.setPleaseChoose("Bitte auswählen");
suchlehrgangsart.addListener(new FilterListener());
return suchlehrgangsart;
}

public DateInput getDatumvon()
{
if (datumvon != null)
{
return datumvon;
}
Date d = null;
String tmp = settings.getString("datum.von", null);
if (tmp != null)
{
try
{
d = new JVDateFormatTTMMJJJJ().parse(tmp);
}
catch (ParseException e)
{
//
}
}
this.datumvon = new DateInput(d, new JVDateFormatTTMMJJJJ());
this.datumvon.setTitle("Datum von");
this.datumvon.setText("Datum von");
return datumvon;
}

public DateInput getDatumbis()
{
if (datumbis != null)
{
return datumbis;
}
Date d = null;
String tmp = settings.getString("datum.bis", null);
if (tmp != null)
{
try
{
d = new JVDateFormatTTMMJJJJ().parse(tmp);
}
catch (ParseException e)
{
//
}
}
this.datumbis = new DateInput(d, new JVDateFormatTTMMJJJJ());
this.datumbis.setTitle("Datum bis");
this.datumbis.setText("Datum bis");
return datumbis;
}

public void handleStore()
{
try
Expand All @@ -282,11 +194,10 @@ public void handleStore()
}
}

public void refresh()
public void TabRefresh()
{
try
{
saveDefaults();
if (lehrgaengeList == null)
{
return;
Expand All @@ -295,8 +206,7 @@ public void refresh()
DBIterator<Lehrgang> lehrgaenge = getIterator();
while (lehrgaenge.hasNext())
{
Lehrgang lg = lehrgaenge.next();
lehrgaengeList.addItem(lg);
lehrgaengeList.addItem(lehrgaenge.next());
}
}
catch (RemoteException e1)
Expand All @@ -309,71 +219,35 @@ private DBIterator<Lehrgang> getIterator() throws RemoteException
{
DBIterator<Lehrgang> lehrgaenge = Einstellungen.getDBService()
.createList(Lehrgang.class);
if (getSuchLehrgangsart().getValue() != null)
lehrgaenge.join("mitglied");
lehrgaenge.addFilter("mitglied.id = lehrgang.mitglied");

if (isSuchnameAktiv() && getSuchname().getValue() != null)
{
String tmpSuchname = (String) getSuchname().getValue();
if (tmpSuchname.length() > 0)
{
lehrgaenge.addFilter("(lower(name) like ?)",
new Object[] { "%" + tmpSuchname.toLowerCase() + "%"});
}
}
if (isSuchLehrgangsartAktiv() && getSuchLehrgangsart().getValue() != null)
{
Lehrgangsart la = (Lehrgangsart) getSuchLehrgangsart().getValue();
lehrgaenge.addFilter("lehrgangsart = ?", new Object[] { la.getID() });
}
if (getDatumvon().getValue() != null)
if (isDatumvonAktiv() && getDatumvon().getValue() != null)
{
lehrgaenge.addFilter("von >= ?",
new Object[] { (Date) getDatumvon().getValue() });
}
if (getDatumbis().getValue() != null)
if (isDatumbisAktiv() && getDatumbis().getValue() != null)
{
lehrgaenge.addFilter("bis <= ?",
new Object[] { (Date) getDatumbis().getValue() });
}
return lehrgaenge;
}

/**
* Default-Werte speichern.
*
* @throws RemoteException
*/
public void saveDefaults() throws RemoteException
{
if (this.suchlehrgangsart != null)
{
Lehrgangsart la = (Lehrgangsart) getSuchLehrgangsart().getValue();
if (la != null)
{
settings.setAttribute("suchlehrgangsart", la.getID());
}
else
{
settings.setAttribute("suchlehrgangsart", "");
}
}
if (this.datumvon != null)
{
Date tmp = (Date) getDatumvon().getValue();
if (tmp != null)
{
settings.setAttribute("datum.von",
new JVDateFormatTTMMJJJJ().format(tmp));
}
else
{
settings.setAttribute("datum.von", "");
}
}

if (this.datumbis != null)
{
Date tmp = (Date) getDatumbis().getValue();
if (tmp != null)
{
settings.setAttribute("datum.bis",
new JVDateFormatTTMMJJJJ().format(tmp));
}
else
{
settings.setAttribute("datum.bis", "");
}
}

return lehrgaenge;
}

public Part getLehrgaengeList() throws RemoteException
Expand Down Expand Up @@ -426,18 +300,4 @@ public String format(Object o)
return lehrgaengeList;
}

private class FilterListener implements Listener
{

@Override
public void handleEvent(Event event)
{
if (event.type != SWT.Selection && event.type != SWT.FocusOut)
{
return;
}
refresh();
}
}

}
32 changes: 15 additions & 17 deletions src/de/jost_net/JVerein/gui/view/LehrgaengeListeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@
import de.jost_net.JVerein.gui.action.DokumentationAction;
import de.jost_net.JVerein.gui.control.LehrgangControl;
import de.willuhn.jameica.gui.AbstractView;
import de.willuhn.jameica.gui.Action;
import de.willuhn.jameica.gui.GUI;
import de.willuhn.jameica.gui.parts.Button;
import de.willuhn.jameica.gui.parts.ButtonArea;
import de.willuhn.jameica.gui.util.ColumnLayout;
import de.willuhn.jameica.gui.util.LabelGroup;
import de.willuhn.util.ApplicationException;
import de.willuhn.jameica.gui.util.SimpleContainer;

public class LehrgaengeListeView extends AbstractView
{
Expand All @@ -37,21 +36,20 @@ public void bind() throws Exception
final LehrgangControl control = new LehrgangControl(this);

LabelGroup group = new LabelGroup(getParent(), "Filter");
group.addLabelPair("Lehrgangsart", control.getSuchLehrgangsart());
group.addLabelPair("Datum von", control.getDatumvon());
group.addLabelPair("Datum bis", control.getDatumbis());
ColumnLayout cl = new ColumnLayout(group.getComposite(), 2);

SimpleContainer left = new SimpleContainer(cl.getComposite());
left.addInput(control.getSuchname());
left.addInput(control.getSuchLehrgangsart());

SimpleContainer right = new SimpleContainer(cl.getComposite());
right.addInput(control.getDatumvon());
right.addInput(control.getDatumbis());

ButtonArea button1 = new ButtonArea();
Button suchen1 = new Button("Suchen", new Action()
{
@Override
public void handleAction(Object context) throws ApplicationException
{
control.refresh();
}
}, null, true, "search.png");
button1.addButton(suchen1);
group.addButtonArea(button1);
ButtonArea fbuttons = new ButtonArea();
fbuttons.addButton(control.getResetButton());
fbuttons.addButton(control.getSuchenButton());
group.addButtonArea(fbuttons);

control.getLehrgaengeList().paint(this.getParent());
ButtonArea buttons = new ButtonArea();
Expand Down

0 comments on commit ed2acba

Please sign in to comment.