Revision 2023 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

View differences:

FormSetButtonBar.java
37 37
import java.util.Map;
38 38
import java.util.Objects;
39 39
import java.util.Set;
40
import javax.swing.AbstractAction;
41 40
import javax.swing.Action;
42 41
import javax.swing.BorderFactory;
43 42

  
......
51 50
import org.apache.commons.lang3.StringUtils;
52 51

  
53 52
import org.gvsig.tools.ToolsLocator;
53
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_CANCEL_NEW;
54
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_CLOSE;
55
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_DELETE;
56
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_FIRST;
57
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_LAST;
58
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_NEW;
59
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_NEXT;
60
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_PREVIOUS;
61
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_SAVE;
62
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_SEARCH;
63
import static org.gvsig.tools.dynform.JDynFormSet.ACTION_SET_CURRENT_RECORD;
54 64
import org.gvsig.tools.i18n.I18nManager;
55 65
import org.gvsig.tools.swing.api.Component;
56 66
import org.slf4j.Logger;
......
61 71
    protected static final Logger logger = LoggerFactory
62 72
            .getLogger(FormSetButtonBar.class);
63 73

  
64
    public static final int ActionFirst = 1;
65
    public static final int ActionPrevious = 2;
66
    public static final int ActionNext = 3;
67
    public static final int ActionLast = 4;
68
    public static final int ActionSave = 5;
69
    public static final int ActionNew = 6;
70
    public static final int ActionCancelNew = 7;
71
    public static final int ActionDelete = 8;
72
    public static final int ActionSearch = 9;
73
    public static final int ActionClose = 10;
74
    public static final int ActionSetCurrentRecord = 11;
75 74

  
76 75
    private static final int MAX_ACTIONS = 11;
77 76

  
......
146 145
        this.listeners.remove(listener);
147 146
    }
148 147

  
149
    protected void fireEvent(int eventid, Object value) {
148
    public void fireEvent(int eventid, Object value) {
150 149
        if (this.readOnly) {
151 150
            Iterator it = this.listeners.iterator();
152 151
            while (it.hasNext()) {
153 152
                FormSetListener listener = (FormSetListener) it.next();
154 153
                try {
155 154
                    switch (eventid) {
156
                        case ActionFirst:
155
                        case ACTION_FIRST:
157 156
                            listener.doActionFirst();
158 157
                            break;
159
                        case ActionPrevious:
158
                        case ACTION_PREVIOUS:
160 159
                            listener.doActionPrevious();
161 160
                            break;
162
                        case ActionNext:
161
                        case ACTION_NEXT:
163 162
                            listener.doActionNext();
164 163
                            break;
165
                        case ActionLast:
164
                        case ACTION_LAST:
166 165
                            listener.doActionLast();
167 166
                            break;
168
                        case ActionSearch:
167
                        case ACTION_SEARCH:
169 168
                            listener.doActionSearch();
170 169
                            break;
171
                        case ActionClose:
170
                        case ACTION_CLOSE:
172 171
                            listener.doActionClose();
173 172
                            break;
174
                        case ActionSetCurrentRecord:
173
                        case ACTION_SET_CURRENT_RECORD:
175 174
                            listener.doSetCurrentRecord(((Integer) value));
176 175
                            break;
177 176
                    }
......
188 187
                FormSetListener listener = (FormSetListener) it.next();
189 188
                try {
190 189
                    switch (eventid) {
191
                        case ActionFirst:
190
                        case ACTION_FIRST:
192 191
                            listener.doActionFirst();
193 192
                            break;
194
                        case ActionPrevious:
193
                        case ACTION_PREVIOUS:
195 194
                            listener.doActionPrevious();
196 195
                            break;
197
                        case ActionNext:
196
                        case ACTION_NEXT:
198 197
                            listener.doActionNext();
199 198
                            break;
200
                        case ActionLast:
199
                        case ACTION_LAST:
201 200
                            listener.doActionLast();
202 201
                            break;
203
                        case ActionSave:
202
                        case ACTION_SAVE:
204 203
                            listener.doActionSave();
205 204
                            break;
206
                        case ActionNew:
205
                        case ACTION_NEW:
207 206
                            listener.doActionNew();
208 207
                            break;
209
                        case ActionCancelNew:
208
                        case ACTION_CANCEL_NEW:
210 209
                            listener.doActionCancelNew();
211 210
                            break;
212
                        case ActionDelete:
211
                        case ACTION_DELETE:
213 212
                            listener.doActionDelete();
214 213
                            break;
215
                        case ActionSearch:
214
                        case ACTION_SEARCH:
216 215
                            listener.doActionSearch();
217 216
                            break;
218
                        case ActionClose:
217
                        case ACTION_CLOSE:
219 218
                            listener.doActionClose();
220 219
                            break;
221
                        case ActionSetCurrentRecord:
220
                        case ACTION_SET_CURRENT_RECORD:
222 221
                            listener.doSetCurrentRecord(((Integer) value));
223 222
                            break;
224 223
                    }
......
233 232
    }
234 233

  
235 234
    private void updateRecords() {
236
        setEnabled(ActionNew, true);
235
        setEnabled(ACTION_NEW, true);
237 236
        if (numrecords <= 0) {
238 237
            this.records.setText("0 / 0");
239
            setEnabled(ActionFirst, false);
240
            setEnabled(ActionPrevious, false);
241
            setEnabled(ActionNext, false);
242
            setEnabled(ActionLast, false);
238
            setEnabled(ACTION_FIRST, false);
239
            setEnabled(ACTION_PREVIOUS, false);
240
            setEnabled(ACTION_NEXT, false);
241
            setEnabled(ACTION_LAST, false);
243 242
            return;
244 243
        }
245 244
        if( this.currentLabel==null ) {
......
249 248
        }
250 249
        if (current <= 0) {
251 250
            current = 0;
252
            setEnabled(ActionFirst, false);
253
            setEnabled(ActionPrevious, false);
254
            setEnabled(ActionNext, true);
255
            setEnabled(ActionLast, true);
251
            setEnabled(ACTION_FIRST, false);
252
            setEnabled(ACTION_PREVIOUS, false);
253
            setEnabled(ACTION_NEXT, true);
254
            setEnabled(ACTION_LAST, true);
256 255
        } else if (current >= numrecords - 1) {
257 256
            current = numrecords - 1;
258
            setEnabled(ActionNext, false);
259
            setEnabled(ActionLast, false);
260
            setEnabled(ActionFirst, true);
261
            setEnabled(ActionPrevious, true);
257
            setEnabled(ACTION_NEXT, false);
258
            setEnabled(ACTION_LAST, false);
259
            setEnabled(ACTION_FIRST, true);
260
            setEnabled(ACTION_PREVIOUS, true);
262 261
        } else {
263
            setEnabled(ActionNext, true);
264
            setEnabled(ActionLast, true);
265
            setEnabled(ActionFirst, true);
266
            setEnabled(ActionPrevious, true);
262
            setEnabled(ACTION_NEXT, true);
263
            setEnabled(ACTION_LAST, true);
264
            setEnabled(ACTION_FIRST, true);
265
            setEnabled(ACTION_PREVIOUS, true);
267 266
        }
268 267
    }
269 268

  
......
281 280
            this.othersButtons.add(new JButton(action));
282 281
        }
283 282

  
284
        this.contents.add(createButton("Close", "close.png", ActionClose, KeyEvent.VK_UNDEFINED));
283
        this.contents.add(createButton("Close", "close.png", ACTION_CLOSE, KeyEvent.VK_UNDEFINED));
285 284
        this.initButtons();
286 285
        this.updateRecords();
287 286
    }
......
291 290
        JPanel contents = new JPanel();
292 291
        contents.setLayout(new FlowLayout(FlowLayout.LEADING, 4, 4));
293 292

  
294
        JComponent firstButton = createButton(i18nManager.getTranslation("_first"), "first.png", ActionFirst, KeyEvent.CTRL_MASK+KeyEvent.VK_PAGE_UP);
293
        JComponent firstButton = createButton(i18nManager.getTranslation("_first"), "first.png", ACTION_FIRST, KeyEvent.CTRL_MASK+KeyEvent.VK_PAGE_UP);
295 294
        contents.add(firstButton);
296
        contents.add(createButton(i18nManager.getTranslation("_back"), "previous.png", ActionPrevious, KeyEvent.VK_PAGE_UP));
295
        contents.add(createButton(i18nManager.getTranslation("_back"), "previous.png", ACTION_PREVIOUS, KeyEvent.VK_PAGE_UP));
297 296

  
298 297
        this.records = new JButton();
299 298
        this.records.setCursor(new Cursor(Cursor.HAND_CURSOR));
......
316 315
        this.records.setHorizontalAlignment(SwingConstants.CENTER);
317 316
        contents.add(this.records);
318 317

  
319
        contents.add(createButton(i18nManager.getTranslation("_next"), "next.png", ActionNext, KeyEvent.VK_PAGE_DOWN));
320
        contents.add(createButton(i18nManager.getTranslation("_last"), "last.png", ActionLast, KeyEvent.CTRL_MASK+KeyEvent.VK_PAGE_DOWN));
318
        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));
321 320

  
322
        contents.add(createButton(i18nManager.getTranslation("guardar"), "save.png", ActionSave, KeyEvent.CTRL_MASK+KeyEvent.VK_S));
323
        contents.add(createButton(i18nManager.getTranslation("nuevo"), "new.png", ActionNew, KeyEvent.VK_F6));
324
        contents.add(createButton(i18nManager.getTranslation("cancelar nuevo"), "cancelnew.png", ActionCancelNew, KeyEvent.VK_F12));
325
        contents.add(createButton(i18nManager.getTranslation("borrar"), "delete.png", ActionDelete, KeyEvent.SHIFT_MASK+KeyEvent.VK_F2));
326
        contents.add(createButton(i18nManager.getTranslation("search"), "search.png", ActionSearch, KeyEvent.CTRL_MASK+KeyEvent.VK_F));
321
        contents.add(createButton(i18nManager.getTranslation("guardar"), "save.png", ACTION_SAVE, KeyEvent.CTRL_MASK+KeyEvent.VK_S));
322
        contents.add(createButton(i18nManager.getTranslation("nuevo"), "new.png", ACTION_NEW, KeyEvent.VK_F6));
323
        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));
327 326

  
328 327
        return contents;
329 328
    }
......
351 350
            );
352 351
            return;
353 352
        }
354
        fireEvent(ActionSetCurrentRecord, record);
353
        fireEvent(ACTION_SET_CURRENT_RECORD, record);
355 354
    }
356 355

  
357 356
    private void initButtons() {
358
        setActionActive(ActionSave, isActionActive(ActionSave));
359
        setActionActive(ActionNew, isActionActive(ActionNew));
360
        setActionActive(ActionSearch, isActionActive(ActionSearch));
361
        setActionActive(ActionDelete, isActionActive(ActionDelete));
362
        setActionActive(ActionClose, isActionActive(ActionClose));
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));
363 362
    }
364 363

  
365 364
    private JComponent createButton(final String tip, final String image, final int action, int mnemonic) {
......
458 457
    }
459 458

  
460 459
    public void setActionActive(int action, boolean active) {
461
        if (action == ActionSave || action == ActionDelete
462
                || action == ActionNew || action == ActionSearch
463
                || action == ActionClose) {
460
        if (action == ACTION_SAVE || action == ACTION_DELETE
461
                || action == ACTION_NEW || action == ACTION_SEARCH
462
                || action == ACTION_CLOSE) {
464 463
            if (this.contents == null) {
465 464
                this.initComponents();
466 465
            }
......
476 475
    public void setReadOnly(boolean readOnly) {
477 476
        this.readOnly = readOnly;
478 477
        
479
        this.setEnabled(ActionSave, !readOnly);
480
        this.setEnabled(ActionNew, !readOnly);
481
        this.setEnabled(ActionCancelNew, !readOnly);
482
        this.setEnabled(ActionDelete, !readOnly);
483
        this.setEnabled(ActionSearch, true);
484
        this.setEnabled(ActionClose, true);
478
        this.setEnabled(ACTION_SAVE, !readOnly);
479
        this.setEnabled(ACTION_NEW, !readOnly);
480
        this.setEnabled(ACTION_CANCEL_NEW, !readOnly);
481
        this.setEnabled(ACTION_DELETE, !readOnly);
482
        this.setEnabled(ACTION_SEARCH, true);
483
        this.setEnabled(ACTION_CLOSE, true);
485 484
        
486 485
        updateRecords();
487 486
    }

Also available in: Unified diff