Revision 2039
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.api/src/main/java/org/gvsig/tools/dynform/JDynFormSet.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
public interface JDynFormSet extends Component { |
37 | 37 |
|
38 |
public static final int ACTION_FIRST = 1;
|
|
39 |
public static final int ACTION_PREVIOUS = 2;
|
|
40 |
public static final int ACTION_NEXT = 3;
|
|
41 |
public static final int ACTION_LAST = 4;
|
|
42 |
public static final int ACTION_SAVE = 5;
|
|
43 |
public static final int ACTION_NEW = 6;
|
|
44 |
public static final int ACTION_CANCEL_NEW = 7;
|
|
45 |
public static final int ACTION_DELETE = 8;
|
|
46 |
public static final int ACTION_SEARCH = 9;
|
|
47 |
public static final int ACTION_CLOSE = 10;
|
|
48 |
public static final int ACTION_SET_CURRENT_RECORD = 11;
|
|
38 |
public static final String ACTION_FIRST = "first";
|
|
39 |
public static final String ACTION_PREVIOUS = "previous";
|
|
40 |
public static final String ACTION_NEXT = "next";
|
|
41 |
public static final String ACTION_LAST = "last";
|
|
42 |
public static final String ACTION_SAVE = "save";
|
|
43 |
public static final String ACTION_NEW = "new";
|
|
44 |
public static final String ACTION_CANCEL_NEW = "cancel-new";
|
|
45 |
public static final String ACTION_DELETE = "delete";
|
|
46 |
public static final String ACTION_SEARCH = "search";
|
|
47 |
public static final String ACTION_CLOSE = "close";
|
|
48 |
public static final String ACTION_SET_CURRENT_RECORD = "set-current-record";
|
|
49 | 49 |
|
50 | 50 |
public interface JDynFormSetListener { |
51 | 51 |
public void formMessage(String message); |
... | ... | |
114 | 114 |
public boolean isActionVisible(String action); |
115 | 115 |
public boolean isActionEnabled(String action); |
116 | 116 |
public JComponent getActionButton(String action); |
117 |
public void fireEvent(int eventid, Object value);
|
|
117 |
public void fireEvent(String action, Object value);
|
|
118 | 118 |
|
119 | 119 |
public void addActionToPopupMenu(DataType tipo, String name, Action action); |
120 | 120 |
public void addSeparatorToPopupMenu(DataType tipo); |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.spi/src/main/java/org/gvsig/tools/dynform/spi/dynformset/AbstractJDynFormSet.java | ||
---|---|---|
87 | 87 |
} |
88 | 88 |
|
89 | 89 |
@Override |
90 |
public void fireEvent(int eventid, Object value) {
|
|
90 |
public void fireEvent(String action, Object value) {
|
|
91 | 91 |
} |
92 | 92 |
|
93 | 93 |
protected JDynFormSetFactory getFactory() { |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynform/AbeilleJDynForm.java | ||
---|---|---|
24 | 24 |
import java.awt.event.ActionListener; |
25 | 25 |
import java.io.File; |
26 | 26 |
import java.util.ArrayList; |
27 |
import java.util.Iterator; |
|
27 | 28 |
import java.util.List; |
28 | 29 |
import javax.swing.JButton; |
29 | 30 |
import javax.swing.JLabel; |
... | ... | |
352 | 353 |
return form; |
353 | 354 |
} |
354 | 355 |
|
356 |
public Iterator getFieldsIterator() { |
|
357 |
if (!this.isContentsInitialized()) { |
|
358 |
this.initComponents(); |
|
359 |
} |
|
360 |
return this.components.values().iterator(); |
|
361 |
} |
|
362 |
|
|
363 |
@Override |
|
364 |
public void setReadOnly(boolean readOnly) { |
|
365 |
if( this.isReadOnly() == readOnly ) { |
|
366 |
return; |
|
367 |
} |
|
368 |
super.setReadOnly(readOnly); |
|
369 |
if (this.isContentsInitialized()) { |
|
370 |
Iterator it = this.getFieldsIterator(); |
|
371 |
while (it.hasNext()) { |
|
372 |
JDynFormField field = (JDynFormField) it.next(); |
|
373 |
if( readOnly ) { |
|
374 |
field.setReadOnly(true); |
|
375 |
} else if( field.getDefinition().isReadOnly() ) { |
|
376 |
field.setReadOnly(true); |
|
377 |
} else { |
|
378 |
field.setReadOnly(false); |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
|
|
355 | 384 |
private void bindUserCode(FormPanel form) { |
356 | 385 |
Script theScript = this.getScript(); |
357 | 386 |
if( theScript==null ) { |
... | ... | |
486 | 515 |
return false; |
487 | 516 |
} |
488 | 517 |
try { |
489 |
return (boolean) this.callUserFunction(USERCODE_FORM_ISMODIFIED, this, values); |
|
518 |
if( this.getScript()!=null ) { |
|
519 |
return (boolean) this.callUserFunction(USERCODE_FORM_ISMODIFIED, this, values); |
|
520 |
} |
|
490 | 521 |
} catch (NoSuchMethodException ex) { |
491 | 522 |
} catch (Exception ex) { |
492 | 523 |
LOGGER.warn("Error calling user function form_IsModified.",ex); |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformset/base/BaseJDynFormSet.java | ||
---|---|---|
46 | 46 |
import org.gvsig.tools.dynform.JDynForm.JDynFormListener; |
47 | 47 |
import org.gvsig.tools.dynform.JDynFormField; |
48 | 48 |
import org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.FormSetListener; |
49 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_CANCEL_NEW; |
|
50 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_CLOSE; |
|
51 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_DELETE; |
|
52 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_FIRST; |
|
53 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_LAST; |
|
54 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_NEW; |
|
55 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_NEXT; |
|
56 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_PREVIOUS; |
|
57 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_SAVE; |
|
58 |
import static org.gvsig.tools.dynform.services.dynformset.base.FormSetButtonBar.ID_ACTION_SEARCH; |
|
49 | 59 |
import org.gvsig.tools.dynform.spi.dynformset.AbstractJDynFormSet; |
50 | 60 |
import org.gvsig.tools.dynform.spi.dynformset.ActionStore; |
51 | 61 |
import org.gvsig.tools.dynform.spi.DynFormSPIManager; |
... | ... | |
164 | 174 |
|
165 | 175 |
this.buttonBar = new FormSetButtonBar(); |
166 | 176 |
this.buttonBar.addListener(this); |
167 |
this.buttonBar.setActionActive(ACTION_DELETE, this.allowDelete()); |
|
168 |
this.buttonBar.setActionActive(ACTION_NEW, this.allowNew()); |
|
169 |
this.buttonBar.setActionActive(ACTION_CANCEL_NEW, this.allowNew()); |
|
170 |
this.buttonBar.setActionActive(ACTION_SAVE, this.allowUpdate()); |
|
171 |
this.buttonBar.setActionActive(ACTION_SEARCH, this.allowSearch()); |
|
172 |
this.buttonBar.setActionActive(ACTION_CLOSE, this.allowClose()); |
|
173 |
this.buttonBar.setVisible(ACTION_CANCEL_NEW, false); |
|
177 |
this.buttonBar.setActionActive(ID_ACTION_DELETE, this.allowDelete());
|
|
178 |
this.buttonBar.setActionActive(ID_ACTION_NEW, this.allowNew());
|
|
179 |
this.buttonBar.setActionActive(ID_ACTION_CANCEL_NEW, this.allowNew());
|
|
180 |
this.buttonBar.setActionActive(ID_ACTION_SAVE, this.allowUpdate());
|
|
181 |
this.buttonBar.setActionActive(ID_ACTION_SEARCH, this.allowSearch());
|
|
182 |
this.buttonBar.setActionActive(ID_ACTION_CLOSE, this.allowClose());
|
|
183 |
this.buttonBar.setVisible(ID_ACTION_CANCEL_NEW, false);
|
|
174 | 184 |
this.buttonBar.setReadOnly(this.isReadOnly()); |
175 | 185 |
this.contents.add(this.form.asJComponent(), BorderLayout.CENTER); |
176 | 186 |
|
... | ... | |
189 | 199 |
public void setAllowDelete(boolean allowDelete) { |
190 | 200 |
super.setAllowDelete(allowDelete); |
191 | 201 |
if( this.buttonBar!=null ) { |
192 |
this.buttonBar.setActionActive(ACTION_DELETE, this.allowDelete()); |
|
202 |
this.buttonBar.setActionActive(ID_ACTION_DELETE, this.allowDelete());
|
|
193 | 203 |
} |
194 | 204 |
} |
195 | 205 |
|
... | ... | |
197 | 207 |
public void setAllowNew(boolean allowNew) { |
198 | 208 |
super.setAllowNew(allowNew); |
199 | 209 |
if( this.buttonBar!=null ) { |
200 |
this.buttonBar.setActionActive(ACTION_NEW, this.allowNew()); |
|
210 |
this.buttonBar.setActionActive(ID_ACTION_NEW, this.allowNew());
|
|
201 | 211 |
} |
202 | 212 |
} |
203 | 213 |
|
... | ... | |
205 | 215 |
this.current = 0; |
206 | 216 |
if (this.values == null || this.values.isEmpty()) { |
207 | 217 |
this.form.setReadOnly(true); |
208 |
this.getButtonBar().setEnabled(ACTION_DELETE, false); |
|
209 |
this.getButtonBar().setEnabled(ACTION_SAVE, false); |
|
210 |
this.getButtonBar().setEnabled(ACTION_NEW, |
|
218 |
this.getButtonBar().setEnabled(ID_ACTION_DELETE, false);
|
|
219 |
this.getButtonBar().setEnabled(ID_ACTION_SAVE, false);
|
|
220 |
this.getButtonBar().setEnabled(ID_ACTION_NEW,
|
|
211 | 221 |
this.allowNew() && !this.isReadOnly()); |
212 | 222 |
this.getButtonBar().setNumrecords(0); |
213 | 223 |
this.form.clear(); |
214 | 224 |
} else { |
215 | 225 |
this.form.setValues((DynObject) this.values.get(this.current)); |
216 |
this.getButtonBar().setEnabled(ACTION_DELETE, |
|
226 |
this.getButtonBar().setEnabled(ID_ACTION_DELETE,
|
|
217 | 227 |
this.allowDelete() && !this.isReadOnly()); |
218 |
this.getButtonBar().setEnabled(ACTION_SAVE, |
|
228 |
this.getButtonBar().setEnabled(ID_ACTION_SAVE,
|
|
219 | 229 |
this.allowUpdate() && !this.isReadOnly()); |
220 | 230 |
this.getButtonBar().setNumrecords(this.values.size()); |
221 | 231 |
} |
... | ... | |
269 | 279 |
this.form.setValues((DynObject) this.values.get(this.current)); |
270 | 280 |
this.buttonBar.setCurrent(this.current); |
271 | 281 |
try { |
272 |
this.getButtonBar().setEnabled(ACTION_DELETE, |
|
282 |
this.getButtonBar().setEnabled(ID_ACTION_DELETE,
|
|
273 | 283 |
this.allowDelete() && !this.isReadOnly()); |
274 |
this.getButtonBar().setEnabled(ACTION_SAVE, |
|
284 |
this.getButtonBar().setEnabled(ID_ACTION_SAVE,
|
|
275 | 285 |
this.allowUpdate() && !this.isReadOnly()); |
276 | 286 |
} catch (Exception ex) { |
277 | 287 |
LOGGER.warn("Can't enable/disable delete and save buttons",ex); |
... | ... | |
466 | 476 |
bar.setCurrentLabel(ToolsLocator.getI18nManager().getTranslation("nuevo")); |
467 | 477 |
bar.setNumrecords(this.countValues()); |
468 | 478 |
|
469 |
bar.setVisible(ACTION_CANCEL_NEW, true); |
|
470 |
bar.setVisible(ACTION_NEW, false); |
|
479 |
bar.setVisible(ID_ACTION_CANCEL_NEW, true);
|
|
480 |
bar.setVisible(ID_ACTION_NEW, false);
|
|
471 | 481 |
|
472 |
bar.setEnabled(ACTION_SAVE,true); |
|
473 |
bar.setEnabled(ACTION_CANCEL_NEW,true); |
|
474 |
bar.setEnabled(ACTION_DELETE,false); |
|
475 |
bar.setEnabled(ACTION_FIRST,false); |
|
476 |
bar.setEnabled(ACTION_NEXT,false); |
|
477 |
bar.setEnabled(ACTION_PREVIOUS,false); |
|
478 |
bar.setEnabled(ACTION_LAST,false); |
|
479 |
bar.setEnabled(ACTION_SEARCH,false); |
|
482 |
bar.setEnabled(ID_ACTION_SAVE,true);
|
|
483 |
bar.setEnabled(ID_ACTION_CANCEL_NEW,true);
|
|
484 |
bar.setEnabled(ID_ACTION_DELETE,false);
|
|
485 |
bar.setEnabled(ID_ACTION_FIRST,false);
|
|
486 |
bar.setEnabled(ID_ACTION_NEXT,false);
|
|
487 |
bar.setEnabled(ID_ACTION_PREVIOUS,false);
|
|
488 |
bar.setEnabled(ID_ACTION_LAST,false);
|
|
489 |
bar.setEnabled(ID_ACTION_SEARCH,false);
|
|
480 | 490 |
} catch (Exception ex) { |
481 | 491 |
LOGGER.warn("Can't enable/disable delete and save buttons",ex); |
482 | 492 |
} |
... | ... | |
491 | 501 |
try { |
492 | 502 |
FormSetButtonBar bar = this.getButtonBar(); |
493 | 503 |
|
494 |
bar.setVisible(ACTION_CANCEL_NEW, false); |
|
495 |
bar.setVisible(ACTION_NEW, true); |
|
504 |
bar.setVisible(ID_ACTION_CANCEL_NEW, false);
|
|
505 |
bar.setVisible(ID_ACTION_NEW, true);
|
|
496 | 506 |
|
497 |
bar.setEnabled(ACTION_SAVE,true); |
|
498 |
bar.setEnabled(ACTION_NEW,true); |
|
499 |
bar.setEnabled(ACTION_DELETE,true); |
|
500 |
bar.setEnabled(ACTION_SEARCH,true); |
|
507 |
bar.setEnabled(ID_ACTION_SAVE,true);
|
|
508 |
bar.setEnabled(ID_ACTION_NEW,true);
|
|
509 |
bar.setEnabled(ID_ACTION_DELETE,true);
|
|
510 |
bar.setEnabled(ID_ACTION_SEARCH,true);
|
|
501 | 511 |
|
502 | 512 |
bar.setCurrentLabel(null); |
503 | 513 |
bar.setNumrecords(this.countValues()); |
... | ... | |
685 | 695 |
} |
686 | 696 |
|
687 | 697 |
@Override |
688 |
public void fireEvent(int eventid, Object value) {
|
|
689 |
this.getButtonBar().fireEvent(eventid, value);
|
|
698 |
public void fireEvent(String action, Object value) {
|
|
699 |
this.getButtonBar().fireEvent(action, value);
|
|
690 | 700 |
} |
691 | 701 |
|
692 | 702 |
} |
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.services/src/main/java/org/gvsig/tools/dynform/services/dynformset/base/FormSetButtonBar.java | ||
---|---|---|
54 | 54 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_CLOSE; |
55 | 55 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_DELETE; |
56 | 56 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_FIRST; |
57 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_LAST; |
|
58 | 57 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_NEW; |
59 | 58 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_NEXT; |
60 | 59 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_PREVIOUS; |
60 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_LAST; |
|
61 | 61 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_SAVE; |
62 | 62 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_SEARCH; |
63 | 63 |
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_SET_CURRENT_RECORD; |
... | ... | |
68 | 68 |
|
69 | 69 |
public class FormSetButtonBar implements Component { |
70 | 70 |
|
71 |
protected static final Logger logger = LoggerFactory
|
|
71 |
protected static final Logger LOGGER = LoggerFactory
|
|
72 | 72 |
.getLogger(FormSetButtonBar.class); |
73 | 73 |
|
74 |
public static final int ID_ACTION_FIRST = 1; |
|
75 |
public static final int ID_ACTION_PREVIOUS = 2; |
|
76 |
public static final int ID_ACTION_NEXT = 3; |
|
77 |
public static final int ID_ACTION_LAST = 4; |
|
78 |
public static final int ID_ACTION_SAVE = 5; |
|
79 |
public static final int ID_ACTION_NEW = 6; |
|
80 |
public static final int ID_ACTION_CANCEL_NEW = 7; |
|
81 |
public static final int ID_ACTION_DELETE = 8; |
|
82 |
public static final int ID_ACTION_SEARCH = 9; |
|
83 |
public static final int ID_ACTION_CLOSE = 10; |
|
84 |
public static final int ID_ACTION_SET_CURRENT_RECORD = 11; |
|
74 | 85 |
|
75 | 86 |
private static final int MAX_ACTIONS = 11; |
76 | 87 |
|
77 |
public Boolean activatedActions[] = new Boolean[MAX_ACTIONS]; |
|
78 |
|
|
79 | 88 |
private static final int COUNTER_HEIGHT = 50; |
80 | 89 |
private static final int COUNTER_WIDTH = 100; |
81 | 90 |
|
... | ... | |
112 | 121 |
|
113 | 122 |
private JPanel othersButtons; |
114 | 123 |
private final List<Action> otherActions; |
115 |
private final Map<String,JButton> otherButtons; |
|
124 |
private final Map<String, JButton> otherButtons; |
|
125 |
|
|
126 |
private final Map<String,Integer> actionNameToId; |
|
116 | 127 |
|
117 | 128 |
private boolean readOnly = false; |
118 | 129 |
|
119 | 130 |
private JButton records; |
120 | 131 |
private final JButton buttons[] = new JButton[MAX_ACTIONS]; |
132 |
private final Boolean activatedActions[] = new Boolean[MAX_ACTIONS]; |
|
121 | 133 |
|
134 |
|
|
122 | 135 |
public FormSetButtonBar() { |
123 | 136 |
// Activamos todas las acciones por defecto |
124 | 137 |
for (int i = 0; i < this.activatedActions.length; i++) { |
125 | 138 |
this.activatedActions[i] = true; |
126 | 139 |
} |
140 |
this.actionNameToId = new HashMap(); |
|
141 |
this.actionNameToId.put(ACTION_FIRST, ID_ACTION_FIRST); |
|
142 |
this.actionNameToId.put(ACTION_PREVIOUS, ID_ACTION_PREVIOUS); |
|
143 |
this.actionNameToId.put(ACTION_NEXT, ID_ACTION_NEXT); |
|
144 |
this.actionNameToId.put(ACTION_LAST, ID_ACTION_LAST); |
|
145 |
this.actionNameToId.put(ACTION_SAVE, ID_ACTION_SAVE); |
|
146 |
this.actionNameToId.put(ACTION_NEW, ID_ACTION_NEW); |
|
147 |
this.actionNameToId.put(ACTION_CANCEL_NEW, ID_ACTION_CANCEL_NEW); |
|
148 |
this.actionNameToId.put(ACTION_DELETE, ID_ACTION_DELETE); |
|
149 |
this.actionNameToId.put(ACTION_SEARCH, ID_ACTION_SEARCH); |
|
150 |
this.actionNameToId.put(ACTION_CLOSE, ID_ACTION_CLOSE); |
|
151 |
this.actionNameToId.put(ACTION_SET_CURRENT_RECORD, ID_ACTION_SET_CURRENT_RECORD); |
|
152 |
|
|
127 | 153 |
this.listeners = new HashSet(); |
128 | 154 |
this.otherActions = new ArrayList<>(); |
129 | 155 |
this.otherButtons = new HashMap<>(); |
... | ... | |
145 | 171 |
this.listeners.remove(listener); |
146 | 172 |
} |
147 | 173 |
|
148 |
public void fireEvent(int eventid, Object value) { |
|
149 |
if (this.readOnly) { |
|
150 |
Iterator it = this.listeners.iterator(); |
|
151 |
while (it.hasNext()) { |
|
152 |
FormSetListener listener = (FormSetListener) it.next(); |
|
153 |
try { |
|
154 |
switch (eventid) { |
|
155 |
case ACTION_FIRST: |
|
156 |
listener.doActionFirst(); |
|
157 |
break; |
|
158 |
case ACTION_PREVIOUS: |
|
159 |
listener.doActionPrevious(); |
|
160 |
break; |
|
161 |
case ACTION_NEXT: |
|
162 |
listener.doActionNext(); |
|
163 |
break; |
|
164 |
case ACTION_LAST: |
|
165 |
listener.doActionLast(); |
|
166 |
break; |
|
167 |
case ACTION_SEARCH: |
|
168 |
listener.doActionSearch(); |
|
169 |
break; |
|
170 |
case ACTION_CLOSE: |
|
171 |
listener.doActionClose(); |
|
172 |
break; |
|
173 |
case ACTION_SET_CURRENT_RECORD: |
|
174 |
listener.doSetCurrentRecord(((Integer) value)); |
|
175 |
break; |
|
176 |
} |
|
177 |
} catch (Exception ex) { |
|
178 |
logger.info("Error calling listener " + listener.toString() |
|
179 |
+ "(" + listener.getClass().getName() + ") from " |
|
180 |
+ this.toString() + "(" + this.getClass().getName() |
|
181 |
+ ").", ex); |
|
182 |
} |
|
174 |
public void fireEvent(String action, Object value) { |
|
175 |
|
|
176 |
Integer actionid = this.actionNameToId.get(action); |
|
177 |
if( actionid==null ) { |
|
178 |
JButton button = this.otherButtons.get(action); |
|
179 |
if( button != null && button.getAction()!=null ) { |
|
180 |
button.getAction().actionPerformed(new ActionEvent(value, 1, action)); |
|
183 | 181 |
} |
182 |
|
|
184 | 183 |
} else { |
185 |
Iterator it = this.listeners.iterator(); |
|
186 |
while (it.hasNext()) { |
|
187 |
FormSetListener listener = (FormSetListener) it.next(); |
|
188 |
try { |
|
189 |
switch (eventid) { |
|
190 |
case ACTION_FIRST: |
|
191 |
listener.doActionFirst(); |
|
192 |
break; |
|
193 |
case ACTION_PREVIOUS: |
|
194 |
listener.doActionPrevious(); |
|
195 |
break; |
|
196 |
case ACTION_NEXT: |
|
197 |
listener.doActionNext(); |
|
198 |
break; |
|
199 |
case ACTION_LAST: |
|
200 |
listener.doActionLast(); |
|
201 |
break; |
|
202 |
case ACTION_SAVE: |
|
203 |
listener.doActionSave(); |
|
204 |
break; |
|
205 |
case ACTION_NEW: |
|
206 |
listener.doActionNew(); |
|
207 |
break; |
|
208 |
case ACTION_CANCEL_NEW: |
|
209 |
listener.doActionCancelNew(); |
|
210 |
break; |
|
211 |
case ACTION_DELETE: |
|
212 |
listener.doActionDelete(); |
|
213 |
break; |
|
214 |
case ACTION_SEARCH: |
|
215 |
listener.doActionSearch(); |
|
216 |
break; |
|
217 |
case ACTION_CLOSE: |
|
218 |
listener.doActionClose(); |
|
219 |
break; |
|
220 |
case ACTION_SET_CURRENT_RECORD: |
|
221 |
listener.doSetCurrentRecord(((Integer) value)); |
|
222 |
break; |
|
184 |
if (this.readOnly) { |
|
185 |
Iterator it = this.listeners.iterator(); |
|
186 |
while (it.hasNext()) { |
|
187 |
FormSetListener listener = (FormSetListener) it.next(); |
|
188 |
try { |
|
189 |
switch (actionid) { |
|
190 |
case ID_ACTION_FIRST: |
|
191 |
listener.doActionFirst(); |
|
192 |
break; |
|
193 |
case ID_ACTION_PREVIOUS: |
|
194 |
listener.doActionPrevious(); |
|
195 |
break; |
|
196 |
case ID_ACTION_NEXT: |
|
197 |
listener.doActionNext(); |
|
198 |
break; |
|
199 |
case ID_ACTION_LAST: |
|
200 |
listener.doActionLast(); |
|
201 |
break; |
|
202 |
case ID_ACTION_SEARCH: |
|
203 |
listener.doActionSearch(); |
|
204 |
break; |
|
205 |
case ID_ACTION_CLOSE: |
|
206 |
listener.doActionClose(); |
|
207 |
break; |
|
208 |
case ID_ACTION_SET_CURRENT_RECORD: |
|
209 |
listener.doSetCurrentRecord(((Integer) value)); |
|
210 |
break; |
|
211 |
} |
|
212 |
} catch (Exception ex) { |
|
213 |
LOGGER.info("Error calling listener " + listener.toString() |
|
214 |
+ "(" + listener.getClass().getName() + ") from " |
|
215 |
+ this.toString() + "(" + this.getClass().getName() |
|
216 |
+ ").", ex); |
|
223 | 217 |
} |
224 |
} catch (Exception ex) { |
|
225 |
logger.info("Error calling listener " + listener.toString() |
|
226 |
+ "(" + listener.getClass().getName() + ") from " |
|
227 |
+ this.toString() + "(" + this.getClass().getName() |
|
228 |
+ ").", ex); |
|
229 | 218 |
} |
219 |
} else { |
|
220 |
Iterator it = this.listeners.iterator(); |
|
221 |
while (it.hasNext()) { |
|
222 |
FormSetListener listener = (FormSetListener) it.next(); |
|
223 |
try { |
|
224 |
switch (actionid) { |
|
225 |
case ID_ACTION_FIRST: |
|
226 |
listener.doActionFirst(); |
|
227 |
break; |
|
228 |
case ID_ACTION_PREVIOUS: |
|
229 |
listener.doActionPrevious(); |
|
230 |
break; |
|
231 |
case ID_ACTION_NEXT: |
|
232 |
listener.doActionNext(); |
|
233 |
break; |
|
234 |
case ID_ACTION_LAST: |
|
235 |
listener.doActionLast(); |
|
236 |
break; |
|
237 |
case ID_ACTION_SAVE: |
|
238 |
listener.doActionSave(); |
|
239 |
break; |
|
240 |
case ID_ACTION_NEW: |
|
241 |
listener.doActionNew(); |
|
242 |
break; |
|
243 |
case ID_ACTION_CANCEL_NEW: |
|
244 |
listener.doActionCancelNew(); |
|
245 |
break; |
|
246 |
case ID_ACTION_DELETE: |
|
247 |
listener.doActionDelete(); |
|
248 |
break; |
|
249 |
case ID_ACTION_SEARCH: |
|
250 |
listener.doActionSearch(); |
|
251 |
break; |
|
252 |
case ID_ACTION_CLOSE: |
|
253 |
listener.doActionClose(); |
|
254 |
break; |
|
255 |
case ID_ACTION_SET_CURRENT_RECORD: |
|
256 |
listener.doSetCurrentRecord(((Integer) value)); |
|
257 |
break; |
|
258 |
} |
|
259 |
} catch (Exception ex) { |
|
260 |
LOGGER.info("Error calling listener " + listener.toString() |
|
261 |
+ "(" + listener.getClass().getName() + ") from " |
|
262 |
+ this.toString() + "(" + this.getClass().getName() |
|
263 |
+ ").", ex); |
|
264 |
} |
|
265 |
} |
|
230 | 266 |
} |
231 | 267 |
} |
232 | 268 |
} |
... | ... | |
235 | 271 |
setEnabled(ACTION_NEW, true); |
236 | 272 |
if (numrecords <= 0) { |
237 | 273 |
this.records.setText("0 / 0"); |
238 |
setEnabled(ACTION_FIRST, false); |
|
239 |
setEnabled(ACTION_PREVIOUS, false); |
|
240 |
setEnabled(ACTION_NEXT, false); |
|
274 |
setEnabled(ID_ACTION_FIRST, false);
|
|
275 |
setEnabled(ID_ACTION_PREVIOUS, false);
|
|
276 |
setEnabled(ID_ACTION_NEXT, false);
|
|
241 | 277 |
setEnabled(ACTION_LAST, false); |
242 | 278 |
return; |
243 | 279 |
} |
244 |
if( this.currentLabel==null ) {
|
|
280 |
if (this.currentLabel == null) {
|
|
245 | 281 |
this.records.setText((current + 1) + " / " + numrecords); |
246 | 282 |
} else { |
247 | 283 |
this.records.setText(this.currentLabel + " / " + numrecords); |
248 | 284 |
} |
249 | 285 |
if (current <= 0) { |
250 | 286 |
current = 0; |
251 |
setEnabled(ACTION_FIRST, false); |
|
252 |
setEnabled(ACTION_PREVIOUS, false); |
|
253 |
setEnabled(ACTION_NEXT, true); |
|
287 |
setEnabled(ID_ACTION_FIRST, false);
|
|
288 |
setEnabled(ID_ACTION_PREVIOUS, false);
|
|
289 |
setEnabled(ID_ACTION_NEXT, true);
|
|
254 | 290 |
setEnabled(ACTION_LAST, true); |
255 | 291 |
} else if (current >= numrecords - 1) { |
256 | 292 |
current = numrecords - 1; |
257 |
setEnabled(ACTION_NEXT, false); |
|
293 |
setEnabled(ID_ACTION_NEXT, false);
|
|
258 | 294 |
setEnabled(ACTION_LAST, false); |
259 |
setEnabled(ACTION_FIRST, true); |
|
260 |
setEnabled(ACTION_PREVIOUS, true); |
|
295 |
setEnabled(ID_ACTION_FIRST, true);
|
|
296 |
setEnabled(ID_ACTION_PREVIOUS, true);
|
|
261 | 297 |
} else { |
262 |
setEnabled(ACTION_NEXT, true); |
|
298 |
setEnabled(ID_ACTION_NEXT, true);
|
|
263 | 299 |
setEnabled(ACTION_LAST, true); |
264 |
setEnabled(ACTION_FIRST, true); |
|
265 |
setEnabled(ACTION_PREVIOUS, true); |
|
300 |
setEnabled(ID_ACTION_FIRST, true);
|
|
301 |
setEnabled(ID_ACTION_PREVIOUS, true);
|
|
266 | 302 |
} |
267 | 303 |
} |
268 | 304 |
|
... | ... | |
290 | 326 |
JPanel contents = new JPanel(); |
291 | 327 |
contents.setLayout(new FlowLayout(FlowLayout.LEADING, 4, 4)); |
292 | 328 |
|
293 |
JComponent firstButton = createButton(i18nManager.getTranslation("_first"), "first.png", ACTION_FIRST, KeyEvent.CTRL_MASK+KeyEvent.VK_PAGE_UP);
|
|
329 |
JComponent firstButton = createButton(i18nManager.getTranslation("_first"), "first.png", ACTION_FIRST, KeyEvent.CTRL_MASK + KeyEvent.VK_PAGE_UP);
|
|
294 | 330 |
contents.add(firstButton); |
295 | 331 |
contents.add(createButton(i18nManager.getTranslation("_back"), "previous.png", ACTION_PREVIOUS, KeyEvent.VK_PAGE_UP)); |
296 | 332 |
|
... | ... | |
316 | 352 |
contents.add(this.records); |
317 | 353 |
|
318 | 354 |
contents.add(createButton(i18nManager.getTranslation("_next"), "next.png", ACTION_NEXT, KeyEvent.VK_PAGE_DOWN)); |
319 |
contents.add(createButton(i18nManager.getTranslation("_last"), "last.png", ACTION_LAST, KeyEvent.CTRL_MASK+KeyEvent.VK_PAGE_DOWN));
|
|
355 |
contents.add(createButton(i18nManager.getTranslation("_last"), "last.png", ACTION_LAST, KeyEvent.CTRL_MASK + KeyEvent.VK_PAGE_DOWN));
|
|
320 | 356 |
|
321 |
contents.add(createButton(i18nManager.getTranslation("guardar"), "save.png", ACTION_SAVE, KeyEvent.CTRL_MASK+KeyEvent.VK_S));
|
|
357 |
contents.add(createButton(i18nManager.getTranslation("guardar"), "save.png", ACTION_SAVE, KeyEvent.CTRL_MASK + KeyEvent.VK_S));
|
|
322 | 358 |
contents.add(createButton(i18nManager.getTranslation("nuevo"), "new.png", ACTION_NEW, KeyEvent.VK_F6)); |
323 | 359 |
contents.add(createButton(i18nManager.getTranslation("cancelar nuevo"), "cancelnew.png", ACTION_CANCEL_NEW, KeyEvent.VK_F12)); |
324 |
contents.add(createButton(i18nManager.getTranslation("borrar"), "delete.png", ACTION_DELETE, KeyEvent.SHIFT_MASK+KeyEvent.VK_F2));
|
|
325 |
contents.add(createButton(i18nManager.getTranslation("search"), "search.png", ACTION_SEARCH, KeyEvent.CTRL_MASK+KeyEvent.VK_F));
|
|
360 |
contents.add(createButton(i18nManager.getTranslation("borrar"), "delete.png", ACTION_DELETE, KeyEvent.SHIFT_MASK + KeyEvent.VK_F2));
|
|
361 |
contents.add(createButton(i18nManager.getTranslation("search"), "search.png", ACTION_SEARCH, KeyEvent.CTRL_MASK + KeyEvent.VK_F));
|
|
326 | 362 |
|
327 | 363 |
return contents; |
328 | 364 |
} |
... | ... | |
354 | 390 |
} |
355 | 391 |
|
356 | 392 |
private void initButtons() { |
357 |
setActionActive(ACTION_SAVE, isActionActive(ACTION_SAVE));
|
|
358 |
setActionActive(ACTION_NEW, isActionActive(ACTION_NEW));
|
|
359 |
setActionActive(ACTION_SEARCH, isActionActive(ACTION_SEARCH));
|
|
360 |
setActionActive(ACTION_DELETE, isActionActive(ACTION_DELETE));
|
|
361 |
setActionActive(ACTION_CLOSE, isActionActive(ACTION_CLOSE));
|
|
393 |
setActionActive(ID_ACTION_SAVE, isActionActive(ID_ACTION_SAVE));
|
|
394 |
setActionActive(ID_ACTION_NEW, isActionActive(ID_ACTION_NEW));
|
|
395 |
setActionActive(ID_ACTION_SEARCH, isActionActive(ID_ACTION_SEARCH));
|
|
396 |
setActionActive(ID_ACTION_DELETE, isActionActive(ID_ACTION_DELETE));
|
|
397 |
setActionActive(ID_ACTION_CLOSE, isActionActive(ID_ACTION_CLOSE));
|
|
362 | 398 |
} |
363 | 399 |
|
364 |
private JComponent createButton(final String tip, final String image, final int action, int mnemonic) { |
|
365 |
|
|
400 |
private JComponent createButton(final String tip, final String image, final String action, int mnemonic) { |
|
401 |
int actionid = this.actionNameToId.get(action); |
|
402 |
|
|
366 | 403 |
URL url = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/" + image); |
367 | 404 |
Icon icon = new ImageIcon(url); |
368 | 405 |
JButton button = new JButton(icon); |
369 |
if( mnemonic!=KeyEvent.VK_UNDEFINED ) {
|
|
406 |
if (mnemonic != KeyEvent.VK_UNDEFINED) {
|
|
370 | 407 |
button.setMnemonic(mnemonic); |
371 | 408 |
} |
372 | 409 |
button.setBorder(BorderFactory.createEmptyBorder()); |
... | ... | |
382 | 419 |
fireEvent(action, null); |
383 | 420 |
} |
384 | 421 |
}); |
385 |
this.buttons[action] = button; |
|
422 |
this.buttons[actionid] = button;
|
|
386 | 423 |
return button; |
387 | 424 |
} |
388 | 425 |
|
... | ... | |
405 | 442 |
} |
406 | 443 |
|
407 | 444 |
public void setVisible(String id, boolean visible) { |
445 |
Integer x = this.actionNameToId.get(id); |
|
446 |
if( x!=null ) { |
|
447 |
this.buttons[x].setVisible(visible); |
|
448 |
return; |
|
449 |
} |
|
408 | 450 |
JButton button = this.otherButtons.get(id); |
409 |
if( button == null ) {
|
|
451 |
if (button == null) {
|
|
410 | 452 |
return; |
411 | 453 |
} |
412 | 454 |
button.setVisible(visible); |
413 | 455 |
} |
414 |
|
|
456 |
|
|
415 | 457 |
public void setEnabled(String id, boolean enabled) { |
458 |
Integer x = this.actionNameToId.get(id); |
|
459 |
if( x!=null ) { // Ojo, si quito el intValue a veces falla |
|
460 |
this.buttons[x.intValue()].setEnabled(enabled); |
|
461 |
return; |
|
462 |
} |
|
416 | 463 |
JButton button = this.otherButtons.get(id); |
417 |
if( button == null ) {
|
|
464 |
if (button == null) {
|
|
418 | 465 |
return; |
419 | 466 |
} |
420 | 467 |
button.setEnabled(enabled); |
421 | 468 |
} |
422 |
|
|
469 |
|
|
423 | 470 |
public boolean isEnabled(String id) { |
471 |
Integer x = this.actionNameToId.get(id); |
|
472 |
if( x!=null ) { |
|
473 |
return this.buttons[x].isEnabled(); |
|
474 |
} |
|
424 | 475 |
JButton button = this.otherButtons.get(id); |
425 |
if( button == null ) {
|
|
426 |
throw new IllegalArgumentException("Don't exists action '"+id+"'.");
|
|
476 |
if (button == null) {
|
|
477 |
throw new IllegalArgumentException("Don't exists action '" + id + "'.");
|
|
427 | 478 |
} |
428 | 479 |
return button.isEnabled(); |
429 | 480 |
} |
430 |
|
|
481 |
|
|
431 | 482 |
public JComponent getActionButton(String id) { |
483 |
Integer x = this.actionNameToId.get(id); |
|
484 |
if( x!=null ) { |
|
485 |
return this.buttons[x]; |
|
486 |
} |
|
432 | 487 |
JButton button = this.otherButtons.get(id); |
433 | 488 |
return button; |
434 | 489 |
} |
435 |
|
|
490 |
|
|
436 | 491 |
public boolean isVisible(String id) { |
492 |
Integer x = this.actionNameToId.get(id); |
|
493 |
if( x!=null ) { |
|
494 |
return this.buttons[x].isVisible(); |
|
495 |
} |
|
437 | 496 |
JButton button = this.otherButtons.get(id); |
438 |
if( button == null ) {
|
|
439 |
throw new IllegalArgumentException("Don't exists action '"+id+"'.");
|
|
497 |
if (button == null) {
|
|
498 |
throw new IllegalArgumentException("Don't exists action '" + id + "'.");
|
|
440 | 499 |
} |
441 | 500 |
return button.isVisible(); |
442 | 501 |
} |
443 |
|
|
502 |
|
|
444 | 503 |
public void setCurrent(int current) { |
445 | 504 |
this.current = current; |
446 | 505 |
updateRecords(); |
... | ... | |
457 | 516 |
} |
458 | 517 |
|
459 | 518 |
public void setActionActive(int action, boolean active) { |
460 |
if (action == ACTION_SAVE || action == ACTION_DELETE
|
|
461 |
|| action == ACTION_NEW || action == ACTION_SEARCH
|
|
462 |
|| action == ACTION_CLOSE) { |
|
519 |
if (action == ID_ACTION_SAVE || action == ID_ACTION_DELETE
|
|
520 |
|| action == ID_ACTION_NEW || action == ID_ACTION_SEARCH
|
|
521 |
|| action == ID_ACTION_CLOSE) {
|
|
463 | 522 |
if (this.contents == null) { |
464 | 523 |
this.initComponents(); |
465 | 524 |
} |
... | ... | |
474 | 533 |
|
475 | 534 |
public void setReadOnly(boolean readOnly) { |
476 | 535 |
this.readOnly = readOnly; |
477 |
|
|
478 |
this.setEnabled(ACTION_SAVE, !readOnly); |
|
536 |
|
|
537 |
this.setEnabled(ID_ACTION_SAVE, !readOnly);
|
|
479 | 538 |
this.setEnabled(ACTION_NEW, !readOnly); |
480 |
this.setEnabled(ACTION_CANCEL_NEW, !readOnly); |
|
539 |
this.setEnabled(ID_ACTION_CANCEL_NEW, !readOnly);
|
|
481 | 540 |
this.setEnabled(ACTION_DELETE, !readOnly); |
482 |
this.setEnabled(ACTION_SEARCH, true); |
|
541 |
this.setEnabled(ID_ACTION_SEARCH, true);
|
|
483 | 542 |
this.setEnabled(ACTION_CLOSE, true); |
484 |
|
|
543 |
|
|
485 | 544 |
updateRecords(); |
486 | 545 |
} |
487 | 546 |
|
... | ... | |
497 | 556 |
button.setContentAreaFilled(false); |
498 | 557 |
button.setCursor(new Cursor(Cursor.HAND_CURSOR)); |
499 | 558 |
String id = Objects.toString(action.getValue(Action.ACTION_COMMAND_KEY), null); |
500 |
if( !StringUtils.isEmpty(id) ) {
|
|
559 |
if (!StringUtils.isEmpty(id)) {
|
|
501 | 560 |
this.otherButtons.put(id, button); |
502 | 561 |
} |
503 | 562 |
this.othersButtons.add(button); |
Also available in: Unified diff