| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.lum.lu.ui.tools.client.configuration; |
| 17 | |
|
| 18 | |
import org.kuali.student.common.ui.client.application.KSAsyncCallback; |
| 19 | |
import org.kuali.student.common.ui.client.configurable.mvc.layouts.TabMenuController; |
| 20 | |
import org.kuali.student.common.ui.client.mvc.*; |
| 21 | |
import org.kuali.student.common.ui.client.service.MetadataRpcService; |
| 22 | |
import org.kuali.student.common.ui.client.service.MetadataRpcServiceAsync; |
| 23 | |
import org.kuali.student.common.ui.client.util.WindowTitleUtils; |
| 24 | |
import org.kuali.student.common.ui.client.widgets.containers.KSTitleContainerImpl; |
| 25 | |
import org.kuali.student.common.ui.client.widgets.progress.BlockingTask; |
| 26 | |
import org.kuali.student.common.ui.client.widgets.progress.KSBlockingProgressIndicator; |
| 27 | |
import org.kuali.student.core.assembly.data.Data; |
| 28 | |
import org.kuali.student.core.assembly.data.Metadata; |
| 29 | |
|
| 30 | |
import com.google.gwt.core.client.GWT; |
| 31 | |
|
| 32 | |
|
| 33 | 0 | public class CatalogBrowserController extends TabMenuController |
| 34 | |
{ |
| 35 | 0 | private MetadataRpcServiceAsync metadataService = GWT.create(MetadataRpcService.class); |
| 36 | 0 | private final DataModel dataModel = new DataModel (); |
| 37 | 0 | private boolean initialized = false; |
| 38 | |
private Controller controller; |
| 39 | 0 | private static KSTitleContainerImpl container = new KSTitleContainerImpl("Catalog Browser"); |
| 40 | 0 | private BlockingTask initializingTask = new BlockingTask("Loading"); |
| 41 | |
|
| 42 | |
public CatalogBrowserController (Controller controller) { |
| 43 | 0 | super(CatalogBrowserController.class.getName()); |
| 44 | 0 | this.controller = controller; |
| 45 | 0 | initialize(); |
| 46 | 0 | } |
| 47 | |
|
| 48 | |
private void initialize () { |
| 49 | 0 | dataModel.setRoot(new Data ()); |
| 50 | |
|
| 51 | 0 | super.setDefaultModelId (CatalogBrowserConfigurer.CATALOG_BROWSER_MODEL); |
| 52 | 0 | super.registerModel (CatalogBrowserConfigurer.CATALOG_BROWSER_MODEL, new ModelProvider<DataModel> () { |
| 53 | |
|
| 54 | |
@Override |
| 55 | |
public void requestModel (final ModelRequestCallback<DataModel> callback) { |
| 56 | 0 | callback.onModelReady (dataModel); |
| 57 | 0 | } |
| 58 | |
}); |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
private static final String METADATA_OBJECT_KEY_BROWSE = "browse"; |
| 62 | |
|
| 63 | |
private void init (final Callback<Boolean> onReadyCallback) |
| 64 | |
{ |
| 65 | |
|
| 66 | 0 | if (initialized) { |
| 67 | 0 | onReadyCallback.exec (true); |
| 68 | |
} else { |
| 69 | 0 | KSBlockingProgressIndicator.addTask(initializingTask); |
| 70 | |
|
| 71 | 0 | metadataService.getMetadata (METADATA_OBJECT_KEY_BROWSE, null, null, new KSAsyncCallback<Metadata> (){ |
| 72 | |
|
| 73 | |
@Override |
| 74 | |
public void handleFailure (Throwable caught) |
| 75 | |
{ |
| 76 | 0 | onReadyCallback.exec (false); |
| 77 | 0 | KSBlockingProgressIndicator.removeTask(initializingTask); |
| 78 | 0 | throw new RuntimeException ("Failed to get model definition for " + METADATA_OBJECT_KEY_BROWSE, caught); |
| 79 | |
} |
| 80 | |
|
| 81 | |
@Override |
| 82 | |
public void onSuccess (Metadata result) |
| 83 | |
{ |
| 84 | 0 | if (result == null) |
| 85 | |
{ |
| 86 | 0 | onReadyCallback.exec (false); |
| 87 | 0 | KSBlockingProgressIndicator.removeTask(initializingTask); |
| 88 | 0 | throw new RuntimeException ("Got null metdata for " + METADATA_OBJECT_KEY_BROWSE); |
| 89 | |
} |
| 90 | 0 | DataModelDefinition def = new DataModelDefinition (result); |
| 91 | 0 | dataModel.setDefinition (def); |
| 92 | 0 | configure (def); |
| 93 | 0 | initialized = true; |
| 94 | 0 | onReadyCallback.exec (true); |
| 95 | 0 | KSBlockingProgressIndicator.removeTask(initializingTask); |
| 96 | 0 | } |
| 97 | |
}); |
| 98 | |
} |
| 99 | 0 | } |
| 100 | |
|
| 101 | |
private void configure (DataModelDefinition modelDefinition) { |
| 102 | 0 | CatalogBrowserConfigurer cfg = new CatalogBrowserConfigurer (); |
| 103 | 0 | cfg.setModelDefinition (modelDefinition); |
| 104 | 0 | cfg.setController (controller); |
| 105 | 0 | cfg.configureCatalogBrowser (this); |
| 106 | 0 | } |
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
|
| 112 | |
@Override |
| 113 | |
public Class<? extends Enum<?>> getViewsEnum (){ |
| 114 | 0 | return CatalogBrowserConfigurer.Sections.class; |
| 115 | |
} |
| 116 | |
|
| 117 | |
@Override |
| 118 | |
public void beforeShow(final Callback<Boolean> onReadyCallback) { |
| 119 | 0 | WindowTitleUtils.setContextTitle(name); |
| 120 | 0 | dataModel.setRoot(new Data ()); |
| 121 | 0 | init (new Callback<Boolean> () { |
| 122 | |
|
| 123 | |
@Override |
| 124 | |
public void exec (Boolean result) |
| 125 | |
{ |
| 126 | 0 | if (result) { |
| 127 | 0 | showDefaultView (onReadyCallback); |
| 128 | |
} else { |
| 129 | 0 | onReadyCallback.exec (false); |
| 130 | |
} |
| 131 | 0 | } |
| 132 | |
|
| 133 | |
}); |
| 134 | 0 | } |
| 135 | |
|
| 136 | |
@Override |
| 137 | |
public Enum<?> getViewEnumValue (String enumValue){ |
| 138 | 0 | return null; |
| 139 | |
} |
| 140 | |
|
| 141 | |
@Override |
| 142 | |
public void setParentController (Controller controller) { |
| 143 | 0 | super.setParentController (controller); |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
} |