Source Code Cross Referenced for AddContactForm.java in  » IDE-Netbeans » collab » org » netbeans » modules » collab » ui » 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 » collab » org.netbeans.modules.collab.ui 
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.collab.ui;
042:
043:        import java.awt.Dialog;
044:        import java.util.*;
045:        import javax.swing.event.*;
046:
047:        import org.openide.*;
048:        import org.openide.util.*;
049:
050:        import com.sun.collablet.*;
051:        import org.netbeans.modules.collab.core.Debug;
052:
053:        /**
054:         *
055:         * @author  sherylsu
056:         */
057:        public class AddContactForm extends javax.swing.JPanel implements 
058:                ListSelectionListener {
059:            private static boolean _isSearching = false;
060:            public static final String DEFAULT_CONTACT_LIST = NbBundle
061:                    .getMessage(AddContactForm.class,
062:                            "AddContactForm_DefaultContactList"); // NOI18N
063:
064:            ////////////////////////////////////////////////////////////////////////////
065:            // Instance variables
066:            ////////////////////////////////////////////////////////////////////////////
067:            private DialogDescriptor dialogDescriptor;
068:            private ArrayList contactList = new ArrayList();
069:            private ResourceBundle addContactBundle;
070:            private CollabSession session;
071:            private boolean limitWasExceeded = false;
072:            private Vector result = new Vector(20);
073:            private boolean useComboBoxes = false; // TAF: Switch for UI style - temp
074:            private ContactGroup group = null;
075:
076:            /**
077:             *
078:             *
079:             */
080:            public AddContactForm(CollabSession session) {
081:                this .session = session;
082:                initialize();
083:            }
084:
085:            public AddContactForm(CollabSession session, ContactGroup group) {
086:                this .session = session;
087:                this .group = group;
088:                initialize();
089:            }
090:
091:            private void initAccessibility() {
092:                getAccessibleContext().setAccessibleName(
093:                        NbBundle.getMessage(AddContactForm.class,
094:                                "ACSD_NAME_AddContactForm"));
095:                getAccessibleContext().setAccessibleDescription(
096:                        NbBundle.getMessage(AddContactForm.class,
097:                                "ACSD_DESC_AddContactForm"));
098:
099:                findContactTextField.getAccessibleContext().setAccessibleName(
100:                        NbBundle.getMessage(AddContactForm.class,
101:                                "ACSD_NAME_AddContactForm_FindContact"));
102:                findContactTextField
103:                        .getAccessibleContext()
104:                        .setAccessibleDescription(
105:                                NbBundle.getMessage(AddContactForm.class,
106:                                        "ACSD_DESC_AddContactForm_FindContact"));
107:
108:                findBtn.getAccessibleContext().setAccessibleName(
109:                        NbBundle.getMessage(AddContactForm.class,
110:                                "ACSD_NAME_AddContactForm_Find"));
111:                findBtn.getAccessibleContext().setAccessibleDescription(
112:                        NbBundle.getMessage(AddContactForm.class,
113:                                "ACSD_DESC_AddContactForm_Find"));
114:
115:                nameTypeRadioButton.getAccessibleContext().setAccessibleName(
116:                        NbBundle.getMessage(AddContactForm.class,
117:                                "ACSD_NAME_AddContactForm_Name"));
118:                nameTypeRadioButton.getAccessibleContext()
119:                        .setAccessibleDescription(
120:                                NbBundle.getMessage(AddContactForm.class,
121:                                        "ACSD_DESC_AddContactForm_Name"));
122:
123:                userIDTypeRadioButton.getAccessibleContext().setAccessibleName(
124:                        NbBundle.getMessage(AddContactForm.class,
125:                                "ACSD_NAME_AddContactForm_UserID"));
126:                userIDTypeRadioButton.getAccessibleContext()
127:                        .setAccessibleDescription(
128:                                NbBundle.getMessage(AddContactForm.class,
129:                                        "ACSD_DESC_AddContactForm_UserID"));
130:
131:                contactJList.getAccessibleContext().setAccessibleName(
132:                        NbBundle.getMessage(AddContactForm.class,
133:                                "ACSD_NAME_AddContactForm_searchResultLabel"));
134:                contactJList.getAccessibleContext().setAccessibleDescription(
135:                        NbBundle.getMessage(AddContactForm.class,
136:                                "ACSD_DESC_AddContactForm_searchResultLabel"));
137:
138:                removeBtn.getAccessibleContext().setAccessibleName(
139:                        NbBundle.getMessage(AddContactForm.class,
140:                                "ACSD_NAME_AddContactForm_Remove"));
141:                removeBtn.getAccessibleContext().setAccessibleDescription(
142:                        NbBundle.getMessage(AddContactForm.class,
143:                                "ACSD_DESC_AddContactForm_Remove"));
144:
145:                groupComboBox.getAccessibleContext().setAccessibleName(
146:                        NbBundle.getMessage(AddContactForm.class,
147:                                "ACSD_NAME_AddContactForm_AddContactTo"));
148:                groupComboBox.getAccessibleContext().setAccessibleDescription(
149:                        NbBundle.getMessage(AddContactForm.class,
150:                                "ACSD_DESC_AddContactForm_AddContactTo"));
151:            }
152:
153:            private void initialize() {
154:                // Create the dialog descriptor here, since we need it in order to
155:                // be able to change the valid state of the dialog
156:                dialogDescriptor = new DialogDescriptor(this , NbBundle
157:                        .getMessage(AddContactForm.class,
158:                                "TITLE_AddContactForm")); // NOI18N
159:                dialogDescriptor.setValid(false);
160:
161:                initComponents();
162:                initAccessibility();
163:
164:                optionsComboBox.setVisible(useComboBoxes);
165:                typeComboBox.setVisible(useComboBoxes);
166:
167:                //	optionsPanel.setVisible(!useComboBoxes);
168:                optionsPanel.setVisible(false);
169:                optionsLb.setVisible(false);
170:                typePanel.setVisible(!useComboBoxes);
171:
172:                addContactBundle = NbBundle.getBundle(AddContactForm.class);
173:                optionsComboBox.addItem(addContactBundle
174:                        .getString("LBL_AddContactForm_Contains")); // NOI18N
175:                optionsComboBox.addItem(addContactBundle
176:                        .getString("LBL_AddContactForm_Ends")); // NOI18N
177:                optionsComboBox.addItem(addContactBundle
178:                        .getString("LBL_AddContactForm_Starts")); // NOI18N
179:
180:                typeComboBox.addItem(addContactBundle
181:                        .getString("LBL_AddContactForm_Name")); // NOI18N
182:                typeComboBox.addItem(addContactBundle
183:                        .getString("LBL_AddContactForm_UserID")); // NOI18N
184:
185:                ContactGroup[] groups = session.getContactGroups();
186:
187:                if (groups.length == 0) {
188:                    try {
189:                        this .group = session
190:                                .createContactGroup(DEFAULT_CONTACT_LIST);
191:                        groups = session.getContactGroups();
192:                    } catch (CollabException ce) {
193:                        Debug.errorManager.notify(ce);
194:                    }
195:                }
196:
197:                for (int i = 0; i < groups.length; i++) {
198:                    groupComboBox.addItem(groups[i].getName());
199:                }
200:
201:                if (group != null) {
202:                    groupComboBox.setSelectedItem(group.getName());
203:                }
204:
205:                ListModel model = new ListModel(contactJList, result, false,
206:                        true, false);
207:
208:                ListRenderer renderer = new ListRenderer(model);
209:                contactJList.setCellRenderer(renderer);
210:                contactJList.setModel(model);
211:                contactJList.addListSelectionListener(this );
212:
213:                // Listen to changes to the search field in order to enable or 
214:                // disable the find button
215:                findContactTextField.getDocument().addDocumentListener(
216:                        new DocumentListener() {
217:                            public void changedUpdate(DocumentEvent e) {
218:                            }
219:
220:                            public void insertUpdate(DocumentEvent e) {
221:                                findBtn.setEnabled((findContactTextField
222:                                        .getText() != null)
223:                                        && (findContactTextField.getText()
224:                                                .length() > 0));
225:                            }
226:
227:                            public void removeUpdate(DocumentEvent e) {
228:                                findBtn.setEnabled((findContactTextField
229:                                        .getText() != null)
230:                                        && (findContactTextField.getText()
231:                                                .length() > 0));
232:                            }
233:                        });
234:            }
235:
236:            public CollabPrincipal[] getNewContacts() {
237:                return (CollabPrincipal[]) contactList.toArray();
238:            }
239:
240:            public void addContacts() {
241:                Dialog dialog = null;
242:
243:                try {
244:                    dialog = DialogDisplayer.getDefault().createDialog(
245:                            dialogDescriptor);
246:                    dialog.show();
247:
248:                    if (dialogDescriptor.getValue() == DialogDescriptor.OK_OPTION) {
249:                        if (sessionExists()) {
250:                            addElementsToBuddyListGroup((String) groupComboBox
251:                                    .getSelectedItem());
252:                        }
253:                    }
254:                } finally {
255:                    dialog.dispose();
256:                }
257:            }
258:
259:            private void addElementsToBuddyListGroup(String grp) {
260:                if (result.size() != 0) {
261:                    Vector tmp = new Vector();
262:                    CollabPrincipal[] sel = getUserSelectionList();
263:
264:                    if (sel == null) {
265:                        final String msg = addContactBundle
266:                                .getString("AddContact_noContacts"); // NOI18N
267:                        DialogDisplayer.getDefault().notify(
268:                                new NotifyDescriptor.Message(msg,
269:                                        NotifyDescriptor.INFORMATION_MESSAGE));
270:
271:                        return;
272:                    }
273:
274:                    ContactGroup group = session.getContactGroup(grp);
275:                    assert group != null : "Group \"" + grp
276:                            + "\" was not found in the group list";
277:
278:                    for (int n = 0; n < sel.length; n++) {
279:                        try {
280:                            if (group.getContact(sel[n].getIdentifier()) == null) {
281:                                group.addContact(sel[n]);
282:
283:                                /*
284:                                sel[n].subscribe();
285:                                sel[n].setStatus(CollabPrincipal.STATUS_PENDING);
286:                                 */
287:                            }
288:                        } catch (CollabException e) {
289:                            // TODO: Nice error message
290:                            Debug.errorManager.notify(e);
291:                        }
292:                    }
293:                } else {
294:                    final String msg = addContactBundle
295:                            .getString("AddContact_noContacts"); // NOI18N
296:                    DialogDisplayer.getDefault().notify(
297:                            new NotifyDescriptor.Message(msg,
298:                                    NotifyDescriptor.INFORMATION_MESSAGE));
299:                }
300:            }
301:
302:            public CollabPrincipal[] getUserSelectionList() {
303:                CollabPrincipal[] ret = new CollabPrincipal[result.size()];
304:                result.copyInto(ret);
305:
306:                return ret;
307:            }
308:
309:            public void search() {
310:                if (!sessionExists()) {
311:                    return;
312:                }
313:
314:                if (findContactTextField.getText().equals("")) {
315:                    String msg = NbBundle.getMessage(AddContactForm.class,
316:                            "Enter_a_String_to_search_for"); // NOI18N
317:                    DialogDisplayer.getDefault().notify(
318:                            new NotifyDescriptor.Message(msg,
319:                                    NotifyDescriptor.INFORMATION_MESSAGE));
320:
321:                    return;
322:                }
323:
324:                if (!isSearchByID()) {
325:                    byte[] x;
326:                    int minLength = 3;
327:                    int length;
328:
329:                    String slen = addContactBundle
330:                            .getString("Minimum_search_length"); // NOI18N
331:
332:                    if (slen != null) {
333:                        try {
334:                            Integer ilen = new Integer(slen);
335:                            minLength = ilen.intValue();
336:                        } catch (Exception e) {
337:                            Debug.debugNotify(e);
338:                        }
339:                    }
340:
341:                    try {
342:                        x = findContactTextField.getText().getBytes("UTF-8"); // NOI18N
343:                        length = x.length;
344:                    } catch (Exception e) {
345:                        length = findContactTextField.getText().length();
346:                        Debug.debugNotify(e);
347:                    }
348:
349:                    if (length < minLength) {
350:                        String msg = NbBundle.getMessage(AddContactForm.class,
351:                                "Enter_at_least_num", // NOI18N
352:                                Integer.toString(minLength));
353:
354:                        // Indicate the problem to user
355:                        searchMessageLabel.setText(msg); // NOI18N
356:
357:                        return;
358:                    }
359:                }
360:
361:                String txt = findContactTextField.getText();
362:                int searchType = CollabSession.SEARCHTYPE_EQUALS;
363:
364:                if (!isSearchByID()) {
365:                    if (useComboBoxes) {
366:                        switch (optionsComboBox.getSelectedIndex()) {
367:                        case 0:
368:                            searchType = CollabSession.SEARCHTYPE_CONTAINS;
369:
370:                            break;
371:
372:                        case 1:
373:                            searchType = CollabSession.SEARCHTYPE_ENDSWITH;
374:
375:                            break;
376:
377:                        case 2:
378:                            searchType = CollabSession.SEARCHTYPE_STARTSWITH;
379:
380:                            break;
381:                        }
382:                    } else {
383:                        /*
384:                        if (containsOptionRadioButton.isSelected())
385:                                searchType = CollabSession.SEARCHTYPE_CONTAINS;
386:                        else
387:                        if (startsOptionRadioButton.isSelected())
388:                                searchType = CollabSession.SEARCHTYPE_STARTSWITH;
389:                        else
390:                        if (endsOptionRadioButton.isSelected())
391:                                searchType = CollabSession.SEARCHTYPE_ENDSWITH;
392:                         */
393:                        searchType = CollabSession.SEARCHTYPE_CONTAINS;
394:                    }
395:                } else {
396:                    searchType = CollabSession.SEARCHTYPE_EQUALS;
397:                }
398:
399:                Debug.out.println(" search type: " + searchType); // NOI18N
400:                doSearch("", txt, searchType); // NOI18N
401:            }
402:
403:            protected void doSearch(String serv, String txt, int searchType) {
404:                if (_isSearching) {
405:                    return;
406:                }
407:
408:                limitWasExceeded = false;
409:
410:                try {
411:                    _isSearching = true;
412:
413:                    findBtn.setEnabled(false);
414:
415:                    // Indicate that searching has begin
416:                    searchMessageLabel.setText(addContactBundle
417:                            .getString("MSG_AddContactForm_Searching")); // NOI18N
418:
419:                    CollabPrincipal[] users = session.findPrincipals(
420:                            searchType, txt);
421:                    Debug.out.println("Matches found for \"" + txt + "\": "
422:                            + ((users != null) ? ("" + users.length) : "null"));
423:
424:                    if ((users == null) || (users.length == 0)) {
425:                        // Let user know there were no matches
426:                        searchMessageLabel.setText(addContactBundle
427:                                .getString("No_Matches_Found")); // NOI18N
428:                    } else if (users != null) {
429:                        Vector selectedUsersCheck = new Vector(result.size());
430:
431:                        for (int i = 0; i < result.size(); i++) {
432:                            selectedUsersCheck.add(((CollabPrincipal) result
433:                                    .get(i)).getIdentifier());
434:                        }
435:
436:                        if (users.length == 1) {
437:                            Debug.out.println("Search result: "
438:                                    + users[0].getIdentifier());
439:
440:                            if (!selectedUsersCheck.contains(users[0]
441:                                    .getIdentifier())) {
442:                                selectedUsersCheck.addElement(users[0]
443:                                        .getIdentifier());
444:                                result.addElement(users[0]);
445:                                Debug.out.println("Added uid to result: "
446:                                        + users[0].getIdentifier());
447:                            }
448:
449:                            // Indicate that a contact was added
450:                            searchMessageLabel
451:                                    .setText(addContactBundle
452:                                            .getString("MSG_AddContactForm_ContactAdded")); // NOI18N
453:
454:                            contactJList.setListData(result);
455:                            updateValidStatus();
456:                        } else if (users.length > 1) {
457:                            SelectUserForm f = new SelectUserForm(users);
458:                            CollabPrincipal[] ip = f.getSelectedUsers();
459:
460:                            if (ip != null) {
461:                                for (int n = 0; n < ip.length; n++) {
462:                                    Debug.out.println("selected uid = "
463:                                            + ip[n].getIdentifier());
464:
465:                                    if (!selectedUsersCheck.contains(ip[n]
466:                                            .getIdentifier())) {
467:                                        selectedUsersCheck.addElement(ip[n]
468:                                                .getIdentifier());
469:                                        result.addElement(ip[n]);
470:                                        Debug.out
471:                                                .println("added uid to result = "
472:                                                        + ip[n].getIdentifier());
473:                                    }
474:                                }
475:
476:                                // Indicate that a contact was added
477:                                searchMessageLabel
478:                                        .setText(addContactBundle
479:                                                .getString("MSG_AddContactForm_ContactAdded")); // NOI18N
480:
481:                                contactJList.setListData(result);
482:                                updateValidStatus();
483:                            } else {
484:                                Debug.out.println("No search result selected");
485:
486:                                // Indicate that no contacts were added
487:                                searchMessageLabel
488:                                        .setText(addContactBundle
489:                                                .getString("MSG_AddContactForm_ContactSelectionCancelled")); // NOI18N
490:                            }
491:                        }
492:
493:                        for (int i = 0; i < users.length; i++) {
494:                            Debug.out.println("search result: "
495:                                    + users[i].getDisplayName());
496:                        }
497:                    }
498:                } catch (Exception e) {
499:                    e.printStackTrace();
500:                    Debug.logDebugException("Unknown error performing search",
501:                            e, true);
502:
503:                    // TODO: Nice exception dialog here
504:                    Debug.debugNotify(e);
505:
506:                    // Let user know there were no matches due to an error
507:                    searchMessageLabel.setText(addContactBundle
508:                            .getString("No_Matches_Found_Error")); // NOI18N
509:                } finally {
510:                    _isSearching = false;
511:                    findBtn.setEnabled(true);
512:                }
513:            }
514:
515:            public boolean isSearchByID() {
516:                if (useComboBoxes) {
517:                    return (typeComboBox.getSelectedIndex() == 1);
518:                } else {
519:                    return !nameTypeRadioButton.isSelected();
520:                }
521:            }
522:
523:            private Vector toUserName(Vector users) {
524:                Vector names = new Vector(users.size());
525:
526:                for (int i = 0; i < users.size(); i++) {
527:                    names.add(((CollabPrincipal) users.elementAt(i))
528:                            .getDisplayName());
529:                }
530:
531:                return names;
532:            }
533:
534:            /**
535:             *
536:             *
537:             */
538:            protected void updateValidStatus() {
539:                dialogDescriptor
540:                        .setValid(contactJList.getModel().getSize() != 0);
541:            }
542:
543:            /**
544:             *
545:             *
546:             */
547:            protected void updateRemoveButtonState() {
548:                // #6176075 ArrayIndexOutOfBoundsException after removing contacts to add
549:                removeBtn.setEnabled((contactJList.getModel().getSize() > 0)
550:                        && !contactJList.isSelectionEmpty());
551:            }
552:
553:            private boolean sessionExists() {
554:                // check session status #5080138
555:                CollabSession[] sessions = CollabManager.getDefault()
556:                        .getSessions();
557:
558:                for (int i = 0; i < sessions.length; i++) {
559:                    if (sessions[i].equals(this .session)) {
560:                        return true;
561:                    }
562:                }
563:
564:                return false;
565:            }
566:
567:            /** This method is called from within the constructor to
568:             * initialize the form.
569:             * WARNING: Do NOT modify this code. The content of this method is
570:             * always regenerated by the Form Editor.
571:             */
572:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
573:            private void initComponents() {
574:                java.awt.GridBagConstraints gridBagConstraints;
575:
576:                optionsButtonGroup = new javax.swing.ButtonGroup();
577:                typeButtonGroup = new javax.swing.ButtonGroup();
578:                searchPanel = new javax.swing.JPanel();
579:                jPanel2 = new javax.swing.JPanel();
580:                findContactLb = new javax.swing.JLabel();
581:                findContactTextField = new javax.swing.JTextField();
582:                findBtn = new javax.swing.JButton();
583:                optionsLb = new javax.swing.JLabel();
584:                optionsPanel = new javax.swing.JPanel();
585:                containsOptionRadioButton = new javax.swing.JRadioButton();
586:                startsOptionRadioButton = new javax.swing.JRadioButton();
587:                endsOptionRadioButton = new javax.swing.JRadioButton();
588:                optionsComboBox = new javax.swing.JComboBox();
589:                TypeLb = new javax.swing.JLabel();
590:                typePanel = new javax.swing.JPanel();
591:                nameTypeRadioButton = new javax.swing.JRadioButton();
592:                userIDTypeRadioButton = new javax.swing.JRadioButton();
593:                typeComboBox = new javax.swing.JComboBox();
594:                searchMessageLabel = new javax.swing.JLabel();
595:                resultsPanel1 = new javax.swing.JPanel();
596:                jPanel1 = new javax.swing.JPanel();
597:                jScrollPane1 = new javax.swing.JScrollPane();
598:                contactJList = new javax.swing.JList();
599:                removeBtn = new javax.swing.JButton();
600:                addToLbl = new javax.swing.JLabel();
601:                groupComboBox = new javax.swing.JComboBox();
602:
603:                FormListener formListener = new FormListener();
604:
605:                setLayout(new java.awt.GridBagLayout());
606:
607:                setBorder(javax.swing.BorderFactory
608:                        .createCompoundBorder(javax.swing.BorderFactory
609:                                .createEmptyBorder(5, 5, 5, 5), null));
610:                setMinimumSize(new java.awt.Dimension(600, 400));
611:                setPreferredSize(new java.awt.Dimension(440, 400));
612:                searchPanel.setLayout(new java.awt.GridBagLayout());
613:
614:                searchPanel
615:                        .setBorder(javax.swing.BorderFactory
616:                                .createCompoundBorder(
617:                                        javax.swing.BorderFactory
618:                                                .createTitledBorder(org.openide.util.NbBundle
619:                                                        .getMessage(
620:                                                                AddContactForm.class,
621:                                                                "KEY_AddContactForm_SearchPanelTitle")),
622:                                        javax.swing.BorderFactory
623:                                                .createEmptyBorder(5, 5, 5, 5))); // NOI18N
624:                jPanel2.setLayout(new java.awt.GridBagLayout());
625:
626:                findContactLb.setLabelFor(findContactTextField);
627:                org.openide.awt.Mnemonics.setLocalizedText(findContactLb,
628:                        org.openide.util.NbBundle.getMessage(
629:                                AddContactForm.class,
630:                                "LBL_AddContactForm_FindContact")); // NOI18N
631:                gridBagConstraints = new java.awt.GridBagConstraints();
632:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
633:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
634:                gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 5);
635:                jPanel2.add(findContactLb, gridBagConstraints);
636:
637:                findContactTextField.setColumns(32);
638:                findContactTextField.addActionListener(formListener);
639:
640:                gridBagConstraints = new java.awt.GridBagConstraints();
641:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
642:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
643:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
644:                gridBagConstraints.weightx = 1.0;
645:                gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 5);
646:                jPanel2.add(findContactTextField, gridBagConstraints);
647:
648:                org.openide.awt.Mnemonics.setLocalizedText(findBtn,
649:                        org.openide.util.NbBundle
650:                                .getMessage(AddContactForm.class,
651:                                        "BTN_AddContactForm_Find")); // NOI18N
652:                findBtn.setEnabled(false);
653:                findBtn.addActionListener(formListener);
654:
655:                gridBagConstraints = new java.awt.GridBagConstraints();
656:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
657:                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
658:                jPanel2.add(findBtn, gridBagConstraints);
659:
660:                org.openide.awt.Mnemonics.setLocalizedText(optionsLb,
661:                        org.openide.util.NbBundle.getMessage(
662:                                AddContactForm.class,
663:                                "LBL_AddContactForm_Options")); // NOI18N
664:                gridBagConstraints = new java.awt.GridBagConstraints();
665:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
666:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
667:                gridBagConstraints.insets = new java.awt.Insets(3, 0, 5, 5);
668:                jPanel2.add(optionsLb, gridBagConstraints);
669:
670:                optionsButtonGroup.add(containsOptionRadioButton);
671:                containsOptionRadioButton.setSelected(true);
672:                org.openide.awt.Mnemonics.setLocalizedText(
673:                        containsOptionRadioButton, org.openide.util.NbBundle
674:                                .getMessage(AddContactForm.class,
675:                                        "LBL_AddContactForm_Contains")); // NOI18N
676:                optionsPanel.add(containsOptionRadioButton);
677:
678:                optionsButtonGroup.add(startsOptionRadioButton);
679:                org.openide.awt.Mnemonics.setLocalizedText(
680:                        startsOptionRadioButton, org.openide.util.NbBundle
681:                                .getMessage(AddContactForm.class,
682:                                        "LBL_AddContactForm_Starts")); // NOI18N
683:                optionsPanel.add(startsOptionRadioButton);
684:
685:                optionsButtonGroup.add(endsOptionRadioButton);
686:                org.openide.awt.Mnemonics.setLocalizedText(
687:                        endsOptionRadioButton, org.openide.util.NbBundle
688:                                .getMessage(AddContactForm.class,
689:                                        "LBL_AddContactForm_Ends")); // NOI18N
690:                optionsPanel.add(endsOptionRadioButton);
691:
692:                gridBagConstraints = new java.awt.GridBagConstraints();
693:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
694:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
695:                gridBagConstraints.weightx = 1.0;
696:                gridBagConstraints.weighty = 1.0;
697:                jPanel2.add(optionsPanel, gridBagConstraints);
698:
699:                gridBagConstraints = new java.awt.GridBagConstraints();
700:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
701:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
702:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
703:                gridBagConstraints.weightx = 1.0;
704:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 5, 0);
705:                jPanel2.add(optionsComboBox, gridBagConstraints);
706:
707:                org.openide.awt.Mnemonics.setLocalizedText(TypeLb,
708:                        org.openide.util.NbBundle
709:                                .getMessage(AddContactForm.class,
710:                                        "LBL_AddContactForm_Type")); // NOI18N
711:                gridBagConstraints = new java.awt.GridBagConstraints();
712:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
713:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
714:                gridBagConstraints.insets = new java.awt.Insets(3, 0, 5, 5);
715:                jPanel2.add(TypeLb, gridBagConstraints);
716:
717:                typeButtonGroup.add(nameTypeRadioButton);
718:                nameTypeRadioButton.setSelected(true);
719:                org.openide.awt.Mnemonics.setLocalizedText(nameTypeRadioButton,
720:                        org.openide.util.NbBundle
721:                                .getMessage(AddContactForm.class,
722:                                        "LBL_AddContactForm_Name")); // NOI18N
723:                typePanel.add(nameTypeRadioButton);
724:
725:                typeButtonGroup.add(userIDTypeRadioButton);
726:                org.openide.awt.Mnemonics.setLocalizedText(
727:                        userIDTypeRadioButton, org.openide.util.NbBundle
728:                                .getMessage(AddContactForm.class,
729:                                        "LBL_AddContactForm_UserID")); // NOI18N
730:                typePanel.add(userIDTypeRadioButton);
731:
732:                gridBagConstraints = new java.awt.GridBagConstraints();
733:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
734:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
735:                jPanel2.add(typePanel, gridBagConstraints);
736:
737:                typeComboBox.addItemListener(formListener);
738:
739:                gridBagConstraints = new java.awt.GridBagConstraints();
740:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
741:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
742:                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
743:                jPanel2.add(typeComboBox, gridBagConstraints);
744:
745:                gridBagConstraints = new java.awt.GridBagConstraints();
746:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
747:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
748:                gridBagConstraints.weightx = 1.0;
749:                searchPanel.add(jPanel2, gridBagConstraints);
750:
751:                searchMessageLabel.setForeground(new java.awt.Color(0, 0, 255));
752:                gridBagConstraints = new java.awt.GridBagConstraints();
753:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
754:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
755:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
756:                gridBagConstraints.weightx = 1.0;
757:                gridBagConstraints.weighty = 1.0;
758:                gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
759:                searchPanel.add(searchMessageLabel, gridBagConstraints);
760:
761:                gridBagConstraints = new java.awt.GridBagConstraints();
762:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
763:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
764:                add(searchPanel, gridBagConstraints);
765:
766:                resultsPanel1.setLayout(new java.awt.GridBagLayout());
767:
768:                resultsPanel1
769:                        .setBorder(javax.swing.BorderFactory
770:                                .createCompoundBorder(
771:                                        javax.swing.BorderFactory
772:                                                .createTitledBorder(org.openide.util.NbBundle
773:                                                        .getMessage(
774:                                                                AddContactForm.class,
775:                                                                "LBL_AddContactForm_searchResultLabel")),
776:                                        javax.swing.BorderFactory
777:                                                .createEmptyBorder(5, 5, 5, 5))); // NOI18N
778:                jPanel1.setLayout(new java.awt.GridBagLayout());
779:
780:                contactJList.setMaximumSize(null);
781:                contactJList.setMinimumSize(null);
782:                contactJList.setPreferredSize(null);
783:                contactJList.setVisibleRowCount(10);
784:                jScrollPane1.setViewportView(contactJList);
785:
786:                gridBagConstraints = new java.awt.GridBagConstraints();
787:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
788:                gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
789:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
790:                gridBagConstraints.weightx = 1.0;
791:                gridBagConstraints.weighty = 1.0;
792:                jPanel1.add(jScrollPane1, gridBagConstraints);
793:
794:                gridBagConstraints = new java.awt.GridBagConstraints();
795:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
796:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
797:                gridBagConstraints.weightx = 1.0;
798:                gridBagConstraints.weighty = 1.0;
799:                resultsPanel1.add(jPanel1, gridBagConstraints);
800:
801:                org.openide.awt.Mnemonics.setLocalizedText(removeBtn,
802:                        org.openide.util.NbBundle.getMessage(
803:                                AddContactForm.class,
804:                                "BTN_AddContactForm_Remove")); // NOI18N
805:                removeBtn.setEnabled(false);
806:                removeBtn.addActionListener(formListener);
807:
808:                gridBagConstraints = new java.awt.GridBagConstraints();
809:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
810:                gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
811:                gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 0);
812:                resultsPanel1.add(removeBtn, gridBagConstraints);
813:
814:                gridBagConstraints = new java.awt.GridBagConstraints();
815:                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
816:                gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
817:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
818:                gridBagConstraints.weightx = 1.0;
819:                gridBagConstraints.weighty = 1.0;
820:                add(resultsPanel1, gridBagConstraints);
821:
822:                addToLbl.setLabelFor(groupComboBox);
823:                org.openide.awt.Mnemonics.setLocalizedText(addToLbl,
824:                        org.openide.util.NbBundle.getMessage(
825:                                AddContactForm.class,
826:                                "LBL_AddContactForm_AddContactTo")); // NOI18N
827:                gridBagConstraints = new java.awt.GridBagConstraints();
828:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
829:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
830:                gridBagConstraints.insets = new java.awt.Insets(5, 3, 0, 5);
831:                add(addToLbl, gridBagConstraints);
832:
833:                groupComboBox.addActionListener(formListener);
834:
835:                gridBagConstraints = new java.awt.GridBagConstraints();
836:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
837:                gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
838:                gridBagConstraints.weightx = 1.0;
839:                gridBagConstraints.insets = new java.awt.Insets(5, 0, 0, 3);
840:                add(groupComboBox, gridBagConstraints);
841:
842:            }
843:
844:            // Code for dispatching events from components to event handlers.
845:
846:            private class FormListener implements 
847:                    java.awt.event.ActionListener, java.awt.event.ItemListener {
848:                FormListener() {
849:                }
850:
851:                public void actionPerformed(java.awt.event.ActionEvent evt) {
852:                    if (evt.getSource() == findContactTextField) {
853:                        AddContactForm.this 
854:                                .findContactTextFieldActionPerformed(evt);
855:                    } else if (evt.getSource() == findBtn) {
856:                        AddContactForm.this .findBtnActionPerformed(evt);
857:                    } else if (evt.getSource() == removeBtn) {
858:                        AddContactForm.this .removeBtnActionPerformed(evt);
859:                    } else if (evt.getSource() == groupComboBox) {
860:                        AddContactForm.this .groupComboBoxActionPerformed(evt);
861:                    }
862:                }
863:
864:                public void itemStateChanged(java.awt.event.ItemEvent evt) {
865:                    if (evt.getSource() == typeComboBox) {
866:                        AddContactForm.this .typeComboBoxItemStateChanged(evt);
867:                    }
868:                }
869:            }// </editor-fold>//GEN-END:initComponents
870:
871:            private void findContactTextFieldActionPerformed(
872:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findContactTextFieldActionPerformed
873:                search();
874:                findContactTextField.selectAll();
875:                findContactTextField.requestFocus();
876:            }//GEN-LAST:event_findContactTextFieldActionPerformed
877:
878:            private void findBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findBtnActionPerformed
879:                search();
880:                findContactTextField.selectAll();
881:                findContactTextField.requestFocus();
882:            }//GEN-LAST:event_findBtnActionPerformed
883:
884:            private void groupComboBoxActionPerformed(
885:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_groupComboBoxActionPerformed
886:
887:                // TODO add your handling code here:
888:            }//GEN-LAST:event_groupComboBoxActionPerformed
889:
890:            private void removeBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeBtnActionPerformed
891:
892:                // Remove the selected contacts from the list
893:                int[] selected = contactJList.getSelectedIndices();
894:
895:                // Retrieve the set of selected elements
896:                List selectedElements = new ArrayList();
897:
898:                for (int i = 0; i < selected.length; i++) {
899:                    selectedElements.add(contactJList.getModel().getElementAt(
900:                            selected[i]));
901:                }
902:
903:                // Remove the elements from the model's vector by identity
904:                for (Iterator i = selectedElements.iterator(); i.hasNext();)
905:                    result.removeElement(i.next());
906:
907:                contactJList.clearSelection();
908:                contactJList.updateUI();
909:                updateValidStatus();
910:                updateRemoveButtonState();
911:            }//GEN-LAST:event_removeBtnActionPerformed
912:
913:            private void typeComboBoxItemStateChanged(
914:                    java.awt.event.ItemEvent evt) {//GEN-FIRST:event_typeComboBoxItemStateChanged
915:
916:                // TODO add your handling code here:
917:            }//GEN-LAST:event_typeComboBoxItemStateChanged
918:
919:            public void valueChanged(ListSelectionEvent event) {
920:                updateRemoveButtonState();
921:            }
922:
923:            // Variables declaration - do not modify//GEN-BEGIN:variables
924:            private javax.swing.JLabel TypeLb;
925:            private javax.swing.JLabel addToLbl;
926:            private javax.swing.JList contactJList;
927:            private javax.swing.JRadioButton containsOptionRadioButton;
928:            private javax.swing.JRadioButton endsOptionRadioButton;
929:            private javax.swing.JButton findBtn;
930:            private javax.swing.JLabel findContactLb;
931:            private javax.swing.JTextField findContactTextField;
932:            private javax.swing.JComboBox groupComboBox;
933:            private javax.swing.JPanel jPanel1;
934:            private javax.swing.JPanel jPanel2;
935:            private javax.swing.JScrollPane jScrollPane1;
936:            private javax.swing.JRadioButton nameTypeRadioButton;
937:            private javax.swing.ButtonGroup optionsButtonGroup;
938:            private javax.swing.JComboBox optionsComboBox;
939:            private javax.swing.JLabel optionsLb;
940:            private javax.swing.JPanel optionsPanel;
941:            private javax.swing.JButton removeBtn;
942:            private javax.swing.JPanel resultsPanel1;
943:            private javax.swing.JLabel searchMessageLabel;
944:            private javax.swing.JPanel searchPanel;
945:            private javax.swing.JRadioButton startsOptionRadioButton;
946:            private javax.swing.ButtonGroup typeButtonGroup;
947:            private javax.swing.JComboBox typeComboBox;
948:            private javax.swing.JPanel typePanel;
949:            private javax.swing.JRadioButton userIDTypeRadioButton;
950:            // End of variables declaration//GEN-END:variables
951:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.