// Chromis POS - The New Face of Open Source POS // Copyright (c) (c) 2015-2016 // http://www.chromis.co.uk // // This file is part of Chromis POS // // Chromis POS 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. // // Chromis POS 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 Chromis POS. If not, see <http://www.gnu.org/licenses/>. package uk.chromis.pos.admin; import java.awt.Component; import java.util.UUID; import java.util.logging.Level; import java.util.logging.Logger; import uk.chromis.basic.BasicException; import uk.chromis.data.user.DirtyManager; import uk.chromis.data.user.EditorRecord; import uk.chromis.format.Formats; import uk.chromis.pos.forms.AppLocal; /** * * @author adrianromero */ public final class RolesView extends javax.swing.JPanel implements EditorRecord { private Object m_oId; private DataLogicAdmin m_dlAdmin; /** * Creates new form RolesEditor * * @param dirty */ public RolesView(DataLogicAdmin dlAdmin, DirtyManager dirty) { initComponents(); m_dlAdmin = dlAdmin; m_jName.getDocument().addDocumentListener(dirty); m_jText.getDocument().addDocumentListener(dirty); jRightsLevel.addChangeListener(dirty); writeValueEOF(); } /** * */ @Override public void writeValueEOF() { m_oId = null; m_jName.setText(null); m_jText.setText(null); m_jName.setEnabled(false); m_jText.setEnabled(false); jRightsLevel.setValue(3); } /** * */ @Override public void writeValueInsert() { m_oId = null; m_jName.setText(null); m_jText.setText(null); m_jName.setEnabled(true); m_jText.setEnabled(true); jRightsLevel.setValue(3); } /** * * @param value */ @Override public void writeValueDelete(Object value) { Object[] role = (Object[]) value; m_oId = role[0]; m_jName.setText(Formats.STRING.formatValue(role[1])); m_jText.setText(Formats.BYTEA.formatValue(role[2])); m_jText.setCaretPosition(0); m_jName.setEnabled(false); m_jText.setEnabled(false); } /** * * @param value */ @Override public void writeValueEdit(Object value) { Object[] role = (Object[]) value; m_oId = role[0]; m_jName.setText(Formats.STRING.formatValue(role[1])); m_jText.setText(Formats.BYTEA.formatValue(role[2])); m_jText.setCaretPosition(0); m_jName.setEnabled(true); m_jText.setEnabled(true); try { jRightsLevel.setValue(m_dlAdmin.getRightsLevel(m_jName.getText())); } catch (BasicException ex) { Logger.getLogger(RolesView.class.getName()).log(Level.SEVERE, null, ex); } } /** * * @return @throws BasicException */ @Override public Object createValue() throws BasicException { Object[] role = new Object[4]; role = new Object[4]; role[0] = m_oId == null ? UUID.randomUUID().toString() : m_oId; role[1] = m_jName.getText(); role[2] = Formats.BYTEA.parseValue(m_jText.getText()); role[3] = jRightsLevel.getValue(); return role; } /** * * @return */ @Override public Component getComponent() { return this; } /** * */ @Override public void refresh() { } /** * 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); m_jText = new javax.swing.JTextArea(); jLabel2 = new javax.swing.JLabel(); m_jName = new javax.swing.JTextField(); jLabel1 = new javax.swing.JLabel(); jRightsLevel = new javax.swing.JSpinner(); m_jText.setFont(new java.awt.Font("DialogInput", 0, 14)); // NOI18N jScrollPane1.setViewportView(m_jText); jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N jLabel2.setText(AppLocal.getIntString("Label.Name")); // NOI18N m_jName.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("pos_messages"); // NOI18N jLabel1.setText(bundle.getString("label.rightslevel")); // NOI18N jRightsLevel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N jRightsLevel.setModel(new javax.swing.SpinnerNumberModel(3, 0, 9, 1)); jRightsLevel.setMinimumSize(new java.awt.Dimension(37, 28)); jRightsLevel.setPreferredSize(new java.awt.Dimension(37, 28)); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1) .addGroup(layout.createSequentialGroup() .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jRightsLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 62, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(m_jName, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1) .addComponent(jRightsLevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE) .addContainerGap()) ); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JSpinner jRightsLevel; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTextField m_jName; private javax.swing.JTextArea m_jText; // End of variables declaration//GEN-END:variables }