Source Code Cross Referenced for WsdlInterfaceDesktopPanel.java in  » Web-Services » soapui-1.7.5 » com » eviware » soapui » impl » wsdl » panels » iface » 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 » Web Services » soapui 1.7.5 » com.eviware.soapui.impl.wsdl.panels.iface 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  soapUI, copyright (C) 2004-2007 eviware.com 
003:         *
004:         *  soapUI is free software; you can redistribute it and/or modify it under the 
005:         *  terms of version 2.1 of the GNU Lesser General Public License as published by 
006:         *  the Free Software Foundation.
007:         *
008:         *  soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 
009:         *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
010:         *  See the GNU Lesser General Public License for more details at gnu.org.
011:         */
012:
013:        package com.eviware.soapui.impl.wsdl.panels.iface;
014:
015:        import java.awt.BorderLayout;
016:        import java.awt.Component;
017:        import java.awt.Dimension;
018:        import java.awt.event.ActionEvent;
019:        import java.awt.event.MouseAdapter;
020:        import java.awt.event.MouseEvent;
021:        import java.io.File;
022:        import java.io.StringWriter;
023:        import java.util.ArrayList;
024:        import java.util.Collections;
025:        import java.util.Comparator;
026:        import java.util.Enumeration;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.List;
030:        import java.util.Map;
031:
032:        import javax.swing.AbstractAction;
033:        import javax.swing.Action;
034:        import javax.swing.BorderFactory;
035:        import javax.swing.JButton;
036:        import javax.swing.JLabel;
037:        import javax.swing.JPanel;
038:        import javax.swing.JProgressBar;
039:        import javax.swing.JScrollPane;
040:        import javax.swing.JSplitPane;
041:        import javax.swing.JTabbedPane;
042:        import javax.swing.JTree;
043:        import javax.swing.event.TreeSelectionEvent;
044:        import javax.swing.event.TreeSelectionListener;
045:        import javax.swing.tree.DefaultMutableTreeNode;
046:        import javax.swing.tree.DefaultTreeModel;
047:        import javax.swing.tree.TreePath;
048:
049:        import org.apache.log4j.Logger;
050:        import org.apache.xmlbeans.XmlCursor;
051:        import org.apache.xmlbeans.XmlLineNumber;
052:        import org.apache.xmlbeans.XmlObject;
053:        import org.apache.xmlbeans.XmlOptions;
054:        import org.syntax.jedit.JEditTextArea;
055:        import org.w3c.dom.Element;
056:
057:        import com.eviware.soapui.SoapUI;
058:        import com.eviware.soapui.impl.wsdl.WsdlInterface;
059:        import com.eviware.soapui.impl.wsdl.actions.iface.ExportDefinitionAction;
060:        import com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction;
061:        import com.eviware.soapui.impl.wsdl.actions.support.ShowOnlineHelpAction;
062:        import com.eviware.soapui.impl.wsdl.support.HelpUrls;
063:        import com.eviware.soapui.impl.wsdl.support.xsd.SchemaUtils;
064:        import com.eviware.soapui.model.ModelItem;
065:        import com.eviware.soapui.support.UISupport;
066:        import com.eviware.soapui.support.action.swing.SwingActionDelegate;
067:        import com.eviware.soapui.support.components.JEditorStatusBar;
068:        import com.eviware.soapui.support.components.JXToolBar;
069:        import com.eviware.soapui.support.components.ProgressDialog;
070:        import com.eviware.soapui.support.types.StringList;
071:        import com.eviware.soapui.support.xml.JXEditTextArea;
072:        import com.eviware.soapui.support.xml.XmlUtils;
073:        import com.eviware.soapui.ui.support.ModelItemDesktopPanel;
074:        import com.eviware.x.dialogs.Worker;
075:        import com.eviware.x.dialogs.XProgressDialog;
076:        import com.eviware.x.dialogs.XProgressMonitor;
077:        import com.jgoodies.forms.builder.ButtonBarBuilder;
078:
079:        /**
080:         * DesktopPanel for WsdlInterface. Loads all referenced wsdls/xsds for the specified WsdlInterface
081:         * and displays these in seperate tabs
082:         * 
083:         * @author Ole.Matzura
084:         */
085:
086:        public class WsdlInterfaceDesktopPanel extends
087:                ModelItemDesktopPanel<WsdlInterface> {
088:            private final static Logger logger = Logger
089:                    .getLogger(WsdlInterfaceDesktopPanel.class);
090:            private JTabbedPane tabbedPane;
091:            private List<JEditTextArea> editors = new ArrayList<JEditTextArea>();
092:            private JTree tree;
093:            private Map<String, DefaultMutableTreeNode> groupNodes = new HashMap<String, DefaultMutableTreeNode>();
094:            private Map<String, TreePath> pathMap = new HashMap<String, TreePath>();
095:            private List<TreePath> navigationHistory = new ArrayList<TreePath>();
096:            private StringList targetNamespaces = new StringList();
097:            public int historyIndex;
098:            public boolean navigating;
099:            private JEditorStatusBar statusBar;
100:
101:            public WsdlInterfaceDesktopPanel(WsdlInterface iface) {
102:                super (iface);
103:
104:                tabbedPane = new JTabbedPane();
105:                tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
106:
107:                DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(
108:                        iface.getName());
109:                DefaultTreeModel treeModel = new DefaultTreeModel(rootNode);
110:                tree = new JTree(treeModel);
111:                tree.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
112:                tree.setExpandsSelectedPaths(true);
113:                tree
114:                        .addTreeSelectionListener(new InternalTreeSelectionListener());
115:                tree.addMouseListener(new MouseAdapter() {
116:
117:                    @Override
118:                    public void mouseClicked(MouseEvent arg0) {
119:                        if (arg0.getClickCount() > 1) {
120:                            TreePath selectionPath = tree.getSelectionPath();
121:                            if (selectionPath != null) {
122:                                DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) selectionPath
123:                                        .getLastPathComponent();
124:                                Object userObject = treeNode.getUserObject();
125:                                if (userObject instanceof  InspectItem) {
126:                                    InspectItem item = (InspectItem) userObject;
127:                                    if (item != null && item.selector != null) {
128:                                        item.selector.selectNode(item);
129:                                    }
130:                                }
131:                            }
132:                        }
133:                    }
134:                });
135:
136:                JScrollPane scrollPane = new JScrollPane(tree);
137:                JSplitPane split = UISupport.createHorizontalSplit(scrollPane,
138:                        UISupport.createTabPanel(tabbedPane, true));
139:
140:                add(split, BorderLayout.CENTER);
141:
142:                split.setDividerLocation(250);
143:                split.setResizeWeight(0.3);
144:
145:                try {
146:                    if (iface.getWsdlContext().loadIfNecessary(false)) {
147:                        XProgressDialog progressDialog = UISupport.getDialogs()
148:                                .createProgressDialog("Loading Defintion", 3,
149:                                        "Initializing definition..", true);
150:                        Loader loader = new Loader(iface);
151:
152:                        if (progressDialog != null)
153:                            progressDialog.setCancelLabel("Run in background");
154:
155:                        progressDialog.run(loader);
156:                        loader = null;
157:                        treeModel.nodeStructureChanged(rootNode);
158:                    }
159:                } catch (Exception e) {
160:                    SoapUI.logError(e);
161:                }
162:
163:                add(buildToolbar(), BorderLayout.PAGE_START);
164:                statusBar = new JEditorStatusBar();
165:                add(statusBar, BorderLayout.PAGE_END);
166:                setPreferredSize(new Dimension(600, 500));
167:            }
168:
169:            private Component buildToolbar() {
170:                JXToolBar toolbar = UISupport.createToolbar();
171:
172:                toolbar.addFixed(new JButton(new BackwardAction()));
173:                toolbar.addFixed(new JButton(new ForwardAction()));
174:                toolbar.addUnrelatedGap();
175:                JButton button = new JButton(SwingActionDelegate
176:                        .createDelegate(UpdateInterfaceAction.SOAPUI_ACTION_ID,
177:                                getModelItem(), null, "/updateDefinition.gif"));
178:                button.setText(null);
179:                toolbar.addFixed(button);
180:                button = new JButton(SwingActionDelegate.createDelegate(
181:                        ExportDefinitionAction.SOAPUI_ACTION_ID,
182:                        getModelItem(), null, "/exportDefinition.gif"));
183:                button.setText(null);
184:                toolbar.addFixed(button);
185:                toolbar.addGlue();
186:                button = new JButton(new ShowOnlineHelpAction(
187:                        HelpUrls.INTERFACE_HELP_URL));
188:                button.setText(null);
189:                toolbar.addFixed(button);
190:
191:                return toolbar;
192:            }
193:
194:            private final class InternalTreeSelectionListener implements 
195:                    TreeSelectionListener {
196:                public void valueChanged(TreeSelectionEvent e) {
197:                    TreePath newLeadSelectionPath = e.getNewLeadSelectionPath();
198:                    if (newLeadSelectionPath != null) {
199:                        if (!navigating) {
200:                            // if we have moved back in history.. reverse before adding
201:                            while (historyIndex < navigationHistory.size() - 1) {
202:                                TreePath path = navigationHistory
203:                                        .remove(navigationHistory.size() - 1);
204:                                navigationHistory.add(historyIndex++, path);
205:                            }
206:
207:                            navigationHistory.add(newLeadSelectionPath);
208:                            historyIndex = navigationHistory.size() - 1;
209:                        }
210:
211:                        DefaultMutableTreeNode tn = (DefaultMutableTreeNode) newLeadSelectionPath
212:                                .getLastPathComponent();
213:                        if (tn.getUserObject() instanceof  InspectItem) {
214:                            InspectItem item = (InspectItem) tn.getUserObject();
215:
216:                            tabbedPane.setSelectedIndex(item.getTabIndex());
217:                            statusBar.setInfo(item.getDescription());
218:
219:                            JEditTextArea editor = editors.get(item
220:                                    .getTabIndex());
221:                            int lineNumber = item.getLineNumber();
222:                            if (lineNumber > 0
223:                                    && editor.getLineStartOffset(lineNumber) >= 0) {
224:                                editor.setCaretPosition(editor
225:                                        .getLineStartOffset(lineNumber));
226:                            } else {
227:                                editor.setCaretPosition(0);
228:                            }
229:                        }
230:
231:                        tree.scrollPathToVisible(newLeadSelectionPath);
232:                        tree.expandPath(newLeadSelectionPath);
233:                    }
234:                }
235:            }
236:
237:            private class Loader implements  Worker {
238:                private ProgressDialog progressDialog;
239:                private final WsdlInterface iface;
240:                private JProgressBar progressBar;
241:
242:                public Loader(WsdlInterface iface) {
243:                    this .iface = iface;
244:                }
245:
246:                public Object construct(XProgressMonitor monitor) {
247:                    try {
248:                        Map<String, XmlObject> schemas = iface.getWsdlContext()
249:                                .getDefinitionParts();
250:                        int tabCount = tabbedPane.getTabCount();
251:
252:                        for (Iterator<String> iter = schemas.keySet()
253:                                .iterator(); iter.hasNext();) {
254:                            String url = iter.next();
255:                            addTab(url, schemas.get(url));
256:                        }
257:
258:                        while (tabCount-- > 0)
259:                            tabbedPane.remove(0);
260:
261:                        return null;
262:                    } catch (Exception e) {
263:                        logger.error("Failed to load WSDL; "
264:                                + e.getClass().getSimpleName() + "; "
265:                                + e.getMessage());
266:                        add(new JLabel("Failed to load WSDL; " + e.toString()),
267:                                BorderLayout.NORTH);
268:
269:                        SoapUI.logError(e);
270:
271:                        return e;
272:                    }
273:                }
274:
275:                private void addTab(String url, XmlObject xmlObject)
276:                        throws Exception {
277:                    int ix = url.startsWith("file:") ? url
278:                            .lastIndexOf(File.separatorChar) : url
279:                            .lastIndexOf('/');
280:                    String title = url.substring(ix + 1);
281:
282:                    if (progressBar != null)
283:                        progressBar.setString(title);
284:                    else if (progressDialog != null)
285:                        progressDialog.setProgress(1, title);
286:
287:                    JPanel panel = new JPanel(new BorderLayout());
288:                    JLabel label = new JLabel(url);
289:                    label
290:                            .setBorder(BorderFactory.createEmptyBorder(3, 3, 3,
291:                                    3));
292:                    panel.add(label, BorderLayout.NORTH);
293:
294:                    JXEditTextArea inputArea = JXEditTextArea.createXmlEditor();
295:                    StringWriter writer = new StringWriter();
296:                    XmlUtils.serializePretty(xmlObject, writer);
297:                    String xmlString = writer.toString();
298:
299:                    // reparse so linenumbers are correct
300:                    xmlObject = XmlObject.Factory.parse(xmlString,
301:                            new XmlOptions().setLoadLineNumbers());
302:
303:                    inputArea.setText(xmlString);
304:                    inputArea.setEditable(false);
305:                    inputArea.getPainter().setLineHighlightEnabled(true);
306:
307:                    panel.add(new JScrollPane(inputArea), BorderLayout.CENTER);
308:                    tabbedPane.addTab(title, panel);
309:
310:                    if (tree != null) {
311:                        initInspectionTree(xmlObject, inputArea);
312:                    }
313:                }
314:
315:                private void initInspectionTree(XmlObject xmlObject,
316:                        JXEditTextArea inputArea) {
317:                    DefaultMutableTreeNode treeRoot = ((DefaultMutableTreeNode) tree
318:                            .getModel().getRoot());
319:
320:                    targetNamespaces.add(SchemaUtils
321:                            .getTargetNamespace(xmlObject));
322:
323:                    int tabCount = tabbedPane.getTabCount() - 1;
324:                    mapTreeItems(
325:                            xmlObject,
326:                            treeRoot,
327:                            false,
328:                            tabCount,
329:                            "Complex Types",
330:                            "declare namespace xs='http://www.w3.org/2001/XMLSchema';//xs:complexType[@name!='']",
331:                            "@name", true, null);
332:
333:                    mapTreeItems(
334:                            xmlObject,
335:                            treeRoot,
336:                            false,
337:                            tabCount,
338:                            "Simple Types",
339:                            "declare namespace xs='http://www.w3.org/2001/XMLSchema';//xs:simpleType[@name!='']",
340:                            "@name", true, null);
341:
342:                    mapTreeItems(
343:                            xmlObject,
344:                            treeRoot,
345:                            false,
346:                            tabCount,
347:                            "Anonymous Complex Types",
348:                            "declare namespace xs='http://www.w3.org/2001/XMLSchema';//xs:complexType[not(exists(@name))]",
349:                            "parent::node()/@name", true, null);
350:
351:                    mapTreeItems(
352:                            xmlObject,
353:                            treeRoot,
354:                            false,
355:                            tabCount,
356:                            "Global Elements",
357:                            "declare namespace xs='http://www.w3.org/2001/XMLSchema';//xs:schema/xs:element[@name!='']",
358:                            "@name", true, new GlobalElementSelector());
359:
360:                    mapTreeItems(
361:                            xmlObject,
362:                            treeRoot,
363:                            false,
364:                            tabCount,
365:                            "Schemas",
366:                            "declare namespace xs='http://www.w3.org/2001/XMLSchema';//xs:schema",
367:                            "@targetNamespace", true, null);
368:
369:                    List<DefaultMutableTreeNode> messages = mapTreeItems(
370:                            xmlObject,
371:                            treeRoot,
372:                            false,
373:                            tabCount,
374:                            "Messages",
375:                            "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';//wsdl:message",
376:                            "@name", true, null);
377:
378:                    for (DefaultMutableTreeNode treeNode : messages) {
379:                        mapTreeItems(
380:                                ((InspectItem) treeNode.getUserObject()).item,
381:                                treeNode,
382:                                false,
383:                                tabCount,
384:                                null,
385:                                "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';wsdl:part",
386:                                "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';concat('part: name=[', @name, '] type=[', @type, '] element=[', @element, ']' )",
387:                                true, new PartSelector());
388:                    }
389:
390:                    List<DefaultMutableTreeNode> portTypes = mapTreeItems(
391:                            xmlObject,
392:                            treeRoot,
393:                            false,
394:                            tabCount,
395:                            "PortTypes",
396:                            "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';//wsdl:portType",
397:                            "@name", true, null);
398:
399:                    for (DefaultMutableTreeNode treeNode : portTypes) {
400:                        List<DefaultMutableTreeNode> operationNodes = mapTreeItems(
401:                                ((InspectItem) treeNode.getUserObject()).item,
402:                                treeNode,
403:                                false,
404:                                tabCount,
405:                                null,
406:                                "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';wsdl:operation",
407:                                "@name", true, null);
408:
409:                        for (DefaultMutableTreeNode treeNode2 : operationNodes) {
410:                            mapTreeItems(
411:                                    ((InspectItem) treeNode2.getUserObject()).item,
412:                                    treeNode2,
413:                                    false,
414:                                    tabCount,
415:                                    null,
416:                                    "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';wsdl:*",
417:                                    "concat( @name, ' [', local-name(), '], message=[', @message, ']' )",
418:                                    false, new MessageSelector());
419:                        }
420:                    }
421:
422:                    List<DefaultMutableTreeNode> bindings = mapTreeItems(
423:                            xmlObject,
424:                            treeRoot,
425:                            false,
426:                            tabCount,
427:                            "Bindings",
428:                            "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';//wsdl:binding",
429:                            "declare namespace wsdlsoap='http://schemas.xmlsoap.org/wsdl/soap/';concat( @name, ' [style=', wsdlsoap:binding/@style, ']' )",
430:                            true, null);
431:
432:                    for (DefaultMutableTreeNode treeNode : bindings) {
433:                        List<DefaultMutableTreeNode> operationNodes = mapTreeItems(
434:                                ((InspectItem) treeNode.getUserObject()).item,
435:                                treeNode,
436:                                false,
437:                                tabCount,
438:                                null,
439:                                "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';wsdl:operation",
440:                                "declare namespace wsdlsoap='http://schemas.xmlsoap.org/wsdl/soap/';concat( @name, ' [soapAction=', wsdlsoap:operation/@soapAction, ']' )",
441:                                true, null);
442:
443:                        for (DefaultMutableTreeNode treeNode2 : operationNodes) {
444:                            mapTreeItems(
445:                                    ((InspectItem) treeNode2.getUserObject()).item,
446:                                    treeNode2,
447:                                    false,
448:                                    tabCount,
449:                                    null,
450:                                    "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';wsdl:*",
451:                                    "concat( @name, ' [', local-name(), ']' )",
452:                                    false, new BindingOperationSelector());
453:                        }
454:                    }
455:
456:                    List<DefaultMutableTreeNode> services = mapTreeItems(
457:                            xmlObject,
458:                            treeRoot,
459:                            false,
460:                            tabCount,
461:                            "Services",
462:                            "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';//wsdl:service",
463:                            "@name", true, null);
464:
465:                    for (DefaultMutableTreeNode treeNode : services) {
466:                        mapTreeItems(
467:                                ((InspectItem) treeNode.getUserObject()).item,
468:                                treeNode,
469:                                false,
470:                                tabCount,
471:                                null,
472:                                "declare namespace wsdl='http://schemas.xmlsoap.org/wsdl/';wsdl:port",
473:                                "concat( 'port: name=[', @name, '] binding=[', @binding, ']' )",
474:                                true, new PortSelector());
475:                    }
476:
477:                    tree.expandRow(0);
478:                    editors.add(inputArea);
479:                }
480:
481:                public void finished() {
482:                    if (progressDialog != null)
483:                        progressDialog.setVisible(false);
484:
485:                    progressDialog = null;
486:                }
487:
488:                public boolean onCancel() {
489:                    progressBar = new JProgressBar(0, 1);
490:                    progressBar.setSize(new Dimension(120, 20));
491:                    progressBar.setStringPainted(true);
492:                    progressBar.setString("Loading Definition..");
493:                    progressBar.setIndeterminate(true);
494:
495:                    ButtonBarBuilder builder = ButtonBarBuilder
496:                            .createLeftToRightBuilder();
497:                    builder.addGlue();
498:                    builder.addFixed(progressBar);
499:                    builder.addGlue();
500:                    builder.setBorder(BorderFactory.createEmptyBorder(10, 10,
501:                            10, 10));
502:
503:                    tabbedPane.addTab("Loading.. ", builder.getPanel());
504:                    return true;
505:                }
506:            }
507:
508:            public boolean dependsOn(ModelItem modelItem) {
509:                return modelItem == getModelItem()
510:                        || modelItem == getModelItem().getProject();
511:            }
512:
513:            public List<DefaultMutableTreeNode> mapTreeItems(
514:                    XmlObject xmlObject, DefaultMutableTreeNode treeRoot,
515:                    boolean createEmpty, int tabIndex, String groupName,
516:                    String query, String nameQuery, boolean sort,
517:                    NodeSelector selector) {
518:                XmlObject[] items = xmlObject.selectPath(query);
519:                List<DefaultMutableTreeNode> treeNodes = new ArrayList<DefaultMutableTreeNode>();
520:                List<DefaultMutableTreeNode> resultNodes = new ArrayList<DefaultMutableTreeNode>();
521:
522:                DefaultMutableTreeNode root = treeRoot;
523:                if (groupName != null) {
524:                    String groupKey = new TreePath(root.getPath()).toString()
525:                            + "/" + groupName;
526:                    root = groupNodes.get(groupKey);
527:                    if (root == null && (items.length > 0 || createEmpty)) {
528:                        root = new DefaultMutableTreeNode(groupName);
529:                        treeRoot.add(root);
530:                        groupNodes.put(groupKey, root);
531:                    } else if (root != null) {
532:                        Enumeration children = root.children();
533:                        while (children.hasMoreElements())
534:                            treeNodes.add((DefaultMutableTreeNode) children
535:                                    .nextElement());
536:                    }
537:                }
538:
539:                if (items.length == 0)
540:                    return resultNodes;
541:
542:                for (XmlObject item : items) {
543:                    XmlObject[] selectPath = item.selectPath(nameQuery);
544:                    if (selectPath.length > 0) {
545:                        DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(
546:                                new InspectItem(item, selectPath[0], tabIndex,
547:                                        selector));
548:                        treeNodes.add(treeNode);
549:                        resultNodes.add(treeNode);
550:                    }
551:                }
552:
553:                if (sort) {
554:                    Collections.sort(treeNodes,
555:                            new Comparator<DefaultMutableTreeNode>() {
556:
557:                                public int compare(DefaultMutableTreeNode o1,
558:                                        DefaultMutableTreeNode o2) {
559:                                    return o1.toString().compareTo(
560:                                            o2.toString());
561:                                }
562:                            });
563:                }
564:
565:                root.removeAllChildren();
566:
567:                for (DefaultMutableTreeNode treeNode : treeNodes) {
568:                    root.add(treeNode);
569:
570:                    String path = "/" + getTreeNodeName(treeNode);
571:                    TreePath treePath = new TreePath(treeNode.getPath());
572:                    while (treeNode.getParent() != null) {
573:                        treeNode = (DefaultMutableTreeNode) treeNode
574:                                .getParent();
575:                        path = "/" + getTreeNodeName(treeNode) + path;
576:                    }
577:
578:                    pathMap.put(path, treePath);
579:                }
580:
581:                return resultNodes;
582:            }
583:
584:            private String getTreeNodeName(DefaultMutableTreeNode treeNode) {
585:                Object userObject = treeNode.getUserObject();
586:                if (userObject instanceof  InspectItem)
587:                    return ((InspectItem) userObject).getName();
588:                else
589:                    return treeNode.toString();
590:            }
591:
592:            private final class InspectItem {
593:                private final XmlObject item;
594:                private String name;
595:                private final int tabIndex;
596:                private XmlLineNumber lineNumber;
597:                private final NodeSelector selector;
598:
599:                public InspectItem(XmlObject item, XmlObject nameObj,
600:                        int tabIndex, NodeSelector selector) {
601:                    this .item = item;
602:                    this .selector = selector;
603:                    this .name = XmlUtils.getNodeValue(nameObj.getDomNode());
604:                    if (name == null)
605:                        name = nameObj.toString();
606:                    this .tabIndex = tabIndex;
607:
608:                    ArrayList list = new ArrayList();
609:                    XmlCursor cursor = item.newCursor();
610:                    cursor.getAllBookmarkRefs(list);
611:
612:                    for (Object o : list)
613:                        if (o instanceof  XmlLineNumber)
614:                            lineNumber = (XmlLineNumber) o;
615:
616:                    cursor.dispose();
617:                }
618:
619:                public String getDescription() {
620:                    return getName() + "@" + targetNamespaces.get(tabIndex);
621:                }
622:
623:                public String getName() {
624:                    int ix = name.indexOf(' ');
625:                    return ix == -1 ? name : name.substring(0, ix);
626:                }
627:
628:                public int getTabIndex() {
629:                    return tabIndex;
630:                }
631:
632:                public int getLineNumber() {
633:                    return lineNumber == null ? -1 : lineNumber.getLine() - 1;
634:                }
635:
636:                @Override
637:                public String toString() {
638:                    return name;
639:                }
640:
641:                public NodeSelector getSelector() {
642:                    return selector;
643:                }
644:
645:                public Element getElement() {
646:                    return (Element) item.getDomNode();
647:                }
648:            }
649:
650:            public String getDescription() {
651:                return "Interface [" + getModelItem().getName() + "]";
652:            }
653:
654:            public boolean onClose(boolean canCancel) {
655:                return release();
656:            }
657:
658:            private void simpleSelect(InspectItem item, String attribute,
659:                    String targetGroup) {
660:                Element elm = item.getElement();
661:                String type = elm.getAttribute(attribute);
662:                if (type.length() > 0) {
663:                    int ix = type.indexOf(':');
664:                    if (ix != -1)
665:                        type = type.substring(ix + 1);
666:
667:                    TreePath treePath = pathMap.get("/"
668:                            + getModelItem().getName() + "/" + targetGroup
669:                            + "/" + type);
670:                    if (treePath != null) {
671:                        tree.setSelectionPath(treePath);
672:                    }
673:                }
674:            }
675:
676:            protected interface NodeSelector {
677:                public void selectNode(InspectItem item);
678:            }
679:
680:            public class PartSelector implements  NodeSelector {
681:                public void selectNode(InspectItem item) {
682:                    Element elm = item.getElement();
683:                    String type = elm.getAttribute("type");
684:                    String element = elm.getAttribute("element");
685:                    if (type.length() > 0) {
686:                        simpleSelect(item, "type", "Complex Types");
687:                    } else if (element.length() > 0) {
688:                        simpleSelect(item, "element", "Global Elements");
689:                    }
690:                }
691:            }
692:
693:            public class MessageSelector implements  NodeSelector {
694:                public void selectNode(InspectItem item) {
695:                    simpleSelect(item, "message", "Messages");
696:                }
697:            }
698:
699:            public class GlobalElementSelector implements  NodeSelector {
700:                public void selectNode(InspectItem item) {
701:                    simpleSelect(item, "type", "Complex Types");
702:                }
703:            }
704:
705:            public class PortSelector implements  NodeSelector {
706:                public void selectNode(InspectItem item) {
707:                    simpleSelect(item, "binding", "Bindings");
708:                }
709:            }
710:
711:            public class BindingOperationSelector implements  NodeSelector {
712:                public void selectNode(InspectItem item) {
713:                    Element elm = item.getElement();
714:                    String name = elm.getAttribute("name");
715:
716:                    Element operationElm = (Element) elm.getParentNode();
717:                    Element bindingElm = (Element) operationElm.getParentNode();
718:
719:                    String type = bindingElm.getAttribute("type");
720:
721:                    if (type.length() > 0) {
722:                        int ix = type.indexOf(':');
723:                        if (ix != -1)
724:                            type = type.substring(ix + 1);
725:
726:                        TreePath treePath = pathMap.get("/"
727:                                + getModelItem().getName() + "/PortTypes/"
728:                                + type + "/"
729:                                + operationElm.getAttribute("name") + "/"
730:                                + name);
731:                        if (treePath != null) {
732:                            tree.setSelectionPath(treePath);
733:                        }
734:                    }
735:                }
736:            }
737:
738:            private class BackwardAction extends AbstractAction {
739:                public BackwardAction() {
740:                    super ("<");
741:                    putValue(Action.SHORT_DESCRIPTION,
742:                            "Navigate to previous selection");
743:                }
744:
745:                public void actionPerformed(ActionEvent arg0) {
746:                    if (historyIndex > 0) {
747:                        historyIndex--;
748:                        navigating = true;
749:                        tree.setSelectionPath(navigationHistory
750:                                .get(historyIndex));
751:                        navigating = false;
752:                    }
753:                }
754:            }
755:
756:            private class ForwardAction extends AbstractAction {
757:                public ForwardAction() {
758:                    super (">");
759:                    putValue(Action.SHORT_DESCRIPTION,
760:                            "Navigate to next selection");
761:                }
762:
763:                public void actionPerformed(ActionEvent arg0) {
764:                    if (historyIndex < navigationHistory.size() - 1) {
765:                        historyIndex++;
766:                        navigating = true;
767:                        tree.setSelectionPath(navigationHistory
768:                                .get(historyIndex));
769:                        navigating = false;
770:                    }
771:
772:                }
773:            }
774:
775:        }
w___w_w.__j_a___v_a_2s___.c__o___m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.