1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.xmlhammer.gui.preferences;
23
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import javax.swing.JFrame;
28 import javax.swing.table.DefaultTableModel;
29
30 import org.xmlhammer.model.jaxp.Mapping;
31
32 /***
33 * This PrefixNamespaceMappingPanel is used to ...
34 *
35 * @version $Revision: 1.11 $, $Date: 2007/06/19 19:29:03 $
36 * @author Edwin Dankert <edankert@gmail.com>
37 */
38 public class PrefixNamespaceMappingsPanel extends PreferencesTablePanel {
39 private static final long serialVersionUID = -378919399586517816L;
40
41 public PrefixNamespaceMappingsPanel(JFrame parent, String name, String helpID) {
42 this(parent, name, helpID, false);
43 }
44
45 public PrefixNamespaceMappingsPanel( JFrame parent, String name, String helpID, boolean project) {
46 super(parent, name, helpID, project);
47 }
48
49 protected DefaultTableModel getModel() {
50 if (model == null) {
51 model = new ActivatableTableModel();
52 model.setColumnCount(3);
53 model.setColumnIdentifiers(new String[] {" ", "Prefix", "Namespace URI"});
54 }
55
56 return model;
57 }
58
59 protected Object[] getDefaultRowContent() {
60 return new Object[] {Boolean.TRUE, "New Prefix", "New Namespace URI"};
61 }
62
63 public void setMappings(List<Mapping> mappings) {
64 while (getModel().getRowCount() > 0) {
65 getModel().removeRow( 0);
66 }
67
68 for (Mapping mapping : mappings) {
69 getModel().addRow( new Object[] {mapping.isActive(), mapping.getPrefix(), mapping.getUri()});
70 }
71 }
72
73 protected int[] getColumnWidths() {
74 return new int[] {25, 50, 950};
75 }
76
77 public List<Mapping> getMappings() {
78 List<Mapping> mappings = new ArrayList<Mapping>();
79
80 for ( int i = 0; i < getModel().getRowCount(); i++) {
81 Mapping mapping = new Mapping();
82 mapping.setActive((Boolean)getModel().getValueAt( i, 0));
83 mapping.setPrefix((String)getModel().getValueAt( i, 1));
84 mapping.setUri((String)getModel().getValueAt( i, 2));
85
86 mappings.add(mapping);
87 }
88
89 return mappings;
90 }
91
92 @Override
93 protected String getName(int row) {
94 return getModel().getValueAt(row, 1).toString();
95 }
96 }