Source Code Cross Referenced for RulesTree.java in  » UML » jrefactory » org » acm » seguin » pmd » swingui » 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 » UML » jrefactory » org.acm.seguin.pmd.swingui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.acm.seguin.pmd.swingui;
002:
003:        import org.acm.seguin.pmd.AbstractRule;
004:        import org.acm.seguin.pmd.PMDException;
005:        import org.acm.seguin.pmd.Rule;
006:        import org.acm.seguin.pmd.RuleSet;
007:        import org.acm.seguin.pmd.swingui.event.ListenerList;
008:        import org.acm.seguin.pmd.swingui.event.RulesEditingEvent;
009:        import org.acm.seguin.pmd.swingui.event.RulesEditingEventListener;
010:
011:        import javax.swing.BorderFactory;
012:        import javax.swing.Icon;
013:        import javax.swing.JCheckBoxMenuItem;
014:        import javax.swing.JMenuItem;
015:        import javax.swing.JPopupMenu;
016:        import javax.swing.JSeparator;
017:        import javax.swing.JTree;
018:        import javax.swing.SwingUtilities;
019:        import javax.swing.UIManager;
020:        import javax.swing.border.EtchedBorder;
021:        import javax.swing.tree.DefaultTreeCellEditor;
022:        import javax.swing.tree.DefaultTreeCellRenderer;
023:        import javax.swing.tree.DefaultTreeModel;
024:        import javax.swing.tree.TreePath;
025:        import java.awt.Color;
026:        import java.awt.Component;
027:        import java.awt.Font;
028:        import java.awt.Graphics;
029:        import java.awt.Point;
030:        import java.awt.event.ActionEvent;
031:        import java.awt.event.ActionListener;
032:        import java.awt.event.MouseAdapter;
033:        import java.awt.event.MouseEvent;
034:        import java.io.ByteArrayOutputStream;
035:        import java.io.File;
036:        import java.io.FileFilter;
037:        import java.io.FileInputStream;
038:        import java.io.FileNotFoundException;
039:        import java.io.IOException;
040:        import java.text.MessageFormat;
041:        import java.util.EventObject;
042:
043:        /**
044:         *
045:         * @author Donald A. Leckie
046:         * @since August 29, 2002
047:         * @version $Revision: 1.2 $, $Date: 2003/08/27 20:33:44 $
048:         */
049:        class RulesTree extends JTree implements  Constants {
050:
051:            private Color m_background;
052:            private boolean m_disablePopupMenu;
053:            private boolean m_disableEditing;
054:
055:            // Constants
056:            private final String UNTITLED = "Untitled";
057:
058:            protected RulesTree() throws PMDException {
059:                super (RulesTreeModel.get());
060:
061:                setRootVisible(true);
062:                setBorder(BorderFactory
063:                        .createEtchedBorder(EtchedBorder.LOWERED));
064:                setCellRenderer(new TreeNodeRenderer());
065:                setCellEditor(new TreeCellEditor());
066:                m_background = UIManager.getColor("pmdTreeBackground");
067:                expandNode(getRootNode());
068:                TreePath treePath = new TreePath(getRootNode().getPath());
069:                setSelectionPath(treePath);
070:                setBackground(m_background);
071:                addMouseListener(new RulesTreeMouseListener());
072:                ListenerList
073:                        .addListener((RulesEditingEventListener) new RulesEditingEventHandler());
074:            }
075:
076:            /**
077:             ******************************************************************************
078:             *
079:             * @return
080:             */
081:            protected RulesTreeNode getRootNode() {
082:                return (RulesTreeNode) ((RulesTreeModel) getModel()).getRoot();
083:            }
084:
085:            /**
086:             ******************************************************************************
087:             *
088:             */
089:            public void updateUI() {
090:                super .updateUI();
091:                setBackground(m_background);
092:            }
093:
094:            /**
095:             ***************************************************************************
096:             *
097:             * @param node
098:             */
099:            protected void expandNode(RulesTreeNode node) {
100:                TreePath treePath = new TreePath(node.getPath());
101:
102:                expandPath(treePath);
103:            }
104:
105:            /**
106:             ***************************************************************************
107:             *
108:             * @return
109:             */
110:            protected RulesTreeNode getSelectedNode() {
111:                TreePath treePath = getSelectionPath();
112:
113:                return (treePath == null) ? null : (RulesTreeNode) treePath
114:                        .getLastPathComponent();
115:            }
116:
117:            /**
118:             ***************************************************************************
119:             *
120:             * @param node
121:             *
122:             * @return
123:             */
124:            protected boolean isExpanded(RulesTreeNode node) {
125:                TreePath treePath = new TreePath(node.getPath());
126:
127:                return isExpanded(treePath);
128:            }
129:
130:            /**
131:             *****************************************************************************
132:             *
133:             * @param setting
134:             */
135:            protected void setDisablePopupMenu(boolean setting) {
136:                m_disablePopupMenu = setting;
137:            }
138:
139:            /**
140:             *****************************************************************************
141:             *
142:             * @param setting
143:             */
144:            protected void setDisableEditing(boolean setting) {
145:                m_disableEditing = setting;
146:            }
147:
148:            /**
149:             *******************************************************************************
150:             *******************************************************************************
151:             *******************************************************************************
152:             */
153:            private class RulesTreeMouseListener extends MouseAdapter {
154:
155:                private JMenuItem m_addRuleSetMenuItem;
156:                private JMenuItem m_removeRuleSetMenuItem;
157:                private JMenuItem m_addRuleMenuItem;
158:                private JMenuItem m_removeRuleMenuItem;
159:                private JMenuItem m_addPropertyMenuItem;
160:                private JMenuItem m_removePropertyMenuItem;
161:                private JMenuItem m_includeMenuItem;
162:
163:                /**
164:                 ***********************************************************************
165:                 *
166:                 * @param event
167:                 */
168:                public void mouseReleased(MouseEvent event) {
169:                    if (event.isPopupTrigger()) {
170:                        RulesTree rulesTree;
171:                        Point location;
172:                        TreePath treePath;
173:                        RulesTreeNode treeNode;
174:                        JPopupMenu popupMenu;
175:
176:                        rulesTree = RulesTree.this ;
177:                        location = event.getPoint();
178:                        treePath = rulesTree.getPathForLocation(location.x,
179:                                location.y);
180:                        rulesTree.setSelectionPath(treePath);
181:                        treeNode = (RulesTreeNode) treePath
182:                                .getLastPathComponent();
183:                        popupMenu = null;
184:
185:                        if (treeNode.isRoot()) {
186:                            popupMenu = createRootPopupMenu();
187:                        } else if (treeNode.isRuleSet()) {
188:                            popupMenu = createRuleSetPopupMenu();
189:                        } else if (treeNode.isRule()) {
190:                            popupMenu = createRulePopupMenu();
191:                        } else if (treeNode.isProperty()) {
192:                            popupMenu = createPropertyPopupMenu();
193:                        }
194:
195:                        if (popupMenu != null) {
196:                            popupMenu.show(rulesTree, location.x, location.y);
197:                        }
198:                    }
199:                }
200:
201:                /**
202:                 ***********************************************************************
203:                 *
204:                 * @return
205:                 */
206:                private JPopupMenu createRootPopupMenu() {
207:                    JPopupMenu popupMenu = createPopupMenu(false);
208:
209:                    m_addRuleSetMenuItem.setEnabled(true);
210:                    m_removeRuleSetMenuItem.setEnabled(false);
211:                    m_addRuleMenuItem.setEnabled(false);
212:                    m_removeRuleMenuItem.setEnabled(false);
213:                    m_addPropertyMenuItem.setEnabled(false);
214:                    m_removePropertyMenuItem.setEnabled(false);
215:
216:                    return popupMenu;
217:                }
218:
219:                /**
220:                 ***********************************************************************
221:                 *
222:                 * @return
223:                 */
224:                private JPopupMenu createRuleSetPopupMenu() {
225:                    JPopupMenu popupMenu = createPopupMenu(true);
226:
227:                    m_addRuleSetMenuItem.setEnabled(false);
228:                    m_removeRuleSetMenuItem.setEnabled(true);
229:                    m_addRuleMenuItem.setEnabled(true);
230:                    m_removeRuleMenuItem.setEnabled(false);
231:                    m_addPropertyMenuItem.setEnabled(false);
232:                    m_removePropertyMenuItem.setEnabled(false);
233:
234:                    return popupMenu;
235:                }
236:
237:                /**
238:                 ***********************************************************************
239:                 *
240:                 * @return
241:                 */
242:                private JPopupMenu createRulePopupMenu() {
243:                    JPopupMenu popupMenu = createPopupMenu(true);
244:
245:                    m_addRuleSetMenuItem.setEnabled(false);
246:                    m_removeRuleSetMenuItem.setEnabled(false);
247:                    m_addRuleMenuItem.setEnabled(false);
248:                    m_removeRuleMenuItem.setEnabled(true);
249:                    m_addPropertyMenuItem.setEnabled(true);
250:                    m_removePropertyMenuItem.setEnabled(false);
251:
252:                    return popupMenu;
253:                }
254:
255:                /**
256:                 ***********************************************************************
257:                 *
258:                 * @return
259:                 */
260:                private JPopupMenu createPropertyPopupMenu() {
261:                    JPopupMenu popupMenu = createPopupMenu(false);
262:
263:                    m_addRuleSetMenuItem.setEnabled(false);
264:                    m_removeRuleSetMenuItem.setEnabled(false);
265:                    m_addRuleMenuItem.setEnabled(false);
266:                    m_removeRuleMenuItem.setEnabled(false);
267:                    m_addPropertyMenuItem.setEnabled(false);
268:                    m_removePropertyMenuItem.setEnabled(true);
269:
270:                    return popupMenu;
271:                }
272:
273:                /**
274:                 ***********************************************************************
275:                 *
276:                 * @return
277:                 */
278:                private JPopupMenu createPopupMenu(boolean addInclude) {
279:                    JPopupMenu popupMenu = new JPopupMenu();
280:
281:                    m_addRuleSetMenuItem = new JMenuItem("Add Rule Set");
282:                    m_addRuleSetMenuItem
283:                            .addActionListener(new AddRuleSetActionListener());
284:                    popupMenu.add(m_addRuleSetMenuItem);
285:
286:                    m_removeRuleSetMenuItem = new JMenuItem("Remove Rule Set");
287:                    m_removeRuleSetMenuItem
288:                            .addActionListener(new RemoveRuleSetActionListener());
289:                    popupMenu.add(m_removeRuleSetMenuItem);
290:
291:                    popupMenu.add(new JSeparator());
292:
293:                    m_addRuleMenuItem = new JMenuItem("Add Rule");
294:                    m_addRuleMenuItem
295:                            .addActionListener(new AddRuleActionListener());
296:                    popupMenu.add(m_addRuleMenuItem);
297:
298:                    m_removeRuleMenuItem = new JMenuItem("Remove Rule");
299:                    m_removeRuleMenuItem
300:                            .addActionListener(new RemoveRuleActionListener());
301:                    popupMenu.add(m_removeRuleMenuItem);
302:
303:                    popupMenu.add(new JSeparator());
304:
305:                    m_addPropertyMenuItem = new JMenuItem("Add Rule Property");
306:                    m_addPropertyMenuItem
307:                            .addActionListener(new AddRulePropertyActionListener());
308:                    popupMenu.add(m_addPropertyMenuItem);
309:
310:                    m_removePropertyMenuItem = new JMenuItem(
311:                            "Remove Rule Property");
312:                    m_removePropertyMenuItem
313:                            .addActionListener(new RemoveRulePropertyActionListener());
314:                    popupMenu.add(m_removePropertyMenuItem);
315:
316:                    if (addInclude) {
317:                        popupMenu.add(new JSeparator());
318:
319:                        m_includeMenuItem = new JCheckBoxMenuItem("Include");
320:                        m_includeMenuItem
321:                                .addActionListener(new IncludeActionListener());
322:                        m_includeMenuItem.setSelected(RulesTree.this 
323:                                .getSelectedNode().include());
324:                        popupMenu.add(m_includeMenuItem);
325:                    }
326:
327:                    return popupMenu;
328:                }
329:            }
330:
331:            /**
332:             *******************************************************************************
333:             *******************************************************************************
334:             *******************************************************************************
335:             */
336:            private class IncludeActionListener implements  ActionListener {
337:
338:                public void actionPerformed(ActionEvent event) {
339:                    JCheckBoxMenuItem includeMenuItem = (JCheckBoxMenuItem) event
340:                            .getSource();
341:                    RulesTree.this .getSelectedNode().setInclude(
342:                            includeMenuItem.isSelected());
343:                    RulesTree.this .updateUI();
344:                    RulesTree.this .repaint();
345:                }
346:            }
347:
348:            /**
349:             *******************************************************************************
350:             *******************************************************************************
351:             *******************************************************************************
352:             */
353:            private class AddRuleSetActionListener implements  ActionListener {
354:
355:                public void actionPerformed(ActionEvent event) {
356:                    RuleSet ruleSet = new RuleSet();
357:                    String ruleSetName = UNTITLED;
358:                    int counter = 0;
359:                    RulesTree rulesTree = RulesTree.this ;
360:                    RulesTreeNode rootNode = rulesTree.getSelectedNode();
361:
362:                    while (rootNode.getChildNode(ruleSetName) != null) {
363:                        counter++;
364:                        ruleSetName = UNTITLED + "-" + counter;
365:                    }
366:
367:                    ruleSet.setName(ruleSetName);
368:
369:                    RulesTreeNode ruleSetNode = new RulesTreeNode(ruleSet);
370:                    DefaultTreeModel treeModel = (DefaultTreeModel) RulesTree.this 
371:                            .getModel();
372:
373:                    rootNode.add(ruleSetNode);
374:                    treeModel.nodeStructureChanged(rootNode);
375:
376:                    if (rulesTree.isExpanded(ruleSetNode) == false) {
377:                        rulesTree.expandNode(ruleSetNode);
378:                    }
379:
380:                    rootNode.sortChildren();
381:                }
382:            }
383:
384:            /**
385:             *******************************************************************************
386:             *******************************************************************************
387:             *******************************************************************************
388:             */
389:            private class RemoveRuleSetActionListener implements  ActionListener {
390:
391:                public void actionPerformed(ActionEvent event) {
392:                    RulesTreeNode ruleSetNode = RulesTree.this 
393:                            .getSelectedNode();
394:
395:                    if (ruleSetNode != null) {
396:                        String ruleSetName = ruleSetNode.getName();
397:                        String template = "Do you really want to remove the rule set \"{0}\"?\nThe remove cannot be undone.";
398:                        String[] args = { ruleSetName };
399:                        String message = MessageFormat.format(template, args);
400:
401:                        if (MessageDialog.answerIsYes(PMDViewer.getViewer(),
402:                                message)) {
403:                            DefaultTreeModel treeModel = (DefaultTreeModel) RulesTree.this 
404:                                    .getModel();
405:                            treeModel.removeNodeFromParent(ruleSetNode);
406:                        }
407:                    }
408:                }
409:            }
410:
411:            /**
412:             *******************************************************************************
413:             *******************************************************************************
414:             *******************************************************************************
415:             */
416:            private class AddRuleActionListener implements  ActionListener {
417:
418:                /**
419:                 ***************************************************************************
420:                 *
421:                 * @param event
422:                 */
423:                public void actionPerformed(ActionEvent event) {
424:                    Rule rule = null;
425:
426:                    try {
427:                        rule = getNewRuleFromUser();
428:                    } catch (PMDException pmdException) {
429:                        String message = pmdException.getMessage();
430:                        Exception exception = pmdException.getReason();
431:                        MessageDialog.show(PMDViewer.getViewer(), message,
432:                                exception);
433:
434:                        return;
435:                    }
436:
437:                    if (rule != null) {
438:                        String className = rule.getClass().getName();
439:                        int index = className.lastIndexOf('.') + 1;
440:                        String baseRuleName = className.substring(index);
441:                        String ruleName = baseRuleName;
442:                        int counter = 0;
443:                        RulesTree rulesTree = RulesTree.this ;
444:                        RulesTreeNode ruleSetNode = rulesTree.getSelectedNode();
445:
446:                        while (ruleSetNode.getChildNode(ruleName) != null) {
447:                            counter++;
448:                            ruleName = baseRuleName + "-" + counter;
449:                        }
450:
451:                        rule.setName(ruleName);
452:
453:                        RulesTreeNode ruleNode = new RulesTreeNode(ruleSetNode,
454:                                rule);
455:                        DefaultTreeModel treeModel = (DefaultTreeModel) rulesTree
456:                                .getModel();
457:
458:                        ruleSetNode.add(ruleNode);
459:                        treeModel.nodeStructureChanged(ruleSetNode);
460:
461:                        if (rulesTree.isExpanded(ruleSetNode) == false) {
462:                            rulesTree.expandNode(ruleSetNode);
463:                        }
464:
465:                        ruleSetNode.sortChildren();
466:                        TreePath treePath = new TreePath(ruleNode.getPath());
467:                        rulesTree.setSelectionPath(treePath);
468:                    }
469:                }
470:
471:                /**
472:                 ***************************************************************************
473:                 *
474:                 * @return
475:                 */
476:                private Rule getNewRuleFromUser() throws PMDException {
477:                    RulesClassSelectDialog dialog = new RulesClassSelectDialog(
478:                            PMDViewer.getViewer());
479:                    dialog.show();
480:
481:                    if (dialog.selectWasPressed()) {
482:                        File selectedFile = dialog.getSelectedClassFile();
483:                        RuleClassLoader classLoader = new RuleClassLoader();
484:                        Class clazz = classLoader.loadClass(selectedFile);
485:
486:                        try {
487:                            Object object = clazz.newInstance();
488:
489:                            if (object instanceof  AbstractRule) {
490:                                return (Rule) object;
491:                            }
492:
493:                            String abstractRuleClassName = AbstractRule.class
494:                                    .getName();
495:                            String template = "The selected class \"{0}\" must subclass the abstract rule class \"{1}\".";
496:                            String[] args = { clazz.getName(),
497:                                    abstractRuleClassName };
498:                            String message = MessageFormat.format(template,
499:                                    args);
500:                            MessageDialog.show(PMDViewer.getViewer(), message);
501:                        } catch (InstantiationException exception) {
502:                            String template = "Could not instantiate class \"{0}\".";
503:                            String[] args = { clazz.getName() };
504:                            String message = MessageFormat.format(template,
505:                                    args);
506:                            MessageDialog.show(PMDViewer.getViewer(), message,
507:                                    exception);
508:                        } catch (IllegalAccessException exception) {
509:                            String template = "Encountered illegal access while instantiating class \"{0}\".";
510:                            String[] args = { clazz.getName() };
511:                            String message = MessageFormat.format(template,
512:                                    args);
513:                            MessageDialog.show(PMDViewer.getViewer(), message,
514:                                    exception);
515:                        }
516:                    }
517:
518:                    return null;
519:                }
520:            }
521:
522:            /**
523:             *******************************************************************************
524:             *******************************************************************************
525:             *******************************************************************************
526:             */
527:            private class RulesFileFilter implements  FileFilter {
528:                /**
529:                 ***************************************************************************
530:                 *
531:                 * @param file
532:                 *
533:                 * @return
534:                 */
535:                public boolean accept(File file) {
536:                    if (file.isDirectory()) {
537:                        return true;
538:                    }
539:
540:                    return file.getName().endsWith(".class");
541:                }
542:
543:                /**
544:                 **************************************************************************
545:                 *
546:                 * @return
547:                 */
548:                public String getDescription() {
549:                    return "Rule Class Files";
550:                }
551:            }
552:
553:            /**
554:             *******************************************************************************
555:             *******************************************************************************
556:             *******************************************************************************
557:             */
558:            private class RuleClassLoader extends ClassLoader {
559:
560:                /**
561:                 **************************************************************************
562:                 *
563:                 */
564:                private RuleClassLoader() {
565:                    super ();
566:                }
567:
568:                /**
569:                 **************************************************************************
570:                 *
571:                 */
572:                private Class loadClass(File file) {
573:                    FileInputStream inputStream = null;
574:                    Class clazz = null;
575:
576:                    try {
577:                        inputStream = new FileInputStream(file);
578:                        clazz = null;
579:
580:                        if (inputStream != null) {
581:                            final int size = 10000;
582:                            int byteCount = 0;
583:                            byte[] buffer = new byte[size];
584:                            ByteArrayOutputStream byteArrayOutputStream;
585:
586:                            byteArrayOutputStream = new ByteArrayOutputStream(
587:                                    size);
588:
589:                            try {
590:                                while ((byteCount = inputStream.read(buffer)) >= 0) {
591:                                    byteArrayOutputStream.write(buffer, 0,
592:                                            byteCount);
593:                                }
594:                            } catch (IOException exception) {
595:                                return null;
596:                            }
597:
598:                            buffer = byteArrayOutputStream.toByteArray();
599:                            clazz = super .defineClass(null, buffer, 0,
600:                                    buffer.length);
601:
602:                            if (clazz != null) {
603:                                resolveClass(clazz);
604:                            }
605:                        }
606:                    } catch (FileNotFoundException exception) {
607:                        clazz = null;
608:                    } finally {
609:                        if (inputStream != null) {
610:                            try {
611:                                inputStream.close();
612:                            } catch (IOException exception) {
613:                                inputStream = null;
614:                            }
615:                        }
616:                    }
617:
618:                    return clazz;
619:                }
620:            }
621:
622:            /**
623:             *******************************************************************************
624:             *******************************************************************************
625:             *******************************************************************************
626:             */
627:            private class RemoveRuleActionListener implements  ActionListener {
628:
629:                public void actionPerformed(ActionEvent event) {
630:                    RulesTreeNode ruleNode = RulesTree.this .getSelectedNode();
631:                    String ruleName = ruleNode.getName();
632:                    String template = "Do you really want to remove the rule \"{0}\"?\nThe remove cannot be undone.";
633:                    String[] args = { ruleName };
634:                    String message = MessageFormat.format(template, args);
635:
636:                    if (MessageDialog.answerIsYes(PMDViewer.getViewer(),
637:                            message)) {
638:                        DefaultTreeModel treeModel = (DefaultTreeModel) RulesTree.this 
639:                                .getModel();
640:                        treeModel.removeNodeFromParent(ruleNode);
641:                    }
642:                }
643:            }
644:
645:            /**
646:             *******************************************************************************
647:             *******************************************************************************
648:             *******************************************************************************
649:             */
650:            private class AddRulePropertyActionListener implements 
651:                    ActionListener {
652:
653:                public void actionPerformed(ActionEvent event) {
654:                    String propertyName = UNTITLED;
655:                    int counter = 0;
656:                    RulesTree rulesTree = RulesTree.this ;
657:                    RulesTreeNode ruleNode = rulesTree.getSelectedNode();
658:
659:                    while (ruleNode.getChildNode(propertyName) != null) {
660:                        counter++;
661:                        propertyName = UNTITLED + "-" + counter;
662:                    }
663:
664:                    RulesTreeNode propertyNode = new RulesTreeNode(ruleNode,
665:                            propertyName, "", STRING);
666:                    DefaultTreeModel treeModel = (DefaultTreeModel) rulesTree
667:                            .getModel();
668:
669:                    ruleNode.add(propertyNode);
670:                    treeModel.nodeStructureChanged(ruleNode);
671:
672:                    if (rulesTree.isExpanded(ruleNode) == false) {
673:                        rulesTree.expandNode(ruleNode);
674:                    }
675:
676:                    ruleNode.sortChildren();
677:                }
678:            }
679:
680:            /**
681:             *******************************************************************************
682:             *******************************************************************************
683:             *******************************************************************************
684:             */
685:            private class RemoveRulePropertyActionListener implements 
686:                    ActionListener {
687:
688:                public void actionPerformed(ActionEvent event) {
689:                    RulesTreeNode propertyNode = RulesTree.this 
690:                            .getSelectedNode();
691:                    String propertyName = propertyNode.getName();
692:                    String template = "Do you really want to remove the property \"{0}\"?\nThe remove cannot be undone.";
693:                    String[] args = { propertyName };
694:                    String message = MessageFormat.format(template, args);
695:
696:                    if (MessageDialog.answerIsYes(PMDViewer.getViewer(),
697:                            message)) {
698:                        DefaultTreeModel treeModel = (DefaultTreeModel) RulesTree.this 
699:                                .getModel();
700:                        treeModel.removeNodeFromParent(propertyNode);
701:                    }
702:                }
703:            }
704:
705:            /**
706:             *******************************************************************************
707:             *******************************************************************************
708:             *******************************************************************************
709:             */
710:            private class TreeCellEditor extends DefaultTreeCellEditor {
711:
712:                /**
713:                 ***************************************************************************
714:                 *
715:                 */
716:                private TreeCellEditor() {
717:                    super (RulesTree.this ,
718:                            (DefaultTreeCellRenderer) RulesTree.this 
719:                                    .getCellRenderer());
720:                }
721:
722:                /**
723:                 ***************************************************************************
724:                 *
725:                 * @return
726:                 */
727:                public boolean isCellEditable(EventObject event) {
728:                    return false;
729:                }
730:            }
731:
732:            /**
733:             ********************************************************************************
734:             ********************************************************************************
735:             ********************************************************************************
736:             */
737:            private class TreeNodeRenderer extends DefaultTreeCellRenderer {
738:
739:                private Icon m_defaultClosedIcon;
740:                private Icon m_defaultLeafIcon;
741:                private Icon m_defaultOpenIcon;
742:                private Icon m_documentIcon;
743:                private Font m_plainFont;
744:                private Font m_italicFont;
745:
746:                /**
747:                 ***************************************************************************
748:                 *
749:                 */
750:                protected TreeNodeRenderer() {
751:                    super ();
752:
753:                    Font font;
754:
755:                    m_defaultClosedIcon = getDefaultClosedIcon();
756:                    m_defaultLeafIcon = getDefaultLeafIcon();
757:                    m_defaultOpenIcon = getDefaultOpenIcon();
758:                    m_documentIcon = UIManager.getIcon("document");
759:                    font = RulesTree.this .getFont();
760:                    m_plainFont = new Font(font.getName(), Font.PLAIN, font
761:                            .getSize());
762:                    m_italicFont = new Font(font.getName(), Font.ITALIC, font
763:                            .getSize());
764:                    setBackgroundNonSelectionColor(UIManager
765:                            .getColor("pmdTreeBackground"));
766:                    setBackgroundSelectionColor(Color.yellow);
767:                }
768:
769:                /**
770:                 **************************************************************************
771:                 *
772:                 * @param tree
773:                 * @param object
774:                 * @param isSelected
775:                 * @param isExpanded
776:                 * @param isLeaf
777:                 * @param row
778:                 * @param hasFocus
779:                 *
780:                 * @return
781:                 */
782:                public Component getTreeCellRendererComponent(JTree tree,
783:                        Object object, boolean isSelected, boolean isExpanded,
784:                        boolean isLeaf, int row, boolean hasFocus) {
785:                    RulesTreeNode treeNode = (RulesTreeNode) object;
786:
787:                    if (treeNode.isProperty()) {
788:                        setClosedIcon(m_defaultClosedIcon);
789:                        setLeafIcon(m_documentIcon);
790:                        setOpenIcon(m_defaultOpenIcon);
791:                    } else {
792:                        setClosedIcon(m_defaultClosedIcon);
793:                        setLeafIcon(m_defaultClosedIcon);
794:                        setOpenIcon(m_defaultOpenIcon);
795:                    }
796:
797:                    if (treeNode.include() && treeNode.includeAncestor()) {
798:                        setTextNonSelectionColor(Color.blue);
799:                        setTextSelectionColor(Color.blue);
800:                        setFont(m_plainFont);
801:                    } else {
802:                        setTextNonSelectionColor(Color.black);
803:                        setTextSelectionColor(Color.black);
804:                        setFont(m_italicFont);
805:
806:                    }
807:
808:                    this .updateUI();
809:
810:                    return super .getTreeCellRendererComponent(tree, object,
811:                            isSelected, isExpanded, isLeaf, row, hasFocus);
812:                }
813:
814:                /**
815:                 **************************************************************************
816:                 *
817:                 * @param graphics
818:                 */
819:                public void paint(Graphics graphics) {
820:                    int x = getX();
821:                    int y = getY();
822:                    int width = getWidth();
823:                    int height = getHeight();
824:                    graphics.clearRect(x, y, width, height);
825:                    super .paint(graphics);
826:                }
827:            }
828:
829:            /**
830:             *******************************************************************************
831:             *******************************************************************************
832:             *******************************************************************************
833:             */
834:            private class RulesEditingEventHandler implements 
835:                    RulesEditingEventListener {
836:
837:                /**
838:                 ***************************************************************************
839:                 *
840:                 * @param event
841:                 */
842:                public void saveData(RulesEditingEvent event) {
843:                    SwingUtilities.invokeLater(new UpdateUI());
844:                }
845:
846:                /**
847:                 ***************************************************************************
848:                 *
849:                 * @param event
850:                 */
851:                public void loadData(RulesEditingEvent event) {
852:                }
853:            }
854:
855:            /**
856:             *******************************************************************************
857:             *******************************************************************************
858:             *******************************************************************************
859:             */
860:            private class UpdateUI implements  Runnable {
861:
862:                /**
863:                 ***************************************************************************
864:                 *
865:                 */
866:                public void run() {
867:                    RulesTree.this.updateUI();
868:                }
869:            }
870:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.