1 56 package org.objectstyle.cayenne.modeler.dialog.pref; 57 58 import java.awt.Component ; 59 60 import org.objectstyle.cayenne.gen.DefaultClassGenerator; 61 import org.objectstyle.cayenne.modeler.util.CayenneController; 62 import org.objectstyle.cayenne.pref.CayennePreferenceEditor; 63 import org.objectstyle.cayenne.pref.CayennePreferenceService; 64 import org.objectstyle.cayenne.pref.Domain; 65 import org.objectstyle.cayenne.pref.PreferenceDetail; 66 import org.objectstyle.cayenne.pref.PreferenceEditor; 67 import org.objectstyle.cayenne.swing.BindingBuilder; 68 import org.objectstyle.cayenne.swing.ObjectBinding; 69 import org.objectstyle.cayenne.validation.ValidationException; 70 71 74 public class GeneralPreferences extends CayenneController { 75 76 public static final String ENCODING_PREFERENCE = "encoding"; 77 78 protected GeneralPreferencesView view; 79 protected CayennePreferenceEditor editor; 80 protected PreferenceDetail classGeneratorPreferences; 81 82 protected ObjectBinding saveIntervalBinding; 83 protected ObjectBinding encodingBinding; 84 85 public GeneralPreferences(PreferenceDialog parentController) { 86 super(parentController); 87 this.view = new GeneralPreferencesView(); 88 89 PreferenceEditor editor = parentController.getEditor(); 90 if (editor instanceof CayennePreferenceEditor) { 91 this.editor = (CayennePreferenceEditor) editor; 92 this.view.setEnabled(true); 93 initBindings(); 94 95 saveIntervalBinding.updateView(); 96 encodingBinding.updateView(); 97 } 98 else { 99 this.view.setEnabled(false); 100 } 101 } 102 103 public Component getView() { 104 return view; 105 } 106 107 protected void initBindings() { 108 Domain classGeneratorDomain = editor.editableInstance(getApplication() 110 .getPreferenceDomain()).getSubdomain(DefaultClassGenerator.class); 111 this.classGeneratorPreferences = classGeneratorDomain 112 .getDetail(ENCODING_PREFERENCE, true); 113 114 EncodingSelector encodingSelector = new EncodingSelector(this, view 116 .getEncodingSelector()); 117 118 BindingBuilder builder = new BindingBuilder( 120 getApplication().getBindingFactory(), 121 this); 122 123 this.saveIntervalBinding = builder.bindToTextField(view.getSaveInterval(), 124 "timeInterval"); 125 126 this.encodingBinding = builder.bindToProperty(encodingSelector, 127 "classGeneratorPreferences.property[\"encoding\"]", 128 EncodingSelector.ENCODING_PROPERTY_BINDING); 129 } 130 131 public double getTimeInterval() { 132 return this.editor.getSaveInterval() / 1000.0; 133 } 134 135 public void setTimeInterval(double d) { 136 int ms = (int) (d * 1000.0); 137 if (ms < CayennePreferenceService.MIN_SAVE_INTERVAL) { 138 throw new ValidationException( 139 "Time interval is too small, minimum allowed is " 140 + (CayennePreferenceService.MIN_SAVE_INTERVAL / 1000.0)); 141 } 142 143 this.editor.setSaveInterval(ms); 144 } 145 146 public PreferenceDetail getClassGeneratorPreferences() { 147 return classGeneratorPreferences; 148 } 149 } | Popular Tags |