| Line | Hits | Source |
|---|---|---|
| 1 | /******************************************************************************* | |
| 2 | * Demetrix process modelling system | |
| 3 | * | |
| 4 | * Copyright (c) 2003, 2004 Dimitri A. Pissarenko | |
| 5 | * | |
| 6 | * This file is part of Demetrix. | |
| 7 | * | |
| 8 | * Demetrix is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2.1 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * Demetrix is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with Demetrix; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | * | |
| 22 | * For further information you may | |
| 23 | * | |
| 24 | * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net | |
| 25 | * - look at http://sourceforge.net/projects/demetrix/ | |
| 26 | * - look at http://demetrix.sourceforge.net/ | |
| 27 | * - look at http://members.inode.at/d.pissarenko/ | |
| 28 | * | |
| 29 | *****************************************************************************/ | |
| 30 | ||
| 31 | package net.sourceforge.demetrix.ui; | |
| 32 | ||
| 33 | import java.awt.event.ActionEvent; | |
| 34 | ||
| 35 | import java.util.*; | |
| 36 | ||
| 37 | import javax.swing.*; | |
| 38 | ||
| 39 | import net.sourceforge.demetrix.Demetrix; | |
| 40 | ||
| 41 | import net.sourceforge.demetrix.properties.*; | |
| 42 | ||
| 43 | import net.sourceforge.demetrix.properties.swixml.*; | |
| 44 | ||
| 45 | import org.apache.log4j.Logger; | |
| 46 | ||
| 47 | import org.swixml.SwingEngine; | |
| 48 | ||
| 49 | import org.swixml.XVBox; | |
| 50 | ||
| 51 | /** | |
| 52 | * @author Dimitri Pissarenko | |
| 53 | * | |
| 54 | */ | |
| 55 | ||
| 56 | 0 | public class PropertiesPanel { |
| 57 | ||
| 58 | 12 | public Action applyButtonAction = new AbstractAction() { |
| 59 | ||
| 60 | public void actionPerformed(ActionEvent event) { | |
| 61 | ||
| 62 | applyButtonAction(); | |
| 63 | ||
| 64 | } | |
| 65 | ||
| 66 | }; | |
| 67 | ||
| 68 | private Logger logger = Logger.getLogger(getClass()); | |
| 69 | ||
| 70 | public JButton newPropertyButton; | |
| 71 | ||
| 72 | 12 | public Action newPropertyButtonAction = new AbstractAction() { |
| 73 | ||
| 74 | public void actionPerformed(ActionEvent event) { | |
| 75 | addNewProperty(); | |
| 76 | } | |
| 77 | ||
| 78 | }; | |
| 79 | ||
| 80 | public JButton applyButton; | |
| 81 | ||
| 82 | public JLabel nodeLabel; | |
| 83 | ||
| 84 | private JPanel panel; | |
| 85 | ||
| 86 | private DemetrixPropertiesHolder propertiesHolder; | |
| 87 | ||
| 88 | private DemetrixPropertyRenderer propertyRenderer; | |
| 89 | ||
| 90 | public XVBox propertyRowsPanel; | |
| 91 | ||
| 92 | private Hashtable representationsByPropertyNames; | |
| 93 | ||
| 94 | 12 | private final String UI_DEF_FILE_NAME = |
| 95 | "net/sourceforge/demetrix/ui/PropertiesPanel.xml"; | |
| 96 | ||
| 97 | 12 | public PropertiesPanel() { |
| 98 | ||
| 99 | try { | |
| 100 | ||
| 101 | 12 | this.panel = |
| 102 | (JPanel) (new SwingEngine(this)).render( | |
| 103 | ClassLoader.getSystemClassLoader().getResource(UI_DEF_FILE_NAME)); | |
| 104 | ||
| 105 | 0 | } catch (Exception exception) { |
| 106 | ||
| 107 | this.logger.error("", exception); | |
| 108 | ||
| 109 | 12 | } |
| 110 | ||
| 111 | 12 | this.propertyRenderer = new SwixMLPropertyRenderer(); |
| 112 | ||
| 113 | 12 | } |
| 114 | ||
| 115 | private void addNewProperty() { | |
| 116 | ||
| 117 | 0 | DemetrixPropertyCreationDialog dialog = null; |
| 118 | ||
| 119 | 0 | DemetrixProperty newProperty = null; |
| 120 | ||
| 121 | 0 | String newPropertyName = null; |
| 122 | ||
| 123 | 0 | dialog = |
| 124 | new DemetrixPropertyCreationDialog( | |
| 125 | this.representationsByPropertyNames); | |
| 126 | ||
| 127 | 0 | dialog.show(); |
| 128 | ||
| 129 | 0 | if (dialog.isClosedWithOk()) { |
| 130 | ||
| 131 | 0 | newPropertyName = dialog.getPropertyName(); |
| 132 | ||
| 133 | 0 | newProperty = dialog.getProperty(); |
| 134 | ||
| 135 | 0 | newProperty.setName(newPropertyName); |
| 136 | ||
| 137 | 0 | this.propertiesHolder.addProperty(newProperty); |
| 138 | ||
| 139 | 0 | this.updatePropertiesPanel(); |
| 140 | ||
| 141 | } | |
| 142 | ||
| 143 | 0 | } |
| 144 | ||
| 145 | public JPanel getPanel() { | |
| 146 | ||
| 147 | 5 | return this.panel; |
| 148 | ||
| 149 | } | |
| 150 | ||
| 151 | protected void updatePropertiesPanel() { | |
| 152 | ||
| 153 | 30 | Iterator propertiesIterator = null; |
| 154 | ||
| 155 | 30 | DemetrixProperty currentProperty = null; |
| 156 | ||
| 157 | 30 | SwixMLDemetrixPropertyRepresentation representation = null; |
| 158 | ||
| 159 | 30 | this.representationsByPropertyNames = new Hashtable(); |
| 160 | ||
| 161 | 30 | this.propertyRowsPanel.removeAll(); |
| 162 | 30 | if (this.propertiesHolder!=null) |
| 163 | { | |
| 164 | 28 | propertiesIterator = this.propertiesHolder.getAllProperties(); |
| 165 | 74 | while (propertiesIterator.hasNext()) { |
| 166 | ||
| 167 | 46 | currentProperty = (DemetrixProperty) propertiesIterator.next(); |
| 168 | ||
| 169 | 46 | representation = |
| 170 | ( | |
| 171 | SwixMLDemetrixPropertyRepresentation) this | |
| 172 | .propertyRenderer | |
| 173 | .renderProperty( | |
| 174 | currentProperty); | |
| 175 | ||
| 176 | 46 | if (representation != null) { |
| 177 | ||
| 178 | 46 | this.propertyRowsPanel.add(representation.getPanel()); |
| 179 | ||
| 180 | 46 | representation.updateRepresentation(currentProperty); |
| 181 | ||
| 182 | 46 | this.representationsByPropertyNames.put( |
| 183 | currentProperty.getName(), | |
| 184 | representation); | |
| 185 | ||
| 186 | } | |
| 187 | ||
| 188 | } | |
| 189 | } | |
| 190 | ||
| 191 | 30 | } |
| 192 | ||
| 193 | private void updatePropertyData() { | |
| 194 | ||
| 195 | 2 | Iterator propertiesIterator = null; |
| 196 | ||
| 197 | 2 | DemetrixProperty currentProperty = null; |
| 198 | ||
| 199 | 2 | DemetrixPropertyRepresentation representation = null; |
| 200 | ||
| 201 | 2 | if (this.propertiesHolder != null) { |
| 202 | ||
| 203 | 2 | propertiesIterator = this.propertiesHolder.getAllProperties(); |
| 204 | ||
| 205 | 10 | while (propertiesIterator.hasNext()) { |
| 206 | ||
| 207 | 8 | currentProperty = (DemetrixProperty) propertiesIterator.next(); |
| 208 | ||
| 209 | 8 | representation = |
| 210 | ( | |
| 211 | DemetrixPropertyRepresentation) this | |
| 212 | .representationsByPropertyNames | |
| 213 | .get( | |
| 214 | currentProperty.getName()); | |
| 215 | this.logger.debug("representation=" + representation); | |
| 216 | this.logger.debug("currentProperty=" + currentProperty); | |
| 217 | 8 | representation.updatePropertyData(currentProperty); |
| 218 | ||
| 219 | } | |
| 220 | ||
| 221 | } | |
| 222 | ||
| 223 | 2 | } |
| 224 | ||
| 225 | public String getInvalidPropertyName() { | |
| 226 | ||
| 227 | 2 | Enumeration enumeration = null; |
| 228 | ||
| 229 | 2 | SwixMLDemetrixPropertyRepresentation representation = null; |
| 230 | ||
| 231 | 2 | String propertyName = null; |
| 232 | ||
| 233 | 2 | boolean everythingValid = true; |
| 234 | ||
| 235 | 2 | enumeration = this.representationsByPropertyNames.keys(); |
| 236 | ||
| 237 | 10 | while (enumeration.hasMoreElements() && everythingValid) { |
| 238 | ||
| 239 | 8 | propertyName = (String) enumeration.nextElement(); |
| 240 | ||
| 241 | 8 | representation = |
| 242 | ( | |
| 243 | SwixMLDemetrixPropertyRepresentation) this | |
| 244 | .representationsByPropertyNames | |
| 245 | .get( | |
| 246 | propertyName); | |
| 247 | ||
| 248 | 8 | if (!representation.isEnteredDataValid()) { |
| 249 | ||
| 250 | 0 | everythingValid = false; |
| 251 | ||
| 252 | } | |
| 253 | ||
| 254 | } | |
| 255 | ||
| 256 | 2 | if (everythingValid) { |
| 257 | ||
| 258 | 2 | return null; |
| 259 | ||
| 260 | } else { | |
| 261 | ||
| 262 | 0 | return propertyName; |
| 263 | ||
| 264 | } | |
| 265 | ||
| 266 | } | |
| 267 | ||
| 268 | public boolean updateDataObject() { | |
| 269 | ||
| 270 | 2 | String invalidPropertyName = null; |
| 271 | ||
| 272 | 2 | boolean everythingOk = false; |
| 273 | ||
| 274 | 2 | invalidPropertyName = this.getInvalidPropertyName(); |
| 275 | ||
| 276 | 2 | if (invalidPropertyName == null) { |
| 277 | ||
| 278 | 2 | updatePropertyData(); |
| 279 | ||
| 280 | 2 | everythingOk = true; |
| 281 | ||
| 282 | } else { | |
| 283 | ||
| 284 | 0 | JOptionPane.showMessageDialog( |
| 285 | this.panel, | |
| 286 | "Property \"" | |
| 287 | + invalidPropertyName | |
| 288 | + "\" can't be changed, the value you entered is not valid.", | |
| 289 | Demetrix.PRODUCT_NAME, | |
| 290 | JOptionPane.ERROR_MESSAGE); | |
| 291 | ||
| 292 | 0 | everythingOk = false; |
| 293 | ||
| 294 | } | |
| 295 | ||
| 296 | 2 | return everythingOk; |
| 297 | ||
| 298 | } | |
| 299 | ||
| 300 | protected void applyButtonAction() { | |
| 301 | ||
| 302 | 0 | if (this.updateDataObject()) { |
| 303 | ||
| 304 | 0 | ProcessChainEditor.getInstance().redrawGraph(); |
| 305 | ||
| 306 | } | |
| 307 | ||
| 308 | 0 | } |
| 309 | ||
| 310 | /** | |
| 311 | * @return | |
| 312 | */ | |
| 313 | ||
| 314 | public DemetrixPropertiesHolder getPropertiesHolder() { | |
| 315 | ||
| 316 | 12 | return propertiesHolder; |
| 317 | ||
| 318 | } | |
| 319 | ||
| 320 | /** | |
| 321 | * @param holder | |
| 322 | */ | |
| 323 | ||
| 324 | public void setPropertiesHolder(DemetrixPropertiesHolder holder) { | |
| 325 | ||
| 326 | 19 | propertiesHolder = holder; |
| 327 | ||
| 328 | 19 | this.updatePropertiesPanel(); |
| 329 | ||
| 330 | 19 | } |
| 331 | ||
| 332 | /** | |
| 333 | * @return | |
| 334 | */ | |
| 335 | protected Hashtable getRepresentationsByPropertyNames() { | |
| 336 | 3 | return representationsByPropertyNames; |
| 337 | } | |
| 338 | ||
| 339 | } |
|
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |