Revision 982
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.15/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultDynFormManager.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.impl; |
|
25 |
|
|
26 |
import java.util.HashMap; |
|
27 |
import java.util.List; |
|
28 |
import java.util.Map; |
|
29 |
|
|
30 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
31 |
import org.gvsig.tools.dynform.DynFormDefinition; |
|
32 |
import org.gvsig.tools.dynform.DynFormManager; |
|
33 |
import org.gvsig.tools.dynform.JDynForm; |
|
34 |
import org.gvsig.tools.dynform.JDynFormField; |
|
35 |
import org.gvsig.tools.dynform.JDynFormSet; |
|
36 |
import org.gvsig.tools.dynform.spi.DynFormSPILocator; |
|
37 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
|
38 |
import org.gvsig.tools.dynobject.DynField; |
|
39 |
import org.gvsig.tools.dynobject.DynObject; |
|
40 |
import org.gvsig.tools.dynobject.DynObjectSet; |
|
41 |
import org.gvsig.tools.dynobject.DynStruct; |
|
42 |
import org.gvsig.tools.service.Service; |
|
43 |
import org.gvsig.tools.service.ServiceException; |
|
44 |
|
|
45 |
@SuppressWarnings({ "unchecked", "rawtypes"}) |
|
46 |
public class DefaultDynFormManager implements DynFormManager { |
|
47 |
|
|
48 |
DynFormSPIManager serviceManager = null; |
|
49 |
|
|
50 |
private Map definitions = null; |
|
51 |
|
|
52 |
public DefaultDynFormManager() { |
|
53 |
} |
|
54 |
|
|
55 |
public DynFormSPIManager getServiceManager() { |
|
56 |
if( serviceManager == null ) { |
|
57 |
serviceManager = DynFormSPILocator.getDynFormSPIManager(); |
|
58 |
} |
|
59 |
return serviceManager; |
|
60 |
} |
|
61 |
|
|
62 |
public Map getDefinitions() { |
|
63 |
if( this.definitions==null ) { |
|
64 |
this.definitions = new HashMap(); |
|
65 |
} |
|
66 |
return this.definitions; |
|
67 |
} |
|
68 |
|
|
69 |
public Service getService(DynObject parameters) throws ServiceException { |
|
70 |
JDynFormField formfield = (JDynFormField) serviceManager.createService(parameters); |
|
71 |
return formfield; |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
public DynFormDefinition getDefinition(String name) { |
|
76 |
DefaultDynFormDefinition x = null; |
|
77 |
x = (DefaultDynFormDefinition) this.getDefinitions().get(name); |
|
78 |
if( x==null ) { |
|
79 |
x = new DefaultDynFormDefinition(name, this); |
|
80 |
this.getDefinitions().put(x.getName(), x); |
|
81 |
} |
|
82 |
return x; |
|
83 |
} |
|
84 |
|
|
85 |
public DynFormDefinition getDefinition(DynStruct definition) { |
|
86 |
String name = definition.getName(); |
|
87 |
DefaultDynFormDefinition x = null; |
|
88 |
x = (DefaultDynFormDefinition) this.getDefinitions().get(name); |
|
89 |
if( x==null ) { |
|
90 |
x = new DefaultDynFormDefinition(name, this); |
|
91 |
this.getDefinitions().put(x.getName(), x); |
|
92 |
DynField[] fields = definition.getDynFields(); |
|
93 |
for( int i=0; i<fields.length; i++ ) { |
|
94 |
x.add(fields[i]); |
|
95 |
} |
|
96 |
} |
|
97 |
return x; |
|
98 |
} |
|
99 |
|
|
100 |
public DynFormDefinition getDefinition(DynObject obj) { |
|
101 |
return this.getDefinition(obj.getDynClass()); |
|
102 |
} |
|
103 |
|
|
104 |
public JDynForm createJDynForm(DynFormDefinition definition) throws ServiceException { |
|
105 |
JDynForm x = new DefaultJDynForm(this, definition); |
|
106 |
return x; |
|
107 |
} |
|
108 |
|
|
109 |
public JDynForm createJDynForm(DynStruct struct) throws ServiceException { |
|
110 |
DynFormDefinition definition = this.getDefinition(struct); |
|
111 |
JDynForm x = new DefaultJDynForm(this, definition); |
|
112 |
return x; |
|
113 |
} |
|
114 |
|
|
115 |
public JDynForm createJDynForm(DynObject obj) throws ServiceException { |
|
116 |
DynFormDefinition definition = this.getDefinition(obj); |
|
117 |
JDynForm x = new DefaultJDynForm(this, definition); |
|
118 |
x.setValues(obj); |
|
119 |
return x; |
|
120 |
} |
|
121 |
|
|
122 |
public JDynFormSet createJDynFormSet(DynFormDefinition definition) |
|
123 |
throws ServiceException { |
|
124 |
JDynFormSet x = new DefaultJDynFormSet(this, definition); |
|
125 |
return x; |
|
126 |
} |
|
127 |
|
|
128 |
public JDynFormSet createJDynFormSet(DynStruct struct) throws ServiceException { |
|
129 |
DynFormDefinition definition = this.getDefinition(struct); |
|
130 |
JDynFormSet x = new DefaultJDynFormSet(this, definition); |
|
131 |
return x; |
|
132 |
} |
|
133 |
|
|
134 |
public JDynFormSet createJDynFormSet(DynObjectSet data) |
|
135 |
throws ServiceException { |
|
136 |
DynObject obj = null; |
|
137 |
try { |
|
138 |
if( data.getSize() < 1 ) { |
|
139 |
throw new IllegalArgumentException("The DynObjectSet not has elements."); |
|
140 |
} |
|
141 |
DisposableIterator it = data.iterator(); |
|
142 |
obj = (DynObject) it.next(); |
|
143 |
|
|
144 |
} catch (Exception e) { |
|
145 |
throw new RuntimeException(e.getLocalizedMessage(), e); |
|
146 |
} |
|
147 |
JDynFormSet form = this.createJDynFormSet(obj.getDynClass()); |
|
148 |
form.setValues(data); |
|
149 |
return form; |
|
150 |
} |
|
151 |
|
|
152 |
public JDynFormSet createJDynFormSet(List data) |
|
153 |
throws ServiceException { |
|
154 |
if( data.size() < 1 ) { |
|
155 |
throw new IllegalArgumentException("The DynObjectSet not has elements."); |
|
156 |
} |
|
157 |
DynObject obj = (DynObject) data.get(0); |
|
158 |
JDynFormSet form = this.createJDynFormSet(obj.getDynClass()); |
|
159 |
form.setValues(data); |
|
160 |
return form; |
|
161 |
} |
|
162 |
|
|
163 |
public DynObject createServiceParameters(String arg0) |
|
164 |
throws ServiceException { |
|
165 |
return null; |
|
166 |
} |
|
167 |
} |
|
0 | 168 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.15/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultDynFormFieldDefinition.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.impl; |
|
25 |
|
|
26 |
import org.gvsig.tools.ToolsLocator; |
|
27 |
import org.gvsig.tools.dynform.DynFormFieldDefinition; |
|
28 |
import org.gvsig.tools.dynobject.DynField; |
|
29 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
30 |
import org.gvsig.tools.dynobject.impl.DefaultDynField; |
|
31 |
import org.gvsig.tools.service.Manager; |
|
32 |
|
|
33 |
public class DefaultDynFormFieldDefinition extends DefaultDynField implements DynFormFieldDefinition { |
|
34 |
|
|
35 |
private DefaultDynFormManager manager = null; |
|
36 |
private String label = null; |
|
37 |
private String groups = null; |
|
38 |
|
|
39 |
public DefaultDynFormFieldDefinition(DefaultDynFormManager manager, DynField definition) { |
|
40 |
super(definition.getName(), |
|
41 |
definition.getType(), |
|
42 |
definition.getDefaultValue(), |
|
43 |
definition.isPersistent(), |
|
44 |
definition.isMandatory()); |
|
45 |
this.setHidden(definition.isHidden()); |
|
46 |
this.setReadOnly(definition.isReadOnly()); |
|
47 |
this.setGroups(definition.getGroup()); |
|
48 |
this.setDescription(definition.getDescription()); |
|
49 |
this.setMaxValue(definition.getMaxValue()); |
|
50 |
this.setMinValue(definition.getMinValue()); |
|
51 |
this.setOrder(definition.getOder()); |
|
52 |
this.setSubtype(definition.getSubtype()); |
|
53 |
this.setAvailableValues(definition.getAvailableValues()); |
|
54 |
|
|
55 |
this.manager = manager; |
|
56 |
DynObjectManager dynManager = ToolsLocator.getDynObjectManager(); |
|
57 |
this.label = dynManager.getAttributeValue(definition, "label"); |
|
58 |
} |
|
59 |
|
|
60 |
public Manager getManager() { |
|
61 |
return this.manager; |
|
62 |
} |
|
63 |
|
|
64 |
public String getLabel() { |
|
65 |
return this.label; |
|
66 |
} |
|
67 |
|
|
68 |
public DynField setLabel(String label) { |
|
69 |
this.label = label; |
|
70 |
return this; |
|
71 |
} |
|
72 |
|
|
73 |
public String getGroup() { |
|
74 |
if( this.groups==null ) { |
|
75 |
return null; |
|
76 |
} |
|
77 |
String parts[] = this.groups.split("/"); |
|
78 |
return parts[0]; |
|
79 |
} |
|
80 |
|
|
81 |
public String getSubgroup() { |
|
82 |
String parts[] = this.groups.split("/"); |
|
83 |
if( parts.length<=1 ) { |
|
84 |
return null; |
|
85 |
} |
|
86 |
return parts[1]; |
|
87 |
} |
|
88 |
|
|
89 |
public String getGroups() { |
|
90 |
return this.groups; |
|
91 |
} |
|
92 |
|
|
93 |
public void setGroups(String groups) { |
|
94 |
this.groups = groups; |
|
95 |
} |
|
96 |
} |
|
0 | 97 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.15/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/FormSetButtonBar.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.impl; |
|
25 |
|
|
26 |
import java.awt.Cursor; |
|
27 |
import java.awt.Dimension; |
|
28 |
import java.awt.FlowLayout; |
|
29 |
import java.awt.event.MouseAdapter; |
|
30 |
import java.awt.event.MouseEvent; |
|
31 |
import java.net.URL; |
|
32 |
import java.util.HashSet; |
|
33 |
import java.util.Iterator; |
|
34 |
import java.util.Set; |
|
35 |
|
|
36 |
import javax.swing.Icon; |
|
37 |
import javax.swing.ImageIcon; |
|
38 |
import javax.swing.JComponent; |
|
39 |
import javax.swing.JLabel; |
|
40 |
import javax.swing.JPanel; |
|
41 |
import javax.swing.SwingConstants; |
|
42 |
|
|
43 |
import org.gvsig.tools.swing.api.Component; |
|
44 |
import org.slf4j.Logger; |
|
45 |
import org.slf4j.LoggerFactory; |
|
46 |
|
|
47 |
public class FormSetButtonBar implements Component { |
|
48 |
|
|
49 |
protected static final Logger logger = LoggerFactory |
|
50 |
.getLogger(FormSetButtonBar.class); |
|
51 |
|
|
52 |
|
|
53 |
public static final int ActionFirst = 1; |
|
54 |
public static final int ActionPrevious = 2; |
|
55 |
public static final int ActionNext = 3; |
|
56 |
public static final int ActionLast = 4; |
|
57 |
public static final int ActionSave = 5; |
|
58 |
public static final int ActionNew = 6; |
|
59 |
public static final int ActionDelete = 7; |
|
60 |
public static final int ActionSearch = 8; |
|
61 |
public static final int ActionClose = 9; |
|
62 |
|
|
63 |
private static final int MAX_ACTIONS = 10; |
|
64 |
|
|
65 |
public Boolean activatedActions[] = new Boolean[MAX_ACTIONS]; |
|
66 |
|
|
67 |
private static final int COUNTER_HEIGHT = 50; |
|
68 |
private static final int COUNTER_WIDTH = 100; |
|
69 |
|
|
70 |
public interface FormSetListener { |
|
71 |
public boolean doActionFirst(); |
|
72 |
public boolean doActionPrevious(); |
|
73 |
public boolean doActionNext(); |
|
74 |
public boolean doActionLast(); |
|
75 |
public boolean doActionSave(); |
|
76 |
public boolean doActionNew(); |
|
77 |
public boolean doActionDelete(); |
|
78 |
public boolean doActionSearch(); |
|
79 |
public boolean doActionClose(); |
|
80 |
} |
|
81 |
|
|
82 |
private JPanel contents = null; |
|
83 |
private Set listeners = null; |
|
84 |
private int current = 0; |
|
85 |
private int numrecords = 0; |
|
86 |
|
|
87 |
|
|
88 |
private JLabel records; |
|
89 |
private JComponent buttons[] = new JLabel[MAX_ACTIONS]; |
|
90 |
|
|
91 |
|
|
92 |
public FormSetButtonBar() { |
|
93 |
// Activamos todas las acciones por defecto |
|
94 |
for(int i = 0; i<this.activatedActions.length; i++){ |
|
95 |
this.activatedActions[i]=true; |
|
96 |
} |
|
97 |
this.listeners = new HashSet(); |
|
98 |
} |
|
99 |
|
|
100 |
public JComponent asJComponent() { |
|
101 |
if( this.contents == null ) { |
|
102 |
this.initComponents(); |
|
103 |
} |
|
104 |
return this.contents; |
|
105 |
} |
|
106 |
|
|
107 |
public void addListener(FormSetListener listener) { |
|
108 |
this.listeners.add(listener); |
|
109 |
} |
|
110 |
|
|
111 |
public void removeListener(FormSetListener listener) { |
|
112 |
this.listeners.remove(listener); |
|
113 |
} |
|
114 |
|
|
115 |
protected void fireEvent(int eventid) { |
|
116 |
Iterator it = this.listeners.iterator(); |
|
117 |
while (it.hasNext()) { |
|
118 |
FormSetListener listener = (FormSetListener) it.next(); |
|
119 |
try { |
|
120 |
switch(eventid) { |
|
121 |
case ActionFirst: |
|
122 |
listener.doActionFirst(); |
|
123 |
break; |
|
124 |
case ActionPrevious: |
|
125 |
listener.doActionPrevious(); |
|
126 |
break; |
|
127 |
case ActionNext: |
|
128 |
listener.doActionNext(); |
|
129 |
break; |
|
130 |
case ActionLast: |
|
131 |
listener.doActionLast(); |
|
132 |
break; |
|
133 |
case ActionSave: |
|
134 |
listener.doActionSave(); |
|
135 |
break; |
|
136 |
case ActionNew: |
|
137 |
listener.doActionNew(); |
|
138 |
break; |
|
139 |
case ActionDelete: |
|
140 |
listener.doActionDelete(); |
|
141 |
break; |
|
142 |
case ActionSearch: |
|
143 |
listener.doActionSearch(); |
|
144 |
break; |
|
145 |
case ActionClose: |
|
146 |
listener.doActionClose(); |
|
147 |
break; |
|
148 |
} |
|
149 |
} catch (Exception ex) { |
|
150 |
logger.info("Error calling listener " + listener.toString() |
|
151 |
+ "(" + listener.getClass().getName() + ") from " |
|
152 |
+ this.toString() + "(" + this.getClass().getName() |
|
153 |
+ ").", ex); |
|
154 |
} |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
private void updateRecords() { |
|
159 |
if( numrecords <= 0 ) { |
|
160 |
this.records.setText( "0 / 0"); |
|
161 |
setEnabled(ActionFirst, false); |
|
162 |
setEnabled(ActionPrevious, false); |
|
163 |
setEnabled(ActionNext, false); |
|
164 |
setEnabled(ActionPrevious, false); |
|
165 |
return; |
|
166 |
} |
|
167 |
this.records.setText((current+1) + " / " + numrecords); |
|
168 |
if( current<=0 ) { |
|
169 |
current = 0; |
|
170 |
setEnabled(ActionFirst, false); |
|
171 |
setEnabled(ActionPrevious, false); |
|
172 |
setEnabled(ActionNext, true); |
|
173 |
setEnabled(ActionLast, true); |
|
174 |
} |
|
175 |
else if( current >= numrecords -1) { |
|
176 |
current = numrecords-1; |
|
177 |
setEnabled(ActionNext, false); |
|
178 |
setEnabled(ActionLast, false); |
|
179 |
setEnabled(ActionFirst, true); |
|
180 |
setEnabled(ActionPrevious, true); |
|
181 |
}else{ |
|
182 |
setEnabled(ActionNext, true); |
|
183 |
setEnabled(ActionLast, true); |
|
184 |
setEnabled(ActionFirst, true); |
|
185 |
setEnabled(ActionPrevious, true); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
private void initComponents() { |
|
190 |
this.contents = new JPanel(); |
|
191 |
this.contents.setLayout( new FlowLayout(FlowLayout.LEADING, 4,4)); |
|
192 |
// this.contents.setBorder( BorderFactory.createLineBorder(Color.GRAY, 1)); |
|
193 |
|
|
194 |
JComponent firstButton = createButton("First", "first.png", ActionFirst); |
|
195 |
this.contents.add(firstButton); |
|
196 |
this.contents.add(createButton("Previous", "previous.png", ActionPrevious)); |
|
197 |
|
|
198 |
this.records = new JLabel(); |
|
199 |
this.records.setPreferredSize(new Dimension(COUNTER_WIDTH, this.records.getFont().getSize())); |
|
200 |
this.records.setHorizontalAlignment( SwingConstants.CENTER ); |
|
201 |
|
|
202 |
this.contents.add(this.records); |
|
203 |
|
|
204 |
this.contents.add(createButton("Next", "next.png", ActionNext)); |
|
205 |
this.contents.add(createButton("Last", "last.png", ActionLast)); |
|
206 |
|
|
207 |
this.contents.add(createButton("Save", "save.png", ActionSave)); |
|
208 |
this.contents.add(createButton("New", "new.png", ActionNew)); |
|
209 |
this.contents.add(createButton("Delete", "delete.png", ActionDelete)); |
|
210 |
this.contents.add(createButton("Search", "search.png", ActionSearch)); |
|
211 |
|
|
212 |
this.contents.add(createButton("Close", "close.png", ActionClose)); |
|
213 |
this.updateRecords(); |
|
214 |
this.initButtons(); |
|
215 |
} |
|
216 |
|
|
217 |
private void initButtons() { |
|
218 |
setActionActive(ActionSave, isActionActive(ActionSave)); |
|
219 |
setActionActive(ActionNew, isActionActive(ActionNew)); |
|
220 |
setActionActive(ActionSearch, isActionActive(ActionSearch)); |
|
221 |
setActionActive(ActionDelete, isActionActive(ActionDelete)); |
|
222 |
} |
|
223 |
|
|
224 |
private JComponent createButton(final String tip, final String image, final int action) { |
|
225 |
JLabel jlabel = new JLabel(); |
|
226 |
jlabel.setToolTipText(tip); |
|
227 |
URL url = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/"+image); |
|
228 |
Icon icon = new ImageIcon(url); |
|
229 |
jlabel.setIcon(icon); |
|
230 |
jlabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
231 |
jlabel.addMouseListener(new MouseAdapter() { |
|
232 |
public void mouseClicked(MouseEvent evt) { |
|
233 |
int count = evt.getClickCount(); |
|
234 |
if (count == 1) { |
|
235 |
fireEvent(action); |
|
236 |
} |
|
237 |
} |
|
238 |
}); |
|
239 |
this.buttons[action] = jlabel; |
|
240 |
return jlabel; |
|
241 |
} |
|
242 |
|
|
243 |
public void setEnabled(int action, boolean enabled) { |
|
244 |
JLabel label = (JLabel) this.buttons[action]; |
|
245 |
if( enabled ) { |
|
246 |
label.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
|
247 |
label.setEnabled(true); |
|
248 |
} else { |
|
249 |
label.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); |
|
250 |
label.setEnabled(false); |
|
251 |
} |
|
252 |
} |
|
253 |
|
|
254 |
public void setCurrent(int current) { |
|
255 |
this.current = current; |
|
256 |
updateRecords(); |
|
257 |
} |
|
258 |
|
|
259 |
public void setNumrecords(int numrecords) { |
|
260 |
this.numrecords = numrecords; |
|
261 |
updateRecords(); |
|
262 |
} |
|
263 |
|
|
264 |
public void setActionActive(int action, boolean active){ |
|
265 |
if(action == ActionSave || action == ActionDelete || |
|
266 |
action == ActionNew || action == ActionSearch){ |
|
267 |
if( this.contents == null ) { |
|
268 |
this.initComponents(); |
|
269 |
} |
|
270 |
this.activatedActions[action] = active; |
|
271 |
this.buttons[action].setVisible(active); |
|
272 |
} |
|
273 |
} |
|
274 |
|
|
275 |
public boolean isActionActive(int action){ |
|
276 |
return this.activatedActions[action]; |
|
277 |
} |
|
278 |
|
|
279 |
} |
|
0 | 280 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.15/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultVisitableSet.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.impl; |
|
25 |
|
|
26 |
import java.util.HashSet; |
|
27 |
import java.util.Iterator; |
|
28 |
|
|
29 |
import org.gvsig.tools.dynform.AbortActionException; |
|
30 |
import org.gvsig.tools.dynform.spi.dynformfield.VisitableSet; |
|
31 |
import org.gvsig.tools.exception.BaseException; |
|
32 |
import org.gvsig.tools.visitor.Visitor; |
|
33 |
import org.slf4j.Logger; |
|
34 |
import org.slf4j.LoggerFactory; |
|
35 |
|
|
36 |
public class DefaultVisitableSet extends HashSet implements VisitableSet { |
|
37 |
|
|
38 |
public static final Logger logger = LoggerFactory.getLogger(DefaultVisitableSet.class); |
|
39 |
/** |
|
40 |
* |
|
41 |
*/ |
|
42 |
private static final long serialVersionUID = -5771630108958038764L; |
|
43 |
|
|
44 |
public void accept(Visitor visitor) throws BaseException { |
|
45 |
Iterator it = this.iterator(); |
|
46 |
while (it.hasNext()) { |
|
47 |
Object value = it.next(); |
|
48 |
try { |
|
49 |
visitor.visit(value); |
|
50 |
} catch (AbortActionException ex) { |
|
51 |
throw ex; |
|
52 |
} catch (Exception ex) { |
|
53 |
logger.info("Error visiting " + value.toString() |
|
54 |
+ "(" + value.getClass().getName() + ") with " |
|
55 |
+ visitor.toString() + "(" + visitor.getClass().getName() |
|
56 |
+ ").", ex); |
|
57 |
} |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
} |
|
0 | 62 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.15/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultDynFormLibrary.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.impl; |
|
25 |
|
|
26 |
|
|
27 |
import org.gvsig.tools.dynform.DynFormLibrary; |
|
28 |
import org.gvsig.tools.dynform.DynFormLocator; |
|
29 |
import org.gvsig.tools.dynform.spi.DynFormSPILocator; |
|
30 |
import org.gvsig.tools.library.AbstractLibrary; |
|
31 |
import org.gvsig.tools.library.LibraryException; |
|
32 |
|
|
33 |
public class DefaultDynFormLibrary extends AbstractLibrary { |
|
34 |
|
|
35 |
public void doRegistration() { |
|
36 |
super.doRegistration(); |
|
37 |
registerAsImplementationOf(DynFormLibrary.class); |
|
38 |
} |
|
39 |
|
|
40 |
protected void doInitialize() throws LibraryException { |
|
41 |
DynFormLocator.registerDefaultDynFormManager(DefaultDynFormManager.class); |
|
42 |
DynFormSPILocator.registerDefaultDynFormSPIManager(DefaultDynFormSPIManager.class); |
|
43 |
} |
|
44 |
|
|
45 |
protected void doPostInitialize() throws LibraryException { |
|
46 |
|
|
47 |
} |
|
48 |
|
|
49 |
} |
|
0 | 50 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.15/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultJDynFormSet.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.impl; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.event.MouseAdapter; |
|
28 |
import java.awt.event.MouseEvent; |
|
29 |
import java.util.ArrayList; |
|
30 |
import java.util.Iterator; |
|
31 |
import java.util.List; |
|
32 |
|
|
33 |
import javax.swing.Action; |
|
34 |
import javax.swing.JComponent; |
|
35 |
import javax.swing.JLabel; |
|
36 |
import javax.swing.JOptionPane; |
|
37 |
import javax.swing.JPanel; |
|
38 |
|
|
39 |
import org.gvsig.tools.lang.Cloneable; |
|
40 |
import org.gvsig.tools.dataTypes.DataType; |
|
41 |
import org.gvsig.tools.dispose.DisposableIterator; |
|
42 |
import org.gvsig.tools.dynform.AbortActionException; |
|
43 |
import org.gvsig.tools.dynform.DynFormDefinition; |
|
44 |
import org.gvsig.tools.dynform.JDynForm; |
|
45 |
import org.gvsig.tools.dynform.JDynForm.JDynFormListener; |
|
46 |
import org.gvsig.tools.dynform.JDynFormSet; |
|
47 |
import org.gvsig.tools.dynform.impl.FormSetButtonBar.FormSetListener; |
|
48 |
import org.gvsig.tools.dynobject.DynObject; |
|
49 |
import org.gvsig.tools.dynobject.DynObjectSet; |
|
50 |
import org.gvsig.tools.exception.BaseException; |
|
51 |
import org.gvsig.tools.service.ServiceException; |
|
52 |
import org.gvsig.tools.visitor.VisitCanceledException; |
|
53 |
import org.gvsig.tools.visitor.Visitor; |
|
54 |
import org.slf4j.Logger; |
|
55 |
import org.slf4j.LoggerFactory; |
|
56 |
|
|
57 |
public class DefaultJDynFormSet implements JDynFormSet, FormSetListener, JDynFormListener { |
|
58 |
|
|
59 |
private static final Logger logger = LoggerFactory.getLogger(DefaultJDynFormSet.class); |
|
60 |
|
|
61 |
private DefaultDynFormManager manager = null; |
|
62 |
private DynFormDefinition definition = null; |
|
63 |
private int layoutMode = USE_PLAIN; |
|
64 |
private JLabel jlabel_messages = null; |
|
65 |
private boolean readOnly = false; |
|
66 |
private JDynForm form = null; |
|
67 |
private FormSetButtonBar buttonBar = null; |
|
68 |
private JPanel contents = null; |
|
69 |
private List values=null; |
|
70 |
private int current=0; |
|
71 |
private DefaultVisitableSet listeners = null; |
|
72 |
private boolean autosave = true; |
|
73 |
|
|
74 |
private boolean hasActionDelete = true; |
|
75 |
private boolean hasActionNew = true; |
|
76 |
private boolean hasActionUpdate = true; |
|
77 |
private boolean hasActionSearch = true; |
|
78 |
|
|
79 |
private int formWidth = -1; |
|
80 |
private int formHeight = -1; |
|
81 |
|
|
82 |
private List<ActionStore> actionsBuffer = new ArrayList<ActionStore>(); |
|
83 |
|
|
84 |
public DefaultJDynFormSet(DefaultDynFormManager manager, DynFormDefinition definition) throws ServiceException { |
|
85 |
this.manager = manager; |
|
86 |
this.definition = definition; |
|
87 |
this.listeners = new DefaultVisitableSet(); |
|
88 |
} |
|
89 |
|
|
90 |
public JComponent asJComponent() { |
|
91 |
if( this.contents == null ) { |
|
92 |
try { |
|
93 |
this.initComponents(); |
|
94 |
} catch (ServiceException e) { |
|
95 |
throw new RuntimeException(e.getLocalizedMessage(),e); |
|
96 |
} |
|
97 |
} |
|
98 |
this.fireFormMovedToEvent(); |
|
99 |
return this.contents; |
|
100 |
} |
|
101 |
|
|
102 |
public void addListener(JDynFormSetListener listener) { |
|
103 |
this.listeners.add(listener); |
|
104 |
} |
|
105 |
|
|
106 |
public void removeListener(JDynFormSetListener listener) { |
|
107 |
this.listeners.remove(listener); |
|
108 |
} |
|
109 |
|
|
110 |
protected void fireMessageEvent(final String message) { |
|
111 |
try { |
|
112 |
this.listeners.accept(new Visitor() { |
|
113 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
114 |
((JDynFormSetListener)listener).formMessage(message); |
|
115 |
} |
|
116 |
}); |
|
117 |
} catch (AbortActionException e) { |
|
118 |
// Do nothing |
|
119 |
} catch (Exception e) { |
|
120 |
logger.info("Error calling to the form message event.",e); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
protected void fireCloseEvent() { |
|
125 |
try { |
|
126 |
this.listeners.accept(new Visitor() { |
|
127 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
128 |
((JDynFormSetListener)listener).formClose(); |
|
129 |
} |
|
130 |
}); |
|
131 |
} catch (AbortActionException e) { |
|
132 |
// Do nothing |
|
133 |
} catch (Exception e) { |
|
134 |
logger.info("Error calling to the form close event.",e); |
|
135 |
} |
|
136 |
} |
|
137 |
|
|
138 |
protected void fireFormMovedToEvent() { |
|
139 |
try { |
|
140 |
this.listeners.accept(new Visitor() { |
|
141 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
142 |
((JDynFormSetListener)listener).formMovedTo(current); |
|
143 |
} |
|
144 |
}); |
|
145 |
} catch (AbortActionException e) { |
|
146 |
// Do nothing |
|
147 |
} catch (Exception e) { |
|
148 |
logger.info("Error calling to the form moved to event.",e); |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
public JLabel getMessagesJLabel() { |
|
153 |
if( this.jlabel_messages == null ) { |
|
154 |
this.jlabel_messages = new JLabel(); |
|
155 |
// this.jlabel_messages.setBorder( BorderFactory.createLoweredBevelBorder()); |
|
156 |
this.jlabel_messages.setText(" "); |
|
157 |
this.jlabel_messages.addMouseListener(new MouseAdapter() { |
|
158 |
public void mouseClicked(MouseEvent evt) { |
|
159 |
int count = evt.getClickCount(); |
|
160 |
if (count == 2) { |
|
161 |
JOptionPane.showMessageDialog(contents,jlabel_messages.getText(),"Status",JOptionPane.INFORMATION_MESSAGE); |
|
162 |
} |
|
163 |
} |
|
164 |
}); |
|
165 |
} |
|
166 |
return this.jlabel_messages; |
|
167 |
} |
|
168 |
|
|
169 |
public void message() { |
|
170 |
this.getMessagesJLabel().setText(" "); |
|
171 |
} |
|
172 |
|
|
173 |
public void message(String msg) { |
|
174 |
this.getMessagesJLabel().setText(msg); |
|
175 |
} |
|
176 |
|
|
177 |
private FormSetButtonBar getButtonBar() throws ServiceException { |
|
178 |
if( this.buttonBar == null ) { |
|
179 |
initComponents(); |
|
180 |
} |
|
181 |
return this.buttonBar; |
|
182 |
} |
|
183 |
|
|
184 |
private void initComponents() throws ServiceException { |
|
185 |
this.contents = new JPanel(); |
|
186 |
this.contents.setLayout(new BorderLayout()); |
|
187 |
|
|
188 |
this.form = this.manager.createJDynForm(definition); |
|
189 |
if(!actionsBuffer.isEmpty()){ |
|
190 |
Iterator it = actionsBuffer.iterator(); |
|
191 |
while(it.hasNext()){ |
|
192 |
ActionStore actStore = (ActionStore) it.next(); |
|
193 |
if(actStore.isSeparator()){ |
|
194 |
form.addSeparatorToPopupMenu( |
|
195 |
actStore.getDataType()); |
|
196 |
}else{ |
|
197 |
form.addActionToPopupMenu( |
|
198 |
actStore.getDataType(), |
|
199 |
actStore.getActionName(), |
|
200 |
actStore.getAction()); |
|
201 |
} |
|
202 |
} |
|
203 |
} |
|
204 |
|
|
205 |
if(this.formHeight > -1 && this.formWidth > -1){ |
|
206 |
this.setFormSize(this.formWidth, this.formHeight); |
|
207 |
} |
|
208 |
this.form.setShowMessageStatus(false); |
|
209 |
this.form.setLayoutMode(this.layoutMode); |
|
210 |
this.form.addListener(this); |
|
211 |
|
|
212 |
this.buttonBar = new FormSetButtonBar(); |
|
213 |
this.buttonBar.addListener(this); |
|
214 |
this.buttonBar.setActionActive(this.buttonBar.ActionDelete, hasActionDelete); |
|
215 |
this.buttonBar.setActionActive(this.buttonBar.ActionNew, hasActionNew); |
|
216 |
this.buttonBar.setActionActive(this.buttonBar.ActionSave, hasActionUpdate); |
|
217 |
this.buttonBar.setActionActive(this.buttonBar.ActionSearch, hasActionSearch); |
|
218 |
|
|
219 |
this.contents.add(this.buttonBar.asJComponent(), BorderLayout.NORTH); |
|
220 |
this.contents.add(this.form.asJComponent(), BorderLayout.CENTER); |
|
221 |
this.contents.add(this.getMessagesJLabel(), BorderLayout.SOUTH); |
|
222 |
if( this.values != null ) { |
|
223 |
doChangeValue(); |
|
224 |
} |
|
225 |
this.form.setReadOnly(this.readOnly); |
|
226 |
} |
|
227 |
|
|
228 |
public int getLayoutMode() { |
|
229 |
return this.layoutMode; |
|
230 |
} |
|
231 |
|
|
232 |
public void setLayoutMode(int layoutMode) { |
|
233 |
if( layoutMode<0 || layoutMode>USE_SEPARATORS) { |
|
234 |
throw new IllegalArgumentException("layoutMode ("+layoutMode+") out of range. Valid values are 0 .. "+ USE_SEPARATORS+"."); |
|
235 |
} |
|
236 |
this.layoutMode = layoutMode; |
|
237 |
} |
|
238 |
|
|
239 |
private void doChangeValue() throws ServiceException { |
|
240 |
this.current = 0; |
|
241 |
this.form.setValues((DynObject) this.values.get(this.current)); |
|
242 |
|
|
243 |
this.getButtonBar().setNumrecords(this.values.size()); |
|
244 |
this.getButtonBar().setCurrent(this.current); |
|
245 |
} |
|
246 |
|
|
247 |
public void setValues(List values) throws ServiceException { |
|
248 |
List x = new ArrayList(); |
|
249 |
x.addAll(values); |
|
250 |
this.values = x; |
|
251 |
if( this.contents != null ) { |
|
252 |
doChangeValue(); |
|
253 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionDelete, true); |
|
254 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionSave, true); |
|
255 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionNew, true); |
|
256 |
} |
|
257 |
} |
|
258 |
|
|
259 |
public void setValues(DynObjectSet values) throws ServiceException { |
|
260 |
List x = new ArrayList(); |
|
261 |
DisposableIterator it; |
|
262 |
try { |
|
263 |
it = values.iterator(); |
|
264 |
} catch (BaseException e) { |
|
265 |
logger.info("Uf! o se que hacer con este error, lo relanzo sin mas.",e); |
|
266 |
throw new RuntimeException(e); |
|
267 |
} |
|
268 |
while(it.hasNext()) { |
|
269 |
DynObject obj = (DynObject) it.next(); |
|
270 |
if( obj instanceof Cloneable ) { |
|
271 |
try { |
|
272 |
obj = (DynObject) ((Cloneable)obj).clone(); |
|
273 |
} catch (CloneNotSupportedException e) { |
|
274 |
// Do nothing |
|
275 |
} |
|
276 |
} |
|
277 |
x.add(obj); |
|
278 |
} |
|
279 |
this.values = x; |
|
280 |
if( this.contents != null ) { |
|
281 |
doChangeValue(); |
|
282 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionDelete, values.isDeleteEnabled()); |
|
283 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionSave, values.isUpdateEnabled()); |
|
284 |
this.getButtonBar().setEnabled(FormSetButtonBar.ActionNew, values.isUpdateEnabled()); |
|
285 |
} |
|
286 |
} |
|
287 |
|
|
288 |
public boolean isReadOnly() { |
|
289 |
return readOnly; |
|
290 |
} |
|
291 |
|
|
292 |
public void setReadOnly(boolean readOnly) { |
|
293 |
this.readOnly = readOnly; |
|
294 |
if( this.form != null ) { |
|
295 |
this.form.setReadOnly(readOnly); |
|
296 |
} |
|
297 |
} |
|
298 |
|
|
299 |
public boolean doActionFirst() { |
|
300 |
if( autosave ) { |
|
301 |
if( !doActionSave() ) { |
|
302 |
return false; |
|
303 |
} |
|
304 |
} |
|
305 |
this.current = 0; |
|
306 |
this.form.setValues((DynObject) this.values.get(this.current)); |
|
307 |
this.buttonBar.setCurrent(this.current); |
|
308 |
this.fireFormMovedToEvent(); |
|
309 |
return true; |
|
310 |
} |
|
311 |
|
|
312 |
public boolean doActionPrevious() { |
|
313 |
if( autosave ) { |
|
314 |
if( !doActionSave() ) { |
|
315 |
return false; |
|
316 |
} |
|
317 |
} |
|
318 |
if( this.current > 0 ) { |
|
319 |
this.current--; |
|
320 |
} |
|
321 |
this.form.setValues((DynObject) this.values.get(this.current)); |
|
322 |
this.buttonBar.setCurrent(this.current); |
|
323 |
this.fireFormMovedToEvent(); |
|
324 |
return true; |
|
325 |
} |
|
326 |
|
|
327 |
public boolean doActionNext() { |
|
328 |
if( autosave ) { |
|
329 |
if( !doActionSave() ) { |
|
330 |
return false; |
|
331 |
} |
|
332 |
} |
|
333 |
if( this.current < this.values.size() ) { |
|
334 |
this.current++; |
|
335 |
} |
|
336 |
this.form.setValues((DynObject) this.values.get(this.current)); |
|
337 |
this.buttonBar.setCurrent(this.current); |
|
338 |
this.fireFormMovedToEvent(); |
|
339 |
return true; |
|
340 |
} |
|
341 |
|
|
342 |
public boolean doActionLast() { |
|
343 |
if( autosave ) { |
|
344 |
if( !doActionSave() ) { |
|
345 |
return false; |
|
346 |
} |
|
347 |
} |
|
348 |
this.current = this.values.size()-1; |
|
349 |
this.form.setValues((DynObject) this.values.get(this.current)); |
|
350 |
this.buttonBar.setCurrent(this.current); |
|
351 |
this.fireFormMovedToEvent(); |
|
352 |
return true; |
|
353 |
} |
|
354 |
|
|
355 |
public boolean doActionSave() { |
|
356 |
if( !this.form.isModified() ) { |
|
357 |
return true; |
|
358 |
} |
|
359 |
try { |
|
360 |
this.listeners.accept(new Visitor() { |
|
361 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
362 |
((JDynFormSetListener)listener).formBeforeSave(); |
|
363 |
} |
|
364 |
}); |
|
365 |
} catch (BaseException e) { |
|
366 |
return true; |
|
367 |
} |
|
368 |
|
|
369 |
List<String> fieldsName = new ArrayList<String>(); |
|
370 |
if( !this.form.haveValidValues(fieldsName) ) { |
|
371 |
String errores = ""; |
|
372 |
Iterator<String> it= fieldsName.iterator(); |
|
373 |
while(it.hasNext()){ |
|
374 |
String name = (String)it.next(); |
|
375 |
errores = errores +" - "+ name + "\n"; |
|
376 |
} |
|
377 |
int r = confirmDialog( |
|
378 |
"There are incorrect data in the following fields:\n" +errores+"\nContinuing the incorrect values will not be saved. Do you want to continue?", "warning", |
|
379 |
JOptionPane.WARNING_MESSAGE, |
|
380 |
JOptionPane.YES_NO_OPTION); |
|
381 |
if( r != JOptionPane.YES_OPTION ) { |
|
382 |
return false; |
|
383 |
} |
|
384 |
} |
|
385 |
if( this.current >=0 && this.current<this.values.size() ) { |
|
386 |
this.form.getValues((DynObject) this.values.get(this.current)); |
|
387 |
} else { |
|
388 |
logger.warn("current out of range."); |
|
389 |
} |
|
390 |
|
|
391 |
|
|
392 |
try { |
|
393 |
this.listeners.accept(new Visitor() { |
|
394 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
395 |
((JDynFormSetListener)listener).formAfterSave(); |
|
396 |
} |
|
397 |
}); |
|
398 |
} catch (BaseException e) { |
|
399 |
return true; |
|
400 |
} |
|
401 |
return true; |
|
402 |
} |
|
403 |
|
|
404 |
public boolean doActionNew() { |
|
405 |
try { |
|
406 |
this.listeners.accept(new Visitor() { |
|
407 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
408 |
((JDynFormSetListener)listener).formBeforeNew(); |
|
409 |
} |
|
410 |
}); |
|
411 |
} catch (BaseException e) { |
|
412 |
return true; |
|
413 |
} |
|
414 |
// Do new Actions |
|
415 |
try { |
|
416 |
this.listeners.accept(new Visitor() { |
|
417 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
418 |
((JDynFormSetListener)listener).formAfterNew(); |
|
419 |
} |
|
420 |
}); |
|
421 |
} catch (BaseException e) { |
|
422 |
return true; |
|
423 |
} |
|
424 |
return true; |
|
425 |
} |
|
426 |
|
|
427 |
public boolean doActionDelete() { |
|
428 |
try { |
|
429 |
this.listeners.accept(new Visitor() { |
|
430 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
431 |
((JDynFormSetListener)listener).formBeforeDelete(); |
|
432 |
} |
|
433 |
}); |
|
434 |
} catch (BaseException e) { |
|
435 |
return true; |
|
436 |
} |
|
437 |
// Do new Actions |
|
438 |
try { |
|
439 |
this.listeners.accept(new Visitor() { |
|
440 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
441 |
((JDynFormSetListener)listener).formAfterDelete(); |
|
442 |
} |
|
443 |
}); |
|
444 |
} catch (BaseException e) { |
|
445 |
return true; |
|
446 |
} return true; |
|
447 |
} |
|
448 |
|
|
449 |
public boolean doActionSearch() { |
|
450 |
try { |
|
451 |
this.listeners.accept(new Visitor() { |
|
452 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
453 |
((JDynFormSetListener)listener).formBeforeSearch(); |
|
454 |
} |
|
455 |
}); |
|
456 |
} catch (BaseException e) { |
|
457 |
return true; |
|
458 |
} |
|
459 |
// Do search |
|
460 |
try { |
|
461 |
this.listeners.accept(new Visitor() { |
|
462 |
public void visit(Object listener) throws VisitCanceledException, BaseException { |
|
463 |
((JDynFormSetListener)listener).formBeforeSearch(); |
|
464 |
} |
|
465 |
}); |
|
466 |
} catch (BaseException e) { |
|
467 |
return true; |
|
468 |
} |
|
469 |
return true; |
|
470 |
} |
|
471 |
|
|
472 |
public boolean doActionClose() { |
|
473 |
fireCloseEvent(); |
|
474 |
return true; |
|
475 |
} |
|
476 |
|
|
477 |
public boolean isAutosave() { |
|
478 |
return this.autosave; |
|
479 |
} |
|
480 |
|
|
481 |
public void setAutosave(boolean autosave) { |
|
482 |
this.autosave = autosave; |
|
483 |
} |
|
484 |
|
|
485 |
public int confirmDialog(final String message, final String title, final int optionType, |
|
486 |
final int messageType) { |
|
487 |
return JOptionPane.showConfirmDialog( |
|
488 |
this.contents, message,title, optionType, messageType); |
|
489 |
} |
|
490 |
|
|
491 |
public boolean allowUpdate() { |
|
492 |
try { |
|
493 |
return this.getButtonBar().isActionActive(this.getButtonBar().ActionSave); |
|
494 |
} catch (ServiceException e) { |
|
495 |
logger.info("Button bar isn't initializated"); |
|
496 |
} |
|
497 |
return false; |
|
498 |
} |
|
499 |
|
|
500 |
public boolean allowDelete() { |
|
501 |
try { |
|
502 |
return this.getButtonBar().isActionActive(this.getButtonBar().ActionDelete); |
|
503 |
} catch (ServiceException e) { |
|
504 |
logger.info("Button bar isn't initializated"); |
|
505 |
} |
|
506 |
return false; |
|
507 |
} |
|
508 |
|
|
509 |
public boolean allowNew() { |
|
510 |
try { |
|
511 |
return this.getButtonBar().isActionActive(this.getButtonBar().ActionNew); |
|
512 |
} catch (ServiceException e) { |
|
513 |
logger.info("Button bar isn't initializated"); |
|
514 |
} |
|
515 |
return false; |
|
516 |
} |
|
517 |
|
|
518 |
public boolean allowSearch() { |
|
519 |
try { |
|
520 |
return this.getButtonBar().isActionActive(this.getButtonBar().ActionSearch); |
|
521 |
} catch (ServiceException e) { |
|
522 |
logger.info("Button bar isn't initializated"); |
|
523 |
} |
|
524 |
return false; |
|
525 |
} |
|
526 |
|
|
527 |
public void setAllowUpdate(boolean allowUpdate) { |
|
528 |
hasActionUpdate = allowUpdate; |
|
529 |
// try { |
|
530 |
// this.getButtonBar().setActionActive(this.getButtonBar().ActionSave, allowUpdate); |
|
531 |
// } catch (ServiceException e) { |
|
532 |
// // TODO Auto-generated catch block |
|
533 |
// e.printStackTrace(); |
|
534 |
// } |
|
535 |
} |
|
536 |
|
|
537 |
public void setAllowDelete(boolean allowDelete) { |
|
538 |
hasActionDelete = allowDelete; |
|
539 |
// try { |
|
540 |
// this.getButtonBar().setActionActive(this.getButtonBar().ActionDelete, allowDelete); |
|
541 |
// } catch (ServiceException e) { |
|
542 |
// // TODO Auto-generated catch block |
|
543 |
// e.printStackTrace(); |
|
544 |
// } |
|
545 |
} |
|
546 |
|
|
547 |
public void setAllowNew(boolean allowNew) { |
|
548 |
hasActionNew = allowNew; |
|
549 |
} |
|
550 |
|
|
551 |
public void setAllowSearch(boolean allowSearch) { |
|
552 |
hasActionSearch = allowSearch; |
|
553 |
// try { |
|
554 |
// this.getButtonBar().setActionActive(this.getButtonBar().ActionSearch, allowSearch); |
|
555 |
// } catch (ServiceException e) { |
|
556 |
// // TODO Auto-generated catch block |
|
557 |
// e.printStackTrace(); |
|
558 |
// } |
|
559 |
} |
|
560 |
|
|
561 |
public void setFormSize(int width, int height) { |
|
562 |
this.formHeight = height; |
|
563 |
this.formWidth = width; |
|
564 |
if(this.form != null){ |
|
565 |
this.form.setFormSize(width, height); |
|
566 |
} |
|
567 |
} |
|
568 |
|
|
569 |
public int getCurrentIndex() { |
|
570 |
return this.current; |
|
571 |
} |
|
572 |
|
|
573 |
public int countValues() { |
|
574 |
return this.values.size(); |
|
575 |
} |
|
576 |
|
|
577 |
public void setCurrentIndex(int index) { |
|
578 |
if( index <0 || index > countValues() ) { |
|
579 |
throw new IllegalArgumentException("Index ("+index+") out of range [0.."+countValues()+"]."); |
|
580 |
} |
|
581 |
this.current = index; |
|
582 |
this.form.setValues((DynObject) this.values.get(this.current)); |
|
583 |
this.buttonBar.setCurrent(this.current); |
|
584 |
this.fireFormMovedToEvent(); |
|
585 |
} |
|
586 |
|
|
587 |
public DynObject get(int position) { |
|
588 |
return (DynObject) this.values.get(position); |
|
589 |
} |
|
590 |
|
|
591 |
public void addActionToPopupMenu(DataType tipo, String name, Action action) { |
|
592 |
try { |
|
593 |
if(this.form==null){ |
|
594 |
this.actionsBuffer.add(new ActionStore(tipo, name, action)); |
|
595 |
}else{ |
|
596 |
this.form.addActionToPopupMenu(tipo, name, action); |
|
597 |
} |
|
598 |
} catch( Exception ex) { |
|
599 |
String s = (tipo==null)? "(null)" : tipo.getName(); |
|
600 |
logger.warn("Can't add popup menu '"+name+"' to the fields of type '"+s+"' of the form.", ex); |
|
601 |
} |
|
602 |
} |
|
603 |
|
|
604 |
public void addSeparatorToPopupMenu(DataType tipo) { |
|
605 |
try { |
|
606 |
if(this.form==null){ |
|
607 |
this.actionsBuffer.add(new ActionStore(tipo)); |
|
608 |
}else{ |
|
609 |
this.form.addSeparatorToPopupMenu(tipo); |
|
610 |
} |
|
611 |
} catch( Exception ex) { |
|
612 |
String s = (tipo==null)? "(null)" : tipo.getName(); |
|
613 |
logger.warn("Can't add separator to the popup menu to the fields of type '"+s+"' of the form.", ex); |
|
614 |
} |
|
615 |
|
|
616 |
} |
|
617 |
|
|
618 |
|
|
619 |
} |
|
0 | 620 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.15/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultZoomDialog.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2013 gvSIG Association. |
|
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 3 |
|
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., 51 Franklin Street, Fifth Floor, Boston, |
|
19 |
* MA 02110-1301, USA. |
|
20 |
* |
|
21 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
package org.gvsig.tools.dynform.impl; |
|
25 |
|
|
26 |
import java.awt.BorderLayout; |
|
27 |
import java.awt.Dimension; |
|
28 |
import java.awt.Toolkit; |
|
29 |
import java.awt.event.ActionEvent; |
|
30 |
import java.awt.event.ActionListener; |
|
31 |
|
|
32 |
import javax.swing.BorderFactory; |
|
33 |
import javax.swing.JButton; |
|
34 |
import javax.swing.JPanel; |
|
35 |
import javax.swing.JScrollPane; |
|
36 |
|
|
37 |
import org.gvsig.tools.dynform.spi.dynformfield.JCustomTextArea; |
|
38 |
import org.gvsig.tools.dynform.spi.dynformfield.JZoomDialog; |
|
39 |
|
|
40 |
public class DefaultZoomDialog extends JZoomDialog { |
|
41 |
|
|
42 |
/** |
|
43 |
* |
|
44 |
*/ |
|
45 |
private static final long serialVersionUID = 7913363575200612492L; |
|
46 |
|
|
47 |
private String value = null; |
|
48 |
private JCustomTextArea text = null; |
|
49 |
|
|
50 |
public DefaultZoomDialog(String title, String value) { |
|
51 |
super(title); |
|
52 |
this.value = value; |
|
53 |
initComponents(); |
|
54 |
|
|
55 |
} |
|
56 |
|
|
57 |
public void setEditable(boolean editable) { |
|
58 |
this.text.setEditable(editable); |
|
59 |
} |
|
60 |
|
|
61 |
private void initComponents() { |
|
62 |
|
|
63 |
JPanel panel = new JPanel(); |
|
64 |
panel.setLayout(new BorderLayout()); |
|
65 |
|
|
66 |
text = new JCustomTextArea(null, false); |
|
67 |
text.setText(value); |
|
68 |
text.setLineWrap(true); |
|
69 |
JScrollPane scroll = new JScrollPane(text); |
|
70 |
panel.add(scroll, BorderLayout.CENTER); |
|
71 |
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); |
|
72 |
|
|
73 |
JPanel p = new JPanel(); |
|
74 |
|
|
75 |
JButton close = new JButton("Close"); |
|
76 |
close.addActionListener(new ActionListener() { |
|
77 |
public void actionPerformed(ActionEvent arg0) { |
|
78 |
value = text.getText(); |
|
79 |
setVisible(false); |
|
80 |
} |
|
81 |
}); |
|
82 |
|
|
83 |
p.setLayout(new BorderLayout()); |
|
84 |
p.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); |
|
85 |
p.add(close,BorderLayout.LINE_END); |
|
86 |
|
|
87 |
panel.add(p, BorderLayout.PAGE_END); |
|
88 |
|
|
89 |
panel.setPreferredSize(new Dimension(600, 250)); |
|
90 |
|
|
91 |
this.setContentPane(panel); |
|
92 |
|
|
93 |
this.center(); |
|
94 |
this.pack(); |
|
95 |
} |
|
96 |
|
|
97 |
public void center() { |
|
98 |
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize(); |
|
99 |
Dimension size = this.getPreferredSize(); |
|
100 |
int x = (int) ((dimension.getWidth() - size.getWidth()) / 2); |
|
101 |
int y = (int) ((dimension.getHeight() - size.getHeight()) / 2); |
|
102 |
this.setLocation(x, y); |
|
103 |
} |
|
104 |
public String getText() { |
|
105 |
return this.value; |
|
106 |
} |
|
107 |
} |
|
0 | 108 |
org.gvsig.tools/library/tags/org.gvsig.tools-3.0.15/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/ActionStore.java | ||
---|---|---|
1 |
package org.gvsig.tools.dynform.impl; |
|
2 |
|
|
3 |
import javax.swing.Action; |
|
4 |
|
|
5 |
import org.gvsig.tools.dataTypes.DataType; |
|
6 |
|
|
7 |
public class ActionStore{ |
|
8 |
private DataType tipo; |
|
9 |
private String name; |
|
10 |
private Action action; |
|
11 |
private boolean isSeparator = false; |
|
12 |
|
|
13 |
public ActionStore(DataType tipo,String name, Action action){ |
|
14 |
this.tipo = tipo; |
|
15 |
this.name = name; |
|
16 |
this.action = action; |
|
17 |
} |
|
18 |
|
|
19 |
public ActionStore(DataType tipo){ |
|
20 |
this.tipo = tipo; |
|
21 |
this.isSeparator = true; |
|
22 |
} |
|
23 |
|
|
24 |
public DataType getDataType(){ |
|
25 |
return tipo; |
|
26 |
} |
|
27 |
|
|
28 |
public String getActionName(){ |
|
29 |
return name; |
|
30 |
} |
|
31 |
|
|
32 |
public Action getAction(){ |
|
33 |
return action; |
|
34 |
} |
|
35 |
|
|
36 |
public boolean isSeparator(){ |
|
37 |
return isSeparator; |
|
38 |
} |
|
39 |
} |
|
0 | 40 |
Also available in: Unified diff