Revision 33666

View differences:

tags/tmp_build/applications/appCatalogAndGazetteerClient/src/es/gva/cit/catalog/utils/SOAPMessageParser.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalog.utils;
43
import es.gva.cit.catalog.metadataxml.XMLNode;
44
import es.gva.cit.catalog.metadataxml.XMLTree;
45

  
46
/**
47
 * This class is used to parse a SOAP message
48
 * 
49
 * 
50
 * @author Jorge Piera Llodra (piera_jor@gva.es)
51
 */
52
public class SOAPMessageParser {
53

  
54
/**
55
 * Cut the SOAP Head
56
 * 
57
 * 
58
 * @return A new node without the SOAP Head
59
 * @param node Node retreived
60
 */
61
    public static XMLNode cutHead(XMLNode node) {        
62
        XMLNode[] children = node.getSubnodes();
63
        for (int i = 0; i < node.getNumSubNodes(); i++)
64
            if (children[i].getName().equals("SOAP-ENV:Body")) {
65
                return children[i];
66
            }
67
        return null;
68
    } 
69

  
70
/**
71
 * Get the fault code (if it exists)
72
 * 
73
 * 
74
 * @return The Fault message or NULL
75
 * @param node The node retrieved
76
 */
77
    public static String getFault(XMLNode node) {        
78
        if (node == null) {
79
            return null;
80
        }
81
        node = cutHead(node);
82
        if (node.getName().equals("SOAP-ENV:Fault")) {
83
            return "FAULT-CODE = " +
84
            XMLTree.searchNodeValue(node, "faultcode") + "\nREASON = " +
85
            "Este error se produce normalmente cuando el " +
86
            "servidor no implementa la operacion getCapabilities";
87
        }
88
        //XMLTree.searchNodeValue(node,"faultstring");
89
        return null;
90
    } 
91
 }
0 92

  
tags/tmp_build/applications/appCatalogAndGazetteerClient/src/es/gva/cit/catalog/utils/CatalogConstants.java
1
package es.gva.cit.catalog.utils;
2

  
3
import java.awt.Dimension;
4

  
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
/* CVS MESSAGES:
46
 *
47
 * $Id: CatalogConstants.java 602 2007-09-24 11:55:02 +0000 (Mon, 24 Sep 2007) jpiera $
48
 * $Log$
49
 * Revision 1.1.2.4  2007/07/24 09:45:52  jorpiell
50
 * Fix some interface bugs
51
 *
52
 * Revision 1.1.2.3  2007/07/23 07:14:25  jorpiell
53
 * Catalog refactoring
54
 *
55
 * Revision 1.1.2.2  2007/07/11 13:01:50  jorpiell
56
 * Catalog UI updated
57
 *
58
 * Revision 1.1.2.1  2007/07/10 11:18:04  jorpiell
59
 * Added the registers
60
 *
61
 *
62
 */
63
/**
64
 * This class has some constants for the catalog client
65
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
66
 */
67
public class CatalogConstants {
68
	public static final int BUTTON_LENGHT = 80;
69
	public static final int BUTTON_WIDTH = 23;
70
	public static final Dimension BUTTON_SIZE = new Dimension(BUTTON_LENGHT,BUTTON_WIDTH);
71
	public static final int RESIZE_WINDOW_BUTTON_SIZE = 30;
72
	
73
	//Action commands
74
	public static final String CLOSE_BUTTON_ACTION_COMMAND = "close";
75
	public static final String NEXT_BUTTON_ACTION_COMMAND = "next";
76
	public static final String LAST_BUTTON_ACTION_COMMAND = "last";
77
	public static final String CANCEL_BUTTON_ACTION_COMMAND = "cancel";
78
	public static final String SEARCH_BUTTON_ACTION_COMMAND = "search";
79
	public static final String PROTOCOL_COMBO_ACTION_COMMAND = "protocolCombo";
80
	public static final String SERVER_COMBO_ACTION_COMMAND = "serverCombo";
81
	public static final String RESIZE_BUTTON_ACTION_COMMAND = "resize";
82
	public static final String CONNECT_BUTTON_ACTION_COMMAND = "connect";
83
	public static final String SERVERPROPERTIES_BUTTON_ACTION_COMMAND = "serverProperties";
84

  
85
	//conordancia
86
	public static final String EXACT_WORDS = "E";
87
	public static final String ANY_WORD = "Y";
88
	public static final String ALL_WORDS = "A";
89
	public static final String OR = "Or";
90
	public static final String AND = "And";
91
	
92
	//Connection 
93
	public static final int GET = 0;
94
	public static final int POST = 1;
95
	public static final int SOAP = 2;
96
	public static final int Z3950 = 4;
97
	
98
	//XML
99
	public static final String XML_HEADER_ENCODING = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
100
	public static final String XML_NS = "xmlns";
101

  
102
}
0 103

  
tags/tmp_build/applications/appCatalogAndGazetteerClient/src/es/gva/cit/catalog/utils/xmltreetable/XMLTreeTableCellEditor.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42
package es.gva.cit.catalog.utils.xmltreetable;
43
import java.awt.Component;
44
import java.awt.event.MouseEvent;
45
import java.io.Serializable;
46
import java.util.EventObject;
47

  
48
import javax.swing.JComponent;
49
import javax.swing.JTable;
50
import javax.swing.JTree;
51
import javax.swing.SwingUtilities;
52
import javax.swing.event.CellEditorListener;
53
import javax.swing.event.ChangeEvent;
54
import javax.swing.event.EventListenerList;
55
import javax.swing.table.TableCellEditor;
56
import javax.swing.tree.TreeCellEditor;
57

  
58
/**
59
 * DOCUMENT ME!
60
 * 
61
 * 
62
 * @author $author$
63
 */
64
public class XMLTreeTableCellEditor implements Serializable, TableCellEditor, TreeCellEditor {
65
/**
66
 * 
67
 * 
68
 */
69
    protected EventListenerList listenerList = new EventListenerList();
70
/**
71
 * 
72
 * 
73
 */
74
    protected transient ChangeEvent changeEvent = null;
75
/**
76
 * 
77
 * 
78
 */
79
    protected JComponent editorComponent = null;
80
/**
81
 * 
82
 * 
83
 */
84
    protected JComponent container = null;
85
// Can be tree or table
86

  
87
/**
88
 * DOCUMENT ME!
89
 * 
90
 * 
91
 * @return DOCUMENT ME!
92
 */
93
    public Component getComponent() {        
94
        return editorComponent;
95
    } 
96

  
97
/**
98
 * DOCUMENT ME!
99
 * 
100
 * 
101
 * @return DOCUMENT ME!
102
 */
103
    public Object getCellEditorValue() {        
104
        return editorComponent;
105
    } 
106

  
107
/**
108
 * DOCUMENT ME!
109
 * 
110
 * 
111
 * @return DOCUMENT ME!
112
 * @param anEvent DOCUMENT ME!
113
 */
114
    public boolean isCellEditable(EventObject anEvent) {        
115
        return true;
116
    } 
117

  
118
/**
119
 * DOCUMENT ME!
120
 * 
121
 * 
122
 * @return DOCUMENT ME!
123
 * @param anEvent DOCUMENT ME!
124
 */
125
    public boolean shouldSelectCell(EventObject anEvent) {        
126
        if ((editorComponent != null) && anEvent instanceof MouseEvent &&
127
                (((MouseEvent) anEvent).getID() == MouseEvent.MOUSE_PRESSED)) {
128
            Component dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent,
129
                    3, 3);
130
            MouseEvent e = (MouseEvent) anEvent;
131
            MouseEvent e2 = new MouseEvent(dispatchComponent,
132
                    MouseEvent.MOUSE_RELEASED, e.getWhen() + 100000,
133
                    e.getModifiers(), 3, 3, e.getClickCount(),
134
                    e.isPopupTrigger());
135
            dispatchComponent.dispatchEvent(e2);
136
            e2 = new MouseEvent(dispatchComponent, MouseEvent.MOUSE_CLICKED,
137
                    e.getWhen() + 100001, e.getModifiers(), 3, 3, 1,
138
                    e.isPopupTrigger());
139
            dispatchComponent.dispatchEvent(e2);
140
        }
141
        return false;
142
    } 
143

  
144
/**
145
 * DOCUMENT ME!
146
 * 
147
 * 
148
 * @return DOCUMENT ME!
149
 */
150
    public boolean stopCellEditing() {        
151
        fireEditingStopped();
152
        return true;
153
    } 
154

  
155
/**
156
 * DOCUMENT ME!
157
 * 
158
 */
159
    public void cancelCellEditing() {        
160
        fireEditingCanceled();
161
    } 
162

  
163
/**
164
 * DOCUMENT ME!
165
 * 
166
 * 
167
 * @param l DOCUMENT ME!
168
 */
169
    public void addCellEditorListener(CellEditorListener l) {        
170
        listenerList.add(CellEditorListener.class, l);
171
    } 
172

  
173
/**
174
 * DOCUMENT ME!
175
 * 
176
 * 
177
 * @param l DOCUMENT ME!
178
 */
179
    public void removeCellEditorListener(CellEditorListener l) {        
180
        listenerList.remove(CellEditorListener.class, l);
181
    } 
182

  
183
/**
184
 * DOCUMENT ME!
185
 * 
186
 */
187
    protected void fireEditingStopped() {        
188
        Object[] listeners = listenerList.getListenerList();
189
        // Process the listeners last to first, notifying
190
        // those that are interested in this event
191
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
192
            if (listeners[i] == CellEditorListener.class) {
193
                // Lazily create the event:
194
                if (changeEvent == null) {
195
                    changeEvent = new ChangeEvent(this);
196
                }
197
                ((CellEditorListener) listeners[i + 1]).editingStopped(changeEvent);
198
            }
199
        }
200
    } 
201

  
202
/**
203
 * DOCUMENT ME!
204
 * 
205
 */
206
    protected void fireEditingCanceled() {        
207
        // Guaranteed to return a non-null array
208
        Object[] listeners = listenerList.getListenerList();
209
        // Process the listeners last to first, notifying
210
        // those that are interested in this event
211
        for (int i = listeners.length - 2; i >= 0; i -= 2) {
212
            if (listeners[i] == CellEditorListener.class) {
213
                // Lazily create the event:
214
                if (changeEvent == null) {
215
                    changeEvent = new ChangeEvent(this);
216
                }
217
                ((CellEditorListener) listeners[i + 1]).editingCanceled(changeEvent);
218
            }
219
        }
220
    } 
221
// implements javax.swing.tree.TreeCellEditor
222

  
223
/**
224
 * 
225
 * 
226
 * 
227
 * @return 
228
 * @param tree 
229
 * @param value 
230
 * @param isSelected 
231
 * @param expanded 
232
 * @param leaf 
233
 * @param row 
234
 */
235
    public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {        
236
        tree.convertValueToText(value, isSelected,
237
                expanded, leaf, row, false);
238
        editorComponent = (JComponent) value;
239
        container = tree;
240
        return editorComponent;
241
    } 
242
// implements javax.swing.table.TableCellEditor
243

  
244
/**
245
 * 
246
 * 
247
 * 
248
 * @return 
249
 * @param table 
250
 * @param value 
251
 * @param isSelected 
252
 * @param row 
253
 * @param column 
254
 */
255
    public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {        
256
        editorComponent = (JComponent) value;
257
        container = table;
258
        return editorComponent;
259
    } 
260
 }
261
// End of class JComponentCellEditor
0 262

  
tags/tmp_build/applications/appCatalogAndGazetteerClient/src/es/gva/cit/catalog/utils/xmltreetable/XMLTreeTableCellRenderer.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalog.utils.xmltreetable;
43
import java.awt.Component;
44

  
45
import javax.swing.JComponent;
46
import javax.swing.JTable;
47
import javax.swing.table.TableCellRenderer;
48

  
49
/**
50
 * 
51
 * 
52
 * 
53
 * @author Jorge Piera Llodra (piera_jor@gva.es)
54
 */
55
class XMLTreeTableCellRenderer implements TableCellRenderer {
56
/* (non-Javadoc)
57
     * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
58
     */
59

  
60
/**
61
 * 
62
 * 
63
 * 
64
 * @return 
65
 * @param table 
66
 * @param value 
67
 * @param isSelected 
68
 * @param hasFocus 
69
 * @param row 
70
 * @param column 
71
 */
72
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {        
73
        // TODO Auto-generated method stub
74
        return (JComponent) value;
75
    } 
76
 }
0 77

  
tags/tmp_build/applications/appCatalogAndGazetteerClient/src/es/gva/cit/catalog/utils/xmltreetable/XMLTreeCellRenderer.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalog.utils.xmltreetable;
43

  
44
/**
45
 * 
46
 * 
47
 * 
48
 * @author Jorge Piera Llodra (piera_jor@gva.es)
49
 */
50
public class XMLTreeCellRenderer extends javax.swing.tree.DefaultTreeCellRenderer {
51

  
52
/**
53
 * 
54
 * 
55
 */
56
    public  XMLTreeCellRenderer() {        
57
        this.setClosedIcon(null);
58
        this.setOpenIcon(null);
59
        this.setLeafIcon(null);
60
    } 
61
 }
0 62

  
tags/tmp_build/applications/appCatalogAndGazetteerClient/src/es/gva/cit/catalog/utils/xmltreetable/XMLTreeTable.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalog.utils.xmltreetable;
43
import javax.swing.JComponent;
44
import javax.swing.JTree;
45

  
46
import next.swing.JTreeTable;
47
import next.swing.TreeTableModel;
48

  
49
/**
50
 * 
51
 * 
52
 * 
53
 * @author Jorge Piera Llodra (piera_jor@gva.es)
54
 */
55
public class XMLTreeTable extends JTreeTable {
56

  
57
/**
58
 * 
59
 * 
60
 * 
61
 * @param treeTableModel 
62
 */
63
    public  XMLTreeTable(TreeTableModel treeTableModel) {        
64
        super(treeTableModel);
65
        tree.setCellRenderer(new XMLTreeCellRenderer());
66
        setDefaultEditor(JComponent.class, new XMLTreeTableCellEditor());
67
    } 
68

  
69
/**
70
 * 
71
 * 
72
 * 
73
 * @return 
74
 */
75
    public JTree getTree() {        
76
        return tree;
77
    } 
78

  
79
/**
80
 * 
81
 * 
82
 * 
83
 * @return 
84
 * @param x 
85
 * @param y 
86
 */
87
    public boolean isCellEditable(int x, int y) {        
88
        return true;
89
    } 
90
 }
0 91

  
tags/tmp_build/applications/appCatalogAndGazetteerClient/src/es/gva/cit/catalog/utils/xmltreetable/XMLTreeTableModel.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalog.utils.xmltreetable;
43
import java.awt.Font;
44
import java.util.Enumeration;
45
import java.util.Vector;
46

  
47
import javax.swing.JEditorPane;
48
import javax.swing.JLabel;
49
import javax.swing.JScrollPane;
50
import javax.swing.JTree;
51
import javax.swing.tree.DefaultMutableTreeNode;
52
import javax.swing.tree.TreePath;
53

  
54
import next.swing.AbstractTreeTableModel;
55
import next.swing.TreeTableModel;
56

  
57
import org.amic.util.date.Date;
58

  
59
import es.gva.cit.catalog.metadataxml.XMLNode;
60
import es.gva.cit.catalog.utils.Strings;
61

  
62
/**
63
 * 
64
 * 
65
 * 
66
 * @author Jorge Piera Llodra (piera_jor@gva.es)
67
 */
68
public class XMLTreeTableModel extends AbstractTreeTableModel {
69

  
70
/**
71
 * 
72
 * 
73
 */
74
    private Vector columns = null;
75

  
76
/**
77
 * 
78
 * 
79
 */
80
    private String[] allowed = null;
81

  
82
/**
83
 * 
84
 * 
85
 */
86
    private String[] forbidden = null;
87

  
88
/**
89
 * 
90
 * 
91
 */
92
    private boolean dynamic = false;
93

  
94
/**
95
 * Creates new XmlTreeTableModel
96
 * 
97
 * 
98
 * @param node 
99
 */
100
    public  XMLTreeTableModel(XMLNode node) {        
101
        this(node, -1, null, null);
102
    } 
103

  
104
/**
105
 * 
106
 * 
107
 * 
108
 * @param node 
109
 * @param level 
110
 * @param allowed 
111
 * @param forbidden 
112
 */
113
    public  XMLTreeTableModel(XMLNode node, int level, String[] allowed, String[] forbidden) {        
114
        super(new DefaultMutableTreeNode(node));
115
        this.allowed = allowed;
116
        this.forbidden = forbidden;
117
        processChildren((DefaultMutableTreeNode) getRoot(), level);
118
    } 
119

  
120
/**
121
 * 
122
 * 
123
 */
124
    public final int ALIGN_LEFT = JLabel.LEFT;
125

  
126
/**
127
 * 
128
 * 
129
 */
130
    public final int ALIGN_RIGHT = JLabel.RIGHT;
131

  
132
/**
133
 * 
134
 * 
135
 */
136
    public final int ALIGN_CENTER = JLabel.CENTER;
137

  
138
/**
139
 * 
140
 * 
141
 * 
142
 * @param value 
143
 */
144
    public void setDynamic(boolean value) {        
145
        dynamic = value;
146
    } 
147

  
148
/**
149
 * 
150
 * 
151
 * 
152
 * @return 
153
 * @param node 
154
 */
155
    public boolean isLeaf(Object node) {        
156
        return (getChildCount(node) == 0) && !dynamic;
157
    } 
158

  
159
/**
160
 * 
161
 * 
162
 * 
163
 * @return 
164
 * @param node 
165
 * @param level 
166
 */
167
    public boolean processChildren(DefaultMutableTreeNode node, int level) {        
168
        if (level == 0) {
169
            return true;
170
        }
171
        boolean doIt = true;
172
        XMLNode n = (XMLNode) node.getUserObject();
173
        if (allowed != null) {
174
            String name = n.getName();
175
            doIt = false;
176
            for (int i = 0; i < allowed.length; i++)
177
                if (allowed[i].equals(name)) {
178
                    doIt = true;
179
                    break;
180
                }
181
        }
182
        if (forbidden != null) {
183
            String name = n.getName();
184
            for (int i = 0; i < forbidden.length; i++)
185
                if (forbidden[i].equals(name)) {
186
                    doIt = false;
187
                    break;
188
                }
189
        }
190
        if (!doIt) {
191
            return false;
192
        }
193
        XMLNode[] nodes = n.getSubnodes();
194
        DefaultMutableTreeNode newNode;
195
        for (int i=0 ; i<nodes.length ; i++) {
196
            newNode = new DefaultMutableTreeNode(nodes[i]);
197
            if (processChildren(newNode, level - 1)) {
198
                node.add(newNode);
199
            }
200
        }
201
        return true;
202
    } 
203

  
204
/**
205
 * 
206
 * 
207
 * 
208
 * @param ctt 
209
 */
210
    public void configureView(XMLTreeTable ctt) {        
211
        Column col;
212
        javax.swing.table.TableColumnModel tcm = ctt.getColumnModel();
213
        ctt.setRowHeight(20);
214
        int total = 0;
215
        for (int i = 1; i < tcm.getColumnCount(); i++) {
216
            col = ((Column) columns.elementAt(i - 1));
217
            tcm.getColumn(i).setPreferredWidth(50);
218
            total += col.width;
219
            tcm.getColumn(i).setCellRenderer(new XMLTreeTableCellRenderer());
220
        }
221
        tcm.getColumn(0).setWidth(100);
222
        setExpandedTree((DefaultMutableTreeNode) getRoot(), ctt.getTree());
223
    } 
224

  
225
/**
226
 * 
227
 * 
228
 * 
229
 * @return 
230
 * @param node 
231
 * @param tree 
232
 */
233
    public boolean setExpandedTree(DefaultMutableTreeNode node, JTree tree) {        
234
        boolean isExpanded = false;
235
        Enumeration children = node.children();
236
        while (children.hasMoreElements()) {
237
            DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement();
238
            if (setExpandedTree(child, tree) && (isExpanded == false)) {
239
                isExpanded = true;
240
            }
241
        }
242
        if (node.isLeaf() && (isValueAt(node) || isAttributeAt(node))) {
243
            tree.expandPath(new TreePath(node.getPath()));
244
            return true;
245
        }
246
        if (isExpanded) {
247
            tree.expandPath(new TreePath(node.getPath()));
248
        }
249
        return isExpanded;
250
    } 
251

  
252
/**
253
 * 
254
 * 
255
 * 
256
 * @param name 
257
 * @param attribute 
258
 * @param label 
259
 * @param width 
260
 */
261
    public void addJScrollPaneColumn(String name, String attribute, String label, int width) {        
262
        addColumn(new Column(name, attribute, label, ALIGN_LEFT, width,
263
                JScrollPane.class, null));
264
    } 
265

  
266
/**
267
 * 
268
 * 
269
 * 
270
 * @param name 
271
 * @param attribute 
272
 * @param label 
273
 * @param width 
274
 */
275
    public void addStringColumn(String name, String attribute, String label, int width) {        
276
        addColumn(new Column(name, attribute, label, ALIGN_LEFT, width,
277
                String.class, null));
278
    } 
279

  
280
/**
281
 * 
282
 * 
283
 * 
284
 * @param name 
285
 * @param attribute 
286
 * @param label 
287
 * @param width 
288
 * @param format 
289
 */
290
    public void addNumberColumn(String name, String attribute, String label, int width, String format) {        
291
        addColumn(new Column(name, attribute, label, ALIGN_RIGHT, width,
292
                Double.class, format));
293
    } 
294

  
295
/**
296
 * 
297
 * 
298
 * 
299
 * @param name 
300
 * @param attribute 
301
 * @param label 
302
 * @param width 
303
 * @param format 
304
 */
305
    public void addDateColumn(String name, String attribute, String label, int width, String format) {        
306
        addColumn(new Column(name, attribute, label, ALIGN_LEFT, width,
307
                Date.class, format));
308
    } 
309

  
310
/**
311
 * 
312
 * 
313
 * 
314
 * @param column 
315
 */
316
    public void addColumn(Column column) {        
317
        if (columns == null) {
318
            columns = new Vector();
319
        }
320
        columns.add(column);
321
    } 
322

  
323
/**
324
 * 
325
 * 
326
 * 
327
 * @return 
328
 * @param parent 
329
 */
330
    public int getChildCount(Object parent) {        
331
        return ((DefaultMutableTreeNode) parent).getChildCount();
332
    } 
333

  
334
/**
335
 * 
336
 * 
337
 * 
338
 * @return 
339
 * @param parent 
340
 * @param index 
341
 */
342
    public Object getChild(Object parent, int index) {        
343
        return ((DefaultMutableTreeNode) parent).getChildAt(index);
344
    } 
345

  
346
/**
347
 * 
348
 * 
349
 * 
350
 * @return 
351
 * @param column 
352
 */
353
    public String getColumnName(int column) {        
354
        if (column == 0) {
355
            return "";
356
        }
357
        return ((Column) columns.elementAt(column - 1)).label;
358
    } 
359

  
360
/**
361
 * 
362
 * 
363
 * 
364
 * @return 
365
 * @param column 
366
 */
367
    public Class getColumnClass(int column) {        
368
        if (column == 0) {
369
            return TreeTableModel.class;
370
        }
371
        return ((Column) columns.elementAt(column - 1)).jClass;
372
    } 
373

  
374
/**
375
 * 
376
 * 
377
 * 
378
 * @return 
379
 * @param node 
380
 */
381
    public boolean isValueAt(Object node) {        
382
        DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) node;
383
        if (currentNode.getUserObject() instanceof XMLNode) {
384
            XMLNode xr = (XMLNode) currentNode.getUserObject();
385
            if (xr != null) {
386
                if (xr.getText() != null) {
387
                    if (!(Strings.replace(xr.getText(), " ", "").equals(""))) {
388
                        return true;
389
                    }
390
                }
391
            }
392
        }
393
        return false;
394
    } 
395

  
396
/**
397
 * 
398
 * 
399
 * 
400
 * @return 
401
 * @param node 
402
 */
403
    public boolean isAttributeAt(Object node) {        
404
        DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) node;
405
        if (currentNode.getUserObject() instanceof XMLNode) {
406
            XMLNode xr = (XMLNode) currentNode.getUserObject();
407
            if (xr != null) {
408
                if (getAttribute(xr) != null) {
409
                    if (!(Strings.replace(getAttribute(xr),
410
                                " ", "").equals(""))) {
411
                        return true;
412
                    }
413
                }
414
            }
415
        }
416
        return false;
417
    } 
418

  
419
/**
420
 * 
421
 * 
422
 * 
423
 * @return 
424
 * @param node 
425
 */
426
    public String getValueAt(Object node) {        
427
        DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) node;
428
        if (currentNode.getUserObject() instanceof XMLNode) {
429
            XMLNode xr = (XMLNode) currentNode.getUserObject();
430
            
431
            return xr.getText();
432
        }
433
        return null;
434
    } 
435

  
436
/**
437
 * 
438
 * 
439
 * 
440
 * @return 
441
 * @param node 
442
 * @param column 
443
 */
444
    public Object getValueAt(Object node, int column) {        
445
        //JScrollPane
446
        JEditorPane editor = new JEditorPane();
447
        editor.setEditable(false);
448
        JScrollPane scroll = new JScrollPane(editor);
449
        scroll.setBorder(null);
450
        //JLabel
451
        JLabel text = new JLabel();
452
        text.setFont(new Font(null, Font.PLAIN, 12));
453
        DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) node;
454
        if (currentNode.getUserObject() instanceof XMLNode) {
455
            XMLNode xr = (XMLNode) currentNode.getUserObject();
456
            if (column == 0) {
457
                return xr.toString();
458
            }
459
            Column col = (Column) columns.elementAt(column - 1);
460
            String att = col.attribute;
461
            try {
462
                if (att.equals("tag-name")) {
463
                    if (xr.getName().trim().length() > 40) {
464
                        editor.setText(xr.getName());
465
                        editor.setCaretPosition(0);
466
                        return scroll;
467
                    }
468
                    text.setText(xr.getName());
469
                    
470
                    return text;
471
                } else if (att.equals("tag-value")) {
472
                    if (xr.getText().trim().length() > 40) {
473
                        editor.setText(xr.getText());
474
                        editor.setCaretPosition(0);
475
                        return scroll;
476
                    }
477
                    text.setText(xr.getText());
478
                    return text;
479
                } else {
480
                    if (getAttribute(xr).trim().length() > 40) {
481
                        editor.setText(getAttribute(xr));
482
                        editor.setCaretPosition(0);
483
                        return scroll;
484
                    }
485
                    text.setText(getAttribute(xr));
486
                    return text;
487
                }
488
            } catch (Exception ex) {
489
            }
490
        }
491
        return null;
492
    } 
493

  
494
/**
495
 * 
496
 * 
497
 * 
498
 * @return 
499
 * @param node 
500
 */
501
    public String getAttribute(XMLNode node) {        
502
        String attributes = "";
503
        Vector vAttributes = node.getAttributeNames();
504
        
505
        for (int i = 0; i < vAttributes.size(); i++){
506
            String att = (String)vAttributes.get(i);
507
            String val = node.getAttribute(att);
508
            attributes = attributes +
509
                att + "=" + val + " ";
510
        }
511
        return attributes;
512
    } 
513

  
514
/**
515
 * 
516
 * 
517
 * 
518
 * @return 
519
 */
520
    public int getColumnCount() {        
521
        if (columns == null) {
522
            return 1;
523
        }
524
        return columns.size() + 1;
525
    } 
526
/**
527
 * 
528
 * 
529
 */
530
public class Column {
531

  
532
/**
533
 * 
534
 * 
535
 */
536
    int align;
537

  
538
/**
539
 * 
540
 * 
541
 */
542
    int width;
543

  
544
/**
545
 * 
546
 * 
547
 */
548
    Class jClass;
549

  
550
/**
551
 * 
552
 * 
553
 */
554
    String name;
555

  
556
/**
557
 * 
558
 * 
559
 */
560
    String attribute;
561

  
562
/**
563
 * 
564
 * 
565
 */
566
    String label;
567

  
568
/**
569
 * 
570
 * 
571
 */
572
    String format;
573

  
574
/**
575
 * 
576
 * 
577
 * 
578
 * @param name 
579
 * @param attribute 
580
 * @param label 
581
 * @param align 
582
 * @param width 
583
 * @param jClass 
584
 * @param format 
585
 */
586
     Column(String name, String attribute, String label, int align, int width, Class jClass, String format) {        
587
            this.name = name;
588
            this.attribute = attribute;
589
            this.label = label;
590
            this.align = align;
591
            this.width = width;
592
            this.jClass = jClass;
593
            this.format = format;
594
    } 
595
 }
596
 }
0 597

  
tags/tmp_build/applications/appCatalogAndGazetteerClient/src/es/gva/cit/catalog/utils/Strings.java
1

  
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
*
4
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
5
*
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
*
20
* For more information, contact:
21
*
22
*  Generalitat Valenciana
23
*   Conselleria d'Infraestructures i Transport
24
*   Av. Blasco Ib??ez, 50
25
*   46010 VALENCIA
26
*   SPAIN
27
*
28
*      +34 963862235
29
*   gvsig@gva.es
30
*      www.gvsig.gva.es
31
*
32
*    or
33
*
34
*   IVER T.I. S.A
35
*   Salamanca 50
36
*   46005 Valencia
37
*   Spain
38
*
39
*   +34 963163400
40
*   dac@iver.es
41
*/
42
package es.gva.cit.catalog.utils;
43

  
44
import java.util.TreeMap;
45
import java.util.Vector;
46

  
47
/**
48
 * String Functions
49
 * 
50
 * 
51
 * @author Jorge Piera Llodra (piera_jor@gva.es)
52
 */
53
public class Strings {
54

  
55
/**
56
 * Replace a part of a String
57
 * 
58
 * 
59
 * @return 
60
 * @param str String to find the pattern
61
 * @param pattern Pattern to find
62
 * @param replace String to replace
63
 */
64
    public static String replace(String str, String pattern, String replace) {        
65
        int s = 0;
66
        int e = 0;
67
        StringBuffer result = new StringBuffer();
68
        while ((e = str.indexOf(pattern, s)) >= 0) {
69
            result.append(str.substring(s, e));
70
            result.append(replace);
71
            s = e + pattern.length();
72
        }
73
        result.append(str.substring(s));
74
        return result.toString();
75
    } 
76

  
77
/**
78
 * Find a pattern into one array
79
 * 
80
 * 
81
 * @return 
82
 * @param pattern 
83
 * @param array 
84
 */
85
    public static boolean find(String pattern, String[] array) {        
86
        if (array != null) {
87
            for (int i = 0; i < array.length; i++)
88
                if (pattern.equals(array[i])) {
89
                    return true;
90
                }
91
        }
92
        return false;
93
    } 
94

  
95
/**
96
 * This function joins two strings
97
 * 
98
 * 
99
 * @return 
100
 * @param s1 
101
 * @param s2 
102
 */
103
    public static String[] join(String[] s1, String[] s2) {        
104
        if (s1 == null) {
105
            return s2;
106
        }
107
        if (s2 == null) {
108
            return s1;
109
        }
110
        String[] out = new String[s1.length + s2.length];
111
        for (int i = 0; i < s1.length; i++)
112
            out[i] = s1[i];
113
        for (int i = 0; i < s2.length; i++)
114
            out[s1.length + i] = s2[i];
115
        return out;
116
    } 
117

  
118
/**
119
 * returns a list (comma-separated) in one unique string
120
 * 
121
 * 
122
 * @return 
123
 * @param input 
124
 */
125
    public static String getComaSeparated(String[] input) {        
126
        return getXSeparated("," , input);
127
    } 
128

  
129
/**
130
 * returns a list (blanck-separated) in one unique string
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff