Coverage details for net.sourceforge.demetrix.ui.PropertiesPanel

LineHitsSource
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  
560public class PropertiesPanel {
57  
5812    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  
7212    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  
9412    private final String UI_DEF_FILE_NAME =
95         "net/sourceforge/demetrix/ui/PropertiesPanel.xml";
96  
9712    public PropertiesPanel() {
98         
99         try {
100  
10112            this.panel =
102                 (JPanel) (new SwingEngine(this)).render(
103             ClassLoader.getSystemClassLoader().getResource(UI_DEF_FILE_NAME));
104  
1050        } catch (Exception exception) {
106  
107             this.logger.error("", exception);
108  
10912        }
110  
11112        this.propertyRenderer = new SwixMLPropertyRenderer();
112  
11312    }
114  
115     private void addNewProperty() {
116  
1170        DemetrixPropertyCreationDialog dialog = null;
118  
1190        DemetrixProperty newProperty = null;
120  
1210        String newPropertyName = null;
122  
1230        dialog =
124             new DemetrixPropertyCreationDialog(
125                 this.representationsByPropertyNames);
126  
1270        dialog.show();
128  
1290        if (dialog.isClosedWithOk()) {
130  
1310            newPropertyName = dialog.getPropertyName();
132  
1330            newProperty = dialog.getProperty();
134  
1350            newProperty.setName(newPropertyName);
136  
1370            this.propertiesHolder.addProperty(newProperty);
138  
1390            this.updatePropertiesPanel();
140  
141         }
142  
1430    }
144  
145     public JPanel getPanel() {
146  
1475        return this.panel;
148  
149     }
150  
151     protected void updatePropertiesPanel() {
152  
15330        Iterator propertiesIterator = null;
154  
15530        DemetrixProperty currentProperty = null;
156  
15730        SwixMLDemetrixPropertyRepresentation representation = null;
158  
15930        this.representationsByPropertyNames = new Hashtable();
160  
16130        this.propertyRowsPanel.removeAll();
16230        if (this.propertiesHolder!=null)
163         {
16428            propertiesIterator = this.propertiesHolder.getAllProperties();
16574            while (propertiesIterator.hasNext()) {
166  
16746                currentProperty = (DemetrixProperty) propertiesIterator.next();
168  
16946                representation =
170                     (
171                         SwixMLDemetrixPropertyRepresentation) this
172                             .propertyRenderer
173                             .renderProperty(
174                         currentProperty);
175  
17646                if (representation != null) {
177  
17846                    this.propertyRowsPanel.add(representation.getPanel());
179  
18046                    representation.updateRepresentation(currentProperty);
181  
18246                    this.representationsByPropertyNames.put(
183                         currentProperty.getName(),
184                         representation);
185  
186                 }
187  
188             }
189         }
190  
19130    }
192  
193     private void updatePropertyData() {
194  
1952        Iterator propertiesIterator = null;
196  
1972        DemetrixProperty currentProperty = null;
198  
1992        DemetrixPropertyRepresentation representation = null;
200  
2012        if (this.propertiesHolder != null) {
202  
2032            propertiesIterator = this.propertiesHolder.getAllProperties();
204  
20510            while (propertiesIterator.hasNext()) {
206  
2078                currentProperty = (DemetrixProperty) propertiesIterator.next();
208  
2098                representation =
210                     (
211                         DemetrixPropertyRepresentation) this
212                             .representationsByPropertyNames
213                             .get(
214                         currentProperty.getName());
215                 this.logger.debug("representation=" + representation);
216                 this.logger.debug("currentProperty=" + currentProperty);
2178                representation.updatePropertyData(currentProperty);
218  
219             }
220  
221         }
222  
2232    }
224  
225     public String getInvalidPropertyName() {
226  
2272        Enumeration enumeration = null;
228  
2292        SwixMLDemetrixPropertyRepresentation representation = null;
230  
2312        String propertyName = null;
232  
2332        boolean everythingValid = true;
234  
2352        enumeration = this.representationsByPropertyNames.keys();
236  
23710        while (enumeration.hasMoreElements() && everythingValid) {
238  
2398            propertyName = (String) enumeration.nextElement();
240  
2418            representation =
242                 (
243                     SwixMLDemetrixPropertyRepresentation) this
244                         .representationsByPropertyNames
245                         .get(
246                     propertyName);
247  
2488            if (!representation.isEnteredDataValid()) {
249  
2500                everythingValid = false;
251  
252             }
253  
254         }
255  
2562        if (everythingValid) {
257  
2582            return null;
259  
260         } else {
261  
2620            return propertyName;
263  
264         }
265  
266     }
267  
268     public boolean updateDataObject() {
269  
2702        String invalidPropertyName = null;
271  
2722        boolean everythingOk = false;
273  
2742        invalidPropertyName = this.getInvalidPropertyName();
275  
2762        if (invalidPropertyName == null) {
277  
2782            updatePropertyData();
279  
2802            everythingOk = true;
281  
282         } else {
283  
2840            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  
2920            everythingOk = false;
293  
294         }
295  
2962        return everythingOk;
297  
298     }
299  
300     protected void applyButtonAction() {
301  
3020        if (this.updateDataObject()) {
303  
3040            ProcessChainEditor.getInstance().redrawGraph();
305  
306         }
307  
3080    }
309  
310     /**
311      * @return
312      */
313  
314     public DemetrixPropertiesHolder getPropertiesHolder() {
315  
31612        return propertiesHolder;
317  
318     }
319  
320     /**
321      * @param holder
322      */
323  
324     public void setPropertiesHolder(DemetrixPropertiesHolder holder) {
325  
32619        propertiesHolder = holder;
327  
32819        this.updatePropertiesPanel();
329  
33019    }
331  
332     /**
333      * @return
334      */
335     protected Hashtable getRepresentationsByPropertyNames() {
3363        return representationsByPropertyNames;
337     }
338  
339 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.