001 /** 002 * Copyright 2010 The Kuali Foundation Licensed under the 003 * Educational Community License, Version 2.0 (the "License"); you may 004 * not use this file except in compliance with the License. You may 005 * obtain a copy of the License at 006 * 007 * http://www.osedu.org/licenses/ECL-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, 010 * software distributed under the License is distributed on an "AS IS" 011 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 012 * or implied. See the License for the specific language governing 013 * permissions and limitations under the License. 014 */ 015 016 package org.kuali.student.common.ui.client.configurable.mvc; 017 018 import java.util.List; 019 020 import org.kuali.student.common.ui.client.mvc.Callback; 021 import org.kuali.student.common.ui.client.mvc.Controller; 022 import org.kuali.student.common.ui.client.mvc.ModelRequestCallback; 023 import org.kuali.student.common.ui.client.mvc.dto.ReferenceModel; 024 025 import com.google.gwt.user.client.Window; 026 import com.google.gwt.user.client.ui.LazyPanel; 027 import com.google.gwt.user.client.ui.Widget; 028 029 /** 030 * A view that delays its generation until it requested to be shown. 031 * 032 * @author Kuali Student Team 033 * 034 */ 035 public abstract class DelayedToolView extends LazyPanel implements ToolView{ 036 private Controller controller; 037 private Enum<?> viewEnum; 038 private String viewName; //View name is being used as menu item label 039 040 private HasReferenceId reference; 041 042 private ModelRequestCallback<ReferenceModel> modelRequestCallback = 043 new ModelRequestCallback<ReferenceModel>(){ 044 public void onModelReady(ReferenceModel model) { 045 reference.setReferenceId(model.getReferenceId()); 046 reference.setReferenceTypeKey(model.getReferenceTypeKey()); 047 reference.setReferenceType(model.getReferenceType()); 048 reference.setReferenceState(model.getReferenceState()); 049 DelayedToolView.this.setVisible(true); 050 } 051 052 public void onRequestFail(Throwable cause) { 053 Window.alert(cause.toString()); 054 } 055 }; 056 057 058 /** 059 * @param controller 060 * @param name 061 */ 062 public DelayedToolView(Controller controller, Enum<?> viewEnum, String viewName) { 063 this.controller = controller; 064 this.viewName = viewName; 065 this.viewEnum = viewEnum; 066 } 067 068 069 public DelayedToolView(Enum<?> viewEnum, String viewName) { 070 this.controller = null; 071 this.viewEnum = viewEnum; 072 this.viewName = viewName; 073 } 074 075 @Override 076 public void beforeShow(final Callback<Boolean> onReadyCallback){ 077 if (getWidget() instanceof HasReferenceId){ 078 reference = (HasReferenceId)getWidget(); 079 controller.requestModel(ReferenceModel.class, modelRequestCallback); 080 } else if (this instanceof HasReferenceId){ 081 reference = (HasReferenceId)this; 082 controller.requestModel(ReferenceModel.class, modelRequestCallback); 083 } else { 084 this.setVisible(true); 085 } 086 // FIXME ? need to wire onReadyCallback into the model request, so that we aren't indicating that we're ready before the model is available? 087 onReadyCallback.exec(true); 088 } 089 090 /** 091 * @see org.kuali.student.common.ui.client.mvc.View#beforeHide() 092 */ 093 @Override 094 public boolean beforeHide() { 095 return true; 096 } 097 098 099 /** 100 * @see org.kuali.student.common.ui.client.mvc.View#getController() 101 */ 102 @Override 103 public Controller getController() { 104 return this.controller; 105 } 106 107 108 /** 109 * @see org.kuali.student.common.ui.client.mvc.View#getName() 110 */ 111 @Override 112 public String getName() { 113 return this.viewName; 114 } 115 116 public Enum<?> getViewEnum() { 117 return viewEnum; 118 } 119 120 /** 121 * @see org.kuali.student.common.ui.client.mvc.View#updateModel() 122 */ 123 @Override 124 public void updateModel() { 125 //There is no model to update here, reference model is read-only 126 } 127 128 public void setController(Controller controller){ 129 this.controller = controller; 130 } 131 132 133 public Widget asWidget(){ 134 return this; 135 } 136 137 @Override 138 public String collectHistory(String historyStack) { 139 return null; 140 } 141 142 143 @Override 144 protected Widget createWidget() { 145 // TODO Auto-generated method stub 146 return null; 147 } 148 149 @Override 150 public void onHistoryEvent(String historyStack) { 151 152 } 153 154 @Override 155 public void collectBreadcrumbNames(List<String> names) { 156 names.add(this.getName()); 157 158 } 159 160 public boolean isExportButtonActive() { 161 return false; 162 } 163 }