| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.common.ui.client.configurable.mvc.views; |
| 17 | |
|
| 18 | |
import com.google.gwt.user.client.Window; |
| 19 | |
import com.google.gwt.user.client.ui.Widget; |
| 20 | |
|
| 21 | |
import org.kuali.student.common.assembly.data.Metadata; |
| 22 | |
import org.kuali.student.common.assembly.data.ModelDefinition; |
| 23 | |
import org.kuali.student.common.ui.client.configurable.mvc.FieldDescriptor; |
| 24 | |
import org.kuali.student.common.ui.client.configurable.mvc.LayoutController; |
| 25 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.BaseSection; |
| 26 | |
import org.kuali.student.common.ui.client.configurable.mvc.sections.Section; |
| 27 | |
import org.kuali.student.common.ui.client.mvc.*; |
| 28 | |
|
| 29 | |
import java.util.ArrayList; |
| 30 | |
import java.util.List; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
public abstract class SectionView extends BaseSection implements View { |
| 40 | |
|
| 41 | |
protected String modelId; |
| 42 | |
protected DataModel model; |
| 43 | |
|
| 44 | |
private Enum<?> viewEnum; |
| 45 | |
private String viewName; |
| 46 | |
|
| 47 | 0 | private List<View> views = new ArrayList<View>(); |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | 0 | public SectionView(Enum<?> viewEnum, String viewName) { |
| 54 | 0 | this.viewEnum = viewEnum; |
| 55 | 0 | this.viewName = viewName; |
| 56 | 0 | } |
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
@Override |
| 64 | |
public Enum<?> getViewEnum() { |
| 65 | 0 | return viewEnum; |
| 66 | |
} |
| 67 | |
|
| 68 | |
public void setViewEnum(Enum<?> viewEnum) { |
| 69 | 0 | this.viewEnum = viewEnum; |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
@Override |
| 81 | |
public void beforeShow(final Callback<Boolean> onReadyCallback) { |
| 82 | |
|
| 83 | 0 | super.clearValidationErrors(); |
| 84 | |
|
| 85 | 0 | if (getController() != null) { |
| 86 | 0 | getController().requestModel(modelId, new ModelRequestCallback<DataModel>() { |
| 87 | |
|
| 88 | |
@Override |
| 89 | |
public void onRequestFail(Throwable cause) { |
| 90 | 0 | Window.alert("Failed to get model: " + modelId + " for SectionView " + getName()); |
| 91 | 0 | onReadyCallback.exec(false); |
| 92 | 0 | } |
| 93 | |
|
| 94 | |
@Override |
| 95 | |
public void onModelReady(DataModel m) { |
| 96 | 0 | model = m; |
| 97 | 0 | updateWidgetData(m); |
| 98 | 0 | resetFieldInteractionFlags(); |
| 99 | 0 | onReadyCallback.exec(true); |
| 100 | 0 | } |
| 101 | |
|
| 102 | |
}); |
| 103 | |
} |
| 104 | |
|
| 105 | 0 | for (Section section : sections) { |
| 106 | 0 | if (section instanceof SectionView) { |
| 107 | 0 | ((SectionView) section).beforeShow(new Callback<Boolean>() { |
| 108 | |
@Override |
| 109 | |
public void exec(Boolean result) { |
| 110 | 0 | } |
| 111 | |
}); |
| 112 | |
} |
| 113 | |
} |
| 114 | 0 | for (View view : views) { |
| 115 | 0 | view.beforeShow(Controller.NO_OP_CALLBACK); |
| 116 | |
} |
| 117 | |
|
| 118 | 0 | } |
| 119 | |
|
| 120 | |
public String getModelId() { |
| 121 | 0 | return modelId; |
| 122 | |
} |
| 123 | |
|
| 124 | |
public void setModelId(String modelId) { |
| 125 | 0 | this.modelId = modelId; |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
|
| 133 | |
|
| 134 | |
@Override |
| 135 | |
public boolean beforeHide() { |
| 136 | 0 | return true; |
| 137 | |
} |
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
@Override |
| 145 | |
public Controller getController() { |
| 146 | 0 | return super.getLayoutController(); |
| 147 | |
} |
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 151 | |
|
| 152 | |
|
| 153 | |
|
| 154 | |
@Override |
| 155 | |
public String getName() { |
| 156 | 0 | return viewName; |
| 157 | |
} |
| 158 | |
|
| 159 | |
public void setName(String name) { |
| 160 | 0 | this.viewName = name; |
| 161 | 0 | } |
| 162 | |
|
| 163 | |
public void setController(Controller controller) { |
| 164 | 0 | if (controller instanceof LayoutController) { |
| 165 | 0 | super.setLayoutController((LayoutController) controller); |
| 166 | |
} else { |
| 167 | 0 | throw new IllegalArgumentException("Configurable UI sections require a LayoutController, not a base MVC controller"); |
| 168 | |
} |
| 169 | 0 | } |
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
public void updateView() { |
| 175 | 0 | getController().requestModel(modelId, new ModelRequestCallback<DataModel>() { |
| 176 | |
@Override |
| 177 | |
public void onModelReady(DataModel m) { |
| 178 | |
|
| 179 | 0 | SectionView.this.model = m; |
| 180 | 0 | updateWidgetData(m); |
| 181 | 0 | } |
| 182 | |
|
| 183 | |
|
| 184 | |
@Override |
| 185 | |
public void onRequestFail(Throwable cause) { |
| 186 | 0 | Window.alert("Failed to get model"); |
| 187 | 0 | } |
| 188 | |
}); |
| 189 | |
|
| 190 | 0 | } |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
public void updateView(DataModel m) { |
| 197 | 0 | this.model = m; |
| 198 | 0 | updateWidgetData(m); |
| 199 | 0 | } |
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
public Widget asWidget() { |
| 205 | 0 | return this.getLayout(); |
| 206 | |
} |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
@Override |
| 212 | |
public String collectHistory(String historyStack) { |
| 213 | 0 | return null; |
| 214 | |
} |
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
@Override |
| 220 | |
public void onHistoryEvent(String historyStack) { |
| 221 | |
|
| 222 | 0 | } |
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
|
| 227 | |
@Override |
| 228 | |
public void collectBreadcrumbNames(List<String> names) { |
| 229 | 0 | names.add(this.getName()); |
| 230 | 0 | } |
| 231 | |
|
| 232 | |
|
| 233 | |
|
| 234 | |
|
| 235 | |
|
| 236 | |
public void addView(View view) { |
| 237 | 0 | views.add(view); |
| 238 | 0 | addWidget(view.asWidget()); |
| 239 | 0 | } |
| 240 | |
|
| 241 | |
public DataModel getModel() { |
| 242 | 0 | return model; |
| 243 | |
} |
| 244 | |
|
| 245 | |
public void updateMetadata(ModelDefinition modelDefinition) { |
| 246 | 0 | updateMetadata(modelDefinition, this); |
| 247 | 0 | } |
| 248 | |
|
| 249 | |
private void updateMetadata(ModelDefinition modelDefinition, Section topSection) { |
| 250 | 0 | for (Section section : topSection.getSections()) { |
| 251 | 0 | updateMetadata(modelDefinition, section); |
| 252 | |
} |
| 253 | 0 | for (FieldDescriptor field : topSection.getFields()) { |
| 254 | 0 | Metadata newMetadata = modelDefinition.getMetadata(field.getFieldKey()); |
| 255 | 0 | if (newMetadata != null) { |
| 256 | 0 | field.setMetadata(newMetadata); |
| 257 | |
} |
| 258 | 0 | } |
| 259 | 0 | } |
| 260 | |
|
| 261 | |
@Override |
| 262 | |
public String toString() { |
| 263 | 0 | return viewName; |
| 264 | |
} |
| 265 | |
|
| 266 | |
public boolean isExportButtonActive() { |
| 267 | 0 | return false; |
| 268 | |
} |
| 269 | |
|
| 270 | |
@Override |
| 271 | |
public void showExport(boolean show) { |
| 272 | |
|
| 273 | |
|
| 274 | 0 | } |
| 275 | |
} |