Print Page | Close Window

[CANCELLED] Adding an Item to the PageNavigatorAdapter

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=571
Printed Date: 28-Apr-2024 at 4:01am


Topic: [CANCELLED] Adding an Item to the PageNavigatorAdapter
Posted By: Linguinut
Subject: [CANCELLED] Adding an Item to the PageNavigatorAdapter
Date Posted: 30-Nov-2007 at 4:58pm

I am not sure if this item has been addressed.  If it has, I apologize for the overlapping post. Ermm

How do I add a button to the PageNavigatorAdapter?  The public class does not appear to allow me to do this:

public class PageNavigatorAdapter : IPageViewToolBar
{
    public PageNavigatorAdapter(BindingNavigator pNavigator);
    public PageNavigatorAdapter(BindingNavigator pNavigator, bool pIsVisible);
    public ToolStripItem AddNewItemButton { protected get; set; }
    public bool AddNewItemEnabled { get; set; }
    public bool AddNewItemVisible { get; set; }
    public BindingSource BindingSource { get; set; }
    public ToolStripItem DeleteItemButton { protected get; set; }
    public bool DeleteItemEnabled { get; set; }
    public bool DeleteItemVisible { get; set; }
    public ToolStripItem EditItemButton { protected get; set; }
    public bool EditItemEnabled { get; set; }
    public bool EditItemVisible { get; set; }
    public ToolStripItem SaveButton { protected get; set; }
    public bool SaveEnabled { get; set; }
    public bool SaveVisible { get; set; }
    public bool Visible { get; set; }
    public WorkItem WorkItem { get; set; }
    public event EventHandler<EventArgs<object>> AddNewItemClick;
    public event EventHandler<EventArgs<object>> DeleteItemClick;
    public event EventHandler<EventArgs<object>> EditItemClick;
    public event EventHandler SaveClick;
}
 
There are plenty of things to utilize for the existing buttons, but no room to add a new button.  I really need this quite badly and I do not want to recreate a navigation toolbar wheel unless I have to.  On second thought, if I did that then I could implement the DevExpress control in its place...hhmmm...
 
Thanks,
Bill



Replies:
Posted By: Linguinut
Date Posted: 30-Nov-2007 at 5:23pm
In the PageNavigatorAdapter class, could I make this function public?
 
/// <summary>Set the Adapter's ToolStripItem that represents a Button in the navigator.</summary>
/// <param name="pAdapterButton">The adapter's reference to the ToolStripItem.</param>
/// <param name="pNewButton">The new reference to the ToolStripItem in the Navigator.</param>
/// <param name="pClickHandler">The button's click handler.</param>
private void SetButton(ref ToolStripItem pAdapterButton, ToolStripItem pNewButton, EventHandler pClickHandler)
 
Of course, I am editing the IdeaBlade.CAB.UI class, but I do not see another way to do this.  Is there?


Posted By: Linguinut
Date Posted: 30-Nov-2007 at 6:34pm
Criminey!!  Nothing is simple.  The approach of changing the method to public introduces a whole gob of complications.  The interface must be changed, for one.  I tried.  What a headache!
 
I am now thinking that I should just hide the default PageNavigatorAdapter and create my own DevExpress DataNavigator.  I could just wire the two together, then add my own buttons however I desire. 
 
Well, if I am going to do that, I might as well go the whole way and create a whole new DataNavigatorAdapter class.  But, then, I would have to replace the PageNavigatorAdapter on the ControlViews...I am sure that will carry with it a tremendously lethal plague of exceptions that I will have to deal with.
 
Where does this end?
 
I am giving up for the day.  Perhaps someone can chime in here and let me know how to add a toolstripitem to the page navigator.  I will be back at this tomorrow.


Posted By: Linguinut
Date Posted: 03-Dec-2007 at 10:03am
Cry


Posted By: Linguinut
Date Posted: 04-Dec-2007 at 9:41am
How do I add an item?  Can it even be done?
Cry Cry


Posted By: Linguinut
Date Posted: 04-Dec-2007 at 6:07pm
Disapprove


Posted By: Linguinut
Date Posted: 05-Dec-2007 at 11:04am
Angry


Posted By: Linguinut
Date Posted: 06-Dec-2007 at 2:24pm
Dead


Posted By: mykel
Date Posted: 12-Dec-2007 at 7:46pm
I think I can help you with this, linguinut (i hope) :) do you still want to hear?


Posted By: mykel
Date Posted: 12-Dec-2007 at 7:52pm

You first add the toolStripItem in the Toolbar of the DevExPageView Form. then take note of the CreateNavigatorAdapter() method inside the code of the form, because you will be setting your newly added button from the PageNavigatorAdapter into the ToolStripItem control.



Posted By: mykel
Date Posted: 12-Dec-2007 at 7:55pm
In the IPageViewToolBar interface, you need to add the following getter and setter of the function you want to add. In my application, I added an Undo functionality and add the following codes:

/// <summary>Get or set the enabled state of the UndoItem button.</summary>

bool UndoItemEnabled { get; set;}

/// <summary>Get or set the visible state of the UndoItem button.</summary>

bool UndoItemVisible { get; set;}

/// <summary>Raised on UndoItem click.</summary>

event EventHandler<EventArgs<Object>> UndoItemClick;

Take note that you will only add the Enabled and Visible codes, if you will need to manipulate the behavior of your control. But the event handler is an important thing here.


Posted By: mykel
Date Posted: 12-Dec-2007 at 7:58pm
Then in the PageNavigatorAdapter, You have to add the ff methods and variables:
 
private ToolStripItem mUndoItemButton;

// <summary>Raised on UndoItem click.</summary>

public event EventHandler<EventArgs<Object>> UndoItemClick;

/// <summary>Set the ToolStripItem that represents the UndoItem Button.</summary>

/// <remarks>

/// Derived classes can "get" this ToolStripItem.

/// </remarks>

public ToolStripItem UndoItemButton

{

protected get { return mUndoItemButton; }

set

{

SetButton(ref mUndoItemButton, value, UndoItemButtonClick);

}

}

private void UndoItemButtonClick(object sender, EventArgs e)

{

InvokeClickHandlerWithCurrentObject(UndoItemClick, true);

}

/// <summary>Get or set the visible state of the Undo button.</summary>

public bool UndoItemVisible

{

get { return GetToolStripItemVisible(UndoAllButton); }

set { SetToolStripItemVisible(UndoAllButton, value); }

}

/// <summary>Get or set the enabled state of the Undo button.</summary>

public bool UndoItemEnabled

{

get { return GetToolStripItemEnabled(UndoItemButton); }

set { SetToolStripItemEnabled(UndoItemButton, value); }

}



Posted By: mykel
Date Posted: 12-Dec-2007 at 8:01pm
Once you added this, Now you have to place a setting code in the DevExPageView CreateNavigatorAdapter() method:

navAdapter.UndoItemButton = undoCurrentToolStripMenuItem;

given that the undoCurrentToolStripMenuItem is the ToolStripItem button you added in your UI.


Posted By: mykel
Date Posted: 12-Dec-2007 at 8:05pm
And then in the generic PageController (ex. SummaryDetailPageController<TRootObject>) you configure the events of your added toolbar.

/// <summary>Configure the UndoItem button.</summary>

protected virtual void ConfigureUndoItemButton()

{

PageToolBar.UndoItemClick += UndoItemHandler;

}

then call this event in the AddCommandHandlers() method.


Posted By: mykel
Date Posted: 12-Dec-2007 at 8:10pm
oh Im sorry, I forgot about the PageController class. You need to add the ff in the PageController, before doing something in the SummaryDetailPageController:
 

#region Undo Item

/// <summary>Handle request to undo an item.</summary>

protected void UndoItemHandler(object sender, EventArgs<Object> e)

{

// ToDo: Use Resources

object item = e.Data;

UndoItem(item);

}

/// <summary>Delete the item.</summary>

/// <remarks>

/// This implementation can only delete

/// an <see cref="Entity"/>.

/// </remarks>

protected virtual void UndoItem(object pItem)

{

if (pItem is Entity)

{

((Entity)pItem).Undo();

((Entity)pItem).ClearErrors();

((CommonEntity)pItem).VerifierResults.Clear();

}

else

{

throw new InvalidOperationException("Can't undo an item of type, " + pItem.GetType());

}

}

#endregion

 

Note that this is only my example for creating an undo functionality. You have to modify the code inside the methods and events in order to implement the functionality of your toolbar button event once you click it.

I think thats all. I am sorry if ever I missed out something. Let me know if you encounter problems with this.
 
Hope this helps. :)


Posted By: Linguinut
Date Posted: 12-Dec-2007 at 8:34pm
mykel, thanks gobs for the response.  Two thumbs up!  Thumbs%20Up Thumbs%20Up
 
My gut is telling me that fiddling with the interfaces on this Adapter is not the way to go, though.  The toolbar's Button.Add functionality (for example) should be exposed so that the user control can add to its basic set of items (Print Report Button, Drop-Down List Control for filtering data, Simple label control for information, etc.).  Adding the proper handler would be module specific.  Your undo example is good and I understand the work involved in making it happen (for the most part); however, an ad hoc toolbar item is what I would like to achieve.  Perhaps, I am dreaming a little too much, eh?


Posted By: mykel
Date Posted: 12-Dec-2007 at 9:03pm

Oh ok. I get it. :) Nope. I think its do-able but I must admit it's hard implementing it in CAB :)



Posted By: Linguinut
Date Posted: 13-Dec-2007 at 8:44am

Somehow a UI extension site might fit in here...I just can't get my head around it, yet.



Posted By: mykel
Date Posted: 13-Dec-2007 at 10:56pm
Ok. I hope you will make it work. :)
 
By the way, Where are the Ideablade Support? :)


Posted By: Linguinut
Date Posted: 14-Dec-2007 at 9:00am
Thanks, me too.  For now, I have given up on this particular item.  Too many other things to concentrate on at the moment.
 
The whole CAB/DF thing is lightly supported through IdeaBlade.  Hopefully, as the days and months waddle by, more resources can be applied to this area.  Thanks a lot for your input.  That is another hope of mine...that more users will interact with these forums.  Shared experiences are quite beneficial in the development process.


Posted By: mykel
Date Posted: 16-Dec-2007 at 10:20pm

Yes you are right. Thanks!




Print Page | Close Window