/* * Copyright (C) 2014 GG-Net GmbH - Oliver Günther * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * 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 eu.ggnet.dwoss.redtape.position; import java.util.function.Consumer; import eu.ggnet.dwoss.configuration.GlobalConfig; import eu.ggnet.dwoss.redtape.api.PositionService; import eu.ggnet.dwoss.redtape.entity.Position; import eu.ggnet.dwoss.redtape.entity.PositionBuilder; import eu.ggnet.dwoss.util.*; import eu.ggnet.saft.api.ui.OnOk; import eu.ggnet.saft.api.ui.Title; import static eu.ggnet.saft.core.Client.hasFound; import static eu.ggnet.saft.core.Client.lookup; /** * * @author pascal.perau */ @Title("Diensleistung/Kleinteil hinzufügen o. bearbeiten") public class ServiceViewCask extends javax.swing.JPanel implements OnOk, Consumer<Position> { private Position position; private PositionUpdateCask positionView; public ServiceViewCask() { initComponents(); positionView = new PositionUpdateCask(); positionPanel.add(positionView); templateList.setCellRenderer(new Tuple2PositionRenderer()); if ( hasFound(PositionService.class) ) { templateList.setListData(lookup(PositionService.class).servicePositionTemplates().toArray()); } else { templateList.setListData(new Position[]{Position.builder().name("ServicePosition").description("").price(0.).build()}); } } public Position getPosition() { // TODO: Why not usding position.getPosition() asks OG position.setPrice(positionView.getPrice()); position.setAfterTaxPrice(MathUtil.roundedApply(position.getPrice(), GlobalConfig.TAX, 0.02)); position.setAmount(positionView.getAmount()); position.setDescription(positionView.getDescription()); position.setName(positionView.getPositionName()); position.setBookingAccount(positionView.getBookingAccount()); return position; } @Override public void accept(Position position) { if ( position == null ) return; this.position = position; positionView.accept(position); } @Override public boolean onOk() { return positionView.onOk(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { positionPanel = new javax.swing.JPanel(); jScrollPane2 = new javax.swing.JScrollPane(); templateList = new javax.swing.JList(); positionPanel.setMinimumSize(new java.awt.Dimension(328, 572)); positionPanel.setPreferredSize(new java.awt.Dimension(328, 572)); positionPanel.setLayout(new java.awt.BorderLayout()); jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); templateList.setModel(new javax.swing.AbstractListModel() { String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; public int getSize() { return strings.length; } public Object getElementAt(int i) { return strings[i]; } }); templateList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); templateList.setToolTipText(""); templateList.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { templateListMouseClicked(evt); } }); jScrollPane2.setViewportView(templateList); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(positionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 386, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(positionPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jScrollPane2) ); }// </editor-fold>//GEN-END:initComponents private void templateListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_templateListMouseClicked if ( evt.getClickCount() == 2 ) { position = (Position)templateList.getSelectedValue(); position = Position.builder().afterTaxPrice(position.getAfterTaxPrice()).amount(position.getAmount()).bookingAccount(position.getBookingAccount()) .description(position.getDescription()).name(position.getName()).price(position.getPrice()).tax(position.getTax()) .type(position.getType()).uniqueUnitId(position.getUniqueUnitId()).uniqueUnitProductId(position.getUniqueUnitProductId()).build(); positionView.accept(position); // positionView.setPositionName(position.getName()); // positionView.setDescription(position.getDescription()); // positionView.setPrice(position.getPrice()); // positionView.setAmount(position.getAmount()); // positionView.setPreDecimal((int)(position.getAmount() - (position.getAmount() % 1))); // positionView.setPostDecimal((int)((position.getAmount() % 1) * 100)); // positionView.bookingAccountBox.getModel().setSelectedItem(position.getBookingAccount()); } }//GEN-LAST:event_templateListMouseClicked // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane jScrollPane2; private javax.swing.JPanel positionPanel; private javax.swing.JList templateList; // End of variables declaration//GEN-END:variables }