Source Code Cross Referenced for UserMain.java in  » Database-Client » GUAM » guam » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » GUAM » guam 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package guam;
002:
003:        import java.awt.*;
004:        import javax.swing.*;
005:        import javax.swing.tree.*;
006:        import java.util.Hashtable;
007:        import java.util.Vector;
008:        import java.awt.event.*;
009:        import javax.swing.event.*;
010:        import java.util.Iterator;
011:        import java.util.Collection;
012:        import java.util.Enumeration;
013:
014:        /**
015:         * Title:        GUAM
016:         * Description:
017:         * Copyright:    Copyright (c) 2002
018:         * Company:
019:         * @author dkc
020:         * @version 1.0
021:         */
022:
023:        public class UserMain extends JFrame {
024:            JTree tabletree = null;
025:            JCheckBox AllPriv = new JCheckBox();
026:            JCheckBox AlterPriv = new JCheckBox();
027:            JCheckBox CreatePriv = new JCheckBox();
028:            JCheckBox DeletePriv = new JCheckBox();
029:            JCheckBox DropPriv = new JCheckBox();
030:            JCheckBox FilePriv = new JCheckBox();
031:            JCheckBox IndexPriv = new JCheckBox();
032:            JCheckBox InsertPriv = new JCheckBox();
033:            JCheckBox ProcessPriv = new JCheckBox();
034:            JCheckBox ReferencesPriv = new JCheckBox();
035:            JCheckBox ReloadPriv = new JCheckBox();
036:            JCheckBox SelectPriv = new JCheckBox();
037:            JCheckBox ShutdownPriv = new JCheckBox();
038:            JCheckBox UpdatePriv = new JCheckBox();
039:            JCheckBox UsagePriv = new JCheckBox();
040:            JButton ApplyButton = new JButton();
041:            JButton CancelButton = new JButton();
042:            JLabel PrivLabel = new JLabel();
043:            String username = null;
044:            MainFrame mymainframe = null;
045:            JCheckBox GrantPriv = new JCheckBox();
046:            Hashtable changes = new Hashtable();
047:            String currdb = null;
048:            String currtable = null;
049:            String currcolumn = null;
050:            JButton PassButton = new JButton();
051:            Hashtable cache = new Hashtable();
052:            Vector currnode = null;
053:            Hashtable checkboxes = new Hashtable();
054:
055:            public UserMain(MainFrame mymainframe, String username,
056:                    Hashtable tables) {
057:                this .username = username;
058:                this .mymainframe = mymainframe;
059:                this .tabletree = new JTree(tables);
060:                try {
061:                    jbInit();
062:                } catch (Exception e) {
063:                    e.printStackTrace();
064:                }
065:            }
066:
067:            private void jbInit() throws Exception {
068:                this .getContentPane().setLayout(null);
069:                tabletree.setAutoscrolls(true);
070:                //    tabletree.setBorder(BorderFactory.createLoweredBevelBorder());
071:                DefaultTreeSelectionModel tsm = new DefaultTreeSelectionModel();
072:                tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
073:                tabletree.setSelectionModel(tsm);
074:                tabletree.setScrollsOnExpand(true);
075:                //    tabletree.setBounds(new Rectangle(9, 9, 222, 397));
076:                tabletree
077:                        .addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
078:                            public void valueChanged(TreeSelectionEvent e) {
079:                                tabletree_valueChanged(e);
080:                            }
081:                        });
082:                JScrollPane DBScroller = new JScrollPane(tabletree);
083:                DBScroller.setBounds(new Rectangle(9, 9, 222, 397));
084:                AllPriv.setText("All Privileges");
085:                AllPriv.setBounds(new Rectangle(257, 25, 100, 21));
086:                checkboxes.put(new Integer(DBInterface.ALL), AllPriv);
087:                AllPriv.addActionListener(new java.awt.event.ActionListener() {
088:                    public void actionPerformed(ActionEvent e) {
089:                        AllPriv_actionPerformed(e);
090:                    }
091:                });
092:                AlterPriv.setBounds(new Rectangle(257, 49, 80, 21));
093:                checkboxes.put(new Integer(DBInterface.ALTER), AlterPriv);
094:                AlterPriv
095:                        .addActionListener(new java.awt.event.ActionListener() {
096:                            public void actionPerformed(ActionEvent e) {
097:                                AlterPriv_actionPerformed(e);
098:                            }
099:                        });
100:                AlterPriv.setText("Alter");
101:                CreatePriv.setBounds(new Rectangle(257, 73, 80, 21));
102:                checkboxes.put(new Integer(DBInterface.CREATE), CreatePriv);
103:                CreatePriv
104:                        .addActionListener(new java.awt.event.ActionListener() {
105:                            public void actionPerformed(ActionEvent e) {
106:                                CreatePriv_actionPerformed(e);
107:                            }
108:                        });
109:                CreatePriv.setText("Create");
110:                DeletePriv.setBounds(new Rectangle(257, 97, 80, 21));
111:                checkboxes.put(new Integer(DBInterface.DELETE), DeletePriv);
112:                DeletePriv
113:                        .addActionListener(new java.awt.event.ActionListener() {
114:                            public void actionPerformed(ActionEvent e) {
115:                                DeletePriv_actionPerformed(e);
116:                            }
117:                        });
118:                DeletePriv.setText("Delete");
119:                DropPriv.setBounds(new Rectangle(257, 121, 80, 21));
120:                checkboxes.put(new Integer(DBInterface.DROP), DropPriv);
121:                DropPriv.addActionListener(new java.awt.event.ActionListener() {
122:                    public void actionPerformed(ActionEvent e) {
123:                        DropPriv_actionPerformed(e);
124:                    }
125:                });
126:                DropPriv.setText("Drop");
127:                FilePriv.setBounds(new Rectangle(257, 145, 80, 21));
128:                checkboxes.put(new Integer(DBInterface.FILE), FilePriv);
129:                FilePriv.addActionListener(new java.awt.event.ActionListener() {
130:                    public void actionPerformed(ActionEvent e) {
131:                        FilePriv_actionPerformed(e);
132:                    }
133:                });
134:                FilePriv.setText("File");
135:                GrantPriv.setBounds(new Rectangle(257, 169, 80, 21));
136:                checkboxes.put(new Integer(DBInterface.GRANT), GrantPriv);
137:                GrantPriv
138:                        .addActionListener(new java.awt.event.ActionListener() {
139:                            public void actionPerformed(ActionEvent e) {
140:                                GrantPriv_actionPerformed(e);
141:                            }
142:                        });
143:                GrantPriv.setText("Grant");
144:                IndexPriv.setBounds(new Rectangle(257, 192, 80, 21));
145:                checkboxes.put(new Integer(DBInterface.INDEX), IndexPriv);
146:                IndexPriv
147:                        .addActionListener(new java.awt.event.ActionListener() {
148:                            public void actionPerformed(ActionEvent e) {
149:                                IndexPriv_actionPerformed(e);
150:                            }
151:                        });
152:                IndexPriv.setText("Index");
153:                InsertPriv.setBounds(new Rectangle(257, 216, 80, 21));
154:                checkboxes.put(new Integer(DBInterface.INSERT), InsertPriv);
155:                InsertPriv
156:                        .addActionListener(new java.awt.event.ActionListener() {
157:                            public void actionPerformed(ActionEvent e) {
158:                                InsertPriv_actionPerformed(e);
159:                            }
160:                        });
161:                InsertPriv.setText("Insert");
162:                ProcessPriv.setBounds(new Rectangle(257, 240, 80, 21));
163:                checkboxes.put(new Integer(DBInterface.PROCESS), ProcessPriv);
164:                ProcessPriv
165:                        .addActionListener(new java.awt.event.ActionListener() {
166:                            public void actionPerformed(ActionEvent e) {
167:                                ProcessPriv_actionPerformed(e);
168:                            }
169:                        });
170:                ProcessPriv.setText("Process");
171:                ReferencesPriv.setBounds(new Rectangle(257, 264, 90, 21));
172:                checkboxes.put(new Integer(DBInterface.REFERENCES),
173:                        ReferencesPriv);
174:                ReferencesPriv
175:                        .addActionListener(new java.awt.event.ActionListener() {
176:                            public void actionPerformed(ActionEvent e) {
177:                                ReferencesPriv_actionPerformed(e);
178:                            }
179:                        });
180:                ReferencesPriv.setText("References");
181:                ReloadPriv.setBounds(new Rectangle(257, 288, 80, 21));
182:                checkboxes.put(new Integer(DBInterface.RELOAD), ReloadPriv);
183:                ReloadPriv
184:                        .addActionListener(new java.awt.event.ActionListener() {
185:                            public void actionPerformed(ActionEvent e) {
186:                                ReloadPriv_actionPerformed(e);
187:                            }
188:                        });
189:                ReloadPriv.setText("Reload");
190:                SelectPriv.setBounds(new Rectangle(257, 312, 80, 21));
191:                checkboxes.put(new Integer(DBInterface.SELECT), SelectPriv);
192:                SelectPriv
193:                        .addActionListener(new java.awt.event.ActionListener() {
194:                            public void actionPerformed(ActionEvent e) {
195:                                SelectPriv_actionPerformed(e);
196:                            }
197:                        });
198:                SelectPriv.setText("Select");
199:                ShutdownPriv.setBounds(new Rectangle(257, 336, 80, 21));
200:                checkboxes.put(new Integer(DBInterface.SHUTDOWN), ShutdownPriv);
201:                ShutdownPriv
202:                        .addActionListener(new java.awt.event.ActionListener() {
203:                            public void actionPerformed(ActionEvent e) {
204:                                ShutdownPriv_actionPerformed(e);
205:                            }
206:                        });
207:                ShutdownPriv.setText("Shutdown");
208:                UpdatePriv.setBounds(new Rectangle(257, 360, 80, 21));
209:                checkboxes.put(new Integer(DBInterface.UPDATE), UpdatePriv);
210:                UpdatePriv
211:                        .addActionListener(new java.awt.event.ActionListener() {
212:                            public void actionPerformed(ActionEvent e) {
213:                                UpdatePriv_actionPerformed(e);
214:                            }
215:                        });
216:                UpdatePriv.setText("Update");
217:                UsagePriv.setBounds(new Rectangle(257, 384, 80, 21));
218:                checkboxes.put(new Integer(DBInterface.USAGE), UsagePriv);
219:                UsagePriv
220:                        .addActionListener(new java.awt.event.ActionListener() {
221:                            public void actionPerformed(ActionEvent e) {
222:                                UsagePriv_actionPerformed(e);
223:                            }
224:                        });
225:                UsagePriv.setText("Usage");
226:                ApplyButton.setText("Apply");
227:                ApplyButton.setBounds(new Rectangle(158, 414, 86, 26));
228:                ApplyButton
229:                        .addActionListener(new java.awt.event.ActionListener() {
230:                            public void actionPerformed(ActionEvent e) {
231:                                ApplyButton_actionPerformed(e);
232:                            }
233:                        });
234:                CancelButton.setBounds(new Rectangle(249, 414, 86, 26));
235:                CancelButton
236:                        .addActionListener(new java.awt.event.ActionListener() {
237:                            public void actionPerformed(ActionEvent e) {
238:                                CancelButton_actionPerformed(e);
239:                            }
240:                        });
241:                CancelButton.setText("Cancel");
242:                PrivLabel.setFont(new java.awt.Font("Dialog", 1, 12));
243:                PrivLabel.setText("Privileges:");
244:                PrivLabel.setBounds(new Rectangle(243, 6, 63, 18));
245:
246:                /*    Enumeration en = checkboxes.keys();
247:                 while(en.hasMoreElements()) {
248:                 JCheckBox cb = (JCheckBox) checkboxes.get(en.nextElement());
249:                 cb.setVisible(false);
250:                 } */
251:
252:                this 
253:                        .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
254:                //    this.getContentPane().add(tabletree, null);
255:                PassButton
256:                        .addActionListener(new java.awt.event.ActionListener() {
257:                            public void actionPerformed(ActionEvent e) {
258:                                PassButton_actionPerformed(e);
259:                            }
260:                        });
261:                PassButton.setBounds(new Rectangle(9, 414, 92, 26));
262:                PassButton.setText("Password");
263:
264:                Enumeration en = checkboxes.keys();
265:                while (en.hasMoreElements()) {
266:                    JCheckBox cb = (JCheckBox) checkboxes.get(en.nextElement());
267:                    this .getContentPane().add(cb, null);
268:                    cb.setVisible(false);
269:                }
270:
271:                this .getContentPane().add(DBScroller, null);
272:                this .getContentPane().add(CancelButton, null);
273:                this .getContentPane().add(ApplyButton, null);
274:                this .getContentPane().add(PassButton, null);
275:                this .getContentPane().add(PrivLabel, null);
276:            }
277:
278:            private void CancelButton_actionPerformed(ActionEvent e) {
279:                int x = 0;
280:                if (changes.size() > 0) {
281:                    x = JOptionPane.showConfirmDialog(this ,
282:                            "Are you sure you want to lose changes?",
283:                            "Confirm cancel", JOptionPane.YES_NO_OPTION,
284:                            JOptionPane.WARNING_MESSAGE);
285:                }
286:                if (x == 0) {
287:                    mymainframe.reEnable();
288:                    this .dispose();
289:                }
290:            }
291:
292:            void ApplyButton_actionPerformed(ActionEvent e) {
293:                Iterator i = changes.values().iterator();
294:                while (i.hasNext()) {
295:                    Hashtable tmp = (Hashtable) i.next();
296:                    Integer priv = (Integer) tmp.get("priv");
297:                    String action = (String) tmp.get("action");
298:                    if (tmp.get("db").equals("")) {
299:                        if (action.equals("G")) {
300:                            GUAM.dbi.grantGlobalPriv(username, priv.intValue());
301:                        } else {
302:                            GUAM.dbi
303:                                    .revokeGlobalPriv(username, priv.intValue());
304:                        }
305:                    } else if (tmp.get("table").equals("")) {
306:                        //db
307:                        String dbn = (String) tmp.get("db");
308:                        if (action.equals("G")) {
309:                            GUAM.dbi
310:                                    .grantDBPriv(username, dbn, priv.intValue());
311:                        } else {
312:                            GUAM.dbi.revokeDBPriv(username, dbn, priv
313:                                    .intValue());
314:                        }
315:                    } else if (tmp.get("column").equals("")) {
316:                        //table
317:                        String dbn = (String) tmp.get("db");
318:                        String tn = (String) tmp.get("table");
319:                        if (action.equals("G")) {
320:                            GUAM.dbi.grantTablePriv(username, dbn, tn, priv
321:                                    .intValue());
322:                        } else {
323:                            GUAM.dbi.revokeTablePriv(username, dbn, tn, priv
324:                                    .intValue());
325:                        }
326:                    } else {
327:                        //column
328:                        String dbn = (String) tmp.get("db");
329:                        String tn = (String) tmp.get("table");
330:                        String cn = (String) tmp.get("column");
331:                        if (action.equals("G")) {
332:                            GUAM.dbi.grantColumnPriv(username, dbn, tn, cn,
333:                                    priv.intValue());
334:                        } else {
335:                            GUAM.dbi.revokeColumnPriv(username, dbn, tn, cn,
336:                                    priv.intValue());
337:                        }
338:                    }
339:                }
340:                mymainframe.reEnable();
341:                this .dispose();
342:            }
343:
344:            private void tabletree_valueChanged(TreeSelectionEvent e) {
345:                TreePath currPath = tabletree.getSelectionPath();
346:                String key;
347:                if (currPath != null) {
348:                    switch (currPath.getPathCount()) {
349:                    case 2:
350:                        currdb = null;
351:                        currtable = null;
352:                        currcolumn = null;
353:                        key = (currdb == null ? "" : currdb) + ":"
354:                                + (currtable == null ? "" : currtable) + ":"
355:                                + (currcolumn == null ? "" : currcolumn);
356:                        doRoot(key);
357:                        break;
358:                    case 3:
359:                        currdb = currPath.getPathComponent(2).toString();
360:                        currtable = null;
361:                        currcolumn = null;
362:                        key = (currdb == null ? "" : currdb) + ":"
363:                                + (currtable == null ? "" : currtable) + ":"
364:                                + (currcolumn == null ? "" : currcolumn);
365:                        doDB(key, currdb);
366:                        break;
367:                    case 4:
368:                        currdb = currPath.getPathComponent(2).toString();
369:                        currtable = currPath.getPathComponent(3).toString();
370:                        currcolumn = null;
371:                        key = (currdb == null ? "" : currdb) + ":"
372:                                + (currtable == null ? "" : currtable) + ":"
373:                                + (currcolumn == null ? "" : currcolumn);
374:                        doTable(key, currdb, currtable);
375:                        break;
376:                    case 5:
377:                        currdb = currPath.getPathComponent(2).toString();
378:                        currtable = currPath.getPathComponent(3).toString();
379:                        currcolumn = currPath.getPathComponent(4).toString();
380:                        key = (currdb == null ? "" : currdb) + ":"
381:                                + (currtable == null ? "" : currtable) + ":"
382:                                + (currcolumn == null ? "" : currcolumn);
383:                        doColumn(key, currdb, currtable, currcolumn);
384:                        break;
385:                    }
386:                }
387:            }
388:
389:            private void restoreFromCache(String key) {
390:                clearAll();
391:                Vector v = (Vector) cache.get(key);
392:                currnode = v;
393:                Iterator i = v.iterator();
394:                while (i.hasNext()) {
395:                    JCheckBox t = (JCheckBox) i.next();
396:                    t.setSelected(true);
397:                }
398:            }
399:
400:            private void doRoot(String key) {
401:                showAll();
402:                if (cache.containsKey(key)) {
403:                    restoreFromCache(key);
404:                } else {
405:                    clearAll();
406:                    Vector v = GUAM.dbi.getGlobalPrivs(username);
407:                    currnode = new Vector();
408:                    cache.put(key, currnode);
409:                    JCheckBox t = null;
410:                    Iterator i = v.iterator();
411:                    while (i.hasNext()) {
412:                        String s = (String) i.next();
413:                        if (s.equals("SELECT")) {
414:                            t = SelectPriv;
415:                        } else if (s.equals("INSERT")) {
416:                            t = InsertPriv;
417:                        } else if (s.equals("UPDATE")) {
418:                            t = UpdatePriv;
419:                        } else if (s.equals("DELETE")) {
420:                            t = DeletePriv;
421:                        } else if (s.equals("CREATE")) {
422:                            t = CreatePriv;
423:                        } else if (s.equals("DROP")) {
424:                            t = DropPriv;
425:                        } else if (s.equals("RELOAD")) {
426:                            t = ReloadPriv;
427:                        } else if (s.equals("SHUTDOWN")) {
428:                            t = ShutdownPriv;
429:                        } else if (s.equals("PROCESS")) {
430:                            t = ProcessPriv;
431:                        } else if (s.equals("FILE")) {
432:                            t = FilePriv;
433:                        } else if (s.equals("GRANT")) {
434:                            t = GrantPriv;
435:                        } else if (s.equals("REFERENCES")) {
436:                            t = ReferencesPriv;
437:                        } else if (s.equals("INDEX")) {
438:                            t = IndexPriv;
439:                        } else if (s.equals("ALTER")) {
440:                            t = AlterPriv;
441:                        } else if (s.equals("ALL")) {
442:                            t = AllPriv;
443:                        } else if (s.equals("USAGE")) {
444:                            t = UsagePriv;
445:                        }
446:                        if (t != null) {
447:                            t.setSelected(true);
448:                            currnode.add(t);
449:                        }
450:                    }
451:                }
452:            }
453:
454:            private void doDB(String key, String dbn) {
455:                showAll();
456:                ReloadPriv.setVisible(false);
457:                ShutdownPriv.setVisible(false);
458:                ProcessPriv.setVisible(false);
459:                FilePriv.setVisible(false);
460:                if (cache.containsKey(key)) {
461:                    restoreFromCache(key);
462:                } else {
463:                    clearAll();
464:                    Vector v = GUAM.dbi.getDBPrivs(username, dbn);
465:                    currnode = new Vector();
466:                    cache.put(key, currnode);
467:                    JCheckBox t = null;
468:                    Iterator i = v.iterator();
469:                    while (i.hasNext()) {
470:                        String s = (String) i.next();
471:                        if (s.equals("SELECT")) {
472:                            t = SelectPriv;
473:                        } else if (s.equals("INSERT")) {
474:                            t = InsertPriv;
475:                        } else if (s.equals("UPDATE")) {
476:                            t = UpdatePriv;
477:                        } else if (s.equals("DELETE")) {
478:                            t = DeletePriv;
479:                        } else if (s.equals("CREATE")) {
480:                            t = CreatePriv;
481:                        } else if (s.equals("DROP")) {
482:                            t = DropPriv;
483:                        } else if (s.equals("GRANT")) {
484:                            t = GrantPriv;
485:                        } else if (s.equals("REFERENCES")) {
486:                            t = ReferencesPriv;
487:                        } else if (s.equals("INDEX")) {
488:                            t = IndexPriv;
489:                        } else if (s.equals("ALTER")) {
490:                            t = AlterPriv;
491:                        } else if (s.equals("ALL")) {
492:                            t = AllPriv;
493:                        } else if (s.equals("USAGE")) {
494:                            t = UsagePriv;
495:                        }
496:                        if (t != null) {
497:                            t.setSelected(true);
498:                            currnode.add(t);
499:                        }
500:                    }
501:                }
502:            }
503:
504:            private void doTable(String key, String dbn, String tn) {
505:                showAll();
506:                ReloadPriv.setVisible(false);
507:                ShutdownPriv.setVisible(false);
508:                ProcessPriv.setVisible(false);
509:                FilePriv.setVisible(false);
510:                ReferencesPriv.setVisible(false);
511:                if (cache.containsKey(key)) {
512:                    restoreFromCache(key);
513:                } else {
514:                    clearAll();
515:                    Vector v = GUAM.dbi.getTablePrivs(username, dbn, tn);
516:                    currnode = new Vector();
517:                    cache.put(key, currnode);
518:                    JCheckBox t = null;
519:                    Iterator i = v.iterator();
520:                    while (i.hasNext()) {
521:                        String s = (String) i.next();
522:                        if (s.equals("Select")) {
523:                            t = SelectPriv;
524:                        } else if (s.equals("Insert")) {
525:                            t = InsertPriv;
526:                        } else if (s.equals("Update")) {
527:                            t = UpdatePriv;
528:                        } else if (s.equals("Delete")) {
529:                            t = DeletePriv;
530:                        } else if (s.equals("Create")) {
531:                            t = CreatePriv;
532:                        } else if (s.equals("Drop")) {
533:                            t = DropPriv;
534:                        } else if (s.equals("Grant")) {
535:                            t = GrantPriv;
536:                        } else if (s.equals("Index")) {
537:                            t = IndexPriv;
538:                        } else if (s.equals("Alter")) {
539:                            t = AlterPriv;
540:                        } else if (s.equals("ALL")) {
541:                            t = AllPriv;
542:                        } else if (s.equals("USAGE")) {
543:                            t = UsagePriv;
544:                        }
545:                        if (t != null) {
546:                            t.setSelected(true);
547:                            currnode.add(t);
548:                        }
549:                    }
550:                }
551:            }
552:
553:            private void doColumn(String key, String dbn, String tn, String cn) {
554:                showAll();
555:                ReloadPriv.setVisible(false);
556:                ShutdownPriv.setVisible(false);
557:                ProcessPriv.setVisible(false);
558:                FilePriv.setVisible(false);
559:                ReferencesPriv.setVisible(false);
560:                DeletePriv.setVisible(false);
561:                CreatePriv.setVisible(false);
562:                DropPriv.setVisible(false);
563:                GrantPriv.setVisible(false);
564:                IndexPriv.setVisible(false);
565:                AlterPriv.setVisible(false);
566:                if (cache.containsKey(key)) {
567:                    restoreFromCache(key);
568:                } else {
569:                    clearAll();
570:                    Vector v = GUAM.dbi.getColumnPrivs(username, dbn, tn, cn);
571:                    currnode = new Vector();
572:                    cache.put(key, currnode);
573:                    JCheckBox t = null;
574:                    Iterator i = v.iterator();
575:                    while (i.hasNext()) {
576:                        String s = (String) i.next();
577:                        if (s.equals("Select")) {
578:                            t = SelectPriv;
579:                        } else if (s.equals("Insert")) {
580:                            t = InsertPriv;
581:                        } else if (s.equals("Update")) {
582:                            t = UpdatePriv;
583:                        } else if (s.equals("ALL")) {
584:                            t = AllPriv;
585:                        } else if (s.equals("USAGE")) {
586:                            t = UsagePriv;
587:                        }
588:                        if (t != null) {
589:                            t.setSelected(true);
590:                            currnode.add(t);
591:                        }
592:                    }
593:                }
594:            }
595:
596:            private void clearAll() {
597:                Enumeration en = checkboxes.keys();
598:                while (en.hasMoreElements()) {
599:                    JCheckBox cb = (JCheckBox) checkboxes.get(en.nextElement());
600:                    cb.setSelected(false);
601:                    cb.setVisible(true);
602:                }
603:            }
604:
605:            private void showAll() {
606:                Enumeration en = checkboxes.keys();
607:                while (en.hasMoreElements()) {
608:                    JCheckBox cb = (JCheckBox) checkboxes.get(en.nextElement());
609:                    cb.setVisible(true);
610:                }
611:            }
612:
613:            private void registerChange(Integer privilege, boolean active) {
614:                String key = "R:" + ((currdb == null) ? "" : currdb) + ":"
615:                        + ((currtable == null) ? "" : currtable) + ":"
616:                        + ((currcolumn == null) ? "" : currcolumn) + ":"
617:                        + username + ":" + privilege;
618:                if (changes.containsKey(key)) {
619:                    changes.remove(key);
620:                } else {
621:                    Hashtable h = new Hashtable();
622:                    h.put("priv", privilege);
623:                    h.put("action", active ? "G" : "R");
624:                    h.put("db", (currdb == null) ? "" : currdb);
625:                    h.put("table", (currtable == null) ? "" : currtable);
626:                    h.put("column", (currcolumn == null) ? "" : currcolumn);
627:                    changes.put(key, h);
628:                }
629:            }
630:
631:            void AllPriv_actionPerformed(ActionEvent e) {
632:                Integer ti = new Integer(DBInterface.ALL);
633:                if (AllPriv.isSelected()) {
634:                    currnode.add(AllPriv);
635:                    registerChange(ti, true);
636:                } else {
637:                    currnode.remove(AllPriv);
638:                    registerChange(ti, false);
639:                }
640:            }
641:
642:            void AlterPriv_actionPerformed(ActionEvent e) {
643:                Integer ti = new Integer(DBInterface.ALTER);
644:                if (AlterPriv.isSelected()) {
645:                    currnode.add(AlterPriv);
646:                    registerChange(ti, true);
647:                } else {
648:                    currnode.remove(AlterPriv);
649:                    registerChange(ti, false);
650:                }
651:            }
652:
653:            void CreatePriv_actionPerformed(ActionEvent e) {
654:                Integer ti = new Integer(DBInterface.CREATE);
655:                if (CreatePriv.isSelected()) {
656:                    currnode.add(CreatePriv);
657:                    registerChange(ti, true);
658:                } else {
659:                    currnode.remove(CreatePriv);
660:                    registerChange(ti, false);
661:                }
662:            }
663:
664:            void DeletePriv_actionPerformed(ActionEvent e) {
665:                Integer ti = new Integer(DBInterface.DELETE);
666:                if (DeletePriv.isSelected()) {
667:                    currnode.add(DeletePriv);
668:                    registerChange(ti, true);
669:                } else {
670:                    currnode.remove(DeletePriv);
671:                    registerChange(ti, false);
672:                }
673:            }
674:
675:            void DropPriv_actionPerformed(ActionEvent e) {
676:                Integer ti = new Integer(DBInterface.DROP);
677:                if (DropPriv.isSelected()) {
678:                    currnode.add(DropPriv);
679:                    registerChange(ti, true);
680:                } else {
681:                    currnode.remove(DropPriv);
682:                    registerChange(ti, false);
683:                }
684:            }
685:
686:            void FilePriv_actionPerformed(ActionEvent e) {
687:                Integer ti = new Integer(DBInterface.FILE);
688:                if (FilePriv.isSelected()) {
689:                    currnode.add(FilePriv);
690:                    registerChange(ti, true);
691:                } else {
692:                    currnode.remove(FilePriv);
693:                    registerChange(ti, false);
694:                }
695:            }
696:
697:            void GrantPriv_actionPerformed(ActionEvent e) {
698:                Integer ti = new Integer(DBInterface.GRANT);
699:                if (GrantPriv.isSelected()) {
700:                    currnode.add(GrantPriv);
701:                    registerChange(ti, true);
702:                } else {
703:                    currnode.remove(GrantPriv);
704:                    registerChange(ti, false);
705:                }
706:            }
707:
708:            void IndexPriv_actionPerformed(ActionEvent e) {
709:                Integer ti = new Integer(DBInterface.INDEX);
710:                if (IndexPriv.isSelected()) {
711:                    currnode.add(IndexPriv);
712:                    registerChange(ti, true);
713:                } else {
714:                    currnode.remove(IndexPriv);
715:                    registerChange(ti, false);
716:                }
717:            }
718:
719:            void InsertPriv_actionPerformed(ActionEvent e) {
720:                Integer ti = new Integer(DBInterface.INSERT);
721:                if (InsertPriv.isSelected()) {
722:                    currnode.add(InsertPriv);
723:                    registerChange(ti, true);
724:                } else {
725:                    currnode.remove(InsertPriv);
726:                    registerChange(ti, false);
727:                }
728:            }
729:
730:            void ProcessPriv_actionPerformed(ActionEvent e) {
731:                Integer ti = new Integer(DBInterface.PROCESS);
732:                if (ProcessPriv.isSelected()) {
733:                    currnode.add(ProcessPriv);
734:                    registerChange(ti, true);
735:                } else {
736:                    currnode.remove(ProcessPriv);
737:                    registerChange(ti, false);
738:                }
739:            }
740:
741:            void ReferencesPriv_actionPerformed(ActionEvent e) {
742:                Integer ti = new Integer(DBInterface.REFERENCES);
743:                if (ReferencesPriv.isSelected()) {
744:                    currnode.add(ReferencesPriv);
745:                    registerChange(ti, true);
746:                } else {
747:                    currnode.remove(ReferencesPriv);
748:                    registerChange(ti, false);
749:                }
750:            }
751:
752:            void ReloadPriv_actionPerformed(ActionEvent e) {
753:                Integer ti = new Integer(DBInterface.RELOAD);
754:                if (ReloadPriv.isSelected()) {
755:                    currnode.add(ReloadPriv);
756:                    registerChange(ti, true);
757:                } else {
758:                    currnode.remove(ReloadPriv);
759:                    registerChange(ti, false);
760:                }
761:            }
762:
763:            void SelectPriv_actionPerformed(ActionEvent e) {
764:                Integer ti = new Integer(DBInterface.SELECT);
765:                if (SelectPriv.isSelected()) {
766:                    currnode.add(SelectPriv);
767:                    registerChange(ti, true);
768:                } else {
769:                    currnode.remove(SelectPriv);
770:                    registerChange(ti, false);
771:                }
772:            }
773:
774:            void ShutdownPriv_actionPerformed(ActionEvent e) {
775:                Integer ti = new Integer(DBInterface.SHUTDOWN);
776:                if (ShutdownPriv.isSelected()) {
777:                    currnode.add(ShutdownPriv);
778:                    registerChange(ti, true);
779:                } else {
780:                    currnode.remove(ShutdownPriv);
781:                    registerChange(ti, false);
782:                }
783:            }
784:
785:            void UpdatePriv_actionPerformed(ActionEvent e) {
786:                Integer ti = new Integer(DBInterface.UPDATE);
787:                if (UpdatePriv.isSelected()) {
788:                    currnode.add(UpdatePriv);
789:                    registerChange(ti, true);
790:                } else {
791:                    currnode.remove(UpdatePriv);
792:                    registerChange(ti, false);
793:                }
794:            }
795:
796:            void UsagePriv_actionPerformed(ActionEvent e) {
797:                Integer ti = new Integer(DBInterface.USAGE);
798:                if (UsagePriv.isSelected()) {
799:                    currnode.add(UsagePriv);
800:                    registerChange(ti, true);
801:                } else {
802:                    currnode.remove(UsagePriv);
803:                    registerChange(ti, false);
804:                }
805:            }
806:
807:            void PassButton_actionPerformed(ActionEvent e) {
808:                UserCreate u = new UserCreate(this , username);
809:                Dimension size = u.getPreferredSize();
810:                Dimension frmSize = getSize();
811:                Point loc = getLocation();
812:                int x = 10 + loc.x;
813:                int y = 10 + loc.y;
814:                u.setBounds(new Rectangle(x, y, 320, 150));
815:                u.setTitle("Change password");
816:                this .setEnabled(false);
817:                u.show();
818:            }
819:
820:            void reEnable() {
821:                this .setEnabled(true);
822:            }
823:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.