Source Code Cross Referenced for ServersCustomizer.java in  » 6.0-JDK-Core » j2eeserver » org » netbeans » modules » j2ee » deployment » impl » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
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
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » j2eeserver » org.netbeans.modules.j2ee.deployment.impl.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
042        package org.netbeans.modules.j2ee.deployment.impl.ui;
043
044        import java.awt.CardLayout;
045        import java.awt.Component;
046        import java.awt.Container;
047        import java.awt.Dimension;
048        import java.awt.GridBagConstraints;
049        import java.awt.GridBagLayout;
050        import java.awt.Image;
051        import java.awt.Window;
052        import java.beans.PropertyChangeListener;
053        import java.beans.PropertyChangeEvent;
054        import java.beans.PropertyVetoException;
055        import java.beans.VetoableChangeListener;
056        import java.util.ArrayList;
057        import java.util.Collection;
058        import java.util.Collections;
059        import java.util.HashMap;
060        import java.util.Iterator;
061        import java.util.List;
062        import javax.swing.UIManager;
063        import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
064        import org.netbeans.modules.j2ee.deployment.impl.ServerInstanceLookup;
065        import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
066        import org.netbeans.modules.j2ee.deployment.impl.ui.wizard.AddServerInstanceWizard;
067        import org.openide.nodes.Node;
068        import org.openide.explorer.ExplorerManager;
069        import org.openide.explorer.view.BeanTreeView;
070        import org.openide.filesystems.Repository;
071        import org.openide.loaders.DataFolder;
072        import org.openide.nodes.AbstractNode;
073        import org.openide.nodes.Children;
074        import org.openide.nodes.FilterNode;
075        import org.openide.util.NbBundle;
076
077        /**
078         * Servers customizer displays a list of registered server and allows to add,
079         * remove and configure them.
080         *
081         * @author  Stepan Herold
082         */
083        public class ServersCustomizer extends javax.swing.JPanel implements 
084                PropertyChangeListener, VetoableChangeListener,
085                ExplorerManager.Provider {
086
087            private static final Dimension MINIMUM_SIZE = new Dimension(720,
088                    400);
089
090            private ServerCategoriesChildren children;
091            private ExplorerManager manager;
092            private ServerInstance initialInstance;
093
094            /** Creates new form PlatformsCustomizer */
095            public ServersCustomizer(ServerInstance initialInstance) {
096                initComponents();
097                serverName.setColumns(30);
098                serverType.setColumns(30);
099                // set the preferred width, height is not very important here
100                servers.setPreferredSize(new Dimension(200, 200));
101                this .initialInstance = initialInstance;
102                setPreferredSize(MINIMUM_SIZE);
103            }
104
105            public void propertyChange(PropertyChangeEvent evt) {
106                if (ExplorerManager.PROP_SELECTED_NODES.equals(evt
107                        .getPropertyName())) {
108                    Node[] nodes = (Node[]) evt.getNewValue();
109                    if (nodes.length != 1) {
110                        selectServer(null);
111                    } else {
112                        selectServer(nodes[0]);
113                    }
114                }
115            }
116
117            public void vetoableChange(PropertyChangeEvent evt)
118                    throws PropertyVetoException {
119                if (ExplorerManager.PROP_SELECTED_NODES.equals(evt
120                        .getPropertyName())) {
121                    Node[] nodes = (Node[]) evt.getNewValue();
122                    if (nodes.length > 1) {
123                        throw new PropertyVetoException("Invalid length", evt); //NOI18N
124                    }
125                }
126            }
127
128            public synchronized ExplorerManager getExplorerManager() {
129                if (this .manager == null) {
130                    this .manager = new ExplorerManager();
131                    this .manager
132                            .setRootContext(new AbstractNode(getChildren()));
133                    this .manager.addPropertyChangeListener(this );
134                    this .manager.addVetoableChangeListener(this );
135                }
136                return manager;
137            }
138
139            public void addNotify() {
140                super .addNotify();
141                expandServers(initialInstance);
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                java.awt.GridBagConstraints gridBagConstraints;
152
153                jPanel3 = new javax.swing.JPanel();
154                servers = new PlatformsView();
155                addButton = new javax.swing.JButton();
156                removeButton = new javax.swing.JButton();
157                cards = new javax.swing.JPanel();
158                messageArea = new javax.swing.JPanel();
159                jPanel1 = new javax.swing.JPanel();
160                jLabel1 = new javax.swing.JLabel();
161                serverName = new javax.swing.JTextField();
162                jLabel2 = new javax.swing.JLabel();
163                serverType = new javax.swing.JTextField();
164                clientArea = new javax.swing.JPanel();
165                serversLabel = new javax.swing.JLabel();
166
167                setLayout(new java.awt.GridBagLayout());
168
169                servers.setPreferredSize(new java.awt.Dimension(220, 400));
170                gridBagConstraints = new java.awt.GridBagConstraints();
171                gridBagConstraints.gridx = 0;
172                gridBagConstraints.gridy = 1;
173                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.RELATIVE;
174                gridBagConstraints.gridheight = java.awt.GridBagConstraints.RELATIVE;
175                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
176                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
177                gridBagConstraints.weighty = 1.0;
178                gridBagConstraints.insets = new java.awt.Insets(3, 12, 6, 6);
179                add(servers, gridBagConstraints);
180                servers.getAccessibleContext().setAccessibleName(
181                        org.openide.util.NbBundle.getMessage(
182                                ServersCustomizer.class,
183                                "ASCN_InstalledServers")); // NOI18N
184                servers.getAccessibleContext().setAccessibleDescription(
185                        org.openide.util.NbBundle.getMessage(
186                                ServersCustomizer.class,
187                                "ASCD_InstalledServers")); // NOI18N
188
189                org.openide.awt.Mnemonics.setLocalizedText(addButton, NbBundle
190                        .getMessage(ServersCustomizer.class, "CTL_AddServer")); // NOI18N
191                addButton
192                        .addActionListener(new java.awt.event.ActionListener() {
193                            public void actionPerformed(
194                                    java.awt.event.ActionEvent evt) {
195                                addServer(evt);
196                            }
197                        });
198                gridBagConstraints = new java.awt.GridBagConstraints();
199                gridBagConstraints.gridx = 0;
200                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
201                gridBagConstraints.insets = new java.awt.Insets(6, 12, 12, 0);
202                add(addButton, gridBagConstraints);
203                addButton.getAccessibleContext().setAccessibleName(
204                        org.openide.util.NbBundle.getMessage(
205                                ServersCustomizer.class, "ASCN_AddServer")); // NOI18N
206                addButton.getAccessibleContext().setAccessibleDescription(
207                        org.openide.util.NbBundle.getMessage(
208                                ServersCustomizer.class, "ASCD_AddServer")); // NOI18N
209
210                org.openide.awt.Mnemonics.setLocalizedText(removeButton,
211                        NbBundle.getMessage(ServersCustomizer.class,
212                                "CTL_Remove")); // NOI18N
213                removeButton.setEnabled(false);
214                removeButton
215                        .addActionListener(new java.awt.event.ActionListener() {
216                            public void actionPerformed(
217                                    java.awt.event.ActionEvent evt) {
218                                removeServer(evt);
219                            }
220                        });
221                gridBagConstraints = new java.awt.GridBagConstraints();
222                gridBagConstraints.gridx = 1;
223                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
224                gridBagConstraints.insets = new java.awt.Insets(6, 6, 12, 6);
225                add(removeButton, gridBagConstraints);
226                removeButton.getAccessibleContext().setAccessibleName(
227                        org.openide.util.NbBundle.getMessage(
228                                ServersCustomizer.class, "ASCN_Remove")); // NOI18N
229                removeButton.getAccessibleContext().setAccessibleDescription(
230                        org.openide.util.NbBundle.getMessage(
231                                ServersCustomizer.class, "ASCD_Remove")); // NOI18N
232
233                cards.setLayout(new java.awt.CardLayout());
234
235                messageArea.setLayout(new java.awt.GridBagLayout());
236                cards.add(messageArea, "card3");
237
238                jPanel1.setLayout(new java.awt.GridBagLayout());
239
240                jLabel1.setLabelFor(serverName);
241                org.openide.awt.Mnemonics.setLocalizedText(jLabel1, NbBundle
242                        .getMessage(ServersCustomizer.class, "CTL_ServerName")); // NOI18N
243                gridBagConstraints = new java.awt.GridBagConstraints();
244                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
245                jPanel1.add(jLabel1, gridBagConstraints);
246                jLabel1.getAccessibleContext().setAccessibleName(
247                        org.openide.util.NbBundle.getMessage(
248                                ServersCustomizer.class, "ASCN_ServerName")); // NOI18N
249                jLabel1.getAccessibleContext().setAccessibleDescription(
250                        org.openide.util.NbBundle.getMessage(
251                                ServersCustomizer.class, "ASCD_ServerName")); // NOI18N
252
253                serverName.setEditable(false);
254                gridBagConstraints = new java.awt.GridBagConstraints();
255                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
256                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
257                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
258                gridBagConstraints.weightx = 1.0;
259                gridBagConstraints.insets = new java.awt.Insets(0, 6, 0, 0);
260                jPanel1.add(serverName, gridBagConstraints);
261                serverName.getAccessibleContext().setAccessibleName(
262                        org.openide.util.NbBundle.getMessage(
263                                ServersCustomizer.class, "ASCN_ServerName")); // NOI18N
264                serverName.getAccessibleContext().setAccessibleDescription(
265                        org.openide.util.NbBundle.getMessage(
266                                ServersCustomizer.class, "ASCD_ServerName")); // NOI18N
267
268                jLabel2.setLabelFor(serverType);
269                org.openide.awt.Mnemonics.setLocalizedText(jLabel2, NbBundle
270                        .getMessage(ServersCustomizer.class, "CTL_ServerType")); // NOI18N
271                gridBagConstraints = new java.awt.GridBagConstraints();
272                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
273                gridBagConstraints.insets = new java.awt.Insets(6, 0, 12, 0);
274                jPanel1.add(jLabel2, gridBagConstraints);
275                jLabel2.getAccessibleContext().setAccessibleName(
276                        org.openide.util.NbBundle.getMessage(
277                                ServersCustomizer.class, "ASCN_ServerType")); // NOI18N
278                jLabel2.getAccessibleContext().setAccessibleDescription(
279                        org.openide.util.NbBundle.getMessage(
280                                ServersCustomizer.class, "ASCD_Server Type")); // NOI18N
281
282                serverType.setEditable(false);
283                gridBagConstraints = new java.awt.GridBagConstraints();
284                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
285                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
286                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
287                gridBagConstraints.weightx = 1.0;
288                gridBagConstraints.insets = new java.awt.Insets(6, 6, 12, 0);
289                jPanel1.add(serverType, gridBagConstraints);
290                serverType.getAccessibleContext().setAccessibleName(
291                        org.openide.util.NbBundle.getMessage(
292                                ServersCustomizer.class, "ASCN_ServerType")); // NOI18N
293                serverType.getAccessibleContext().setAccessibleDescription(
294                        org.openide.util.NbBundle.getMessage(
295                                ServersCustomizer.class, "ASCD_Server Type")); // NOI18N
296
297                clientArea.setLayout(new java.awt.GridBagLayout());
298                gridBagConstraints = new java.awt.GridBagConstraints();
299                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
300                gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
301                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
302                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
303                gridBagConstraints.weightx = 1.0;
304                gridBagConstraints.weighty = 1.0;
305                jPanel1.add(clientArea, gridBagConstraints);
306
307                cards.add(jPanel1, "card2");
308
309                gridBagConstraints = new java.awt.GridBagConstraints();
310                gridBagConstraints.gridx = 2;
311                gridBagConstraints.gridy = 1;
312                gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
313                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
314                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
315                gridBagConstraints.weightx = 1.0;
316                gridBagConstraints.weighty = 1.0;
317                gridBagConstraints.insets = new java.awt.Insets(6, 6, 6, 12);
318                add(cards, gridBagConstraints);
319
320                serversLabel.setLabelFor(servers);
321                org.openide.awt.Mnemonics.setLocalizedText(serversLabel,
322                        org.openide.util.NbBundle.getMessage(
323                                ServersCustomizer.class, "CTL_Servers")); // NOI18N
324                gridBagConstraints = new java.awt.GridBagConstraints();
325                gridBagConstraints.gridx = 0;
326                gridBagConstraints.gridy = 0;
327                gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
328                gridBagConstraints.insets = new java.awt.Insets(12, 12, 0, 0);
329                add(serversLabel, gridBagConstraints);
330                serversLabel.getAccessibleContext().setAccessibleName(
331                        org.openide.util.NbBundle.getMessage(
332                                ServersCustomizer.class, "LBL_Servers")); // NOI18N
333                java.util.ResourceBundle bundle = java.util.ResourceBundle
334                        .getBundle("org/netbeans/modules/j2ee/deployment/impl/ui/Bundle"); // NOI18N
335                serversLabel.getAccessibleContext().setAccessibleDescription(
336                        bundle.getString("ACSD_ServerList")); // NOI18N
337
338                getAccessibleContext().setAccessibleName(
339                        bundle.getString("ASCN_ServerManager")); // NOI18N
340                getAccessibleContext().setAccessibleDescription(
341                        org.openide.util.NbBundle.getMessage(
342                                ServersCustomizer.class,
343                                "ASCD_ServerCustomizer")); // NOI18N
344            }// </editor-fold>//GEN-END:initComponents
345
346            private void removeServer(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeServer
347                Node[] nodes = getExplorerManager().getSelectedNodes();
348                if (nodes.length != 1) {
349                    assert false : "Illegal number of selected nodes"; //NOI18N
350                    return;
351                }
352                if (nodes[0] instanceof  ServerNode) {
353                    ServerInstance serverInstance = ((ServerNode) nodes[0])
354                            .getServerInstance();
355                    if (!serverInstance.isRemoveForbidden()) {
356                        serverInstance.remove();
357                        getChildren().refreshServers();
358                        expandServers(null);
359                    }
360                }
361            }//GEN-LAST:event_removeServer
362
363            private void addServer(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addServer
364                String serverInstanceId = AddServerInstanceWizard
365                        .showAddServerInstanceWizard();
366                if (serverInstanceId != null) {
367                    getChildren().refreshServers();
368                    ServerInstance serverInstance = ServerRegistry
369                            .getInstance().getServerInstance(serverInstanceId);
370                    if (serverInstance != null) {
371                        expandServers(serverInstance);
372                    }
373                }
374            }//GEN-LAST:event_addServer
375
376            private synchronized ServerCategoriesChildren getChildren() {
377                if (this .children == null) {
378                    this .children = new ServerCategoriesChildren();
379                }
380                return this .children;
381            }
382
383            private void selectServer(Node aNode) {
384                clientArea.removeAll();
385
386                if (aNode instanceof  ServerNode) {
387                    ServerInstance serverInstance = ((ServerNode) aNode)
388                            .getServerInstance();
389                    serverName.setText(serverInstance.getDisplayName());
390                    serverType.setText(serverInstance.getServer()
391                            .getDisplayName());
392                    if (serverInstance.isRemoveForbidden()) {
393                        removeButton.setEnabled(false);
394                    } else {
395                        removeButton.setEnabled(true);
396                    }
397                } else {
398                    removeButton.setEnabled(false);
399                    ((CardLayout) cards.getLayout()).first(cards);
400                    return;
401                }
402
403                if (aNode.hasCustomizer()) {
404                    Component component = aNode.getCustomizer();
405                    if (component != null) {
406                        addComponent(clientArea, component);
407                    }
408                }
409                // handle the correct window size
410                int height = getHeight();
411                int width = getWidth();
412                // reset the preferred size so that it can be computed during revalidation
413                setPreferredSize(null);
414                revalidate();
415                // now we have the new computed preferred size
416                Dimension prefSize = getPreferredSize();
417                int prefWidth = (int) (prefSize.getWidth() > MINIMUM_SIZE
418                        .getWidth() ? prefSize.getWidth() : MINIMUM_SIZE
419                        .getWidth());
420                int prefHeight = (int) (prefSize.getHeight() > MINIMUM_SIZE
421                        .getHeight() ? prefSize.getHeight() : MINIMUM_SIZE
422                        .getHeight());
423                // do we need to resize the manager window?
424                if (prefHeight > height || prefWidth > width) {
425                    setPreferredSize(new Dimension(
426                            prefWidth > width ? prefWidth : width,
427                            prefHeight > height ? prefHeight : height));
428                    // repack the parent window
429                    for (Container parent = getParent(); parent != null; parent = parent
430                            .getParent()) {
431                        if (parent instanceof  Window) {
432                            ((Window) parent).pack();
433                            break;
434                        }
435                    }
436                }
437                CardLayout cl = (CardLayout) cards.getLayout();
438                cl.last(cards);
439            }
440
441            private static void addComponent(Container container,
442                    Component component) {
443                GridBagConstraints c = new GridBagConstraints();
444                c.gridx = c.gridy = GridBagConstraints.RELATIVE;
445                c.gridheight = c.gridwidth = GridBagConstraints.REMAINDER;
446                c.fill = GridBagConstraints.BOTH;
447                c.anchor = GridBagConstraints.NORTHWEST;
448                c.weightx = c.weighty = 1.0;
449                ((GridBagLayout) container.getLayout()).setConstraints(
450                        component, c);
451                container.add(component);
452            }
453
454            private void expandServers(ServerInstance servInst) {
455                ExplorerManager mgr = this .getExplorerManager();
456                Node node = mgr.getRootContext();
457                expandAllNodes(servers, node, mgr, servInst);
458            }
459
460            private static void expandAllNodes(BeanTreeView btv, Node node,
461                    ExplorerManager mgr, ServerInstance servInst) {
462                btv.expandNode(node);
463                Children ch = node.getChildren();
464
465                // preselect node for the specified server instance
466                if (servInst != null && ch == Children.LEAF
467                        && node instanceof  ServerNode) {
468                    try {
469                        if (((ServerNode) node).getServerInstance() == servInst) {
470                            mgr.setSelectedNodes(new Node[] { node });
471                        }
472                    } catch (PropertyVetoException e) {
473                        //Ignore it
474                    }
475                }
476
477                // preselect first server
478                if (servInst == null && ch == Children.LEAF
479                        && mgr.getSelectedNodes().length == 0) {
480                    try {
481                        mgr.setSelectedNodes(new Node[] { node });
482                    } catch (PropertyVetoException e) {
483                        //Ignore it
484                    }
485                }
486                Node nodes[] = ch.getNodes(true);
487                for (int i = 0; i < nodes.length; i++) {
488                    expandAllNodes(btv, nodes[i], mgr, servInst);
489                }
490            }
491
492            // Variables declaration - do not modify//GEN-BEGIN:variables
493            private javax.swing.JButton addButton;
494            private javax.swing.JPanel cards;
495            private javax.swing.JPanel clientArea;
496            private javax.swing.JLabel jLabel1;
497            private javax.swing.JLabel jLabel2;
498            private javax.swing.JPanel jPanel1;
499            private javax.swing.JPanel jPanel3;
500            private javax.swing.JPanel messageArea;
501            private javax.swing.JButton removeButton;
502            private javax.swing.JTextField serverName;
503            private javax.swing.JTextField serverType;
504            private org.openide.explorer.view.BeanTreeView servers;
505            private javax.swing.JLabel serversLabel;
506
507            // End of variables declaration//GEN-END:variables
508
509            private static class PlatformsView extends BeanTreeView {
510
511                public PlatformsView() {
512                    super ();
513                    this .setPopupAllowed(false);
514                    this .setDefaultActionAllowed(false);
515                    this .setRootVisible(false);
516                    this .tree.setEditable(false);
517                    this .tree.setShowsRootHandles(false);
518                    this .setBorder(UIManager.getBorder("Nb.ScrollPane.border")); // NOI18N
519                }
520
521            }
522
523            private static class ServerCategoriesDescriptor implements 
524                    Comparable {
525                private final String categoryName;
526                private final List/*<Node>*/servers;
527
528                public ServerCategoriesDescriptor(String categoryName) {
529                    assert categoryName != null;
530                    this .categoryName = categoryName;
531                    this .servers = new ArrayList();
532                }
533
534                public String getName() {
535                    return categoryName;
536                }
537
538                public List getServers() {
539                    Collections.sort(servers);
540                    return Collections.unmodifiableList(servers);
541                }
542
543                public void add(Node node) {
544                    servers.add(node);
545                }
546
547                public int hashCode() {
548                    return categoryName.hashCode();
549                }
550
551                public boolean equals(Object other) {
552                    if (other instanceof  ServerCategoriesDescriptor) {
553                        ServerCategoriesDescriptor desc = (ServerCategoriesDescriptor) other;
554                        return categoryName.equals(desc.categoryName)
555                                && servers.size() == desc.servers.size();
556                    }
557                    return false;
558                }
559
560                public int compareTo(Object other) {
561                    if (!(other instanceof  ServerCategoriesDescriptor)) {
562                        throw new IllegalArgumentException();
563                    }
564                    ServerCategoriesDescriptor desc = (ServerCategoriesDescriptor) other;
565                    return categoryName.compareTo(desc.categoryName);
566                }
567
568            }
569
570            private static class ServersChildren extends Children.Keys {
571
572                private List servers;
573
574                public ServersChildren(List/*<Node>*/servers) {
575                    this .servers = servers;
576                }
577
578                protected void addNotify() {
579                    super .addNotify();
580                    this .setKeys(this .servers);
581                }
582
583                protected void removeNotify() {
584                    super .removeNotify();
585                    this .setKeys(new Object[0]);
586                }
587
588                protected Node[] createNodes(Object key) {
589                    return new Node[] { (Node) key };
590                }
591            }
592
593            private static class ServerNode extends FilterNode implements 
594                    Comparable {
595
596                private final ServerInstance serverInstance;
597
598                public ServerNode(ServerInstance serverInstance) {
599                    super (serverInstance.getServer().getRegistryNodeFactory()
600                            .getManagerNode(
601                                    new ServerInstanceLookup(serverInstance,
602                                            serverInstance.getServer()
603                                                    .getDeploymentFactory(),
604                                            null)));
605                    disableDelegation(DELEGATE_GET_DISPLAY_NAME
606                            | DELEGATE_SET_DISPLAY_NAME | DELEGATE_GET_NAME
607                            | DELEGATE_SET_NAME);
608                    this .serverInstance = serverInstance;
609                    setChildren(Children.LEAF);
610                    setDisplayName(serverInstance.getDisplayName());
611                    setName(serverInstance.getUrl());
612                }
613
614                public ServerInstance getServerInstance() {
615                    return serverInstance;
616                }
617
618                public int compareTo(Object other) {
619                    if (!(other instanceof  ServerNode)) {
620                        throw new IllegalArgumentException();
621                    }
622                    return serverInstance
623                            .compareTo(((ServerNode) other).serverInstance);
624                }
625            }
626
627            private static class ServerCategoryNode extends AbstractNode {
628
629                private final ServerCategoriesDescriptor desc;
630                private Node iconDelegate;
631
632                public ServerCategoryNode(ServerCategoriesDescriptor desc) {
633                    super (new ServersChildren(desc.getServers()));
634                    this .desc = desc;
635                    this .iconDelegate = DataFolder.findFolder(
636                            Repository.getDefault().getDefaultFileSystem()
637                                    .getRoot()).getNodeDelegate();
638                }
639
640                public String getDisplayName() {
641                    return desc.getName();
642                }
643
644                public Image getIcon(int type) {
645                    return iconDelegate.getIcon(type);
646                }
647
648                public Image getOpenedIcon(int type) {
649                    return iconDelegate.getOpenedIcon(type);
650                }
651            }
652
653            private static class ServerCategoriesChildren extends Children.Keys {
654
655                protected void addNotify() {
656                    super .addNotify();
657                    this .refreshServers();
658                }
659
660                protected void removeNotify() {
661                    super .removeNotify();
662                }
663
664                protected Node[] createNodes(Object key) {
665                    if (key instanceof  ServerCategoriesDescriptor) {
666                        ServerCategoriesDescriptor desc = (ServerCategoriesDescriptor) key;
667                        return new Node[] { new ServerCategoryNode(desc) };
668                    } else if (key instanceof  Node) {
669                        return new Node[] { new FilterNode((Node) key,
670                                Children.LEAF) };
671                    } else {
672                        return new Node[0];
673                    }
674                }
675
676                private void refreshServers() {
677                    Collection servInstances = ServerRegistry.getInstance()
678                            .getInstances();
679                    HashMap/*<String,ServerCategoriesDescriptor>*/categories = new HashMap();
680
681                    // currently we have only j2eeServers category
682                    final String J2EE_SERVERS_CATEGORY = NbBundle.getMessage(
683                            ServersCustomizer.class, "LBL_J2eeServersNode"); // NOI18N
684                    ServerCategoriesDescriptor j2eeServers = new ServerCategoriesDescriptor(
685                            J2EE_SERVERS_CATEGORY);
686                    for (Iterator it = servInstances.iterator(); it.hasNext();) {
687                        ServerInstance serverInstance = (ServerInstance) it
688                                .next();
689                        j2eeServers.add(new ServerNode(serverInstance));
690                    }
691                    categories.put(J2EE_SERVERS_CATEGORY, j2eeServers);
692                    List keys = new ArrayList(categories.values());
693                    Collections.sort(keys);
694                    this.setKeys(keys);
695                }
696            }
697        }
ww_w___.__j_ava2__s__.c__o___m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.