* Fjerner transport fra ordre eller ettersending.
*
* @param window1
*/
final void removeTransport(final WindowInterface window1) {
PostShipmentManager postShipmentManager = (PostShipmentManager) ModelUtil
.getBean("postShipmentManager");
int index = tableOrders
.convertRowIndexToModel(transportableSelectionList
.getSelectionIndex());
if (index != -1) {
Transportable transportable = (Transportable) transportableSelectionList
.getElementAt(index);
if (transportable instanceof Order) {
Order order = (Order) transportable;
orderViewHandler
.lazyLoadOrder(order, new LazyLoadOrderEnum[] {
LazyLoadOrderEnum.POST_SHIPMENTS,
LazyLoadOrderEnum.COMMENTS,
LazyLoadOrderEnum.COLLIES });
} else {
PostShipment postShipment = (PostShipment) transportable;
postShipmentManager.lazyLoad(postShipment,
new LazyLoadPostShipmentEnum[] {
LazyLoadPostShipmentEnum.POST_SHIPMENT_REFS,
LazyLoadPostShipmentEnum.ORDER_COMMENTS,
LazyLoadPostShipmentEnum.COLLIES });
}
if (transportable.getPostShipments() != null
&& transportable.getPostShipments().size() != 0) {
Util.showErrorDialog(window1, "Ordre har etterleveringer",
"Kan ikke fjerne ordre som har etterleveringer.");
return;
}
transportable.setSentBool(false);
transportable.setTransport(null);
if (transportable instanceof Order) {
Order order = (Order) transportable;
orderViewHandler.lazyLoadOrder(order, new LazyLoadOrderEnum[] {
LazyLoadOrderEnum.COLLIES,
LazyLoadOrderEnum.ORDER_LINES,
LazyLoadOrderEnum.ORDER_COSTS });
Set<Colli> collies = order.getCollies();
removeSentFromCollies(collies);
Set<OrderLine> orderLines = order.getOrderLines();
if (orderLines != null) {
PostShipment postShipment;
for (OrderLine orderLine : orderLines) {
postShipment = orderLine.getPostShipment();
Deviation deviation;
if (postShipment != null) {
orderLine.setPostShipment(null);
deviation = postShipment.getDeviation();
postShipment.setOrder(null);
postShipmentManager
.removePostShipment(postShipment);
if (deviation != null) {
managerRepository.getDeviationManager()
.removeObject(deviation);
}
}
}
}
orderViewHandler.refreshOrder(order);
order.setSentBool(false);
order.setTransport(null);
try {
vismaFileCreator.createVismaFileForTransport(order);
orderViewHandler.getOrderManager().saveOrder(order);
} catch (ProTransException e) {
Util.showErrorDialog(window1, "Feil", e.getMessage());
e.printStackTrace();
return;
}
overviewManager
.refreshObject(((TransportModel) transportPresentationModel
.getBean()).getObject());
} else {
postShipmentManager
.savePostShipment((PostShipment) transportable);
}
transportableList.remove(index);
fireSentChange();
transportPresentationModel.triggerCommit();