Skip to content

Commit

Permalink
[#4] use tree view for contract list [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
janrieke committed Jun 27, 2019
1 parent 0e62b4f commit cc91b0f
Show file tree
Hide file tree
Showing 10 changed files with 237 additions and 234 deletions.
75 changes: 38 additions & 37 deletions ContractManager/.classpath
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/updates/java">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/updates/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 1 addition & 1 deletion ContractManager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-resources</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package de.janrieke.contractmanager.gui.action;

import java.rmi.RemoteException;
import java.util.Optional;

import de.janrieke.contractmanager.Settings;
import de.janrieke.contractmanager.rmi.Contract;
Expand All @@ -31,28 +32,36 @@
*/
public class DismissNextReminder implements Action {

private TablePart tablePart;
private Optional<TablePart> tablePart;

public DismissNextReminder(TablePart tablePart) {
this.tablePart = tablePart;
this.tablePart = Optional.ofNullable(tablePart);
}

/**
* @see de.willuhn.jameica.gui.Action#handleAction(java.lang.Object)
*/
@Override
public void handleAction(Object context) throws ApplicationException {

// check if the context is a contract
if (context == null || !(context instanceof Contract))
if (context == null || !(context instanceof Contract)) {
throw new ApplicationException(Settings.i18n().tr(
"Please choose a contract."));
}

Contract c = (Contract) context;

try {
c.doNotRemindAboutNextCancellation();
c.store();
tablePart.updateItem(c, c);
tablePart.ifPresent(tP -> {
try {
tP.updateItem(c, c);
} catch (RemoteException e) {
Logger.error("Unable to update contract table.", e);
}
});
} catch (RemoteException e) {
Logger.error("error while dismissing reminder", e);
throw new ApplicationException(Settings.i18n().tr(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package de.janrieke.contractmanager.gui.control;

import static de.janrieke.contractmanager.util.DateUtils.calculateNextTermBeginAfter;

import java.rmi.RemoteException;
import java.text.NumberFormat;
import java.text.ParseException;
Expand All @@ -38,7 +40,7 @@
import de.janrieke.contractmanager.gui.input.PositiveIntegerInput;
import de.janrieke.contractmanager.gui.menu.ContractListMenu;
import de.janrieke.contractmanager.gui.menu.CostsListMenu;
import de.janrieke.contractmanager.gui.parts.ContractListTablePart;
import de.janrieke.contractmanager.gui.parts.ContractListTreePart;
import de.janrieke.contractmanager.gui.parts.CostsListTablePart;
import de.janrieke.contractmanager.gui.parts.SizeableTablePart;
import de.janrieke.contractmanager.gui.view.ContractDetailView;
Expand All @@ -47,6 +49,7 @@
import de.janrieke.contractmanager.rmi.Costs;
import de.janrieke.contractmanager.rmi.IntervalType;
import de.janrieke.contractmanager.rmi.Transaction;
import de.janrieke.contractmanager.util.ValidRuntimes;
import de.willuhn.datasource.GenericIterator;
import de.willuhn.datasource.pseudo.PseudoIterator;
import de.willuhn.datasource.rmi.DBIterator;
Expand All @@ -57,7 +60,7 @@
import de.willuhn.jameica.gui.dialogs.CalendarDialog;
import de.willuhn.jameica.gui.formatter.CurrencyFormatter;
import de.willuhn.jameica.gui.formatter.DateFormatter;
import de.willuhn.jameica.gui.formatter.TableFormatter;
import de.willuhn.jameica.gui.formatter.TreeFormatter;
import de.willuhn.jameica.gui.input.CheckboxInput;
import de.willuhn.jameica.gui.input.Input;
import de.willuhn.jameica.gui.input.IntegerInput;
Expand All @@ -78,7 +81,7 @@
public class ContractControl extends AbstractControl {

// list of all contracts
private ContractListTablePart contractList;
private ContractListTreePart contractTree;
// list of all contracts with cancellation warnings
private SizeableTablePart contractListWarnings;

Expand Down Expand Up @@ -153,13 +156,15 @@ public class ContractControl extends AbstractControl {
private final ValidationProvider endDateValidationProvider = time -> {
Calendar calendar = Calendar.getInstance();
calendar.setTime(time);
calendar.add(Calendar.DAY_OF_MONTH, -2); // a little tolerance
calendar.add(Calendar.DAY_OF_MONTH, -5); // a little tolerance
try {
Date startDate = getContract().getStartDate();
if (startDate == null) {
return Optional.empty();
}
Date nextTermBegin = getContract().getNextTermBeginAfter(startDate);
Date nextTermBegin = calculateNextTermBeginAfter(startDate, startDate, false,
ValidRuntimes.getValidRuntimes(getContract()));

if (nextTermBegin == null) {
return Optional.empty();
}
Expand Down Expand Up @@ -677,50 +682,50 @@ public Input getPartnerCountry() throws RemoteException {
* @return a table with contracts.
* @throws RemoteException
*/
public ContractListTablePart getContractsTable() throws RemoteException {
if (contractList != null) {
return contractList;
public ContractListTreePart getContractsTable() throws RemoteException {
if (contractTree != null) {
return contractTree;
}

GenericIterator<Contract> allContracts = getContracts();
Date today = new Date();
List<Contract> contracts = new ArrayList<>();

double total = 0d;
// double total = 0d;
while (allContracts.hasNext()) {
Contract c = allContracts.next();
if (c.isActiveInMonth(today)) {
// Only add active contracts.
total += c.getMoneyPerMonth();
// total += c.getMoneyPerMonth();
contracts.add(c);
}
}

// 4) create the table
contractList = new ContractListTablePart(
// 4) create the tree
contractTree = new ContractListTreePart(
contracts,
new de.janrieke.contractmanager.gui.action.ShowContractDetailView());
contractList.setSum(total);
// contractTree.setSum(total);

// 5) now we have to add some columns.
contractList.addColumn(Settings.i18n().tr("Name of Contract"), "name");
contractList.addColumn(Settings.i18n().tr("Contract Partner"), Contract.PARTNER_NAME);
contractList.addColumn(Settings.i18n().tr("Start Date"), "startdate",
contractTree.addColumn(Settings.i18n().tr("Name of Contract"), "name");
contractTree.addColumn(Settings.i18n().tr("Contract Partner"), Contract.PARTNER_NAME);
contractTree.addColumn(Settings.i18n().tr("Start Date"), "startdate",
new DateFormatter(Settings.getNewDateFormat()));
contractList.addColumn(Settings.i18n().tr("End Date"), "enddate",
contractTree.addColumn(Settings.i18n().tr("End Date"), "enddate",
new DateFormatter(Settings.getNewDateFormat()));
contractList.addColumn(
contractTree.addColumn(
Settings.i18n().tr("Next Cancellation Deadline"),
Contract.NEXT_CANCELLATION_DEADLINE,
new DateFormatter(Settings.getNewDateFormat()));
contractList.addColumn(Settings.i18n().tr("Money per Term"),
contractTree.addColumn(Settings.i18n().tr("Money per Term"),
Contract.MONEY_PER_TERM, new CurrencyFormatter(
Settings.CURRENCY, Settings.DECIMALFORMAT), false,
Column.ALIGN_RIGHT);
contractList.addColumn(Settings.i18n().tr("Money per Month"),
contractTree.addColumn(Settings.i18n().tr("Money per Month"),
Contract.MONEY_PER_MONTH, new CurrencyFormatter(
Settings.CURRENCY, Settings.DECIMALFORMAT));
contractList.addColumn(Settings.i18n().tr("Remind?"), "ignore_cancellations", o -> {
contractTree.addColumn(Settings.i18n().tr("Remind?"), "ignore_cancellations", o -> {
if (o instanceof Integer) {
if (((Integer)o).intValue() == 0) {
return "\u2611";
Expand All @@ -733,9 +738,9 @@ Contract.MONEY_PER_MONTH, new CurrencyFormatter(
}, true, Column.ALIGN_LEFT);

// 7) we are adding a context menu
contractList.setContextMenu(new ContractListMenu(contractList, true));
contractTree.setContextMenu(new ContractListMenu(null, true));

TableFormatter formatter = item -> {
TreeFormatter formatter = item -> {
if (item.getData() instanceof Contract) {
Contract contract = (Contract) item.getData();
try {
Expand All @@ -759,8 +764,8 @@ Contract.MONEY_PER_MONTH, new CurrencyFormatter(
}
}
};
contractList.setFormatter(formatter);
return contractList;
contractTree.setFormatter(formatter);
return contractTree;
}

/**
Expand All @@ -775,33 +780,29 @@ public CheckboxInput getActiveFilterSwitch() {
activeFilterSwitch.setValue(true);
activeFilterSwitch.addListener(event -> {
try {
System.out.println(event.type);
if (event.type != SWT.Selection) {
return;
}
Object selection = contractTree.getSelection();
contractTree.removeAll();
if ((Boolean)activeFilterSwitch.getValue()) {
// Checkbox was active; remove inactive contracts.
Date today = new Date();
List<Contract> contractsToRemove = new ArrayList<>();
for (Object item : contractList.getItems()) {
if (!((Contract)item).isActiveInMonth(today)) {
contractsToRemove.add((Contract) item);
GenericIterator<Contract> contracts = getContracts();
List<Contract> activeContracts = new ArrayList<>();
while (contracts.hasNext()) {
Contract item = contracts.next();
if (item.isActiveInMonth(today)) {
activeContracts.add(item);
}
}
for (Contract c : contractsToRemove) {
contractList.removeItem(c);
}
contractTree.setList(activeContracts);
} else {
// Checkbox was inactive; add all contracts.
Object selection = contractList.getSelection();
contractList.removeAll();
GenericIterator<Contract> contracts = getContracts();
while (contracts.hasNext()) {
contractList.addItem(contracts.next());
}
contractList.select(selection);
contractList.sort();
contractTree.setList(contracts);
}
contractTree.select(selection);
} catch (RemoteException e) {
Logger.error("Error while repopulating contract table", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -23,20 +23,18 @@
import de.janrieke.contractmanager.gui.action.GenerateOdfDocument;
import de.janrieke.contractmanager.gui.action.ShowContractDetailView;
import de.janrieke.contractmanager.gui.parts.OnlyForContractsWithRemindersContextMenuItem;
import de.willuhn.jameica.gui.Action;
import de.willuhn.jameica.gui.parts.CheckedContextMenuItem;
import de.willuhn.jameica.gui.parts.ContextMenu;
import de.willuhn.jameica.gui.parts.ContextMenuItem;
import de.willuhn.jameica.gui.parts.TablePart;
import de.willuhn.util.ApplicationException;

/**
* Prepared context menu for project tables.
*/
public class ContractListMenu extends ContextMenu {
/**
* ct.
*
*
* @param showNew
*/
public ContractListMenu(TablePart tablePart, boolean showNew) {
Expand All @@ -55,16 +53,9 @@ public ContractListMenu(TablePart tablePart, boolean showNew) {
if (showNew) {
// separator
addItem(ContextMenuItem.SEPARATOR);

addItem(new ContextMenuItem(Settings.i18n().tr(
"Create a new contract..."), new Action() {
public void handleAction(Object context)
throws ApplicationException {
// we force the context to be null to create a new
// project in any case
new ShowContractDetailView().handleAction(null);
}
}, "document-new.png"));
"Create a new contract..."), context -> new ShowContractDetailView().handleAction(null), "document-new.png"));

addItem(ContextMenuItem.SEPARATOR);
addItem(new CheckedContextMenuItem(Settings.i18n().tr(
Expand Down
Loading

0 comments on commit cc91b0f

Please sign in to comment.