Source Code Cross Referenced for Config.java in  » J2EE » jag » com » finalist » jaggenerator » modules » 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 » J2EE » jag » com.finalist.jaggenerator.modules 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*   Copyright (C) 2003 Finalist IT Group
002:         *
003:         *   This file is part of JAG - the Java J2EE Application Generator
004:         *
005:         *   JAG is free software; you can redistribute it and/or modify
006:         *   it under the terms of the GNU General Public License as published by
007:         *   the Free Software Foundation; either version 2 of the License, or
008:         *   (at your option) any later version.
009:         *   JAG is distributed in the hope that it will be useful,
010:         *   but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         *   GNU General Public License for more details.
013:         *   You should have received a copy of the GNU General Public License
014:         *   along with JAG; if not, write to the Free Software
015:         *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
016:         */
017:        package com.finalist.jaggenerator.modules;
018:
019:        import java.io.File;
020:        import java.util.Enumeration;
021:        import java.util.HashMap;
022:        import java.util.Iterator;
023:        import java.util.Map;
024:
025:        import javax.swing.*;
026:        import javax.swing.event.ListSelectionEvent;
027:        import javax.swing.event.ListSelectionListener;
028:        import javax.swing.border.TitledBorder;
029:        import javax.swing.tree.DefaultMutableTreeNode;
030:        import javax.xml.parsers.ParserConfigurationException;
031:
032:        import org.w3c.dom.Document;
033:        import org.w3c.dom.Element;
034:        import org.w3c.dom.Node;
035:        import org.w3c.dom.NodeList;
036:
037:        import com.finalist.jaggenerator.JagGenerator;
038:        import com.finalist.jaggenerator.template.Template;
039:        import com.finalist.jaggenerator.template.TemplateConfigException;
040:        import com.finalist.jaggenerator.template.TemplateConfigPanel;
041:
042:        /**
043:         * @author hillie
044:         */
045:        public class Config extends DefaultMutableTreeNode implements  JagBean,
046:                ListSelectionListener {
047:            private DefaultListModel listModel = new DefaultListModel();
048:            private static final File DEFAULT_TEMPLATE = new File(
049:                    "../templates/java5_2_tier");
050:            private Template template;
051:            public Template selectedTemplate = null;
052:            private TemplateConfigPanel templatePanel;
053:            private static final String XMLTAG_CONFIG_PARAM = "config-param";
054:            private static final String NAME_ATTRIBUTE = "name";
055:            private static final String VALUE_ATTRIBUTE = "value";
056:
057:            /**
058:             * Creates new form Config
059:             */
060:            public Config() {
061:                initComponents();
062:                setTemplate(DEFAULT_TEMPLATE);
063:                templateList
064:                        .setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
065:                templateList.setModel(listModel);
066:                templateList.addListSelectionListener(this );
067:            }
068:
069:            public Config(Element el) {
070:                initComponents();
071:                templateList
072:                        .setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
073:                templateList.setModel(listModel);
074:                templateList.addListSelectionListener(this );
075:                NodeList nl = el.getChildNodes();
076:                for (int i = 0; i < nl.getLength(); i++) {
077:                    if (nl.item(i) instanceof  Element) {
078:                        Element child = (Element) nl.item(i);
079:                        String nodeName = child.getNodeName();
080:                        if (nodeName.equalsIgnoreCase("author")) {
081:                            Node node = child.getFirstChild();
082:                            if (node != null) {
083:                                authorText.setText(node.getNodeValue());
084:                            }
085:                            continue;
086:                        }
087:                        if (nodeName.equalsIgnoreCase("version")) {
088:                            Node node = child.getFirstChild();
089:                            if (node != null) {
090:                                versionText.setText(node.getNodeValue());
091:                            }
092:                            continue;
093:                        }
094:                        if (nodeName.equalsIgnoreCase("company")) {
095:                            Node node = child.getFirstChild();
096:                            if (node != null) {
097:                                companyText.setText(node.getNodeValue());
098:                            }
099:                            continue;
100:                        }
101:                        if (nodeName.equalsIgnoreCase("templates")) {
102:                            NodeList templates = child
103:                                    .getElementsByTagName("template-root");
104:                            for (int j = 0; j < templates.getLength(); j++) {
105:                                Node templateRootText = templates.item(j)
106:                                        .getFirstChild();
107:                                setTemplate(new File(templateRootText
108:                                        .getNodeValue()));
109:                            }
110:
111:                            NodeList params = child
112:                                    .getElementsByTagName(XMLTAG_CONFIG_PARAM);
113:                            for (int j = 0; j < params.getLength(); j++) {
114:                                Node paramNode = params.item(j);
115:                                String paramName = paramNode.getAttributes()
116:                                        .getNamedItem(NAME_ATTRIBUTE)
117:                                        .getNodeValue();
118:                                String paramValue = paramNode.getAttributes()
119:                                        .getNamedItem(VALUE_ATTRIBUTE)
120:                                        .getNodeValue();
121:                                Map components = templatePanel
122:                                        .getConfigComponents();
123:                                JComponent component = (JComponent) components
124:                                        .get(paramName);
125:                                if (component == null) {
126:                                    JagGenerator
127:                                            .logToConsole("Application file contains an unrecognised template config-param: "
128:                                                    + paramName);
129:                                } else {
130:                                    if (component instanceof  JTextField) {
131:                                        ((JTextField) component)
132:                                                .setText(paramValue);
133:                                    } else if (component instanceof  JCheckBox) {
134:                                        ((JCheckBox) component)
135:                                                .setSelected(new Boolean(
136:                                                        paramValue)
137:                                                        .booleanValue());
138:                                    } else if (component instanceof  JComboBox) {
139:                                        ((JComboBox) component)
140:                                                .setSelectedItem(paramValue);
141:                                    }
142:                                }
143:                            }
144:                        }
145:                    }
146:                }
147:            }
148:
149:            public void setAuthor(String text) {
150:                this .authorText.setText(text);
151:            }
152:
153:            public void setVersion(String text) {
154:                this .versionText.setText(text);
155:            }
156:
157:            public void setCompany(String text) {
158:                this .companyText.setText(text);
159:            }
160:
161:            /**
162:             * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The
163:             * content of this method is always regenerated by the Form Editor.
164:             */
165:            private void initComponents() {
166:                panel = new javax.swing.JPanel();
167:                authorLabel = new javax.swing.JLabel();
168:                versionLabel = new javax.swing.JLabel();
169:                companyLabel = new javax.swing.JLabel();
170:                rootPackageLabel = new javax.swing.JLabel();
171:                authorText = new javax.swing.JTextField();
172:                versionText = new javax.swing.JTextField();
173:                companyText = new javax.swing.JTextField();
174:                editButton = new javax.swing.JButton();
175:                scrollPane = new javax.swing.JScrollPane();
176:                templateList = new javax.swing.JList();
177:                templateSettingsPanel = new javax.swing.JPanel();
178:                templateSettingsScrollPane = new javax.swing.JScrollPane();
179:
180:                panel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
181:
182:                authorLabel
183:                        .setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
184:                authorLabel.setText("Author: ");
185:                panel.add(authorLabel,
186:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(20,
187:                                10, 90, -1));
188:
189:                versionLabel
190:                        .setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
191:                versionLabel.setText("Version: ");
192:                panel.add(versionLabel,
193:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(20,
194:                                40, 90, -1));
195:
196:                companyLabel
197:                        .setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
198:                companyLabel.setText("Company: ");
199:                panel.add(companyLabel,
200:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(20,
201:                                70, 90, -1));
202:
203:                rootPackageLabel
204:                        .setHorizontalAlignment(javax.swing.SwingConstants.TRAILING);
205:                rootPackageLabel.setText("Template: ");
206:                panel.add(rootPackageLabel,
207:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(20,
208:                                120, 90, -1));
209:
210:                authorText.addFocusListener(new java.awt.event.FocusAdapter() {
211:                    public void focusLost(java.awt.event.FocusEvent evt) {
212:                        authorTextFocusLost(evt);
213:                    }
214:                });
215:
216:                panel.add(authorText,
217:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
218:                                10, 320, -1));
219:
220:                versionText.setText("1.0");
221:                versionText.addFocusListener(new java.awt.event.FocusAdapter() {
222:                    public void focusLost(java.awt.event.FocusEvent evt) {
223:                        versionTextFocusLost(evt);
224:                    }
225:                });
226:
227:                panel.add(versionText,
228:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
229:                                40, 320, -1));
230:
231:                companyText.setText("Finalist IT Group");
232:                companyText.addFocusListener(new java.awt.event.FocusAdapter() {
233:                    public void focusLost(java.awt.event.FocusEvent evt) {
234:                        companyTextFocusLost(evt);
235:                    }
236:                });
237:
238:                panel.add(companyText,
239:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
240:                                70, 320, -1));
241:
242:                editButton.setText("Select generation template");
243:                editButton
244:                        .setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
245:                editButton.setMaximumSize(new java.awt.Dimension(400, 26));
246:                editButton.setMinimumSize(new java.awt.Dimension(400, 26));
247:                editButton.setPreferredSize(new java.awt.Dimension(400, 26));
248:                editButton
249:                        .addActionListener(new java.awt.event.ActionListener() {
250:                            public void actionPerformed(
251:                                    java.awt.event.ActionEvent evt) {
252:                                editButtonActionPerformed(evt);
253:                            }
254:                        });
255:
256:                panel.add(editButton,
257:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(180,
258:                                180, 190, 20));
259:
260:                templateList.setBorder(new javax.swing.border.EtchedBorder());
261:                scrollPane.setViewportView(templateList);
262:
263:                panel.add(scrollPane,
264:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(120,
265:                                100, 320, 60));
266:
267:                templateSettingsPanel.setLayout(new java.awt.BorderLayout());
268:
269:                templateSettingsPanel
270:                        .setBorder(new javax.swing.border.TitledBorder(
271:                                "Template settings:"));
272:
273:                templateSettingsPanel.add(templateSettingsScrollPane,
274:                        java.awt.BorderLayout.CENTER);
275:
276:                panel.add(templateSettingsPanel,
277:                        new org.netbeans.lib.awtextra.AbsoluteConstraints(60,
278:                                220, 400, 250));
279:
280:            }
281:
282:            private void companyTextFocusLost(java.awt.event.FocusEvent evt) {
283:                JagGenerator.stateChanged(false);
284:            }
285:
286:            private void versionTextFocusLost(java.awt.event.FocusEvent evt) {
287:                JagGenerator.stateChanged(false);
288:            }
289:
290:            private void authorTextFocusLost(java.awt.event.FocusEvent evt) {
291:                JagGenerator.stateChanged(false);
292:            }
293:
294:            private void editButtonActionPerformed(
295:                    java.awt.event.ActionEvent evt) {
296:                int fileChooserStatus;
297:
298:                String path = ((Template) listModel.get(0)).getTemplateDir()
299:                        .getAbsolutePath();
300:                JFileChooser fileChooser = new JFileChooser(path);
301:                fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
302:                fileChooser
303:                        .setDialogTitle("Select a generation template (directory)..");
304:                fileChooserStatus = fileChooser.showDialog(null, "Select");
305:                if (fileChooserStatus == JFileChooser.APPROVE_OPTION) {
306:                    File file = fileChooser.getSelectedFile();
307:                    setTemplate(file);
308:                }
309:                JagGenerator.stateChanged(false);
310:            }
311:
312:            // Handler for list selection changes
313:            public void valueChanged(ListSelectionEvent event) {
314:                // See if this is a listbox selection and the
315:                // event stream has settled
316:                if (event.getSource() == templateList
317:                        && !event.getValueIsAdjusting()) {
318:                    // Get the current selection and place it in the
319:                    // edit field
320:                    Template template = (Template) templateList
321:                            .getSelectedValue();
322:                    if (template != null) {
323:                        selectedTemplate = template;
324:                        setTemplate(selectedTemplate.getTemplateDir());
325:                    }
326:                }
327:            }
328:
329:            private void setTemplate(File path) {
330:                try {
331:                    listModel.clear();
332:                    File parent = path.getParentFile();
333:                    File[] fileList = parent.listFiles();
334:                    int index = 0;
335:                    for (int i = 0; i < fileList.length; i++) {
336:                        if (fileList[i].isDirectory()) {
337:                            // Now check if there is a template.xml file in the dir.
338:                            File templateFile = new File(fileList[i]
339:                                    + File.separator + "template.xml");
340:                            if (templateFile.exists()) {
341:                                template = new Template(fileList[i]);
342:                                if (fileList[i].equals(path)) {
343:                                    selectedTemplate = template;
344:                                }
345:                                listModel.add(index, template);
346:                                index++;
347:                            }
348:                        }
349:                    }
350:                    if (selectedTemplate == null) {
351:                        System.out.println("No templates found!");
352:                        return;
353:                    }
354:                    templatePanel = new TemplateConfigPanel(selectedTemplate
355:                            .getConfigParams(), selectedTemplate.getName());
356:                    // templatePanel.setBorder(new javax.swing.border.TitledBorder("Template settings: " + selectedTemplate.getName()));
357:                    TitledBorder border = (TitledBorder) templateSettingsPanel
358:                            .getBorder();
359:                    // border.setTitle("Template settings: " + selectedTemplate.getName());
360:                    templateSettingsScrollPane.setViewportView(templatePanel);
361:
362:                } catch (TemplateConfigException tce) {
363:                    JOptionPane.showMessageDialog(JagGenerator.jagGenerator,
364:                            tce.getMessage(), "Invalid template!",
365:                            javax.swing.JOptionPane.ERROR_MESSAGE);
366:                }
367:            }
368:
369:            public String toString() {
370:                return "Configuration";
371:            }
372:
373:            public JPanel getPanel() {
374:                return panel;
375:            }
376:
377:            public void getXML(Element el) throws ParserConfigurationException {
378:                Document doc = el.getOwnerDocument();
379:                Element config = doc.createElement("config");
380:
381:                Element author = doc.createElement("author");
382:                if (authorText.getText() != null) {
383:                    author
384:                            .appendChild(doc.createTextNode(authorText
385:                                    .getText()));
386:                }
387:                config.appendChild(author);
388:
389:                Element version = doc.createElement("version");
390:                if (versionText.getText() != null) {
391:                    version.appendChild(doc.createTextNode(versionText
392:                            .getText()));
393:                }
394:                config.appendChild(version);
395:
396:                Element company = doc.createElement("company");
397:                if (companyText.getText() != null) {
398:                    company.appendChild(doc.createTextNode(companyText
399:                            .getText()));
400:                }
401:                config.appendChild(company);
402:
403:                Element templates = doc.createElement("templates");
404:                Enumeration children = listModel.elements();
405:                while (children.hasMoreElements()) {
406:                    String templatePath = ".";
407:                    Element templateRoot = doc.createElement("template-root");
408:
409:                    if (selectedTemplate != null) {
410:                        templatePath = selectedTemplate.getTemplateDir()
411:                                .getPath();
412:                    } else {
413:                        templatePath = ((Template) children.nextElement())
414:                                .getTemplateDir().getPath();
415:                    }
416:                    templatePath = templatePath.replace('\\', '/');
417:                    // Make sure that paths is stored os independent
418:                    templateRoot.appendChild(doc.createTextNode(templatePath));
419:                    templates.appendChild(templateRoot);
420:                    break;
421:                }
422:                Map configSettings = getTemplateSettings();
423:                Iterator i = configSettings.entrySet().iterator();
424:                while (i.hasNext()) {
425:                    Map.Entry entry = (Map.Entry) i.next();
426:                    Element param = doc.createElement(XMLTAG_CONFIG_PARAM);
427:                    param.setAttribute(NAME_ATTRIBUTE, (String) entry.getKey());
428:                    param.setAttribute(VALUE_ATTRIBUTE, (String) entry
429:                            .getValue());
430:                    templates.appendChild(param);
431:                }
432:
433:                config.appendChild(templates);
434:
435:                el.appendChild(config);
436:            }
437:
438:            /**
439:             * Gets the chosen application generaton template.
440:             * @return
441:             */
442:            public Template getTemplate() {
443:                return template;
444:            }
445:
446:            public String getRefName() {
447:                return null;
448:            }
449:
450:            /**
451:             * check if the Container-managed relations checkbox was checked.
452:             * @return
453:             */
454:            public Boolean useRelations() {
455:                String templateValue = (String) getTemplateSettings().get(
456:                        JagGenerator.TEMPLATE_USE_RELATIONS);
457:                if (templateValue == null
458:                        || "false".equalsIgnoreCase(templateValue)) {
459:                    return new Boolean(false);
460:                } else {
461:                    return new Boolean(true);
462:                }
463:            }
464:
465:            /**
466:             * check if the useMock checkbox was checked to generate a mock implementation.
467:             * @return
468:             */
469:            public Boolean useMock() {
470:                String templateValue = (String) getTemplateSettings().get(
471:                        JagGenerator.TEMPLATE_USE_MOCK);
472:                if (templateValue == null
473:                        || "false".equalsIgnoreCase(templateValue)) {
474:                    return new Boolean(false);
475:                } else {
476:                    return new Boolean(true);
477:                }
478:            }
479:
480:            /**
481:             * check if the useJava5 checkbox was checked to generate java5 support.
482:             * @return
483:             */
484:            public Boolean useJava5() {
485:                String templateValue = (String) getTemplateSettings().get(
486:                        JagGenerator.TEMPLATE_USE_JAVA5);
487:                if (templateValue == null
488:                        || "false".equalsIgnoreCase(templateValue)) {
489:                    return new Boolean(false);
490:                } else {
491:                    return new Boolean(true);
492:                }
493:            }
494:
495:            /**
496:             * check if the useWebService checkbox was checked to generate a webservice.
497:             * @return true if webservice has been enabled.
498:             */
499:            public Boolean useWebService() {
500:                String templateValue = (String) getTemplateSettings().get(
501:                        JagGenerator.TEMPLATE_USE_WEB_SERVICE);
502:                if (templateValue == null
503:                        || "false".equalsIgnoreCase(templateValue)) {
504:                    return new Boolean(false);
505:                } else {
506:                    return new Boolean(true);
507:                }
508:            }
509:
510:            /**
511:             * check if the useSecurity checkbox was checked to generate security.
512:             * @return true if security was enabled.
513:             */
514:            public Boolean useSecurity() {
515:                String templateValue = (String) getTemplateSettings().get(
516:                        JagGenerator.TEMPLATE_USE_SECURITY);
517:                if (templateValue == null
518:                        || "false".equalsIgnoreCase(templateValue)) {
519:                    return new Boolean(false);
520:                } else {
521:                    return new Boolean(true);
522:                }
523:            }
524:
525:            /**
526:             * check if the useSecurity checkbox was checked to generate security.
527:             * @return true if security was enabled.
528:             */
529:            public Boolean useRss() {
530:                return check("rssEnabled");
531:            }
532:
533:            /**
534:             * Generic method for checking if a checkbox was enabled.
535:             * @return true if webservice has been enabled.
536:             */
537:            public Boolean check(String checkBoxField) {
538:                String templateValue = (String) getTemplateSettings().get(
539:                        checkBoxField);
540:                if (templateValue == null
541:                        || "false".equalsIgnoreCase(templateValue)) {
542:                    return new Boolean(false);
543:                } else {
544:                    return new Boolean(true);
545:                }
546:            }
547:
548:            /**
549:             * Gets the configuration settings as set by the user in the GUI.
550:             * @return a Map of (String) configuration parameter id --> (String) value.
551:             */
552:            public Map getTemplateSettings() {
553:                String value = null;
554:                HashMap settings = new HashMap();
555:                Map componentsMap = templatePanel.getConfigComponents();
556:                Iterator components = componentsMap.entrySet().iterator();
557:
558:                while (components.hasNext()) {
559:                    Map.Entry entry = (Map.Entry) components.next();
560:                    JComponent component = (JComponent) entry.getValue();
561:                    if (component instanceof  JTextField) {
562:                        value = ((JTextField) component).getText();
563:                    } else if (component instanceof  JCheckBox) {
564:                        value = "" + ((JCheckBox) component).isSelected();
565:                    } else if (component instanceof  JComboBox) {
566:                        value = "" + ((JComboBox) component).getSelectedItem();
567:                    }
568:                    settings.put(entry.getKey(), value);
569:                }
570:                return settings;
571:            }
572:
573:            /**
574:             * Set the template settings.
575:             */
576:            public void setTemplateSettings(Map templateSettings) {
577:
578:                Map componentsMap = templatePanel.getConfigComponents();
579:                Iterator components = componentsMap.entrySet().iterator();
580:
581:                while (components.hasNext()) {
582:                    Map.Entry entry = (Map.Entry) components.next();
583:                    JComponent component = (JComponent) entry.getValue();
584:                    String name = component.getName();
585:                    String value = (String) templateSettings.get(name);
586:                    if (value != null) {
587:                        if (component instanceof  JTextField) {
588:                            ((JTextField) component).setText(value);
589:                        } else if (component instanceof  JCheckBox) {
590:                            if ("true".equalsIgnoreCase(value)) {
591:                                ((JCheckBox) component).setSelected(true);
592:                            } else {
593:                                ((JCheckBox) component).setSelected(false);
594:                            }
595:                        } else if (component instanceof  JComboBox) {
596:                            ((JComboBox) component).setSelectedItem(value);
597:                        }
598:                    }
599:                }
600:
601:            }
602:
603:            /**
604:             * Helper method to determine if the selected appserver matches the passed string. A match is made in the selected
605:             * appserver equals or starts with the passed value ignoring cases. This method can be used to ignore version
606:             * numbers. So if you want to know that a JBoss appserver was selected, just match with "jboss".
607:             * @param value
608:             * @return Boolean true if there is a match.
609:             */
610:            public Boolean matchAppserver(String value) {
611:                String selectedAppserver = (String) getTemplateSettings().get(
612:                        JagGenerator.TEMPLATE_APPLICATION_SERVER);
613:                selectedAppserver = selectedAppserver.toLowerCase();
614:                value = value.toLowerCase();
615:                if (selectedAppserver == null || "".equals(selectedAppserver)
616:                        || value == null || "".equals(value)) {
617:                    return new Boolean(false);
618:                }
619:                if (selectedAppserver.equals(value)
620:                        || selectedAppserver.startsWith(value)) {
621:                    return new Boolean(true);
622:                } else {
623:                    return new Boolean(false);
624:                }
625:            }
626:
627:            /**
628:             * Helper method to determine if the selected business tier matches the passed string. A match is made in the
629:             * selected appserver equals or starts with the passed value ignoring cases. This method can be used to ignore
630:             * version numbers.
631:             * @param value
632:             * @return Boolean true if there is a match.
633:             */
634:            public Boolean matchBusinessTier(String value) {
635:                String selectedBusinessTier = (String) getTemplateSettings()
636:                        .get(JagGenerator.TEMPLATE_BUSINESS_TIER);
637:                selectedBusinessTier = selectedBusinessTier.toLowerCase();
638:                value = value.toLowerCase();
639:                if (selectedBusinessTier == null
640:                        || "".equals(selectedBusinessTier) || value == null
641:                        || "".equals(value)) {
642:                    return new Boolean(false);
643:                }
644:                if (selectedBusinessTier.equals(value)
645:                        || selectedBusinessTier.startsWith(value)) {
646:                    return new Boolean(true);
647:                } else {
648:                    return new Boolean(false);
649:                }
650:            }
651:
652:            /**
653:             * Helper method to determine if the selected service tier matches the passed string. A match is made if the selected
654:             * service tier equals or starts with the passed value ignoring cases. This method can be used to ignore version
655:             * numbers.
656:             * @param value
657:             * @return Boolean true if there is a match.
658:             */
659:            public Boolean matchServiceTier(String value) {
660:                String selectedServiceTier = (String) getTemplateSettings()
661:                        .get(JagGenerator.TEMPLATE_SERVICE_TIER);
662:                selectedServiceTier = selectedServiceTier.toLowerCase();
663:                value = value.toLowerCase();
664:                if (selectedServiceTier == null
665:                        || "".equals(selectedServiceTier) || value == null
666:                        || "".equals(value)) {
667:                    return new Boolean(false);
668:                }
669:                if (selectedServiceTier.equals(value)
670:                        || selectedServiceTier.startsWith(value)) {
671:                    return new Boolean(true);
672:                } else {
673:                    return new Boolean(false);
674:                }
675:            }
676:
677:            /**
678:             * Helper method to determine if the selected web tier matches the passed string. A match is made in the selected
679:             * appserver equals or starts with the passed value ignoring cases. This method can be used to ignore version
680:             * numbers.
681:             * @param value
682:             * @return Boolean true if there is a match.
683:             */
684:            public Boolean matchWebTier(String value) {
685:                String selectedWebTier = (String) getTemplateSettings().get(
686:                        JagGenerator.TEMPLATE_WEB_TIER);
687:                selectedWebTier = selectedWebTier.toLowerCase();
688:                value = value.toLowerCase();
689:                if (selectedWebTier == null || "".equals(selectedWebTier)
690:                        || value == null || "".equals(value)) {
691:                    return new Boolean(false);
692:                }
693:                if (selectedWebTier.equals(value)
694:                        || selectedWebTier.startsWith(value)) {
695:                    return new Boolean(true);
696:                } else {
697:                    return new Boolean(false);
698:                }
699:            }
700:
701:            public String getAuthorText() {
702:                return authorText.getText().toString();
703:            }
704:
705:            public String getVersionText() {
706:                return versionText.getText().toString();
707:            }
708:
709:            public String getCompanyText() {
710:                return companyText.getText().toString();
711:            }
712:
713:            // Variables declaration - do not modify
714:            private javax.swing.JLabel authorLabel;
715:            private javax.swing.JTextField authorText;
716:            private javax.swing.JLabel companyLabel;
717:            private javax.swing.JTextField companyText;
718:            private javax.swing.JButton editButton;
719:            private javax.swing.JPanel panel;
720:            private javax.swing.JLabel rootPackageLabel;
721:            private javax.swing.JScrollPane scrollPane;
722:            public javax.swing.JList templateList;
723:            private javax.swing.JPanel templateSettingsPanel;
724:            private javax.swing.JScrollPane templateSettingsScrollPane;
725:            private javax.swing.JLabel versionLabel;
726:            private javax.swing.JTextField versionText;
727:            // End of variables declaration
728:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.