Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Is it Possible to drag items from one calendar to another. (DualView) (Read 417 times)
Michael Hopkins
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Apr 5th, 2022
Is it Possible to drag items from one calendar to another. (DualView)
Jan 5th, 2024 at 11:56pm
Print Post  
Hi,

We are using the calendar to show on the left a month view of a jplanner calendar and on the right and timeline view of a day on the calendar. This is exactly like the DualView sample.

We would like to be able to drag items from the right calendar and drop them on a day on the left calendar, catch that drop and then modify the item so that it's start date is the day that they dropped it on.

Is this possible and if so, do you have any hints or suggestions on how to do it?

I played around with adding a transfer handler on both of the calendars but it doesn't seem to hit the breakpoint I set in the canImport method.

Do I need to do something to the item to make it draggable to the other calendar?

I am going to paste in the code from the DualView Sample with some minor changes I made. Note that myTransferHandler just extends transfer handler and does nothing because I wanted to just check if the code was ran or not.

Code (Java)
Select All
// Calendar initialization start
		calendar.beginInit();
		calendar.setCurrentView(CalendarView.MonthRange);
		calendar.setTheme(ThemeType.Silver);
		calendar.getMonthRangeSettings().setMonthsPerRow(1);
		calendar.getMonthRangeSettings().setNumberOfMonths(2);
		calendar.getMonthRangeSettings().setScrollInterval(1);
		calendar.getSelection().setAllowMultiple(false);
		calendar.getMonthSettings().getDaySettings().setHeaderSize(0);
		// Select the current date
		calendar.getSelection().set(DateTime.today());
		calendar.setDate(DateTime.today());

		calendar.endInit();
		// Calendar initialization end

		_schedule = new Calendar();
		_schedule.setCurrentView(CalendarView.Timetable);

		// Synchronize both views
		_schedule.beginInit();
		_schedule.setSchedule(calendar.getSchedule());
		_schedule.setTheme(ThemeType.Silver);
		_schedule.setDate(calendar.getDate());
		_schedule.setEndDate(calendar.getEndDate());
		_schedule.setAllowDrag(true);
		_schedule.endInit();

		Appointment app = new Appointment();
		app.setStartTime(new DateTime(LocalDateTime.now().withHour(12).withMinute(0).withSecond(0).withNano(0)));
		app.setEndTime(new DateTime(LocalDateTime.now().withHour(13).withMinute(0).withSecond(0).withNano(0)));
		app.setHeaderText("Some Appointment");

		MyTransferHandler handler = new MyTransferHandler();
		_schedule.setTransferHandler(handler);
		calendar.setTransferHandler(handler);

		_schedule.getSchedule().getAllItems().add(app);

		// Listen for selection changes
		calendar.getSelection().addChangeListener(new ChangeListener(){
			@Override
			public void changed(EventObject e) {
				onSelectionChanged();
			}
		});

		// Listen for item creation/deletion/modification
		_schedule.addCalendarListener(new CalendarAdapter(){
			public void itemCreated(ItemEvent e) {
				onItemCreated(e);
			}
			public void itemDeleted(ItemEvent e) {
				onItemDeleted(e);
			}
		});

		JSplitPane pane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, calendar, _schedule);
		pane.setDividerLocation(250);
		content.add(pane); 




Thanks in advance. Smiley
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Is it Possible to drag items from one calendar to another. (DualView)
Reply #1 - Jan 8th, 2024 at 7:28am
Print Post  
Hi,

The calendar moves items by handling mouse events rather than data transfers, so target transfer handler won't be triggered automatically. You will have to initiate drag operation by calling source handler's exportAsDrag handler -

Code
Select All
_schedule.addCalendarListener(new CalendarAdapter(){
	@Override
	public void itemModifying(ItemModifyConfirmEvent e)
	{
		e.setConfirm(false);
		_schedule.cancelModify();
		_schedule.getTransferHandler().exportAsDrag(
			_schedule, lastPress, TransferHandler.MOVE);
	}
});

_schedule.addMouseListener(new MouseAdapter() {
	@Override
	public void mousePressed(MouseEvent e) {
		lastPress = e;
	}
});

...
MouseEvent lastPress;
 



If you need the timetable view to support both internal dragging and transfers, you might try calling exportAsDrag only when mouse pointer is near the calendar's borders, or e.g. based on modifier key state.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Michael Hopkins
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 23
Joined: Apr 5th, 2022
Re: Is it Possible to drag items from one calendar to another. (DualView)
Reply #2 - Jan 26th, 2024 at 6:49pm
Print Post  
Something came up and we haven't had a chance to try this out until now. We do need to do both drag inside the calendar and catch the drag unto a day on the month view. We tried what you suggested to check if they try to drag the item close to the edge of the calendar but the problem we are seeing is that when the item is all the way to the left and you try and drag directly left to the other calendar, the item modified event does not fire. It makes sense because the item isn't being modified.

Any suggestions or routes we can try?

Thanks a ton!!! You guys are awesome. Smiley
« Last Edit: Jan 26th, 2024 at 8:24pm by Michael Hopkins »  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Is it Possible to drag items from one calendar to another. (DualView)
Reply #3 - Jan 29th, 2024 at 8:12am
Print Post  
You could set a flag from itemClick event, and then decide whether to external-drag based on that:

Code
Select All
Item draggedItem = null;
MouseEvent lastPress = null;

_schedule.addCalendarListener(
    new CalendarAdapter()
    {
        @Override
        public void itemClick(ItemMouseEvent e)
        {
            draggedItem = e.getItem();
        }
        ....
    });

_schedule.addMouseListener(
    new MouseAdapter()
    {
        @Override
        public void mousePressed(MouseEvent e)
        {
            lastPress = e;
        }

        @Override
        public void mouseExited(MouseEvent e)
        {
            if (draggedItem != null)
            {
                _schedule.getTransferHandler().exportAsDrag(
                    _schedule, lastPress, TransferHandler.MOVE);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e)
        {
            draggedItem = null;
        }
    }); 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint