View Javadoc
1 /*** 2 * $Header: 3 * 4 * 5 */ 6 package com.sun.xml.registry.client.browser; 7 8 import java.util.*; 9 import javax.swing.*; 10 import java.beans.*; //Property change stuff 11 import java.awt.*; 12 import java.awt.event.*; 13 14 import javax.xml.registry.*; 15 import javax.xml.registry.infomodel.*; 16 17 /*** 18 * A JBDialog that has an object at its model and serves as a UI editor for that model object. 19 */ 20 public class JBEditorDialog extends JBDialog { 21 22 JBPanel panel = null; 23 24 25 26 public JBEditorDialog(JFrame parent, boolean modal) { 27 28 super(parent, modal); 29 JBEditorDialog_initialize(); 30 } 31 32 public JBEditorDialog(JDialog parent, boolean modal) { 33 34 super(parent, modal); 35 JBEditorDialog_initialize(); 36 } 37 38 private void JBEditorDialog_initialize() { 39 } 40 41 42 public Object getModel() throws JAXRException { 43 Object model = null; 44 45 if (panel != null) { 46 model = panel.getModel(); 47 } 48 49 return model; 50 } 51 52 public void setModel(Object model) throws JAXRException { 53 status = JBDialog.CANCEL_STATUS; 54 55 Class oldClass = null; 56 Class newClass = null; 57 58 Object oldModel = getModel(); 59 60 if ((model != null)) { 61 62 if (oldModel != null) { 63 oldClass = oldModel.getClass(); 64 } 65 newClass = model.getClass(); 66 67 if (newClass != oldClass) { 68 try { 69 //The Class has changed so we need to instantiate an instance of <newClass>Panel. 70 String newClassName = newClass.getName(); 71 String packagePrefix = newClassName.substring(0, newClassName.lastIndexOf(".")+1); 72 newClassName = newClassName.substring(newClassName.lastIndexOf(".")+1); 73 74 if (newClassName.endsWith("Impl")) { 75 //Remove Impl suffix for JAXR provider Impl classes 76 newClassName = newClassName.substring(0, newClassName.length() -4); 77 } 78 79 setTitle(newClassName); 80 String panelClassName = null; 81 82 Class panelClass = null; 83 try { 84 //First try same package as model class for panel class's package 85 panelClassName = packagePrefix + newClassName + "Panel"; 86 panelClass = Class.forName(panelClassName); 87 } 88 catch (ClassNotFoundException e) { 89 //Next try default package as a fallback for panel class's package 90 panelClassName = "com.sun.xml.registry.client.browser." + newClassName + "Panel"; 91 panelClass = Class.forName(panelClassName); 92 } 93 94 //Now create an instance of the panelClass 95 panel = (JBPanel)panelClass.newInstance(); 96 panel.setModel(model); 97 panel.setEditable(editable); 98 99 //Add panel to dialog 100 JScrollPane scrPane = new JScrollPane(panel); 101 mainPanel.removeAll(); 102 mainPanel.add(scrPane, BorderLayout.CENTER); 103 pack(); 104 } 105 catch (ClassNotFoundException e) { 106 throw new JAXRException(e); 107 } 108 catch (InstantiationException e) { 109 throw new JAXRException(e); 110 } 111 catch (IllegalAccessException e) { 112 throw new JAXRException(e); 113 } 114 } 115 } 116 117 } 118 119 protected void okAction() { 120 super.okAction(); 121 122 if (status == JBDialog.OK_STATUS) { 123 try { 124 firePropertyChange(PROPERTY_DIALOG_OK, "OK", getModel()); 125 } 126 catch (JAXRException e) { 127 RegistryBrowser.displayError(e); 128 } 129 } 130 } 131 132 public static JBEditorDialog showObjectDetails(Component parent, Object obj, boolean modal, boolean editable) { 133 JBEditorDialog dialog = null; 134 try { 135 dialog = null; 136 Window window = (Window)(SwingUtilities.getRoot(parent)); 137 if (window instanceof JFrame) { 138 dialog = new JBEditorDialog((JFrame)window, modal); 139 } 140 else if (window instanceof JDialog) { 141 dialog = new JBEditorDialog((JDialog)window, modal); 142 } 143 144 dialog.setLocation((int)(window.getLocation().getX()+30), (int)(window.getLocation().getY()+30)); 145 dialog.setModel(obj); 146 dialog.setEditable(editable); 147 148 if (obj instanceof PropertyChangeListener) { 149 dialog.addPropertyChangeListener((PropertyChangeListener)obj); 150 } 151 152 dialog.pack(); 153 dialog.setVisible(true); 154 } 155 catch (JAXRException e) { 156 RegistryBrowser.displayError(e); 157 } 158 159 return dialog; 160 } 161 162 protected void validateInput() throws JAXRException { 163 super.validateInput(); 164 if (panel != null) { 165 panel.validateInput(); 166 } 167 } 168 169 public void clear() throws JAXRException { 170 super.clear(); 171 if (panel != null) { 172 panel.clear(); 173 } 174 } 175 176 /*** 177 * Sets whether this dialog is read-only or editable. 178 */ 179 public void setEditable(boolean editable) { 180 super.setEditable(editable); 181 if (panel != null) { 182 panel.setEditable(editable); 183 } 184 } 185 186 187 }

This page was automatically generated by Maven