Lior Vernia has uploaded a new change for review. Change subject: webadmin: Houskeeping in Provider main tab and popup ......................................................................
webadmin: Houskeeping in Provider main tab and popup Closed possible loopholes, removed redundant code, changed method access modifiers, added constants to represent command names, formatted code for uniformity within files. Change-Id: Ie5d4225174e733588010a46325674df2165c8814 Signed-off-by: Lior Vernia <[email protected]> --- M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderListModel.java M frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java 2 files changed, 159 insertions(+), 196 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/93/14693/1 diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderListModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderListModel.java index fcf69d5..45a1b31 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderListModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderListModel.java @@ -23,8 +23,11 @@ import org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback; import org.ovirt.engine.ui.uicompat.ObservableCollection; -public class ProviderListModel extends ListWithDetailsModel implements ISupportSystemTreeContext -{ +public class ProviderListModel extends ListWithDetailsModel implements ISupportSystemTreeContext { + + private static final String CMD_ADD = "Add"; //$NON-NLS-1$ + private static final String CMD_REMOVE = "Remove"; //$NON-NLS-1$ + private UICommand addCommand; private UICommand removeCommand; @@ -39,140 +42,13 @@ // setSearchObjects(new String[] { SearchObjects.PROVIDER_OBJ_NAME, SearchObjects.PROVIDER_PLU_OBJ_NAME }); setAvailableInModes(ApplicationMode.VirtOnly); - setAddCommand(new UICommand("Add", this)); //$NON-NLS-1$ - setRemoveCommand(new UICommand("Remove", this)); //$NON-NLS-1$ + setAddCommand(new UICommand(CMD_ADD, this)); + setRemoveCommand(new UICommand(CMD_REMOVE, this)); UpdateActionAvailability(); getSearchNextPageCommand().setIsAvailable(true); getSearchPreviousPageCommand().setIsAvailable(true); - } - - public void add() { - if (getWindow() != null) - { - return; - } - - final ProviderModel providerModel = new ProviderModel(this); - setWindow(providerModel); - } - - public void remove() { - Frontend.RunAction(VdcActionType.RemoveProvider, new ProviderParameters((Provider) getSelectedItem()), - new IFrontendActionAsyncCallback() { - - @Override - public void Executed(FrontendActionAsyncResult result) { - getSearchCommand().Execute(); - } - - }); - } - - @Override - protected void InitDetailModels() { - super.InitDetailModels(); - - ObservableCollection<EntityModel> list = new ObservableCollection<EntityModel>(); - - list.add(new ProviderGeneralModel()); - - setDetailModels(list); - } - - @Override - public boolean IsSearchStringMatch(String searchString) { - return searchString.trim().toLowerCase().startsWith("provider"); //$NON-NLS-1$ - } - - @Override - protected void SyncSearch() { - AsyncQuery asyncQuery = new AsyncQuery(); - asyncQuery.asyncCallback = new INewAsyncCallback() { - @Override - public void OnSuccess(Object model, Object ReturnValue) - { - setItems((List<Provider>) ((VdcQueryReturnValue) ReturnValue).getReturnValue()); - } - }; - - VdcQueryParametersBase params = - new VdcQueryParametersBase(); - params.setRefresh(getIsQueryFirstTime()); - Frontend.RunQuery(VdcQueryType.GetAllProviders, - params, - asyncQuery); - } - - @Override - protected void AsyncSearch() { - // super.AsyncSearch(); - // - // setAsyncResult(Frontend.RegisterSearch(getSearchString(), SearchType.Provider, getSearchPageSize())); - // setItems(getAsyncResult().getData()); - } - - @Override - protected void OnSelectedItemChanged() { - super.OnSelectedItemChanged(); - UpdateActionAvailability(); - } - - @Override - protected void SelectedItemsChanged() { - super.SelectedItemsChanged(); - UpdateActionAvailability(); - } - - private void UpdateActionAvailability() { - List tempVar = getSelectedItems(); - ArrayList selectedItems = - (ArrayList) ((tempVar != null) ? tempVar : new ArrayList()); - - getRemoveCommand().setIsExecutionAllowed(selectedItems.size() > 0); - } - - @Override - public void ExecuteCommand(UICommand command) { - super.ExecuteCommand(command); - - if (command == getAddCommand()) - { - add(); - } - else if (command == getRemoveCommand()) - { - remove(); - } - } - - @Override - public SystemTreeItemModel getSystemTreeSelectedItem() { - return systemTreeSelectedItem; - } - - @Override - public void setSystemTreeSelectedItem(SystemTreeItemModel value) { - if (systemTreeSelectedItem != value) - { - systemTreeSelectedItem = value; - OnSystemTreeSelectedItemChanged(); - } - } - - private void OnSystemTreeSelectedItemChanged() { - UpdateActionAvailability(); - } - - @Override - public Provider getEntity() { - return (Provider) super.getEntity(); - } - - @Override - protected String getListName() { - return "ProviderListModel"; //$NON-NLS-1$ } public UICommand getAddCommand() { @@ -190,4 +66,112 @@ private void setRemoveCommand(UICommand value) { removeCommand = value; } + + @Override + protected void InitDetailModels() { + super.InitDetailModels(); + + ObservableCollection<EntityModel> list = new ObservableCollection<EntityModel>(); + + list.add(new ProviderGeneralModel()); + + setDetailModels(list); + } + + @Override + protected String getListName() { + return "ProviderListModel"; //$NON-NLS-1$ + } + + @Override + public SystemTreeItemModel getSystemTreeSelectedItem() { + return systemTreeSelectedItem; + } + + @Override + public void setSystemTreeSelectedItem(SystemTreeItemModel value) { + if (systemTreeSelectedItem != value) { + systemTreeSelectedItem = value; + OnSystemTreeSelectedItemChanged(); + } + } + + private void OnSystemTreeSelectedItemChanged() { + UpdateActionAvailability(); + } + + @Override + protected void OnSelectedItemChanged() { + super.OnSelectedItemChanged(); + UpdateActionAvailability(); + } + + @Override + protected void SelectedItemsChanged() { + super.SelectedItemsChanged(); + UpdateActionAvailability(); + } + + @SuppressWarnings("rawtypes") + private void UpdateActionAvailability() { + List tempVar = getSelectedItems(); + List selectedItems = (tempVar != null) ? tempVar : new ArrayList(); + + getRemoveCommand().setIsExecutionAllowed(selectedItems.size() > 0); + } + + @Override + public boolean IsSearchStringMatch(String searchString) { + return searchString.trim().toLowerCase().startsWith("provider"); //$NON-NLS-1$ + } + + @Override + protected void SyncSearch() { + AsyncQuery asyncQuery = new AsyncQuery(); + asyncQuery.asyncCallback = new INewAsyncCallback() { + + @SuppressWarnings("unchecked") + @Override + public void OnSuccess(Object model, Object ReturnValue) { + setItems((List<Provider>) ((VdcQueryReturnValue) ReturnValue).getReturnValue()); + } + }; + + VdcQueryParametersBase params = + new VdcQueryParametersBase(); + params.setRefresh(getIsQueryFirstTime()); + Frontend.RunQuery(VdcQueryType.GetAllProviders, + params, + asyncQuery); + } + + private void add() { + if (getWindow() != null) { + return; + } + setWindow(new ProviderModel(this)); + } + + private void remove() { + Frontend.RunAction(VdcActionType.RemoveProvider, new ProviderParameters((Provider) getSelectedItem()), + new IFrontendActionAsyncCallback() { + + @Override + public void Executed(FrontendActionAsyncResult result) { + getSearchCommand().Execute(); + } + }); + } + + @Override + public void ExecuteCommand(UICommand command) { + super.ExecuteCommand(command); + + if (command == getAddCommand()) { + add(); + } else if (command == getRemoveCommand()) { + remove(); + } + } + } diff --git a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java index 44c7e18..2bfaea5 100644 --- a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java +++ b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/providers/ProviderModel.java @@ -3,26 +3,53 @@ import org.ovirt.engine.core.common.action.ProviderParameters; import org.ovirt.engine.core.common.action.VdcActionType; import org.ovirt.engine.core.common.businessentities.Provider; -import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.compat.StringHelper; import org.ovirt.engine.ui.frontend.Frontend; import org.ovirt.engine.ui.uicommonweb.UICommand; import org.ovirt.engine.ui.uicommonweb.models.EntityModel; -import org.ovirt.engine.ui.uicommonweb.models.ListModel; import org.ovirt.engine.ui.uicommonweb.models.Model; +import org.ovirt.engine.ui.uicommonweb.models.SearchableListModel; import org.ovirt.engine.ui.uicompat.ConstantsManager; import org.ovirt.engine.ui.uicompat.FrontendActionAsyncResult; import org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback; -public class ProviderModel extends Model -{ +@SuppressWarnings("deprecation") +public class ProviderModel extends Model { + + private static final String CMD_SAVE = "OnSave"; //$NON-NLS-1$ + private static final String CMD_CANCEL = "Cancel"; //$NON-NLS-1$ + + private final SearchableListModel sourceListModel; + private EntityModel privateName; private EntityModel privateDescription; private EntityModel privateUrl; - private final ProviderListModel sourceListModel; - public ProviderModel(ProviderListModel sourceListModel) - { + public EntityModel getName() { + return privateName; + } + + private void setName(EntityModel value) { + privateName = value; + } + + public EntityModel getDescription() { + return privateDescription; + } + + private void setDescription(EntityModel value) { + privateDescription = value; + } + + public EntityModel getUrl() { + return privateUrl; + } + + private void setUrl(EntityModel value) { + privateUrl = value; + } + + public ProviderModel(SearchableListModel sourceListModel) { this.sourceListModel = sourceListModel; setName(new EntityModel()); @@ -32,72 +59,26 @@ setTitle(ConstantsManager.getInstance().getConstants().addProviderTitle()); setHashName("add_provider"); //$NON-NLS-1$ - UICommand tempVar = new UICommand("OnSave", this); //$NON-NLS-1$ + UICommand tempVar = new UICommand(CMD_SAVE, this); tempVar.setTitle(ConstantsManager.getInstance().getConstants().ok()); tempVar.setIsDefault(true); getCommands().add(tempVar); - UICommand tempVar2 = new UICommand("Cancel", this); //$NON-NLS-1$ + UICommand tempVar2 = new UICommand(CMD_CANCEL, this); tempVar2.setTitle(ConstantsManager.getInstance().getConstants().cancel()); tempVar2.setIsCancel(true); getCommands().add(tempVar2); } - public EntityModel getName() - { - return privateName; - } - - private void setName(EntityModel value) - { - privateName = value; - } - - public EntityModel getDescription() - { - return privateDescription; - } - - private void setDescription(EntityModel value) - { - privateDescription = value; - } - - public EntityModel getUrl() - { - return privateUrl; - } - - private void setUrl(EntityModel value) - { - privateUrl = value; - } - - public ListModel getSourceListModel() { - return sourceListModel; - } - - public boolean Validate() - { + private boolean Validate() { return true; - } - - protected void postSaveAction(Guid networkGuid, boolean succeeded) { - if (succeeded) - { - cancel(); - } - StopProgress(); } private void cancel() { sourceListModel.setWindow(null); - sourceListModel.setConfirmWindow(null); } - public void onSave() - { - if (!Validate()) - { + private void onSave() { + if (!Validate()) { return; } @@ -113,21 +94,19 @@ sourceListModel.getSearchCommand().Execute(); } }); + cancel(); } @Override - public void ExecuteCommand(UICommand command) - { + public void ExecuteCommand(UICommand command) { super.ExecuteCommand(command); - if (StringHelper.stringsEqual(command.getName(), "OnSave")) //$NON-NLS-1$ - { + if (StringHelper.stringsEqual(command.getName(), CMD_SAVE)) { onSave(); - } - else if (StringHelper.stringsEqual(command.getName(), "Cancel")) //$NON-NLS-1$ - { + } else if (StringHelper.stringsEqual(command.getName(), CMD_CANCEL)) { cancel(); } } + } -- To view, visit http://gerrit.ovirt.org/14693 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie5d4225174e733588010a46325674df2165c8814 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Lior Vernia <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
