Author Topic: Create/add own button to existing view.  (Read 7832 times)

Offline MJaskowski

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Create/add own button to existing view.
« on: February 25, 2020, 08:54:20 PM »
Hello everyone,

I have question about create/add new button to existing view. Is it possible?

I want add button programatically to ContactInfoHistoryMultiRegion and exactly to ContactInformationView -> DockPanelContactHistoryContent -> Toolbar_Copy. I can't access to it and I don't know how to bite it. Did you have similar case?

Thank you for all tips.

Regards
Matt

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Re: Create/add own button to existing view.
« Reply #1 on: February 26, 2020, 11:11:48 AM »
Check WDE samples. There is a Button sample.


Enviado de meu SM-N9600 usando o Tapatalk


Offline MJaskowski

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: Create/add own button to existing view.
« Reply #2 on: February 26, 2020, 11:31:09 AM »
Hello cavagnaro,

thank you for answer. I know sample with button, I hope we talk about the same sample - I can create buttton in my NEW/OWN view, for example to ToolbarWorkplaceRegion I add new tab with button, right?

But my question is about existing view created default in WDE and more precisly I'm talking about Contacts History Tab. Or maybe I misunderstood you? Could you expand your thought?

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Re: Create/add own button to existing view.
« Reply #3 on: February 26, 2020, 11:33:05 AM »
Yeah, same, just get the View name, also at Documentation, and elaborate into that.


Enviado de meu SM-N9600 usando o Tapatalk


Offline MJaskowski

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: Create/add own button to existing view.
« Reply #4 on: February 26, 2020, 04:03:33 PM »
Cavagnaro,

I suppose to do something wrong or I don't know about any method. I found where is my problem, I'm adding new ViewActivator to ContactTabBottomHistoryMultiRegion but this region doesn't exist yet when ExtensionModule do Initialize() method.

[code]
public void Initialize()
{           
    container.RegisterType<IMyView, MyView>();
    container.RegisterType<IMyViewModel, MyViewModel>();
}

[/code]

then I made viewEventManager.Subscribe(CheckingEvent) which raise event after select email in ContactHistoryView

[code]

private void CheckingEvent(object obj)
        {
            string loadedAction = (obj as GenericEvent).Action[0].Action as string;
            ViewActivator toolbarContainer = null;

            if (loadedAction == "LoadInteractionInformation")
            {
                foreach (ViewActivator view in viewManager.ViewsByRegionName["ContactInfoHistoryMultiRegion"])
                {             
                    if (view.ViewName == "ContactInformationView")
                    {
                        viewManager.ViewsByRegionName["ContactTabBottomHistoryMultiRegion"].Add(
                              new ViewActivator()
                              {
                                  ViewType = typeof(IMyView),
                                  ViewName = "MyView",
                                  ActivateView = true
                              }
                        );                     
                        break;
                    }
                }
            }           
        }

[/code]

ViewActivator correctly add to region but unfortunately I don't see result. If I will add the same view to eg. ToolbarWorkplaceRegion, I see my view. I can't catch what is point.

Should I do it any other way?







Offline Kubig

  • Hero Member
  • *****
  • Posts: 2752
  • Karma: 44
Re: Create/add own button to existing view.
« Reply #5 on: February 26, 2020, 04:11:08 PM »
I do not see any reason for iterating the existing view. You can directly add your custom view into existing region through the ViewManager. You just need to load your module after the ContactModule is loaded, thus why you cannot insert view right now as you trying to insert it so early.

I use ContactTabBottomHistoryMultiRegion region is several projects and never have encountered any issue on that.

Offline MJaskowski

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: Create/add own button to existing view.
« Reply #6 on: February 26, 2020, 04:58:45 PM »
My guess is I try too early to load my view that's why I made own event but this is wrong way. Did you do the same way or do you load view by other method? I can't catch where I am wrong.
Any keywords?

If I add ViewActivator by own event (when I have and I see ContactInfoHistoryMultiRegion region) then my view isn't visible, should I use any method or something yet?
« Last Edit: February 26, 2020, 05:10:15 PM by MJaskowski »

Offline MJaskowski

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: Create/add own button to existing view.
« Reply #7 on: February 26, 2020, 08:37:13 PM »
[quote] You just need to load your module after the ContactModule is loaded [/quote]

How can I catch it? By event? Could you expand thought?



Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 126
  • Karma: 13
Re: Create/add own button to existing view.
« Reply #8 on: February 27, 2020, 03:08:45 PM »
Hi Matt,

In initialize method try using the viewManager.AddViewsToRegion method, then you don't need to wait for the region to already exist:


[code]            viewManager.AddViewsToRegion("ContactTabBottomHistoryMultiRegion", new List<ViewActivator>() {
                new ViewActivator()
                {
                    ViewType = typeof(ICancelRecordView),
                ViewName = "MyView",
                ActivateView = true,
                ActivateOrder = 30
                }

            });[/code]

Offline MJaskowski

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: Create/add own button to existing view.
« Reply #9 on: February 27, 2020, 03:39:02 PM »
Pete!

You are an amazing guy! Thank you so much. Such a small change, and allowed me to do it the way I wanted. I understand that the AddViewsToRegion method creates a non-existent region? Something like a placeholder?

Thank you for your knowledge, again!


Matt

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Re: Create/add own button to existing view.
« Reply #10 on: February 27, 2020, 04:03:38 PM »
Pete is THE guy [emoji41]

Enviado de meu SM-N9600 usando o Tapatalk


Offline Kubig

  • Hero Member
  • *****
  • Posts: 2752
  • Karma: 44
Re: Create/add own button to existing view.
« Reply #11 on: March 02, 2020, 12:05:36 PM »
Honestly, I am using both approaches (using AddViewsToRegion and ViewsByRegionName methods) and never have encountered issue with instanting custom view/part. I suppose there might be another issue that causes your custom part is not visible at all.

Offline MJaskowski

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: Create/add own button to existing view.
« Reply #12 on: March 03, 2020, 12:43:08 PM »
I don't know why the .Add () method for viewManager did not work for the region "ContactTabBottomHistoryMultiRegion". I checked the "ToolbarWorksheetRegion" region and it works fine.

The .AddViewsToRegion () method works well in both cases. Everything is located in the main module Initialize() loaded at startup (the same as ExtensionSampleModule). Maybe it's a bug? Have I implemented something bad maybe? But I didn't create something special, so I don't think so. Any idea what could I check?

Offline Kubig

  • Hero Member
  • *****
  • Posts: 2752
  • Karma: 44
Re: Create/add own button to existing view.
« Reply #13 on: March 03, 2020, 02:18:05 PM »
Which version of IWS/WDE are you using?

Offline MJaskowski

  • Newbie
  • *
  • Posts: 27
  • Karma: 0
Re: Create/add own button to existing view.
« Reply #14 on: March 03, 2020, 02:22:20 PM »
WDE 8.5.127.06