Source Code Cross Referenced for SchemaImportGUI.java in  » IDE-Netbeans » xml » org » netbeans » modules » xml » wizard » 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 » IDE Netbeans » xml » org.netbeans.modules.xml.wizard 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:        package org.netbeans.modules.xml.wizard;
042:
043:        import java.awt.Component;
044:
045:        import java.awt.BorderLayout;
046:        import java.awt.event.ActionEvent;
047:        import java.awt.event.ActionListener;
048:        import java.awt.event.MouseAdapter;
049:        import java.awt.event.MouseEvent;
050:        import java.beans.Customizer;
051:        import java.beans.PropertyChangeEvent;
052:        import java.beans.PropertyChangeListener;
053:        import java.net.*;
054:        import java.io.*;
055:        import java.util.Iterator;
056:        import javax.swing.DefaultComboBoxModel;
057:        import javax.swing.text.JTextComponent;
058:        import org.openide.explorer.ExplorerManager;
059:        import org.openide.explorer.view.TreeTableView;
060:        import javax.swing.tree.TreeSelectionModel;
061:        import org.openide.filesystems.FileObject;
062:        import org.openide.loaders.DataObject;
063:        import org.openide.nodes.AbstractNode;
064:        import org.openide.nodes.Children;
065:        import org.openide.nodes.Node;
066:        import org.openide.nodes.PropertySupport;
067:        import java.lang.reflect.InvocationTargetException;
068:        import java.util.Collection;
069:        import java.util.HashMap;
070:        import java.util.LinkedList;
071:        import java.util.List;
072:        import java.util.Map;
073:        import org.openide.loaders.TemplateWizard;
074:        import org.openide.loaders.DataFolder;
075:        import org.netbeans.api.project.FileOwnerQuery;
076:        import org.netbeans.api.project.Project;
077:        import org.netbeans.spi.project.SubprojectProvider;
078:        import org.netbeans.spi.project.ui.LogicalViewProvider;
079:        import java.util.Set;
080:        import javax.swing.JDialog;
081:        import javax.swing.JFrame;
082:        import javax.swing.JPanel;
083:        import javax.swing.tree.TreePath;
084:        import org.openide.explorer.view.Visualizer;
085:        import org.openide.filesystems.FileUtil;
086:        import org.openide.util.NbBundle;
087:
088:        /**
089:         * This panel gathers data that are necessary for instantiting of XML
090:         * document conforming to given XML Schema.
091:         * <p>
092:         * Data allows to create a document that respect restrictions of current parser
093:         * implementations (they use schemaLocation hint specifically).
094:         *
095:         * @author  Petr Kuzel
096:         */
097:        public class SchemaImportGUI extends JPanel implements 
098:                ExplorerManager.Provider, PropertyChangeListener {
099:            /** Serial Version UID */
100:            private static final long serialVersionUID = -7568909683682244030L;
101:            private transient ExplorerManager explorerManager;
102:            private TemplateWizard templateWizard;
103:            private ExternalReferenceDecorator decorator;
104:            /** Map of registered nodes, keyed by their representative DataObject. */
105:            private Map registeredNodes;
106:            private FileObject primarySchema = null;
107:            private boolean first = false;
108:            private boolean removeFlag = false;
109:
110:            /** Creates new form SchemaPanel */
111:            public SchemaImportGUI(TemplateWizard tw) {
112:                initComponents();
113:                initAccessibility();
114:                this .templateWizard = tw;
115:                registeredNodes = new HashMap();
116:                decorator = new ExternalReferenceDecorator(this );
117:                // View for selecting an external reference.
118:                TreeTableView locationView = new LocationView();
119:                locationView.setDefaultActionAllowed(false);
120:                locationView.setPopupAllowed(false);
121:                locationView
122:                        .setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
123:                locationView.setRootVisible(false);
124:                locationView.getAccessibleContext().setAccessibleName(
125:                        locationLabel.getToolTipText());
126:                locationView.getAccessibleContext().setAccessibleDescription(
127:                        locationLabel.getToolTipText());
128:                Node.Property[] columns = new Node.Property[] {
129:                        new Column(ExternalReferenceDataNode.PROP_NAME,
130:                                String.class, true),
131:                        new ImportColumn(referenceTypeName()),
132:                //new Column(ExternalReferenceDataNode.PROP_PREFIX, String.class, false),
133:                };
134:                locationView.setProperties(columns);
135:                locationView.setTreePreferredWidth(200);
136:                locationView.setTableColumnPreferredWidth(0, 25);
137:                //        locationView.setTableColumnPreferredWidth(1, 25);
138:                locationPanel.add(locationView, BorderLayout.CENTER);
139:                explorerManager = new ExplorerManager();
140:                explorerManager.addPropertyChangeListener(this );
141:                explorerManager.setRootContext(createRootNode());
142:            }
143:
144:            /** This method is called from within the constructor to
145:             * initialize the form.
146:             * WARNING: Do NOT modify this code. The content of this method is
147:             * always regenerated by the Form Editor.
148:             */
149:            // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
150:            private void initComponents() {
151:
152:                locationPanel = new javax.swing.JPanel();
153:                locationLabel = new javax.swing.JLabel();
154:
155:                setName(Util.THIS.getString("PROP_schema_panel_name")); // NOI18N
156:
157:                locationPanel.setBorder(javax.swing.BorderFactory
158:                        .createEtchedBorder());
159:                locationPanel.setLayout(new java.awt.BorderLayout());
160:
161:                locationLabel.setLabelFor(locationPanel);
162:                locationLabel.setText(org.openide.util.NbBundle.getMessage(
163:                        SchemaImportGUI.class, "LBL_SchemaPanel_Location")); // NOI18N
164:                locationLabel.setToolTipText(org.openide.util.NbBundle
165:                        .getMessage(SchemaImportGUI.class,
166:                                "TIP_SchemaPanel_Location")); // NOI18N
167:
168:                org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
169:                        this );
170:                this .setLayout(layout);
171:                layout
172:                        .setHorizontalGroup(layout
173:                                .createParallelGroup(
174:                                        org.jdesktop.layout.GroupLayout.LEADING)
175:                                .add(
176:                                        layout
177:                                                .createSequentialGroup()
178:                                                .addContainerGap()
179:                                                .add(
180:                                                        layout
181:                                                                .createParallelGroup(
182:                                                                        org.jdesktop.layout.GroupLayout.TRAILING)
183:                                                                .add(
184:                                                                        org.jdesktop.layout.GroupLayout.LEADING,
185:                                                                        locationLabel)
186:                                                                .add(
187:                                                                        locationPanel,
188:                                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
189:                                                                        545,
190:                                                                        Short.MAX_VALUE))
191:                                                .addContainerGap()));
192:                layout
193:                        .setVerticalGroup(layout
194:                                .createParallelGroup(
195:                                        org.jdesktop.layout.GroupLayout.LEADING)
196:                                .add(
197:                                        layout
198:                                                .createSequentialGroup()
199:                                                .addContainerGap()
200:                                                .add(locationLabel)
201:                                                .addPreferredGap(
202:                                                        org.jdesktop.layout.LayoutStyle.RELATED)
203:                                                .add(
204:                                                        locationPanel,
205:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
206:                                                        247,
207:                                                        org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
208:                                                .addContainerGap(
209:                                                        org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
210:                                                        Short.MAX_VALUE)));
211:            }// </editor-fold>//GEN-END:initComponents
212:
213:            private void primarySchemaCheckBoxActionPerformed(
214:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_primarySchemaCheckBoxActionPerformed
215:                //   fireChange();
216:
217:            }//GEN-LAST:event_primarySchemaCheckBoxActionPerformed
218:
219:            private void initAccessibility() {
220:
221:                // memonics
222:                Util util = Util.THIS;
223:                locationLabel.setDisplayedMnemonic(util
224:                        .getChar("PROP_schema_locationLabel_mne"));
225:
226:            }
227:
228:            protected class Column extends PropertySupport.ReadOnly {
229:                /** The keyword for this column. */
230:                private String key;
231:
232:                /**
233:                 * Constructs a new instance of Column.
234:                 *
235:                 * @param  key   keyword for this column.
236:                 * @param  type  type of the property (e.g. String.class).
237:                 * @param  tree  true if this is the 'tree' column.
238:                 */
239:                public Column(String key, Class type, boolean tree) {
240:                    super (key, type, NbBundle.getMessage(Column.class,
241:                            "CTL_SchemaPanel_Column_Name_" + key), NbBundle
242:                            .getMessage(Column.class,
243:                                    "CTL_SchemaPanel_Column_Desc_" + key));
244:                    this .key = key;
245:                    setValue("TreeColumnTTV", Boolean.valueOf(tree));
246:                }
247:
248:                public Object getValue() throws IllegalAccessException,
249:                        InvocationTargetException {
250:                    return key;
251:                }
252:            }
253:
254:            protected class ImportColumn extends PropertySupport.ReadOnly {
255:                /** The keyword for this column. */
256:                private String key;
257:
258:                /**
259:                 * Creates a new instance of ImportColumn.
260:                 *
261:                 * @param  name  the column's name.
262:                 */
263:                public ImportColumn(String name) {
264:                    super ("selected", Boolean.TYPE, name, NbBundle.getMessage(
265:                            Column.class,
266:                            "CTL_SchemaPanel_Column_Desc_selected"));
267:                    this .key = "selected";
268:                    setValue("TreeColumnTTV", Boolean.FALSE);
269:                }
270:
271:                public Object getValue() throws IllegalAccessException,
272:                        InvocationTargetException {
273:                    return key;
274:                }
275:            }
276:
277:            protected Node createRootNode() {
278:                try {
279:                    DataFolder folder = templateWizard.getTargetFolder();
280:                    Project project = FileOwnerQuery.getOwner(folder
281:                            .getPrimaryFile());
282:                    SubprojectProvider provider = (SubprojectProvider) project
283:                            .getLookup().lookup(SubprojectProvider.class);
284:                    Set refProjects = provider.getSubprojects();
285:                    Iterator it = refProjects.iterator();
286:
287:                    Node[] rootNodes = new Node[1 + (refProjects == null ? 0
288:                            : refProjects.size())];
289:                    LogicalViewProvider viewProvider = (LogicalViewProvider) project
290:                            .getLookup().lookup(LogicalViewProvider.class);
291:                    rootNodes[0] = decorator
292:                            .createExternalReferenceNode(viewProvider
293:                                    .createLogicalView());
294:                    int rootIndex = 1;
295:
296:                    java.util.List projectRoots = new java.util.ArrayList();
297:                    projectRoots.add(project.getProjectDirectory());
298:                    if (refProjects != null) {
299:                        while (it.hasNext()) {
300:                            // for (Object o : refProjects) {
301:                            Object o = it.next();
302:                            Project refPrj = (Project) o;
303:                            viewProvider = (LogicalViewProvider) refPrj
304:                                    .getLookup().lookup(
305:                                            LogicalViewProvider.class);
306:                            rootNodes[rootIndex++] = decorator
307:                                    .createExternalReferenceNode(viewProvider
308:                                            .createLogicalView());
309:                            projectRoots.add(refPrj.getProjectDirectory());
310:                        }
311:                    }
312:                    FileObject[] roots = (FileObject[]) projectRoots
313:                            .toArray(new FileObject[projectRoots.size()]);
314:                    Children fileChildren = new Children.Array();
315:                    fileChildren.add(rootNodes);
316:                    Node byFilesNode = new FolderNode(fileChildren);
317:                    byFilesNode.setDisplayName(NbBundle.getMessage(
318:                            SchemaImportGUI.class,
319:                            "LBL_SchemaPanel_Category_By_File"));
320:
321:                    // Construct the By Namespace node.
322:                    Children nsChildren = new NamespaceChildren(roots,
323:                            decorator);
324:                    Node byNsNode = new FolderNode(nsChildren);
325:                    byNsNode.setDisplayName(NbBundle.getMessage(
326:                            SchemaImportGUI.class,
327:                            "LBL_SchemaPanel_Category_By_Namespace"));
328:                    Children categories = new Children.Array();
329:                    categories.add(new Node[] { byFilesNode, byNsNode });
330:                    Node rootNode = new AbstractNode(categories);
331:                    // Surprisingly, this becomes the name and description of the first column.
332:                    rootNode.setDisplayName(NbBundle.getMessage(
333:                            SchemaImportGUI.class,
334:                            "CTL_SchemaPanel_Column_Name_name"));
335:                    rootNode.setShortDescription(NbBundle.getMessage(
336:                            SchemaImportGUI.class,
337:                            "CTL_SchemaPanel_Column_Desc_name"));
338:                    return rootNode;
339:                } catch (Exception e) {
340:                    e.printStackTrace();
341:                }
342:                return null;
343:            }
344:
345:            public ExplorerManager getExplorerManager() {
346:                return explorerManager;
347:            }
348:
349:            public ExternalReferenceDataNode createExternalReferenceNode(
350:                    Node original) {
351:                DataObject dobj = (DataObject) original.getLookup().lookup(
352:                        DataObject.class);
353:                NodeSet set = (NodeSet) registeredNodes.get(dobj);
354:                if (set == null) {
355:                    set = new NodeSet(this );
356:                    registeredNodes.put(dobj, set);
357:                }
358:                ExternalReferenceDataNode erdn = new ExternalReferenceDataNode(
359:                        original, decorator);
360:                set.add(erdn);
361:                if (set.isSelected() && erdn.canSelect()) {
362:                    erdn.setSelected(true);
363:                }
364:                erdn.addPropertyChangeListener(this );
365:                return erdn;
366:            }
367:
368:            /**
369:             * Manages the state of a set of nodes.
370:             */
371:            private static class NodeSet {
372:                /** The property change listener for each node. */
373:                private PropertyChangeListener listener;
374:                /** Nodes in this set. */
375:                private List nodes;
376:                /** True if this set is selected, false otherwise. */
377:                private boolean selected;
378:
379:                /**
380:                 * Creates a new instance of NodeSet.
381:                 *
382:                 * @param  listener  listens to the Node.
383:                 */
384:                public NodeSet(PropertyChangeListener listener) {
385:                    this .listener = listener;
386:                }
387:
388:                /**
389:                 * Add the given node to this set.
390:                 *
391:                 * @param  node  node to be added to set.
392:                 */
393:                public void add(ExternalReferenceDataNode node) {
394:                    if (nodes == null) {
395:                        nodes = new LinkedList();
396:                    }
397:                    nodes.add(node);
398:                }
399:
400:                /**
401:                 * Returns the list of nodes in this set.
402:                 *
403:                 * @return  list of nodes.
404:                 */
405:                public List getNodes() {
406:                    return nodes;
407:                }
408:
409:                /**
410:                 * Indicates if this set is selected or not.
411:                 *
412:                 * @return  true if selected, false otherwise.
413:                 */
414:                public boolean isSelected() {
415:                    return selected;
416:                }
417:
418:                /**
419:                 * Set the prefix for Nodes in this group.
420:                 *
421:                 * @param  prefix  new namespace prefix.
422:                 */
423:                public void setPrefix(String prefix) {
424:                    for (int i = 0; i < nodes.size(); i++) {
425:                        ExternalReferenceDataNode node = (ExternalReferenceDataNode) nodes
426:                                .get(i);
427:                        if (!node.getPrefix().equals(prefix)) {
428:                            node.removePropertyChangeListener(listener);
429:                            node.setPrefix(prefix);
430:                            node.addPropertyChangeListener(listener);
431:                        }
432:                    }
433:                }
434:
435:                /**
436:                 * Set this group of Nodes as being selected.
437:                 *
438:                 * @param  select  true to select, false to de-select.
439:                 */
440:                public void setSelected(boolean select) {
441:                    selected = select;
442:                    for (int i = 0; i < nodes.size(); i++) {
443:                        ExternalReferenceDataNode node = (ExternalReferenceDataNode) nodes
444:                                .get(i);
445:                        if (node.canSelect()) {
446:                            node.removePropertyChangeListener(listener);
447:                            node.setSelected(select);
448:                            node.addPropertyChangeListener(listener);
449:                        }
450:                    }
451:                }
452:            }
453:
454:            public void propertyChange(PropertyChangeEvent event) {
455:                String pname = event.getPropertyName();
456:                if (ExplorerManager.PROP_SELECTED_NODES.equals(pname)) {
457:                    Node[] nodes = (Node[]) event.getNewValue();
458:                    // Validate the node selection.
459:                    if (nodes != null && nodes.length > 0
460:                            && nodes[0] instanceof  ExternalReferenceDataNode) {
461:                        ExternalReferenceDataNode node = (ExternalReferenceDataNode) nodes[0];
462:                        validateInput(node);
463:                    }
464:                } else if (pname.equals(ExternalReferenceDataNode.PROP_PREFIX)) {
465:                    ExternalReferenceDataNode erdn = (ExternalReferenceDataNode) event
466:                            .getSource();
467:                    // Look up the node in the map of sets, and ensure they all
468:                    // have the same prefix.
469:                    String prefix = (String) event.getNewValue();
470:                    DataObject dobj = (DataObject) erdn.getLookup().lookup(
471:                            DataObject.class);
472:                    NodeSet set = (NodeSet) registeredNodes.get(dobj);
473:                    // Ideally the set should already exist, but cope gracefully.
474:                    assert set != null : "node not created by customizer";
475:                    if (set == null) {
476:                        set = new NodeSet(this );
477:                        set.add(erdn);
478:                    }
479:                    set.setPrefix(prefix);
480:                    validateInput(erdn);
481:                } else if (pname
482:                        .equals(ExternalReferenceDataNode.PROP_SELECTED)) {
483:                    ExternalReferenceDataNode erdn = (ExternalReferenceDataNode) event
484:                            .getSource();
485:                    // Look up the node in the map of sets, and ensure they are all
486:                    // selected as a unit.
487:                    boolean selected = ((Boolean) event.getNewValue())
488:                            .booleanValue();
489:                    DataObject dobj = (DataObject) erdn.getLookup().lookup(
490:                            DataObject.class);
491:                    NodeSet set = (NodeSet) registeredNodes.get(dobj);
492:                    // Ideally the set should already exist, but cope gracefully.
493:                    assert set != null : "node not created by customizer";
494:                    if (set == null) {
495:                        set = new NodeSet(this );
496:                        set.add(erdn);
497:                    }
498:                    set.setSelected(selected);
499:                    //setPrimarySchema(erdn, selected, false); 
500:                    // Check if the current selection is valid.
501:                    validateInput(erdn);
502:                }
503:            }
504:
505:            /**
506:             * Determine if the user's input is valid or not. This will enable
507:             * or disable the save/reset controls based on the results, as well
508:             * as issue error messages.
509:             *
510:             * @param  node  selected node.
511:             */
512:            private void validateInput(ExternalReferenceDataNode erdn) {
513:                String msg = null;
514:                String ep = erdn.getPrefix();
515:                // Must be a non-empty prefix, that is not already in use, and
516:                // is unique among the selected nodes (and be selected itself).
517:                if (ep.length() == 0
518:                        || (!isValidPrefix(erdn) && erdn.isSelected())) {
519:                    msg = NbBundle.getMessage(SchemaImportGUI.class,
520:                            "LBL_SchemaPanel_InvalidPrefix");
521:                }
522:
523:                int selected = countSelectedNodes();
524:                if (selected < 0)
525:                    msg = "ERROR MSG";
526:                // Must have selected nodes, and no error messages.
527:                //setSaveEnabled((allowEmptySelection() || selected > 0) );
528:            }
529:
530:            /**
531:             * Check if prefix is unique on UI.
532:             *
533:             * @return  true if Prefix is not unique on UI, false otherwise.
534:             */
535:            private boolean isValidPrefix(ExternalReferenceDataNode node) {
536:                DataObject dobj = (DataObject) node.getLookup().lookup(
537:                        DataObject.class);
538:                NodeSet nodeSet = (NodeSet) registeredNodes.get(dobj);
539:                Collection sets = registeredNodes.values();
540:                Iterator it = sets.iterator();
541:                while (it.hasNext()) {
542:                    // Ignore the set which contains the given node, and those
543:                    // sets which are not selected.
544:                    NodeSet set = (NodeSet) it.next();
545:                    if (!set.equals(nodeSet) && set.isSelected()) {
546:                        // Only need to check the first node, as all of them have
547:                        // the same prefix (or at least that is the idea).
548:                        ExternalReferenceDataNode other = (ExternalReferenceDataNode) set
549:                                .getNodes().get(0);
550:                        if (node.getPrefix().equals(other.getPrefix())) {
551:                            return false;
552:                        }
553:                    }
554:                }
555:                return true;
556:            }
557:
558:            /**
559:             * Determine the number of nodes that the user selected, useful for
560:             * knowing if any nodes are selected or not.
561:             *
562:             * @return  number of selected nodes.
563:             */
564:            public int countSelectedNodes() {
565:                int results = 0;
566:                Collection sets = registeredNodes.values();
567:                Iterator it = sets.iterator();
568:                while (it.hasNext()) {
569:                    NodeSet set = (NodeSet) it.next();
570:                    List nodes = set.getNodes();
571:                    if (nodes.size() > 0) {
572:                        results++;
573:                    }
574:                }
575:
576:                return results;
577:            }
578:
579:            /**
580:             * A TreeTableView that toggles the selection of the external reference
581:             * data nodes using a single mouse click.
582:             */
583:            private class LocationView extends TreeTableView {
584:                /** silence compiler warnings */
585:                private static final long serialVersionUID = 1L;
586:
587:                /**
588:                 * Creates a new instance of LocationView.
589:                 */
590:                public LocationView() {
591:                    super ();
592:                    tree.addMouseListener(new MouseAdapter() {
593:                        public void mouseClicked(MouseEvent e) {
594:                            // Invert the selection of the data node, if such a
595:                            // node was clicked on.
596:                            TreePath path = tree.getPathForLocation(e.getX(), e
597:                                    .getY());
598:                            if (path != null) {
599:                                Object comp = path.getLastPathComponent();
600:                                Node node = Visualizer.findNode(comp);
601:                                if (node instanceof  ExternalReferenceDataNode) {
602:                                    ExternalReferenceDataNode erdn = (ExternalReferenceDataNode) node;
603:                                    if (erdn.canSelect()) {
604:                                        boolean selected = !erdn.isSelected();
605:                                        //setPrimarySchema(erdn, selected, true);
606:
607:                                    }
608:                                }
609:                            }
610:                        }
611:                    });
612:                }
613:            }
614:
615:            public boolean isPrimarySchemaSelected() {
616:                if (rootModel.getSize() == 0)
617:                    return false;
618:                else
619:                    return true;
620:            }
621:
622:            /**
623:             * Retrieve the list of nodes that the user selected.
624:             *
625:             * @return  list of selected nodes (empty if none).
626:             */
627:            protected List getSelectedNodes() {
628:                List results = new LinkedList();
629:                Collection sets = registeredNodes.values();
630:                Iterator it = sets.iterator();
631:                while (it.hasNext()) {
632:                    NodeSet set = (NodeSet) it.next();
633:                    if (set.isSelected()) {
634:                        List nodes = set.getNodes();
635:                        if (nodes.size() > 0) {
636:                            // Use just one of the corresponding nodes, as the
637:                            // others are basically duplicates.
638:                            results.add(nodes.get(0));
639:                        }
640:                    }
641:                }
642:                return results;
643:            }
644:
645:            /*   private void setPrimarySchema(ExternalReferenceDataNode erdn, boolean selected, boolean fromTreeView) {
646:                   String ns = null;
647:                   DataObject dobj = (DataObject) erdn.getLookup().lookup(DataObject.class);
648:                   FileObject fobj = dobj.getPrimaryFile();
649:                   
650:                    //if the schema was selected by clicking in the import column, then we dont need to set this
651:                   if(fromTreeView) {
652:                       erdn.setSelected(selected);
653:                       return;
654:                   }
655:                   
656:                   if (selected) {
657:                       // Have to collect the namespace value
658:                       // when the node is selected.
659:                       if(!fobj.isFolder()) {
660:                           ns= erdn.getNamespace();
661:                            String key = fobj.getNameExt() + " (" + ns + ")" ;
662:                            removeFlag=false;
663:                            namespaceModel.addElement(new SchemaComboItem(key, fobj));
664:                       }
665:                   } else {
666:                       if(!fobj.isFolder()) {
667:                           ns=erdn.getNamespace();
668:                           String key=fobj.getNameExt() + " (" + ns + ")";
669:                           for(int i = 0 ; i<namespaceModel.getSize()  ; i++ ) {
670:                               SchemaComboItem item = (SchemaComboItem)namespaceModel.getElementAt(i);
671:                               if(key.equals(item.toString()) && fobj.equals(item.getValue()) ) {
672:                                   removeFlag=true;
673:                                   namespaceModel.removeElement(item);
674:                                   break;
675:                               }
676:                           }
677:                           
678:                           
679:                       }
680:                       
681:                   }             
682:               } */
683:
684:            protected String referenceTypeName() {
685:                return NbBundle.getMessage(SchemaImportGUI.class,
686:                        "LBL_SchemaPanel_ImportCreator_Type");
687:            }
688:
689:            private class SchemaComboItem {
690:                String name;
691:                FileObject value;
692:
693:                public SchemaComboItem(String key, FileObject val) {
694:                    name = key;
695:                    this .value = val;
696:                }
697:
698:                public FileObject getValue() {
699:                    return value;
700:                }
701:
702:                public String toString() {
703:                    return name;
704:                }
705:            }
706:
707:            private DefaultComboBoxModel nsModel;
708:            private DefaultComboBoxModel rootModel;
709:            private DefaultComboBoxModel namespaceModel;
710:
711:            // Variables declaration - do not modify//GEN-BEGIN:variables
712:            private javax.swing.JLabel locationLabel;
713:            private javax.swing.JPanel locationPanel;
714:            // End of variables declaration//GEN-END:variables
715:
716:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.