Monday 12 September 2011

Integrating NetBeans MultiView with XAM/XDM based XML Object Model


Overview

As part of my ongoing side-line work with the NetBeans Coherence Module I have finally had the time to reimplement the GUI Editor associated with the Coherence pof-config.xml file. As you may remember from my previous entry "Implementing XML Object Model based on XAM/XDM" I converted my existing JAXB Implementation of the pof-config.xml to the NetBeans preferred XAM/XDM model. Now it is time to change GUI interface so that it uses this new XML Object Model. In addition because this will be shipped post NetBeans 7.1 I decided to use the new NetBeans MultiView functionality.

Creating the MultiView

To create the XML MultiView component we first need a standard NetBeans Module Project with a base path (package), in my case, of org.netbeans.modules.coherence and in addition I have created the package org.netbeans.coherence.editor.pof for the MultiView classes and org.netbeans.modules.coherence.resources.icons for the icons associated with the file type. To create a MultiView Editor in 7.1 is simplicity itself and can be done by following the instructions below.

  1. Create New File Type:
    1. MIME Type : text/coh-pof+xml
    2. Namespace : http://xmlns.oracle.com/coherence/coherence-pof-config

      MultiView
  2. Next
  3. Name, Icon and Location
    1. Class Name Prefix : PofConfig
    2. Icon : Path to pof file icon
    3. MultiView : checked (This is a new feature of NetBeans 7.1)
    4. Package : org.netbeans.modules.coherence.editor.pof

      MultiView
  4. Finish
This will create two Java files, in addition to a number of xml files :

  • PofConfigDataObject.java
  • PofConfigVisualElement.java (.form)
These two files provide all the base functionality to implement the MultiView functionality for the pof-config.xml file.

PofConfigDataObject.java

 1 /*
 2  * To change this template, choose Tools | Templates and open the template in
 3  * the editor.
 4  */
 5 package org.netbeans.modules.coherence.editor.pof;
 6 
 7 import java.io.IOException;
 8 import org.netbeans.core.spi.multiview.MultiViewElement;
 9 import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
10 import org.openide.filesystems.FileObject;
11 import org.openide.loaders.DataObjectExistsException;
12 import org.openide.loaders.MultiDataObject;
13 import org.openide.loaders.MultiFileLoader;
14 import org.openide.util.Lookup;
15 import org.openide.windows.TopComponent;
16 
17 public class PofConfigDataObject extends MultiDataObject {
18 
19     public PofConfigDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
20         super(pf, loader);
21         registerEditor("text/coh-pof+xml", true);
22     }
23 
24     @Override
25     protected int associateLookup() {
26         return 1;
27     }
28 
29     @MultiViewElement.Registration(displayName = "#LBL_PofConfig_EDITOR",
30     iconBase = "org/netbeans/modules/coherence/resources/icons/pof.png",
31     mimeType = "text/coh-pof+xml",
32     persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
33     preferredID = "PofConfig",
34     position = 1000)
35     public static MultiViewEditorElement createEditor(Lookup lkp) {
36         return new MultiViewEditorElement(lkp);
37     }
38 }
39 
40 

PofConfigVisualElement.java

  1 /*
  2  * To change this template, choose Tools | Templates and open the template in
  3  * the editor.
  4  */
  5 package org.netbeans.modules.coherence.editor.pof;
  6 
  7 import javax.swing.Action;
  8 import javax.swing.JComponent;
  9 import javax.swing.JPanel;
 10 import javax.swing.JToolBar;
 11 import org.netbeans.core.spi.multiview.CloseOperationState;
 12 import org.netbeans.core.spi.multiview.MultiViewElement;
 13 import org.netbeans.core.spi.multiview.MultiViewElementCallback;
 14 import org.openide.awt.UndoRedo;
 15 import org.openide.util.Lookup;
 16 import org.openide.util.NbBundle.Messages;
 17 import org.openide.windows.TopComponent;
 18 
 19 @MultiViewElement.Registration(displayName = "#LBL_PofConfig_VISUAL",
 20 iconBase = "org/netbeans/modules/coherence/resources/icons/pof.png",
 21 mimeType = "text/coh-pof+xml",
 22 persistenceType = TopComponent.PERSISTENCE_NEVER,
 23 preferredID = "PofConfigVisual",
 24 position = 2000)
 25 @Messages({
 26     "LBL_PofConfig_VISUAL=Visual"
 27 })
 28 public final class PofConfigVisualElement extends JPanel implements MultiViewElement {
 29 
 30     private PofConfigDataObject obj;
 31     private JToolBar toolbar = new JToolBar();
 32     private transient MultiViewElementCallback callback;
 33 
 34     public PofConfigVisualElement(Lookup lkp) {
 35         obj = lkp.lookup(PofConfigDataObject.class);
 36         assert obj != null;
 37         initComponents();
 38     }
 39 
 40     @Override
 41     public String getName() {
 42         return "PofConfigVisualElement";
 43     }
 44 
 45     /** This method is called from within the constructor to
 46      * initialize the form.
 47      * WARNING: Do NOT modify this code. The content of this method is
 48      * always regenerated by the Form Editor.
 49      */
 50     //                           
 51     private void initComponents() {
 52 
 53         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
 54         this.setLayout(layout);
 55         layout.setHorizontalGroup(
 56             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 57             .addGap(0, 400, Short.MAX_VALUE)
 58         );
 59         layout.setVerticalGroup(
 60             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 61             .addGap(0, 300, Short.MAX_VALUE)
 62         );
 63     }//                         
 64 
 65     // Variables declaration - do not modify                     
 66     // End of variables declaration                   
 67     @Override
 68     public JComponent getVisualRepresentation() {
 69         return this;
 70     }
 71 
 72     @Override
 73     public JComponent getToolbarRepresentation() {
 74         return toolbar;
 75     }
 76 
 77     @Override
 78     public Action[] getActions() {
 79         return new Action[0];
 80     }
 81 
 82     @Override
 83     public Lookup getLookup() {
 84         return obj.getLookup();
 85     }
 86 
 87     @Override
 88     public void componentOpened() {
 89     }
 90 
 91     @Override
 92     public void componentClosed() {
 93     }
 94 
 95     @Override
 96     public void componentShowing() {
 97     }
 98 
 99     @Override
100     public void componentHidden() {
101     }
102 
103     @Override
104     public void componentActivated() {
105     }
106 
107     @Override
108     public void componentDeactivated() {
109     }
110 
111     @Override
112     public UndoRedo getUndoRedo() {
113         return UndoRedo.NONE;
114     }
115 
116     @Override
117     public void setMultiViewCallback(MultiViewElementCallback callback) {
118         this.callback = callback;
119     }
120 
121     @Override
122     public CloseOperationState canCloseElement() {
123         return CloseOperationState.STATE_OK;
124     }
125 }
126 
127 
We now need to add the following libraries.
Libraries

Now run the project and we will see that the pof-config.xml files have a green file icon and opening the file will initially display the "Source" view but we also have "Visual" tab that if selected will simply display an empty windows and this is because we have not added any visual components.

MultiView

MultiView


Extending the MultiView

Obviously an empty Visual Component is not what we want and so it is now time to edit the Visual component to display the XML in our chosen Visual Format. In addition we will change the name of the Visual component and place it first in the list. The end result will be as follows:

MultiView
I will not go into detail about how to create the visual component but will assume the reader has created swing based NetBeans components before. The resulting code is displayed below.

PofConfigDataObject.java

 1 /*
 2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 3  *
 4  * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
 5  *
 6  * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
 7  * Other names may be trademarks of their respective owners.
 8  *
 9  * The contents of this file are subject to the terms of either the GNU
10  * General Public License Version 2 only ("GPL") or the Common
11  * Development and Distribution License("CDDL") (collectively, the
12  * "License"). You may not use this file except in compliance with the
13  * License. You can obtain a copy of the License at
14  * http://www.netbeans.org/cddl-gplv2.html
15  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16  * specific language governing permissions and limitations under the
17  * License.  When distributing the software, include this License Header
18  * Notice in each file and include the License file at
19  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20  * particular file as subject to the "Classpath" exception as provided
21  * by Oracle in the GPL Version 2 section of the License file that
22  * accompanied this code. If applicable, add the following below the
23  * License Header, with the fields enclosed by brackets [] replaced by
24  * your own identifying information:
25  * "Portions Copyrighted [year] [name of copyright owner]"
26  *
27  * If you wish your version of this file to be governed by only the CDDL
28  * or only the GPL Version 2, indicate your decision by adding
29  * "[Contributor] elects to include this software in this distribution
30  * under the [CDDL or GPL Version 2] license." If you do not indicate a
31  * single choice of license, a recipient has the option to distribute
32  * your version of this file under either the CDDL, the GPL Version 2 or
33  * to extend the choice of license to its licensees as provided above.
34  * However, if you add GPL Version 2 code and therefore, elected the GPL
35  * Version 2 license, then the option applies only if the new code is
36  * made subject to such option by the copyright holder.
37  *
38  * Contributor(s):
39  *
40  * Portions Copyrighted 2011 Sun Microsystems, Inc.
41  */
42 package org.netbeans.modules.coherence.editor.pof;
43 
44 import java.io.IOException;
45 import org.netbeans.core.spi.multiview.MultiViewElement;
46 import org.netbeans.core.spi.multiview.text.MultiViewEditorElement;
47 import org.openide.filesystems.FileObject;
48 import org.openide.loaders.DataObjectExistsException;
49 import org.openide.loaders.MultiDataObject;
50 import org.openide.loaders.MultiFileLoader;
51 import org.openide.util.Lookup;
52 import org.openide.windows.TopComponent;
53 
54 /**
55  *
56  * @author Andrew Hopkinson (Oracle A-Team)
57  */
58 public class PofConfigDataObject extends MultiDataObject {
59 
60     public PofConfigDataObject(FileObject pf, MultiFileLoader loader) throws DataObjectExistsException, IOException {
61         super(pf, loader);
62         registerEditor("text/coh-pof+xml", true);
63     }
64 
65     @Override
66     protected int associateLookup() {
67         return 1;
68     }
69 
70     @MultiViewElement.Registration(displayName = "#LBL_PofConfig_EDITOR",
71     iconBase = "org/netbeans/modules/coherence/resources/icons/pof.png",
72     mimeType = "text/coh-pof+xml",
73     persistenceType = TopComponent.PERSISTENCE_ONLY_OPENED,
74     preferredID = "PofConfig",
75     position = 2000)
76     public static MultiViewEditorElement createEditor(Lookup lkp) {
77         return new MultiViewEditorElement(lkp);
78     }
79 }
80 
81 

PofConfigVisualElement.java

   1 /*
   2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   3  *
   4  * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
   5  *
   6  * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   7  * Other names may be trademarks of their respective owners.
   8  *
   9  * The contents of this file are subject to the terms of either the GNU
  10  * General Public License Version 2 only ("GPL") or the Common
  11  * Development and Distribution License("CDDL") (collectively, the
  12  * "License"). You may not use this file except in compliance with the
  13  * License. You can obtain a copy of the License at
  14  * http://www.netbeans.org/cddl-gplv2.html
  15  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16  * specific language governing permissions and limitations under the
  17  * License.  When distributing the software, include this License Header
  18  * Notice in each file and include the License file at
  19  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  20  * particular file as subject to the "Classpath" exception as provided
  21  * by Oracle in the GPL Version 2 section of the License file that
  22  * accompanied this code. If applicable, add the following below the
  23  * License Header, with the fields enclosed by brackets [] replaced by
  24  * your own identifying information:
  25  * "Portions Copyrighted [year] [name of copyright owner]"
  26  *
  27  * If you wish your version of this file to be governed by only the CDDL
  28  * or only the GPL Version 2, indicate your decision by adding
  29  * "[Contributor] elects to include this software in this distribution
  30  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  31  * single choice of license, a recipient has the option to distribute
  32  * your version of this file under either the CDDL, the GPL Version 2 or
  33  * to extend the choice of license to its licensees as provided above.
  34  * However, if you add GPL Version 2 code and therefore, elected the GPL
  35  * Version 2 license, then the option applies only if the new code is
  36  * made subject to such option by the copyright holder.
  37  *
  38  * Contributor(s):
  39  *
  40  * Portions Copyrighted 2011 Sun Microsystems, Inc.
  41  */
  42 package org.netbeans.modules.coherence.editor.pof;
  43 
  44 import com.sun.istack.logging.Logger;
  45 import java.util.ArrayList;
  46 import java.util.List;
  47 import java.util.logging.Level;
  48 import javax.swing.Action;
  49 import javax.swing.JComponent;
  50 import javax.swing.JOptionPane;
  51 import javax.swing.JPanel;
  52 import javax.swing.JToolBar;
  53 import javax.swing.event.ListSelectionEvent;
  54 import javax.swing.event.ListSelectionListener;
  55 import javax.swing.event.TableModelEvent;
  56 import javax.swing.event.TableModelListener;
  57 import javax.swing.table.AbstractTableModel;
  58 import org.jdesktop.beansbinding.AutoBinding.UpdateStrategy;
  59 import org.jdesktop.beansbinding.BeanProperty;
  60 import org.jdesktop.beansbinding.Binding;
  61 import org.jdesktop.beansbinding.Binding.SyncFailure;
  62 import org.jdesktop.beansbinding.BindingGroup;
  63 import org.jdesktop.beansbinding.BindingListener;
  64 import org.jdesktop.beansbinding.Bindings;
  65 import org.jdesktop.beansbinding.Property;
  66 import org.jdesktop.beansbinding.PropertyStateEvent;
  67 import org.netbeans.core.spi.multiview.CloseOperationState;
  68 import org.netbeans.core.spi.multiview.MultiViewElement;
  69 import org.netbeans.core.spi.multiview.MultiViewElementCallback;
  70 import org.netbeans.modules.coherence.xml.pof.PofConfig;
  71 import org.netbeans.modules.coherence.xml.pof.PofConfigComponentFactory;
  72 import org.netbeans.modules.coherence.xml.pof.PofConfigModel;
  73 import org.netbeans.modules.coherence.xml.pof.PofConfigModelFactory;
  74 import org.netbeans.modules.coherence.xml.pof.Serializer;
  75 import org.netbeans.modules.coherence.xml.pof.UserType;
  76 import org.netbeans.modules.coherence.xml.pof.UserTypeList;
  77 import org.netbeans.modules.coherence.xml.pof.ValueNotPermittedException;
  78 import org.netbeans.modules.xml.retriever.catalog.Utilities;
  79 import org.netbeans.modules.xml.xam.ModelSource;
  80 import org.openide.awt.StatusDisplayer;
  81 import org.openide.awt.UndoRedo;
  82 import org.openide.util.Exceptions;
  83 import org.openide.util.Lookup;
  84 import org.openide.util.NbBundle.Messages;
  85 import org.openide.windows.TopComponent;
  86 
  87 @MultiViewElement.Registration(displayName = "#LBL_PofConfig_VISUAL",
  88 iconBase = "org/netbeans/modules/coherence/resources/icons/pof.png",
  89 mimeType = "text/coh-pof+xml",
  90 persistenceType = TopComponent.PERSISTENCE_NEVER,
  91 preferredID = "PofConfigVisual",
  92 position = 1000)
  93 @Messages({
  94     "LBL_PofConfig_VISUAL=General"
  95 })
  96 /**
  97  *
  98  * @author Andrew Hopkinson (Oracle A-Team)
  99  */
 100 public final class PofConfigVisualElement extends JPanel implements MultiViewElement, TableModelListener, ListSelectionListener, BindingListener {
 101 
 102     private PofConfigDataObject obj;
 103     private JToolBar toolbar = new JToolBar();
 104     private transient MultiViewElementCallback callback;
 105 
 106     public PofConfigVisualElement(Lookup lkp) {
 107         obj = lkp.lookup(PofConfigDataObject.class);
 108         assert obj != null;
 109         initComponents();
 110         initialise();
 111     }
 112 
 113     @Override
 114     public String getName() {
 115         return "PofConfigVisualElement";
 116     }
 117 
 118     /** This method is called from within the constructor to
 119      * initialize the form.
 120      * WARNING: Do NOT modify this code. The content of this method is
 121      * always regenerated by the Form Editor.
 122      */
 123     //                           
 124     private void initComponents() {
 125 
 126         jScrollPane3 = new javax.swing.JScrollPane();
 127         topPanel = new javax.swing.JPanel();
 128         generalPanel = new javax.swing.JPanel();
 129         jPanel9 = new javax.swing.JPanel();
 130         jToggleButton1 = new javax.swing.JToggleButton();
 131         jPanel2 = new javax.swing.JPanel();
 132         cbAllowInterfaces = new javax.swing.JCheckBox();
 133         cbAllowSubclesses = new javax.swing.JCheckBox();
 134         jPanel7 = new javax.swing.JPanel();
 135         jLabel1 = new javax.swing.JLabel();
 136         tfClassName = new javax.swing.JTextField();
 137         standardPanel = new javax.swing.JPanel();
 138         jPanel3 = new javax.swing.JPanel();
 139         jToggleButton2 = new javax.swing.JToggleButton();
 140         jPanel4 = new javax.swing.JPanel();
 141         jScrollPane1 = new javax.swing.JScrollPane();
 142         tabStandardUT = new javax.swing.JTable();
 143         customPanel = new javax.swing.JPanel();
 144         jPanel5 = new javax.swing.JPanel();
 145         jToggleButton3 = new javax.swing.JToggleButton();
 146         jPanel6 = new javax.swing.JPanel();
 147         jScrollPane2 = new javax.swing.JScrollPane();
 148         tabCustomUT = new javax.swing.JTable();
 149         jPanel8 = new javax.swing.JPanel();
 150         btnAdd = new javax.swing.JButton();
 151         btnEdit = new javax.swing.JButton();
 152         btnRemove = new javax.swing.JButton();
 153         jPanel1 = new javax.swing.JPanel();
 154         btnEditImage = new javax.swing.JButton();
 155         btnAddImage = new javax.swing.JButton();
 156         btnDeleteImage = new javax.swing.JButton();
 157 
 158         jToggleButton1.setSelected(true);
 159         org.openide.awt.Mnemonics.setLocalizedText(jToggleButton1, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.jToggleButton1.text")); // NOI18N
 160         jToggleButton1.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
 161         jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
 162             public void actionPerformed(java.awt.event.ActionEvent evt) {
 163                 jToggleButton1ActionPerformed(evt);
 164             }
 165         });
 166 
 167         org.openide.awt.Mnemonics.setLocalizedText(cbAllowInterfaces, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.cbAllowInterfaces.text")); // NOI18N
 168 
 169         org.openide.awt.Mnemonics.setLocalizedText(cbAllowSubclesses, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.cbAllowSubclesses.text")); // NOI18N
 170 
 171         jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.jPanel7.border.title"))); // NOI18N
 172 
 173         org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.jLabel1.text")); // NOI18N
 174 
 175         javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
 176         jPanel7.setLayout(jPanel7Layout);
 177         jPanel7Layout.setHorizontalGroup(
 178             jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 179             .addGroup(jPanel7Layout.createSequentialGroup()
 180                 .addContainerGap()
 181                 .addComponent(jLabel1)
 182                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 183                 .addComponent(tfClassName, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE))
 184         );
 185         jPanel7Layout.setVerticalGroup(
 186             jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 187             .addGroup(jPanel7Layout.createSequentialGroup()
 188                 .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 189                     .addComponent(jLabel1)
 190                     .addComponent(tfClassName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 191                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 192         );
 193 
 194         javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
 195         jPanel2.setLayout(jPanel2Layout);
 196         jPanel2Layout.setHorizontalGroup(
 197             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 198             .addGroup(jPanel2Layout.createSequentialGroup()
 199                 .addContainerGap()
 200                 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 201                     .addComponent(cbAllowInterfaces)
 202                     .addComponent(cbAllowSubclesses)
 203                     .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 204                 .addContainerGap(22, Short.MAX_VALUE))
 205         );
 206         jPanel2Layout.setVerticalGroup(
 207             jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 208             .addGroup(jPanel2Layout.createSequentialGroup()
 209                 .addComponent(cbAllowInterfaces)
 210                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
 211                 .addComponent(cbAllowSubclesses)
 212                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 213                 .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 214                 .addContainerGap(15, Short.MAX_VALUE))
 215         );
 216 
 217         javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
 218         jPanel9.setLayout(jPanel9Layout);
 219         jPanel9Layout.setHorizontalGroup(
 220             jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 221             .addGroup(jPanel9Layout.createSequentialGroup()
 222                 .addGap(10, 10, 10)
 223                 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 224                 .addContainerGap(75, Short.MAX_VALUE))
 225             .addComponent(jToggleButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE)
 226         );
 227         jPanel9Layout.setVerticalGroup(
 228             jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 229             .addGroup(jPanel9Layout.createSequentialGroup()
 230                 .addComponent(jToggleButton1)
 231                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 232                 .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 233         );
 234 
 235         javax.swing.GroupLayout generalPanelLayout = new javax.swing.GroupLayout(generalPanel);
 236         generalPanel.setLayout(generalPanelLayout);
 237         generalPanelLayout.setHorizontalGroup(
 238             generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 239             .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 240         );
 241         generalPanelLayout.setVerticalGroup(
 242             generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 243             .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 244         );
 245 
 246         org.openide.awt.Mnemonics.setLocalizedText(jToggleButton2, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.jToggleButton2.text")); // NOI18N
 247         jToggleButton2.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
 248         jToggleButton2.addActionListener(new java.awt.event.ActionListener() {
 249             public void actionPerformed(java.awt.event.ActionEvent evt) {
 250                 jToggleButton2ActionPerformed(evt);
 251             }
 252         });
 253 
 254         javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
 255         jPanel3.setLayout(jPanel3Layout);
 256         jPanel3Layout.setHorizontalGroup(
 257             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 258             .addComponent(jToggleButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE)
 259         );
 260         jPanel3Layout.setVerticalGroup(
 261             jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 262             .addComponent(jToggleButton2)
 263         );
 264 
 265         tabStandardUT.setModel(getStandardUserTypes());
 266         tabStandardUT.setFillsViewportHeight(true);
 267         jScrollPane1.setViewportView(tabStandardUT);
 268 
 269         javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
 270         jPanel4.setLayout(jPanel4Layout);
 271         jPanel4Layout.setHorizontalGroup(
 272             jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 273             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE)
 274         );
 275         jPanel4Layout.setVerticalGroup(
 276             jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 277             .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
 278         );
 279 
 280         javax.swing.GroupLayout standardPanelLayout = new javax.swing.GroupLayout(standardPanel);
 281         standardPanel.setLayout(standardPanelLayout);
 282         standardPanelLayout.setHorizontalGroup(
 283             standardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 284             .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 285             .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 286         );
 287         standardPanelLayout.setVerticalGroup(
 288             standardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 289             .addGroup(standardPanelLayout.createSequentialGroup()
 290                 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 291                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 292                 .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 293         );
 294 
 295         org.openide.awt.Mnemonics.setLocalizedText(jToggleButton3, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.jToggleButton3.text")); // NOI18N
 296         jToggleButton3.setHorizontalAlignment(javax.swing.SwingConstants.LEADING);
 297         jToggleButton3.addActionListener(new java.awt.event.ActionListener() {
 298             public void actionPerformed(java.awt.event.ActionEvent evt) {
 299                 jToggleButton3ActionPerformed(evt);
 300             }
 301         });
 302 
 303         javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
 304         jPanel5.setLayout(jPanel5Layout);
 305         jPanel5Layout.setHorizontalGroup(
 306             jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 307             .addComponent(jToggleButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 628, Short.MAX_VALUE)
 308         );
 309         jPanel5Layout.setVerticalGroup(
 310             jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 311             .addGroup(jPanel5Layout.createSequentialGroup()
 312                 .addComponent(jToggleButton3)
 313                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 314         );
 315 
 316         tabCustomUT.setModel(getCustomUserTypes());
 317         tabCustomUT.setFillsViewportHeight(true);
 318         jScrollPane2.setViewportView(tabCustomUT);
 319 
 320         org.openide.awt.Mnemonics.setLocalizedText(btnAdd, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.btnAdd.text")); // NOI18N
 321         btnAdd.addActionListener(new java.awt.event.ActionListener() {
 322             public void actionPerformed(java.awt.event.ActionEvent evt) {
 323                 btnAddActionPerformed(evt);
 324             }
 325         });
 326 
 327         org.openide.awt.Mnemonics.setLocalizedText(btnEdit, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.btnEdit.text")); // NOI18N
 328         btnEdit.setEnabled(false);
 329         btnEdit.addActionListener(new java.awt.event.ActionListener() {
 330             public void actionPerformed(java.awt.event.ActionEvent evt) {
 331                 btnEditActionPerformed(evt);
 332             }
 333         });
 334 
 335         org.openide.awt.Mnemonics.setLocalizedText(btnRemove, org.openide.util.NbBundle.getMessage(PofConfigVisualElement.class, "PofConfigVisualElement.btnRemove.text")); // NOI18N
 336         btnRemove.setEnabled(false);
 337         btnRemove.addActionListener(new java.awt.event.ActionListener() {
 338             public void actionPerformed(java.awt.event.ActionEvent evt) {
 339                 btnRemoveActionPerformed(evt);
 340             }
 341         });
 342 
 343         javax.swing.GroupLayout jPanel8Layout = new javax.swing.GroupLayout(jPanel8);
 344         jPanel8.setLayout(jPanel8Layout);
 345         jPanel8Layout.setHorizontalGroup(
 346             jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 347             .addGroup(jPanel8Layout.createSequentialGroup()
 348                 .addContainerGap()
 349                 .addComponent(btnAdd)
 350                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 351                 .addComponent(btnEdit)
 352                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 353                 .addComponent(btnRemove)
 354                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 355         );
 356         jPanel8Layout.setVerticalGroup(
 357             jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 358             .addGroup(jPanel8Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
 359                 .addComponent(btnAdd)
 360                 .addComponent(btnEdit)
 361                 .addComponent(btnRemove))
 362         );
 363 
 364         btnEditImage.setBorderPainted(false);
 365         btnEditImage.setContentAreaFilled(false);
 366         btnEditImage.setEnabled(false);
 367         btnEditImage.setMargin(new java.awt.Insets(2, 2, 2, 2));
 368         btnEditImage.addActionListener(new java.awt.event.ActionListener() {
 369             public void actionPerformed(java.awt.event.ActionEvent evt) {
 370                 btnEditImageActionPerformed(evt);
 371             }
 372         });
 373 
 374         btnAddImage.setBorderPainted(false);
 375         btnAddImage.setContentAreaFilled(false);
 376         btnAddImage.setMargin(new java.awt.Insets(2, 2, 2, 2));
 377         btnAddImage.addActionListener(new java.awt.event.ActionListener() {
 378             public void actionPerformed(java.awt.event.ActionEvent evt) {
 379                 btnAddImageActionPerformed(evt);
 380             }
 381         });
 382 
 383         btnDeleteImage.setBorderPainted(false);
 384         btnDeleteImage.setContentAreaFilled(false);
 385         btnDeleteImage.setEnabled(false);
 386         btnDeleteImage.setMargin(new java.awt.Insets(2, 2, 2, 2));
 387         btnDeleteImage.addActionListener(new java.awt.event.ActionListener() {
 388             public void actionPerformed(java.awt.event.ActionEvent evt) {
 389                 btnDeleteImageActionPerformed(evt);
 390             }
 391         });
 392 
 393         javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
 394         jPanel1.setLayout(jPanel1Layout);
 395         jPanel1Layout.setHorizontalGroup(
 396             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 397             .addComponent(btnEditImage)
 398             .addComponent(btnAddImage)
 399             .addComponent(btnDeleteImage)
 400         );
 401         jPanel1Layout.setVerticalGroup(
 402             jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 403             .addGroup(jPanel1Layout.createSequentialGroup()
 404                 .addComponent(btnAddImage)
 405                 .addGap(6, 6, 6)
 406                 .addComponent(btnEditImage)
 407                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 408                 .addComponent(btnDeleteImage)
 409                 .addContainerGap(43, Short.MAX_VALUE))
 410         );
 411 
 412         javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
 413         jPanel6.setLayout(jPanel6Layout);
 414         jPanel6Layout.setHorizontalGroup(
 415             jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 416             .addGroup(jPanel6Layout.createSequentialGroup()
 417                 .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 418                     .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 419                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
 420                         .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 603, Short.MAX_VALUE)
 421                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 422                         .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
 423                 .addContainerGap())
 424         );
 425         jPanel6Layout.setVerticalGroup(
 426             jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 427             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
 428                 .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
 429                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 430                 .addComponent(jPanel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
 431             .addGroup(jPanel6Layout.createSequentialGroup()
 432                 .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 433                 .addContainerGap())
 434         );
 435 
 436         javax.swing.GroupLayout customPanelLayout = new javax.swing.GroupLayout(customPanel);
 437         customPanel.setLayout(customPanelLayout);
 438         customPanelLayout.setHorizontalGroup(
 439             customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 440             .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 441             .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 442         );
 443         customPanelLayout.setVerticalGroup(
 444             customPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 445             .addGroup(customPanelLayout.createSequentialGroup()
 446                 .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 447                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 448                 .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 449         );
 450 
 451         javax.swing.GroupLayout topPanelLayout = new javax.swing.GroupLayout(topPanel);
 452         topPanel.setLayout(topPanelLayout);
 453         topPanelLayout.setHorizontalGroup(
 454             topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 455             .addComponent(standardPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 456             .addComponent(generalPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 457             .addComponent(customPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
 458         );
 459         topPanelLayout.setVerticalGroup(
 460             topPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 461             .addGroup(topPanelLayout.createSequentialGroup()
 462                 .addComponent(generalPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 463                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 464                 .addComponent(standardPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
 465                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
 466                 .addComponent(customPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
 467         );
 468 
 469         jScrollPane3.setViewportView(topPanel);
 470 
 471         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
 472         this.setLayout(layout);
 473         layout.setHorizontalGroup(
 474             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 475             .addGap(0, 400, Short.MAX_VALUE)
 476             .addGroup(layout.createSequentialGroup()
 477                 .addContainerGap()
 478                 .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE))
 479         );
 480         layout.setVerticalGroup(
 481             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
 482             .addGap(0, 300, Short.MAX_VALUE)
 483             .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
 484         );
 485     }//                         
 486 
 487 private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                               
 488     jPanel2.setVisible(jToggleButton1.isSelected());
 489 }                                              
 490 
 491 private void jToggleButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                               
 492     jPanel4.setVisible(jToggleButton2.isSelected());
 493 }                                              
 494 
 495 private void jToggleButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                               
 496     jPanel6.setVisible(jToggleButton3.isSelected());
 497 }                                              
 498 
 499 private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {                                       
 500     java.awt.EventQueue.invokeLater(new Runnable() {
 501 
 502         public void run() {
 503             EditUserTypeDialog dialog = new EditUserTypeDialog(null, true, null);
 504             dialog.setLocationRelativeTo(null);
 505             dialog.setVisible(true);
 506             if (dialog.getReturnStatus() == dialog.RET_OK) {
 507                 getModel().startTransaction();
 508                 try {
 509                     UserType ut = getFactory().createUserType();
 510                     ut.setClassName(getFactory().createClassName());
 511                     ut.getClassName().setValue(dialog.getClassname());
 512                     ut.setTypeId(getFactory().createTypeId());
 513                     ut.getTypeId().setValue(Integer.parseInt(dialog.getTypeId()));
 514                     String serializer = dialog.getSerializerClassname();
 515                     if (serializer != null & serializer.trim().length() > 0) {
 516                         Serializer utSerializer = getFactory().createSerializer();
 517                         utSerializer.setClassName(getFactory().createClassName());
 518                         utSerializer.getClassName().setValue(serializer);
 519                         ut.setSerializer(utSerializer);
 520                     }
 521                     PofConfig pofConfig = getPofConfig();
 522                     pofConfig.getUserTypeList().addElement(ut);
 523                     customUserTypes.addRow(ut.getTypeId().getValue(), ut.getClassName().getValue(), serializer, ut);
 524                     setModified();
 525                     //                    serialize();
 526                 } catch (ValueNotPermittedException ex) {
 527                     Exceptions.printStackTrace(ex);
 528                 }
 529                 getModel().endTransaction();
 530             }
 531         }
 532     });
 533 }                                      
 534 
 535 private void btnEditActionPerformed(java.awt.event.ActionEvent evt) {                                        
 536     java.awt.EventQueue.invokeLater(new Runnable() {
 537 
 538         public void run() {
 539             int rowNum = tabCustomUT.getSelectedRow();
 540             UserType ut = (UserType) customUserTypes.getUserType(rowNum);
 541             EditUserTypeDialog dialog = new EditUserTypeDialog(null, true, ut);
 542             dialog.setLocationRelativeTo(null);
 543             dialog.setVisible(true);
 544             if (dialog.getReturnStatus() == dialog.RET_OK) {
 545                 getModel().startTransaction();
 546                 try {
 547                     ut.getClassName().setValue(dialog.getClassname());
 548                     ut.getTypeId().setValue(Integer.parseInt(dialog.getTypeId()));
 549                     String serializer = dialog.getSerializerClassname();
 550                     if (serializer != null & serializer.trim().length() > 0) {
 551                         Serializer utSerializer = getFactory().createSerializer();
 552                         if (utSerializer.getClassName() == null) {
 553                             utSerializer.setClassName(getFactory().createClassName());
 554                         }
 555                         utSerializer.getClassName().setValue(serializer);
 556                         ut.setSerializer(utSerializer);
 557                     }
 558                     //                    PofConfig pofConfig = getPofConfig();
 559                     //                    pofConfig.getUserTypeList().getUserTypeOrInclude().add(ut);
 560                     customUserTypes.updateRow(rowNum, ut.getTypeId().getValue(), ut.getClassName().getValue(), serializer);
 561                     setModified();
 562                     //                    serialize();
 563                 } catch (ValueNotPermittedException ex) {
 564                     Exceptions.printStackTrace(ex);
 565                 }
 566                 getModel().endTransaction();
 567             }
 568         }
 569     });
 570 }                                       
 571 
 572 private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {                                          
 573     java.awt.EventQueue.invokeLater(new Runnable() {
 574 
 575         public void run() {
 576             int option = JOptionPane.showConfirmDialog(customPanel, "Please Confirm User Type Removal", "", JOptionPane.OK_CANCEL_OPTION);
 577             if (option == JOptionPane.OK_OPTION) {
 578                 int rowNum = tabCustomUT.getSelectedRow();
 579                 UserType ut = (UserType) customUserTypes.getUserType(rowNum);
 580                 customUserTypes.removeRow(rowNum);
 581 
 582                 getModel().startTransaction();
 583                 for (UserType xmlUT : getPofConfig().getUserTypeList().getUserTypes()) {
 584                     if (xmlUT.getTypeId().equals(ut.getTypeId()) && xmlUT.getClassName().equals(ut.getClassName())) {
 585                         getPofConfig().getUserTypeList().removeElement(xmlUT);
 586                         break;
 587                     }
 588                 }
 589                 setModified();
 590                 getModel().endTransaction();
 591 //                    serialize();
 592             }
 593         }
 594     });
 595 }                                         
 596 
 597 private void btnEditImageActionPerformed(java.awt.event.ActionEvent evt) {                                             
 598     btnEditActionPerformed(evt);
 599 }                                            
 600 
 601 private void btnAddImageActionPerformed(java.awt.event.ActionEvent evt) {                                            
 602     btnAddActionPerformed(evt);
 603 }                                           
 604 
 605 private void btnDeleteImageActionPerformed(java.awt.event.ActionEvent evt) {                                               
 606     btnRemoveActionPerformed(evt);
 607 }                                              
 608     // Variables declaration - do not modify                     
 609     private javax.swing.JButton btnAdd;
 610     private javax.swing.JButton btnAddImage;
 611     private javax.swing.JButton btnDeleteImage;
 612     private javax.swing.JButton btnEdit;
 613     private javax.swing.JButton btnEditImage;
 614     private javax.swing.JButton btnRemove;
 615     private javax.swing.JCheckBox cbAllowInterfaces;
 616     private javax.swing.JCheckBox cbAllowSubclesses;
 617     private javax.swing.JPanel customPanel;
 618     private javax.swing.JPanel generalPanel;
 619     private javax.swing.JLabel jLabel1;
 620     private javax.swing.JPanel jPanel1;
 621     private javax.swing.JPanel jPanel2;
 622     private javax.swing.JPanel jPanel3;
 623     private javax.swing.JPanel jPanel4;
 624     private javax.swing.JPanel jPanel5;
 625     private javax.swing.JPanel jPanel6;
 626     private javax.swing.JPanel jPanel7;
 627     private javax.swing.JPanel jPanel8;
 628     private javax.swing.JPanel jPanel9;
 629     private javax.swing.JScrollPane jScrollPane1;
 630     private javax.swing.JScrollPane jScrollPane2;
 631     private javax.swing.JScrollPane jScrollPane3;
 632     private javax.swing.JToggleButton jToggleButton1;
 633     private javax.swing.JToggleButton jToggleButton2;
 634     private javax.swing.JToggleButton jToggleButton3;
 635     private javax.swing.JPanel standardPanel;
 636     private javax.swing.JTable tabCustomUT;
 637     private javax.swing.JTable tabStandardUT;
 638     private javax.swing.JTextField tfClassName;
 639     private javax.swing.JPanel topPanel;
 640     // End of variables declaration                   
 641 
 642     @Override
 643     public JComponent getVisualRepresentation() {
 644         return this;
 645     }
 646 
 647     @Override
 648     public JComponent getToolbarRepresentation() {
 649         return toolbar;
 650     }
 651 
 652     @Override
 653     public Action[] getActions() {
 654         return new Action[0];
 655     }
 656 
 657     @Override
 658     public Lookup getLookup() {
 659         return obj.getLookup();
 660     }
 661 
 662     @Override
 663     public void componentOpened() {
 664     }
 665 
 666     @Override
 667     public void componentClosed() {
 668     }
 669 
 670     @Override
 671     public void componentShowing() {
 672     }
 673 
 674     @Override
 675     public void componentHidden() {
 676     }
 677 
 678     @Override
 679     public void componentActivated() {
 680         Logger.getLogger(this.getClass()).log(Level.INFO, "*** APH-I1 : Allowed Subclasses : " + getRoot().getAllowSubclasses().getValue());
 681         refreshBindings();
 682     }
 683 
 684     @Override
 685     public void componentDeactivated() {
 686     }
 687 
 688     @Override
 689     public UndoRedo getUndoRedo() {
 690         return UndoRedo.NONE;
 691     }
 692 
 693     @Override
 694     public void setMultiViewCallback(MultiViewElementCallback callback) {
 695         this.callback = callback;
 696     }
 697 
 698     @Override
 699     public CloseOperationState canCloseElement() {
 700         return CloseOperationState.STATE_OK;
 701     }
 702 
 703     @Override
 704     public void tableChanged(TableModelEvent e) {
 705     }
 706 
 707     @Override
 708     public void valueChanged(ListSelectionEvent e) {
 709         btnEdit.setEnabled(true);
 710         btnRemove.setEnabled(true);
 711         btnEditImage.setEnabled(true);
 712         btnDeleteImage.setEnabled(true);
 713     }
 714 
 715     @Override
 716     public void bindingBecameBound(Binding binding) {
 717     }
 718 
 719     @Override
 720     public void bindingBecameUnbound(Binding binding) {
 721     }
 722 
 723     @Override
 724     public void syncFailed(Binding binding, SyncFailure failure) {
 725     }
 726 
 727     @Override
 728     public void synced(Binding binding) {
 729     }
 730 
 731     @Override
 732     public void sourceChanged(Binding binding, PropertyStateEvent event) {
 733     }
 734 
 735     @Override
 736     public void targetChanged(Binding binding, PropertyStateEvent event) {
 737     }
 738 
 739     /*
 740      * =========================================================================
 741      * START: Custom Code
 742      * =========================================================================
 743      */
 744     private PofConfigModel myModel = null;
 745     private PofConfig myRoot = null;
 746     private ModelSource myModelSource = null;
 747     private PofConfigComponentFactory myFactory = null;
 748     private UserTypesTableModel standardUserTypes = new UserTypesTableModel();
 749     private UserTypesTableModel customUserTypes = new UserTypesTableModel();
 750     private BindingGroup bindingGroup = new BindingGroup();
 751 
 752     private PofConfig getPofConfig() {
 753         return getRoot();
 754     }
 755 
 756     private PofConfig getRoot() {
 757         if (myRoot == null) {
 758             myRoot = getModel().getPofConfig();
 759         }
 760         return myRoot;
 761     }
 762 
 763     private PofConfigModel getModel() {
 764         if (myModel == null) {
 765             // Get Model
 766             myModel = PofConfigModelFactory.getInstance().getModel(getModelSource());
 767         }
 768         return myModel;
 769     }
 770 
 771     private ModelSource getModelSource() {
 772         if (myModelSource == null) {
 773             myModelSource = Utilities.getModelSource(obj.getPrimaryFile(), true);
 774         }
 775         return myModelSource;
 776     }
 777 
 778     private PofConfigComponentFactory getFactory() {
 779         if (myFactory == null) {
 780             myFactory = getModel().getFactory();
 781         }
 782         return myFactory;
 783     }
 784     /*
 785      * Custom Inner Classes
 786      */
 787 
 788     public class UserTypesTableModel extends AbstractTableModel {
 789 
 790         private final String[] columnNames = {"Type Id", "Class Name", "Serializer"};
 791         private List data = new ArrayList();  792         private boolean[] edittable = {false, false, false};  793   794         @Override  795         public int getRowCount() {  796             return data.size();  797         }  798   799         @Override  800         public int getColumnCount() {  801             return columnNames.length;  802         }  803   804         @Override  805         public Object getValueAt(int rowIndex, int columnIndex) {  806             Object value = null;  807   808             if (rowIndex < getRowCount() && columnIndex < getColumnCount()) {  809                 value = data.get(rowIndex)[columnIndex];  810             }  811             return value;  812         }  813   814         @Override  815         public void setValueAt(Object aValue, int rowIndex, int columnIndex) {  816             if (rowIndex < getRowCount() && columnIndex < getColumnCount()) {  817                 data.get(rowIndex)[columnIndex] = aValue;  818                 fireTableCellUpdated(rowIndex, columnIndex);  819             }  820         }  821   822         @Override  823         public String getColumnName(int column) {  824             return columnNames[column];  825         }  826   827         @Override  828         public boolean isCellEditable(int rowIndex, int columnIndex) {  829             if (getEdittable() == null || columnIndex > getEdittable().length) {  830                 return false;  831             } else {  832                 return getEdittable()[columnIndex];  833             }  834         }  835   836         public boolean[] getEdittable() {  837             return edittable;  838         }  839   840         public void setEdittable(boolean[] edittable) {  841             this.edittable = edittable;  842         }  843   844         public void addRow(int id, String name, String serializer, Object node) {  845             Object[] row = {Integer.valueOf(id), name, serializer, node};  846             data.add(row);  847             fireTableDataChanged();  848         }  849   850         public void clear() {  851             data.clear();  852             fireTableDataChanged();  853         }  854   855         public void updateRow(int rowNum, int id, String name, String serializer) {  856             try {  857                 data.get(rowNum)[0] = id;  858                 data.get(rowNum)[1] = name;  859                 data.get(rowNum)[2] = serializer;  860                 UserType ut = (UserType) data.get(rowNum)[3];  861                 ut.getClassName().setValue(name);  862                 ut.getTypeId().setValue(id);  863                 ut.getSerializer().getClassName().setValue(serializer);  864                 fireTableDataChanged();  865             } catch (ValueNotPermittedException ex) {  866                 Exceptions.printStackTrace(ex);  867             }  868         }  869   870         public Object getUserType(int rowIndex) {  871             Object value = null;  872   873             if (rowIndex < getRowCount()) {  874                 value = data.get(rowIndex)[3];  875             }  876             return value;  877         }  878   879         public void removeRow(int rowIndex) {  880             if (rowIndex < getRowCount()) {  881                 data.remove(rowIndex);  882             }  883             fireTableDataChanged();  884         }  885   886         public List getData() {  887             return data;  888         }  889   890         public void setData(List data) {  891             this.data = data;  892             fireTableDataChanged();  893         }  894     }  895   896     public UserTypesTableModel getCustomUserTypes() {  897         return customUserTypes;  898     }  899   900     public UserTypesTableModel getStandardUserTypes() {  901         return standardUserTypes;  902     }  903   904     private void setModified() {  905     }  906   907     private void initialise() {  908         // Set Display State of Panels based on Toggle Button Status  909         jToggleButton1ActionPerformed(null);  910         jToggleButton2ActionPerformed(null);  911         jToggleButton3ActionPerformed(null);  912         // Assign Change listener to Table  913         tabCustomUT.getSelectionModel().addListSelectionListener(this);  914         // Add Listeners  915     }  916   917     private void refreshBindings() {  918         for (Binding b : bindingGroup.getBindings()) {  919             bindingGroup.removeBinding(b);  920         }  921         setupBindings();  922     }  923   924     private void setupBindings() {  925         PofConfig pofConfig = getPofConfig();  926         // Set Bindings  927         Property propertyTextValue = BeanProperty.create("text");  928         Property propertySelected = BeanProperty.create("selected");  929         Property propertySelectedItem = BeanProperty.create("selectedItem");  930         Property propertyData = BeanProperty.create("data");  931         // EditionName  932         Property propertyDefaultSerializer = BeanProperty.create("defaultSerializer");  933         Binding bindingDefaultSerializer = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, propertyDefaultSerializer, tfClassName, propertyTextValue);  934         bindingGroup.addBinding(bindingDefaultSerializer);  935         // Allow SubClasses  936         Property propertyAllowSubclasses = BeanProperty.create("allowSubclasses");  937         Binding bindingAllowSubclasses = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, propertyAllowSubclasses, cbAllowSubclesses, propertySelected);  938         bindingGroup.addBinding(bindingAllowSubclasses);  939         // Allow Interfaces  940         Property propertyAllowInterfaces = BeanProperty.create("allowInterfaces");  941         Binding bindingAllowInterfaces = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, propertyAllowInterfaces, cbAllowInterfaces, propertySelected);  942         bindingGroup.addBinding(bindingAllowInterfaces);  943         // Standard Types  944         Property propertyStandardTypes = BeanProperty.create("standardUserTypeRows");  945         Binding bindingStandardTypes = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, propertyStandardTypes, standardUserTypes, propertyData);  946         bindingGroup.addBinding(bindingStandardTypes);  947         // Standard Types  948         Property propertyCustomTypes = BeanProperty.create("customUserTypeRows");  949         Binding bindingCustomTypes = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, this, propertyCustomTypes, customUserTypes, propertyData);  950         bindingGroup.addBinding(bindingCustomTypes);  951         // Bind All  952         bindingGroup.addBindingListener(this);  953         bindingGroup.bind();  954     }  955     /*  956      * Binding Methods  957      */  958   959     public void setAllowInterfaces(boolean b) {  960         getModel().startTransaction();  961         if (getPofConfig().getAllowInterfaces() == null) {  962             getPofConfig().setAllowInterfaces(getFactory().createAllowInterfaces());  963         }  964         getPofConfig().getAllowInterfaces().setValue(b);  965         getModel().endTransaction();  966     }  967   968     public boolean isAllowInterfaces() {  969         if (getPofConfig().getAllowInterfaces() == null) {  970             getPofConfig().setAllowInterfaces(getFactory().createAllowInterfaces());  971         }  972         return getPofConfig().getAllowInterfaces().getValue();  973     }  974   975     public boolean getAllowInterfaces() {  976         return isAllowInterfaces();  977     }  978   979     public void setAllowSubclasses(boolean b) {  980         getModel().startTransaction();  981         if (getPofConfig().getAllowSubclasses() == null) {  982             getPofConfig().setAllowSubclasses(getFactory().createAllowSubclasses());  983         }  984         getPofConfig().getAllowSubclasses().setValue(b);  985         getModel().endTransaction();  986     }  987   988     public boolean isAllowSubclasses() {  989         if (getPofConfig().getAllowSubclasses() == null) {  990             getPofConfig().setAllowSubclasses(getFactory().createAllowSubclasses());  991         }  992         return getPofConfig().getAllowSubclasses().getValue();  993     }  994   995     public boolean getAllSubclasses() {  996         return isAllowSubclasses();  997     }  998   999     public void setDefaultSerializer(String s) { 1000         getModel().startTransaction(); 1001         if (s == null || s.trim().length() == 0) { 1002             getPofConfig().setDefaultSerializer(null); 1003         } else { 1004             if (getPofConfig().getDefaultSerializer() == null) { 1005                 getPofConfig().setDefaultSerializer(getFactory().createDefaultSerializer()); 1006             } 1007             if (getPofConfig().getDefaultSerializer().getClassName() == null) { 1008                 getPofConfig().getDefaultSerializer().setClassName(getFactory().createClassName()); 1009             } 1010             getPofConfig().getDefaultSerializer().getClassName().setValue(s); 1011         } 1012         getModel().endTransaction(); 1013     } 1014  1015     public String getDefaultSerializer() { 1016         String s = null; 1017         if (getPofConfig().getDefaultSerializer() != null) { 1018             if (getPofConfig().getDefaultSerializer().getClassName() != null) { 1019                 s = getPofConfig().getDefaultSerializer().getClassName().getValue(); 1020             } 1021         } 1022         return s; 1023     } 1024  1025     public void setStandardUserTypeRows(List data) { 1026         PofConfig pofConfig = getPofConfig(); 1027         if (data != null) { 1028 //            for (Object[] oArray : data) { 1029 //            } 1030         } 1031     } 1032  1033     public List getStandardUserTypeRows() { 1034         PofConfig pofConfig = getPofConfig(); 1035         List objArrayList = new ArrayList(); 1036         Object[] row = null; 1037         // Process User Type 1038         UserTypeList utl = pofConfig.getUserTypeList(); 1039         if (utl != null) { 1040             List utoiList = utl.getUserTypes(); 1041             String serializer = null; 1042             if (utoiList != null) { 1043                 for (UserType ut : utoiList) { 1044                     try { 1045                         serializer = null; 1046                         if (ut.getTypeId().getValue() < 1000) { 1047                             if (ut.getSerializer() != null) { 1048                                 serializer = ut.getSerializer().getClassName().getValue(); 1049                             } 1050                             row = new Object[4]; 1051                             row[0] = ut.getTypeId().getValue(); 1052                             row[1] = ut.getClassName(); 1053                             row[2] = serializer; 1054                             row[3] = ut; 1055                             objArrayList.add(row); 1056                         } 1057                     } catch (Exception e) { 1058                         StatusDisplayer.getDefault().setStatusText("Failed to parse type"); 1059                     } 1060                 } 1061             } 1062         } 1063         return objArrayList; 1064     } 1065  1066     public void setCustomUserTypeRows(List data) { 1067         PofConfig pofConfig = getPofConfig(); 1068         if (data != null) { 1069 //            for (Object[] oArray : data) { 1070 //            } 1071         } 1072     } 1073  1074     public List getCustomUserTypeRows() { 1075         PofConfig pofConfig = getPofConfig(); 1076         List objArrayList = new ArrayList(); 1077         Object[] row = null; 1078         // Process User Type 1079         UserTypeList utl = pofConfig.getUserTypeList(); 1080         if (utl != null) { 1081             List utoiList = utl.getUserTypes(); 1082             String serializer = null; 1083             if (utoiList != null) { 1084                 for (UserType ut : utoiList) { 1085                     try { 1086                         serializer = null; 1087                         if (ut.getTypeId().getValue() >= 1000) { 1088                             if (ut.getSerializer() != null) { 1089                                 serializer = ut.getSerializer().getClassName().getValue(); 1090                             } 1091                             row = new Object[4]; 1092                             row[0] = ut.getTypeId().getValue(); 1093                             row[1] = ut.getClassName(); 1094                             row[2] = serializer; 1095                             row[3] = ut; 1096                             objArrayList.add(row); 1097                         } 1098                     } catch (Exception e) { 1099                         StatusDisplayer.getDefault().setStatusText("Failed to parse type"); 1100                     } 1101                 } 1102             } 1103         } 1104         return objArrayList; 1105     } 1106     /* 1107      * ========================================================================= 1108      * END: Custom Code 1109      * ========================================================================= 1110      */ 1111 } 1112  1113  

The key changes that modify the MultiView tab display name and order are done within the Annotaions in the PofConfigVisualElement.java.


 86
 87 @MultiViewElement.Registration(displayName = "#LBL_PofConfig_VISUAL",
 88 iconBase = "org/netbeans/modules/coherence/resources/icons/pof.png",
 89 mimeType = "text/coh-pof+xml",
 90 persistenceType = TopComponent.PERSISTENCE_NEVER,
 91 preferredID = "PofConfigVisual",
 92 position = 1000)
 93 @Messages({
 94 "LBL_PofConfig_VISUAL=General"
 95 })
 96 /**
 97 *
 98 * @author Andrew Hopkinson (Oracle A-Team)
 99 */
To change the name of the tab we simply modify line 94 whilst editting line 92 will change the position of the teb on the bar. What I did for positioning was modify 92 to the value that is in the PofConfigDataObject.java (line 75) and vica versa.

We now have the graphical portion complete and all we need to do is link the previously built XAM/XDM XML Object Model into the Visual Component.

Integrating the XAM/XDM Code

When integrating the XAM/XDM Object Model we need to initially create a model based on the Primary File associated with the DataObject (see line 773 below). You will notice from the code below that I build the XAM/XDM Object Model as required and this is only done once because at every other point within the Visual Code I access the Model using the getPofConfig() method.

 102 private PofConfigDataObject obj;
 103 private JToolBar toolbar = new JToolBar();
 104 private transient MultiViewElementCallback callback;
 105
 106 public PofConfigVisualElement(Lookup lkp) {
 107 obj = lkp.lookup(PofConfigDataObject.class);
 108 assert obj != null;
 109 initComponents();
 110 initialise();
 111 }
 112

 739 /*
 740 * =========================================================================
 741 * START: Custom Code
 742 * =========================================================================
 743 */
 744 private PofConfigModel myModel = null;
 745 private PofConfig myRoot = null;
 746 private ModelSource myModelSource = null;
 747 private PofConfigComponentFactory myFactory = null;
 748 private UserTypesTableModel standardUserTypes = new UserTypesTableModel();
 749 private UserTypesTableModel customUserTypes = new UserTypesTableModel();
 750 private BindingGroup bindingGroup = new BindingGroup();
 751
 752 private PofConfig getPofConfig() {
 753 return getRoot();
 754 }
 755
 756 private PofConfig getRoot() {
 757 if (myRoot == null) {
 758 myRoot = getModel().getPofConfig();
 759 }
 760 return myRoot;
 761 }
 762
 763 private PofConfigModel getModel() {
 764 if (myModel == null) {
 765 // Get Model
 766 myModel = PofConfigModelFactory.getInstance().getModel(getModelSource());
 767 }
 768 return myModel;
 769 }
 770
 771 private ModelSource getModelSource() {
 772 if (myModelSource == null) {
 773 myModelSource = Utilities.getModelSource(obj.getPrimaryFile(), true);
 774 }
 775 return myModelSource;
 776 }
 777
 778 private PofConfigComponentFactory getFactory() {
 779 if (myFactory == null) {
 780 myFactory = getModel().getFactory();
 781 }
 782 return myFactory;
 783 }
You will also notice within the full code that I use the Java Bindings functionality to link the Object model with the displayed fields. To achieve this I have written a number of Model Accessor methods getters and setters because when modifying the Model we will need to do it transactionally. If we consider the AllowInterfaces Element we can see from the methods below that when setting the value of the Element we will need to start a transaction against the model (line 960) then check is the Element exists (line 961) and create it if it does not (line 962) before writing and completing the transaction (line 965). The result of this process is that the Text version will be updated and when the user switches views they will see the updated values. You can also see from the code fragment below that within the get I test for and create the Element if it does not exist. Reviewing the full code listing above you will notice that all accessor methods are implemented in a similar fashion.

 955 /*
 956 * Binding Methods
 957 */
 958
 959 public void setAllowInterfaces(boolean b) {
 960 getModel().startTransaction();
 961 if (getPofConfig().getAllowInterfaces() == null) {
 962 getPofConfig().setAllowInterfaces(getFactory().createAllowInterfaces());
 963 }
 964 getPofConfig().getAllowInterfaces().setValue(b);
 965 getModel().endTransaction();
 966 }
 967
 968 public boolean isAllowInterfaces() {
 969 if (getPofConfig().getAllowInterfaces() == null) {
 970 getPofConfig().setAllowInterfaces(getFactory().createAllowInterfaces());
 971 }
 972 return getPofConfig().getAllowInterfaces().getValue();
 973 }
 974
 975 public boolean getAllowInterfaces() {
 976 return isAllowInterfaces();
 977 }
The functionaly above differs from that used when accessing a JAXB Object Model because we do not need to start transactions and in the majority of cases we can assume the Element exists or will be created when we get its value.



No comments:

Post a Comment