Revision 44531 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.swing/org.gvsig.fmap.dal.swing.impl/src/main/java/org/gvsig/featureform/swing/impl/DefaultJFeaturesForm.java
DefaultJFeaturesForm.java | ||
---|---|---|
27 | 27 |
import java.awt.event.ActionEvent; |
28 | 28 |
import java.awt.event.ComponentAdapter; |
29 | 29 |
import java.awt.event.ComponentEvent; |
30 |
import java.net.URL; |
|
30 | 31 |
import java.util.ArrayList; |
31 | 32 |
import java.util.Collection; |
32 | 33 |
import java.util.List; |
... | ... | |
110 | 111 |
|
111 | 112 |
private final String STARTEDITING_ACTION = "startEditing"; |
112 | 113 |
private final String FINISHEDITING_ACTION = "finishEditing"; |
114 |
private final String REFRESHFORM_ACTION = "refreshForm"; |
|
113 | 115 |
|
114 | 116 |
|
115 | 117 |
public class DefaultFeaturesFormContext implements FeaturesFormContext { |
... | ... | |
222 | 224 |
}); |
223 | 225 |
} |
224 | 226 |
|
227 |
public static void selfRegister() { |
|
228 |
String[][] iconNames = new String[][]{ |
|
229 |
new String[]{"dalswing", "form-refresh-data"} |
|
230 |
}; |
|
231 |
IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent(); |
|
232 |
for (String[] icon : iconNames) { |
|
233 |
URL url = DefaultJFeaturesForm.class.getResource(icon[1] + ".png"); |
|
234 |
theme.registerDefault("DALSwing", icon[0], icon[1], null, url); |
|
235 |
} |
|
236 |
|
|
237 |
} |
|
225 | 238 |
@Override |
226 | 239 |
public void setPreferredSize(Dimension dimension) { |
227 | 240 |
// panel.setPreferredSize(dimension); |
... | ... | |
319 | 332 |
|
320 | 333 |
this.formset.addAction(new StartEditingAction()); |
321 | 334 |
this.formset.addAction(new FinishEditingAction()); |
335 |
this.formset.addAction(new RefreshAction()); |
|
322 | 336 |
|
323 | 337 |
FormActionContext actionContext = new FormActionContext(); |
324 | 338 |
Collection<DALActionFactory> factories = DALSwingLocator.getSwingManager().getStoreActions(); |
... | ... | |
366 | 380 |
return null; |
367 | 381 |
} |
368 | 382 |
} |
383 |
|
|
384 |
private class RefreshAction extends AbstractAction { |
|
369 | 385 |
|
386 |
@SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) |
|
387 |
public RefreshAction() { |
|
388 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
|
389 |
IconTheme iconTheme = ToolsSwingLocator.getIconThemeManager().getDefault(); |
|
390 |
|
|
391 |
this.putValue(NAME, null); |
|
392 |
this.putValue(SHORT_DESCRIPTION, i18nManager.getTranslation("_Refresh")); |
|
393 |
this.putValue(SMALL_ICON, iconTheme.get("form-refresh-data")); |
|
394 |
this.putValue(ACTION_COMMAND_KEY, REFRESHFORM_ACTION); |
|
395 |
this.setEnabled(!formset.isInNewState()); |
|
396 |
} |
|
397 |
|
|
398 |
@Override |
|
399 |
public void actionPerformed(ActionEvent ae) { |
|
400 |
try { |
|
401 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
402 |
formset.message(i18n.getTranslation("_Form_refreshed")); |
|
403 |
updateForm(); |
|
404 |
} catch (Exception ex) { |
|
405 |
LOGGER.warn("Can't refresh form", ex); |
|
406 |
} |
|
407 |
} |
|
408 |
} |
|
409 |
|
|
410 |
|
|
370 | 411 |
private class FinishEditingAction extends AbstractAction implements Observer { |
371 | 412 |
|
372 | 413 |
@SuppressWarnings({"OverridableMethodCallInConstructor", "LeakingThisInConstructor"}) |
... | ... | |
411 | 452 |
} |
412 | 453 |
updateButtonEnabledStatus(); |
413 | 454 |
} |
414 |
|
|
455 |
|
|
415 | 456 |
@Override |
416 | 457 |
public void update(Observable observable, Object notification) { |
417 | 458 |
if( store == null || formset==null ) { |
... | ... | |
550 | 591 |
feature = ((EditableFeature) feature).getNotEditableCopy(); |
551 | 592 |
} |
552 | 593 |
features.delete(feature); |
594 |
|
|
553 | 595 |
this.formset.message(i18n.getTranslation("_Record_removed")); |
596 |
|
|
597 |
this.formset.setValues(features.asListOfDynObjects()); |
|
598 |
if (features.getTotalSize()-1<index) { |
|
599 |
index = index-1; |
|
600 |
} |
|
601 |
this.formset.setCurrentIndex(index); |
|
554 | 602 |
|
555 | 603 |
} catch (Exception ex) { |
556 | 604 |
theFormSet.message(i18n.getTranslation("error_removing_data_will_not_remove")); |
... | ... | |
591 | 639 |
formset.setActionEnabled(ACTION_CANCEL_NEW,false); |
592 | 640 |
formset.setActionEnabled(ACTION_SAVE,false); |
593 | 641 |
formset.setActionEnabled(ACTION_SEARCH,false); |
642 |
formset.setActionEnabled(REFRESHFORM_ACTION, true); |
|
594 | 643 |
return; |
595 | 644 |
} |
596 | 645 |
if( store.isEditing() ) { |
... | ... | |
605 | 654 |
formset.setActionEnabled(ACTION_NEW,false); |
606 | 655 |
formset.setActionEnabled(ACTION_CANCEL_NEW,true); |
607 | 656 |
formset.setActionEnabled(ACTION_SAVE,true); |
657 |
formset.setActionEnabled(REFRESHFORM_ACTION, false); |
|
608 | 658 |
|
609 | 659 |
} else if( this.features!=null && this.features.isEmpty() ) { |
610 | 660 |
formset.setActionEnabled(ACTION_DELETE, false); |
... | ... | |
612 | 662 |
formset.setActionEnabled(ACTION_NEW,true); |
613 | 663 |
formset.setActionEnabled(ACTION_CANCEL_NEW,true); |
614 | 664 |
formset.setActionEnabled(ACTION_SAVE,false); |
665 |
formset.setActionEnabled(REFRESHFORM_ACTION, true); |
|
615 | 666 |
|
616 | 667 |
} else if( formset.getForm().isModified() ) { |
617 | 668 |
formset.setActionEnabled(ACTION_DELETE, true); |
... | ... | |
619 | 670 |
formset.setActionEnabled(ACTION_NEW,true); |
620 | 671 |
formset.setActionEnabled(ACTION_CANCEL_NEW,false); |
621 | 672 |
formset.setActionEnabled(ACTION_SAVE,true); |
673 |
formset.setActionEnabled(REFRESHFORM_ACTION, true); |
|
622 | 674 |
|
623 | 675 |
} else { |
624 | 676 |
formset.setActionEnabled(ACTION_DELETE, true); |
... | ... | |
626 | 678 |
formset.setActionEnabled(ACTION_NEW,true); |
627 | 679 |
formset.setActionEnabled(ACTION_CANCEL_NEW,false); |
628 | 680 |
formset.setActionEnabled(ACTION_SAVE,true); //false); |
681 |
formset.setActionEnabled(REFRESHFORM_ACTION, true); |
|
629 | 682 |
} |
630 | 683 |
|
631 | 684 |
return; |
... | ... | |
640 | 693 |
formset.setActionEnabled(ACTION_CANCEL_NEW,false); |
641 | 694 |
formset.setActionEnabled(ACTION_SAVE,false); |
642 | 695 |
formset.setActionEnabled(ACTION_SEARCH,true); |
696 |
formset.setActionEnabled(REFRESHFORM_ACTION,true); |
|
643 | 697 |
} |
644 | 698 |
|
645 | 699 |
@Override |
Also available in: Unified diff