PageRenderTime 67ms CodeModel.GetById 20ms app.highlight 10ms RepoModel.GetById 31ms app.codeStats 0ms

/src/mpv5/ui/dialogs/subcomponents/GroupDialog.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 114 lines | 77 code | 15 blank | 22 comment | 2 complexity | 4e95b4611fc6aae613fc9b89118cc05b MD5 | raw file
  1/*
  2 * To change this template, choose Tools | Templates
  3 * and open the template in the editor.
  4 */
  5
  6/*
  7 * GroupDialog.java
  8 *
  9 * Created on 08.03.2009, 22:03:40
 10 */
 11package mpv5.ui.dialogs.subcomponents;
 12
 13import java.util.ArrayList;
 14import java.util.logging.Level;
 15import java.util.logging.Logger;
 16import javax.swing.tree.DefaultMutableTreeNode;
 17import mpv5.db.common.Context;
 18import mpv5.db.common.DatabaseObject;
 19import mpv5.db.common.NodataFoundException;
 20import mpv5.globals.Messages;
 21import mpv5.db.objects.Group;
 22import mpv5.logging.Log;
 23import mpv5.ui.panels.DataPanel;
 24import mpv5.utils.arrays.ArrayUtilities;
 25import mpv5.utils.models.MPTreeModel;
 26import mpv5.utils.trees.TreeFormat;
 27
 28/**
 29 *
 30 *  
 31 */
 32public class GroupDialog extends javax.swing.JPanel {
 33    private DataPanel view;
 34
 35    /** Creates new form GroupDialog */
 36    public GroupDialog(DataPanel view) {
 37        initComponents();
 38        try {
 39            refresh();
 40        } catch (NodataFoundException ex) {
 41            mpv5.logging.Log.Debug(ex);//Logger.getLogger(GroupDialog.class.getName()).log(Level.SEVERE, null, ex);
 42        }
 43        this.view = view;
 44    }
 45
 46    /** This method is called from within the constructor to
 47     * initialize the form.
 48     * WARNING: Do NOT modify this code. The content of this method is
 49     * always regenerated by the Form Editor.
 50     */
 51    @SuppressWarnings("unchecked")
 52    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 53    private void initComponents() {
 54
 55        jScrollPane1 = new javax.swing.JScrollPane();
 56        tree = new javax.swing.JTree();
 57
 58        setName("Form"); // NOI18N
 59
 60        jScrollPane1.setName("jScrollPane1"); // NOI18N
 61
 62        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("root");
 63        tree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
 64        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
 65        tree.setToolTipText(bundle.getString("ControlPanel_Groups.tree.toolTipText")); // NOI18N
 66        tree.setName("tree"); // NOI18N
 67        tree.addMouseListener(new java.awt.event.MouseAdapter() {
 68            public void mouseClicked(java.awt.event.MouseEvent evt) {
 69                treeMouseClicked(evt);
 70            }
 71        });
 72        jScrollPane1.setViewportView(tree);
 73
 74        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
 75        this.setLayout(layout);
 76        layout.setHorizontalGroup(
 77            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 78            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 298, Short.MAX_VALUE)
 79        );
 80        layout.setVerticalGroup(
 81            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 82            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 283, Short.MAX_VALUE)
 83        );
 84    }// </editor-fold>//GEN-END:initComponents
 85
 86    public void refresh() throws NodataFoundException {
 87       
 88        Group root;
 89        try {
 90            root = (Group) DatabaseObject.getObject(Context.getGroup(), "groupsids", 0);
 91        } catch (NodataFoundException ex) {
 92            root = new Group(Messages.GROUPNAMES.toString());
 93            root.setIDS(-1);
 94        }
 95        tree.setModel(MPTreeModel.toTreeModel( root));
 96
 97        TreeFormat.expandTree(tree);
 98    }
 99
100    private void treeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treeMouseClicked
101        evt.consume();
102        DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
103
104        if (node != null) {
105            Group g = (Group) node.getUserObject();
106            view.getDataOwner().setGroupsids(g.__getIDS());
107            view.setDataOwner(view.getDataOwner(),true);
108        }
109}//GEN-LAST:event_treeMouseClicked
110    // Variables declaration - do not modify//GEN-BEGIN:variables
111    private javax.swing.JScrollPane jScrollPane1;
112    private javax.swing.JTree tree;
113    // End of variables declaration//GEN-END:variables
114}