[ovirt-devel] popup dialog

Leaboy wlbleaboy at 126.com
Thu Aug 14 04:19:17 UTC 2014


Hi,Vojtech Szocs:
    Thanks for your help, I have let it work,

    The Error I got just because I miss the step 3 you noted.

Another question is how could I got the returnValue after
executeCommand , and let the returnValue display on the oher
Popup dialog.


在 8/14/14, 0:07, "Vojtech Szocs" <vszocs at redhat.com> 写入:

>Hi,
>
>forgot to mention, one more thing needs to be done:
>
>  // in PresenterModule
>  bindPresenterWidget(TemplateBackupPopupPresenterWidget.class,
>    TemplateBackupPopupPresenterWidget.ViewDef.class,
>    TemplateBackupPopupView.class);
>
>(Above binds popup PresenterWidget/View within GIN DI context.)
>
>Regards,
>Vojtech
>
>
>----- Original Message -----
>> From: "Vojtech Szocs" <vszocs at redhat.com>
>> To: "力波 王" <wlbleaboy at 126.com>
>> Cc: devel at ovirt.org
>> Sent: Wednesday, August 13, 2014 6:00:08 PM
>> Subject: Re: [ovirt-devel] popup dialog
>> 
>> Hi,
>> 
>> in order to add new dialog, follow these steps:
>> 
>> 1, create UiCommon model for the dialog, I see you already did this
>>    (TemplateBackupModel) - however from your code I don't understand
>>    why is there an unused "_asyncQuery" inside model constructor
>>    
>> 2, modify existing list model to trigger your new dialog, I see you
>>    also did this (second code snippet), I assume you put that code
>>    inside TemplateListModel:
>> 
>>   // inside TemplateListModel#backup - this method should be private
>>   // since UI code executes this method via associated UICommand
>>   ...
>>   TemplateBackupModel model = new TemplateBackupModel();
>>   setWindow(model);
>>   
>>model.setTitle(ConstantsManager.getInstance().getConstants().templateBack
>>upTitle());
>>   model.setHelpTag(HelpTag.template_backup);
>>   model.setHashName("template_backup");//$NON-NLS-1$
>>   ...
>> 
>>    now, expose UICommand that triggers your dialog like this:
>> 
>>   public UICommand getTemplateBackupCommand() {
>>     return privateTemplateBackupCommand;
>>   }
>> 
>>   private void setTemplateBackupCommand(UICommand value) {
>>     privateExportCommand = value;
>>   }
>> 
>>   // inside TemplateListModel constructor
>>   ...
>>   setTemplateBackupCommand(new UICommand("TemplateBackup", this));
>>   //$NON-NLS-1$
>>   ...
>> 
>>   // inside TemplateListModel#executeCommand
>>   ...
>>   else if (command == getTemplateBackupCommand()) {
>>     backup();
>>   }
>>   ...
>> 
>> 3, tell UI (GWTP) infra how to handle your dialog model - in this
>>    particular case, edit TemplateModule#getTemplateListProvider:
>> 
>>   ...
>>   if (lastExecutedCommand == model.getEditCommand()) {
>>     return popupProvider.get();
>>   } else if (lastExecutedCommand == getModel().getExportCommand()) {
>>     return exportPopupProvider.get();
>>   } else if (lastExecutedCommand ==
>>getModel().getTemplateBackupCommand()) {
>>     return templateBackupProvider.get();
>>   } else {
>>     return super.getModelPopup(source, lastExecutedCommand,
>>windowModel);
>>   }
>>   ...
>> 
>>    now, add parameter to TemplateModule#getTemplateListProvider:
>> 
>>   @Provides
>>   @Singleton
>>   public MainModelProvider<VmTemplate, TemplateListModel>
>>   getTemplateListProvider(
>>     ...
>>     final Provider<TemplateBackupPopupPresenterWidget>
>>     templateBackupPopupProvider) {
>>   ...
>> 
>> 4, create PresenterWidget & View for your dialog, this is the visual
>>    part of the dialog (dialog model just encapsulates the dialog logic)
>> 
>>   public class TemplateBackupPopupPresenterWidget extends
>>   AbstractModelBoundPopupPresenterWidget<TemplateBackupModel,
>>   TemplateBackupPopupPresenterWidget.ViewDef> {
>> 
>>     public interface ViewDef extends
>>     AbstractModelBoundPopupPresenterWidget.ViewDef<TemplateBackupModel>
>>{
>>     }
>> 
>>     @Inject
>>     public TemplateBackupPopupPresenterWidget(EventBus eventBus, ViewDef
>>     view) {
>>       super(eventBus, view);
>>     }
>> 
>>   }
>> 
>>   ---
>> 
>>   public class TemplateBackupPopupView extends
>>   AbstractModelBoundPopupView<TemplateBackupModel> implements
>>   TemplateBackupPopupPresenterWidget.ViewDef {
>> 
>>     // you can get some inspiration from VmExportPopupView
>> 
>>   }
>> 
>> 5, you are done :)
>> 
>> Vojtech
>> 
>> 
>> ----- Original Message -----
>> > From: "力波 王" <wlbleaboy at 126.com>
>> > To: devel at ovirt.org
>> > Sent: Tuesday, August 12, 2014 7:57:24 AM
>> > Subject: [ovirt-devel] popup dialog
>> > 
>> > Hi, everyone:
>> > I add a button, named backup in the Template Tab,
>> > And the click event is ok.
>> > Now I want add a dialog after clicked the button,
>> > So, I add a model , but the dialog didn’t display at all.
>> > 
>> > So, I want to know is there some necessary class need
>> > To modify or add?
>> > 
>> > The model code is like this:
>> > TemplateBackupModel.java
>> > ========================================================
>> > public class TemplateBackupModel extends Model {
>> > 
>> > private EntityModel privatePassword;
>> > 
>> > public EntityModel getPassword()
>> > {
>> > return privatePassword;
>> > }
>> > 
>> > public void setPassword(EntityModel value)
>> > {
>> > privatePassword = value;
>> > }
>> > 
>> > public TemplateBackupModel(){
>> > 
>> > setPassword(new EntityModel());
>> > 
>> > AsyncQuery _asyncQuery = new AsyncQuery();
>> > _asyncQuery.setModel(this);
>> > _asyncQuery.asyncCallback = new INewAsyncCallback() {
>> > @Override
>> > public void onSuccess(Object model, Object result)
>> > {
>> > 
>> > }
>> > };
>> > 
>> > }
>> > 
>> > @Override
>> > public void eventRaised(Event ev, Object sender, EventArgs args) {
>> > super.eventRaised(ev, sender, args);
>> > }
>> > 
>> > public boolean validate(){
>> > return true;
>> > }
>> > }
>> > ========================================================
>> > 
>> > And created a model in the backup button click callback like this:
>> > ========================================================
>> > public void backup()
>> > {
>> > 
>> > if (getWindow() != null)
>> > {
>> > return;
>> > }
>> > 
>> > TemplateBackupModel model = new TemplateBackupModel();
>> > setWindow(model);
>> > model.setTitle("TemplateBackup");//$NON-NLS-1$
>> > model.setHashName("TemplateBackup");//$NON-NLS-1$
>> > 
>> > 
>> > UICommand tempVar = new UICommand("OnBackup", this); //$NON-NLS-1$
>> > tempVar.setTitle(ConstantsManager.getInstance().getConstants().ok());
>> > tempVar.setIsDefault(true);
>> > model.getCommands().add(tempVar);
>> > UICommand tempVar2 = new UICommand("Cancel", this); //$NON-NLS-1$
>> > 
>>tempVar2.setTitle(ConstantsManager.getInstance().getConstants().cancel())
>>;
>> > tempVar2.setIsCancel(true);
>> > model.getCommands().add(tempVar2);
>> > 
>> > }
>> > ========================================================
>> > 
>> > _______________________________________________
>> > Devel mailing list
>> > Devel at ovirt.org
>> > http://lists.ovirt.org/mailman/listinfo/devel
>> _______________________________________________
>> Devel mailing list
>> Devel at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/devel






More information about the Devel mailing list