How to disable past days in ZK Calendar? - zk

I'm using ZK CE-9.0.0 & zk-calendar-2.1.5 source code.
Currently all the days are enabled in the calendar.
I need to disable the past days (greyed out & no click event), from all the views(Day/Week/Month), but not able to find any such feature directly available.
Can anyone help me with this please?
Thanks,
RAS

I don't think there is such feature.
A workaround would be to disable event click on past days and change the color.
1 . Catch clicks in your controller :
#Wire("#course-calendar")
private Calendars courseCalendar;
#Listen("onEventCreate = #course-calendar")
public void clickCreateEvent(CalendarsEvent event) {
if (event.getBeginDate().before(new Date())) {
// disable click if event is before now
} else {
//do something on event create
}
}
#Listen("onEventEdit = #course-calendar")
public void clickEditEvent(CalendarsEvent event) {
if (event.getBeginDate().before(new Date())) {
// disable click if event is before now
} else {
// do something on event edit
}
}
Grey out events on event creation :
for (MyEvent me : myManager.getEvents()) {
final SimpleCalendarEvent simpleCalendarEvent = new SimpleCalendarEvent();
// set grey color event before now
if (me.startDate < new Date()) {
simpleCalendarEvent.setContentColor("#aaaaaa");
simpleCalendarEvent.setHeaderColor("#aaaaaa");
simpleCalendarEvent.setLocked(true);
} else {
simpleCalendarEvent.setContentColor("#4363d8");
simpleCalendarEvent.setHeaderColor("#4363d8");
simpleCalendarEvent.setLocked(false);
}
simpleCalendarEvent.setContent(me.getContent());
simpleCalendarEvent.setBeginDate(me.startDate);
simpleCalendarEvent.setEndDate(me.endDate);
simpleCalendarEvent.setTitle(me.getTitle());
getSimpleCalendarModel().add(simpleCalendarEvent);
}

Related

Unity3D - Button not triggered once?

I have some issues for match the string and the InputField.text it's triggering multiple times after Active or Dead Active Gameobject when press Submit button(in this case is "Cek Jawaban").
this my script
public void Answer(int index)
{
inputPanel.SetActive(true);
inputField.text = "";
inputPanel.transform.Find("KunciBtn").GetComponent<Button>().onClick.AddListener(() =>
{
if (inputField.text != "")
{
if (inputField.text == jawaban[index])
{
Debug.Log("Right");
}
else
{
Debug.Log("Wrong");
}
inputPanel.SetActive(false);
}
else
{
Debug.Log("jangan kosong");
}
});
}
[![Many Buttons][1]][1]
as you can see on the console at the first that triggers once but after the second time its triggers twice. Also, my Answer() called on every button.
The issue is that you are adding listeners to the onClick of the button every time Answer is called, but you are never removing them. So the second time you click the button, a second listener has been added and it will look like you have pressed the button twice.
To fix this, you either need to remove the listener after you have handled the button logic:
...
else
{
Debug.Log("jangan kosong");
}
inputPanel.transform.Find("KunciBtn").GetComponent<Button>().onClick.RemoveAllListeners();
Or add the listener on Start() so that it is set once and then remove it in either OnDisable() or OnDestroy().

UWP Custom ListView to scroll down

So, I have a listview and I want it whenever an item is created to scroll to that item (bottom). Because I am using MVVM I found really nice explanation on how to make a new control that inherits from listview that scrolls down. The problem is that this answer (the third) is referring to WPF 6 years ago.
I am making a UWP app, so I copied the code and tried to format it to my needs. The following code doesn't give any error or exception but instead it loads the "ChatListView" as I call it perfectly and then does nothing. The comments are only a bit edited compared to the original code.
What can I do ? Thank you in advance!
public class ChatListView : ListView
{
//Define the AutoScroll property. If enabled, causes the ListBox to scroll to
//the last item whenever a new item is added.
public static readonly DependencyProperty AutoScrollProperty =
DependencyProperty.Register(
"AutoScroll",
typeof(Boolean),
typeof(ChatListView),
new PropertyMetadata(
true, //Default value.
new PropertyChangedCallback(AutoScroll_PropertyChanged)));
//Gets or sets whether or not the list should scroll to the last item
//when a new item is added.
public bool AutoScroll
{
get { return (bool)GetValue(AutoScrollProperty); }
set { SetValue(AutoScrollProperty, value); }
}
//Event handler for when the AutoScroll property is changed.
//This delegates the call to SubscribeToAutoScroll_ItemsCollectionChanged().
//d = The DependencyObject whose property was changed.</param>
//e = Change event args.</param>
private static void AutoScroll_PropertyChanged(
DependencyObject d, DependencyPropertyChangedEventArgs e)
{
SubscribeToAutoScroll_ItemsCollectionChanged(
(ChatListView)d,
(bool)e.NewValue);
}
//Subscribes to the list items' collection changed event if AutoScroll is enabled.
//Otherwise, it unsubscribes from that event.
//For this to work, the underlying list must implement INotifyCollectionChanged.
//
//(This function was only creative for brevity)
//listBox = The list box containing the items collection.
//subscribe = Subscribe to the collection changed event?
private static void SubscribeToAutoScroll_ItemsCollectionChanged(
ChatListView listView, bool subscribe)
{
INotifyCollectionChanged notifyCollection =
listView as INotifyCollectionChanged;
if (notifyCollection != null)
{
if (subscribe)
{
//AutoScroll is turned on, subscribe to collection changed events.
notifyCollection.CollectionChanged +=
listView.AutoScroll_ItemsCollectionChanged;
}
else
{
//AutoScroll is turned off, unsubscribe from collection changed events.
notifyCollection.CollectionChanged -=
listView.AutoScroll_ItemsCollectionChanged;
}
}
}
//Event handler called only when the ItemCollection changes
//and if AutoScroll is enabled.
//sender = The ItemCollection.
//e = Change event args.
private void AutoScroll_ItemsCollectionChanged(
object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
int count = Items.Count;
ScrollIntoView(Items[count - 1]);
}
}
//Constructor a new ChatListView.
public ChatListView()
{
//Subscribe to the AutoScroll property's items collection
//changed handler by default if AutoScroll is enabled by default.
SubscribeToAutoScroll_ItemsCollectionChanged(
this, (bool)AutoScrollProperty.GetMetadata(typeof(ChatListView)).DefaultValue);
}
}
If you want to create a chat application you can use the ItemsStackPanel's ItemsUpdatingScrollMode particular property to KeepLastItemInView value to scroll to the latest item.
Usage:
<ListView>
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel ItemsUpdatingScrollMode="KeepLastItemInView" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
Note: KeepLastItemInView enum member was introduced in the 14393 SDK.
Related link:
https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Controls.ItemsStackPanel#properties_
The accepted answer is pretty nice. However I there is one thing it won't do (at least if I simply copy and paste the above XAML): it won't do its intended scrolling if, say, the user was away from that page while new items were added, and then they navigated to the page.
For that I had to hook into
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (MyListView.Items.Count == 0)
return;
object lastItem = MyListView.Items[MyListView.Items.Count - 1];
MyListView.ScrollIntoView(lastItem);
}

Block gwt DisclosurePanel on open state

How may I block a gwt DisclosurePanel on the open state ?
I mean, how can I prevent this DisclosurePanel to close if the user click the header more than once ?
(My header is a textBox, I want the user to enter a text, and the panel should remain open if the user unfocus the textBox and focus newly by clicking it. The DisclosurePanel content has a "cancel" button that closes the panel)
Thank you very much.
I edit my question after 2 first answers: I would like to avoid to reopen the DisclosurePanel once closed to avoid flashing effect. I actually want to prevent the DisclosurePanel to close. Maybe sinkEvents can help me... if so, how? Thanks.
A NativePreviewHandler receives all events before they are fired to their handlers. By registering a nativePreviewHandler the first time your disclosurePanel is opened, you can cancel the click event. You can later decide to remove this handler by preventClose.removeHandler();
HandlerRegistration preventClose = null;
....
panel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
if (preventClose == null){
preventClose = Event.addNativePreviewHandler(new NativePreviewHandler() {
#Override
public void onPreviewNativeEvent(NativePreviewEvent event) {
if (event.getTypeInt()==Event.ONCLICK && event.getNativeEvent().getEventTarget() == panel.getHeader().getElement().cast())
event.cancel();
}
});
}
}
});
The obvious answer is review the javadoc here: https://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/ui/DisclosurePanel.html
There is a setOpen() method that: Changes the visible state of this DisclosurePanel.
Set it to false from a click event to capture the user action.
The JavaDoc is right here: https://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/ui/DisclosurePanel.html
jamesDrinkard pointed the old 1.5 javadoc.
You can use the addCloseHandler(CloseHandler<DisclosurePanel> handler) method to add a handler so when the user tries to close it you can reopen it again with setOpen().
Maybe not the best way, but it worked for me (maybe just one of both will work too):
dPanel.setOpen(true);
dPanel.addOpenHandler(new OpenHandler<DisclosurePanel>() {
#Override
public void onOpen(OpenEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});
dPanel.addCloseHandler(new CloseHandler<DisclosurePanel>() {
#Override
public void onClose(CloseEvent<DisclosurePanel> event) {
dPanel.setOpen(true);
}
});

GWT: handling more than one events on Label

I want handle events on a Label when user holds down some key (Ctrl) and then clicks the mouse button together (Ctrl + mouse click), like open some window etc...
How could i do that in GWT? Should i get add two handlers or can do it with one?
thank you.
al
In your click handler you can check if the Ctrl key is pressed when the event was fired, see example below. You also might want to check for the specific mouse button the user clicked on. I've also added that to the example:
yourLabel.addClickHandler(new ClickHandler() {
if(NativeEvent.BUTTON_LEFT == event.getNativeButton() &&
event.isControlKeyDown()) {
//do what you want
}
});
Or for older version of GWT instead of event.isControlKeyDown use event.getNativeEvent().getCtrlKey(), which returns a boolean value true if the control key is pressed when this event is fired.
Edit: this code is buggy, please look at Hilbrand's answer
To be honest, I don't think you can do it with 1 or 2 handlers. I think you would need 3 handler.
A KeyDownHandler that sets a boolean you can later read form the MouseDownHandler
A MouseDownHandler that does what you want
A KeyUpHandler that resets the value of the boolean in the KeyDownHandler
boolean ctrlPressed;
yourLabel.addDomHandler(new KeyDownHandler() {
public void onKeyDown(KeyDownEvent event) {
if(event.getAssociatedType().equals(KeyCodes.KEY_CTRL))
ctrlPressed=true;
}
}, KeyDownEvent.getType());
yourLabel.addDomHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
if(event.getAssociatedType().equals(KeyCodes.KEY_CTRL))
ctrlPressed=false;
}
}, KeyUpEvent.getType());
yourLabel.addClickHandler(new ClickHandler() {
if(ctrlPressed) {
//do what you want
}
});

GWT/MVP: detecting change events in a table with proper MVP pattern

We're using gwt-presenter, but not really a question specific to that...
I've got a table with users in it. As I build the table in the view (from the data provided by the presenter), I need to add two action buttons ("Edit", and "Delete") at the end of the row.
What's the best way to assign click handlers to these buttons so the presenter knows which was clicked? Previous to this, we could pass a private field from the view to the presenter and attach a discrete click handler to that button. However, this method is rather rigid and doesn't work in this scenario very well.
Thanks in advance.
How about having the view allowing the subscription for edit/delete click events, registering internally the individual row click events, and then delegating the event handling to the ones registered by the view?
I mean something like the following pesudo code:
View:
addRowEditClickHandler(ClickHandler handler) {
this.rowEditClickHandler = handler;
}
addRowDeleteClickHandler(ClickHandler handler) {
this.rowDeleteClickHandler = handler;
}
//... somewhere when setting up of the grid...
rowEditButton.addClickHandler = new ClickHandler() {
onClick(args) {
this.rowEditClickHandler.onClick(args)
}
rowDeleteButton.addClickHandler = new ClickHandler() {
onClick(args) {
this.rowDeleteClickHandler.onClick(args)
}
Presenter:
View view = new View();
view.addRowEditClickHandler( new ClickHandler() {
onClick(args) {
doSomething();
}
});
view.addRowDeleteClickHandler( new ClickHandler() {
onClick(args) {
doSomething();
}
});