Flex Scheduling Framework:ScheduleViewer Simple Layout Sample
From Adobe Labs
One of the supplied layout manager is com.adobe.ac.controls.scheduleClasses.layout.SimpleLayout which places entries exactly as defined in the dataProvider. This means, that when using SimpleLayout, each item of the dataProvider is expected to be of type mx.collection.IList since it represents a row. Each row IList collection is expected to contain IScheduleEntry objects. You can write your own layout manager, check the BestFitLayout and SimpleLayout and their base classes and implemented interfaces for how to do that.
This sample shows how to setup a ScheduleViewer with the supplied SimpleLayout manager. Notice the different structure of the dataProvider, which now exactly determines how entries are being laid out. Furthermore, SimpleLayout does not check entries for overlapping. Therefore, in the second row of ScheduleViewerSample2 you can see one entry overlapping.
Notice also the entry renderer in this sample. Instead the default gradient renderer we now use com.adobe.ac.controls.scheduleClasses.renderers.SolidScheduleEntryRenderer.
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2006. Adobe Systems Incorporated.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Adobe Systems Incorporated nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
@ignore
-->
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:controls="com.adobe.ac.controls.*"
creationComplete="onCreationComplete();">
<mx:Script>
<![CDATA[
import com.adobe.ac.controls.scheduleClasses.SimpleScheduleEntry;
import com.adobe.ac.util.DateUtil;
import mx.collections.IList;
import mx.collections.ArrayCollection;
[Bindable]
private var dataProvider : ArrayCollection;
[Bindable]
private var startDate : Date;
[Bindable]
private var endDate : Date;
private function onCreationComplete() : void
{
setTimeframe();
initDataProvider();
}
private function setTimeframe() : void
{
startDate = DateUtil.clearTime( new Date() );
endDate = getEndDate( startDate );
}
private function getEndDate( startDate : Date ) : Date
{
var duration : Number = DateUtil.DAY_IN_MILLISECONDS * 1;
var endDate : Date = new Date( startDate.getTime() + duration );
return endDate;
}
private function initDataProvider() : void
{
var entries : ArrayCollection = new ArrayCollection();
var row : IList = new ArrayCollection();
var entry : SimpleScheduleEntry = new SimpleScheduleEntry();
entry.startDate = DateUtil.clearTime( new Date() );
entry.endDate = new Date( entry.startDate.getTime() + DateUtil.HOUR_IN_MILLISECONDS * 5 );
entry.label = "Our first entry!";
row.addItem( entry );
entries.addItem( row );
row = new ArrayCollection();
entry = new SimpleScheduleEntry();
entry.startDate = DateUtil.setTime( new Date(), DateUtil.HOUR_IN_MILLISECONDS );
entry.endDate = new Date( entry.startDate.getTime() + DateUtil.HOUR_IN_MILLISECONDS * 15 );
entry.label = "Our second entry!";
row.addItem( entry );
entry = new SimpleScheduleEntry();
entry.startDate = DateUtil.setTime( new Date(), DateUtil.HOUR_IN_MILLISECONDS * 14 );
entry.endDate = new Date( entry.startDate.getTime() + DateUtil.HOUR_IN_MILLISECONDS * 4 );
entry.label = "Overlapping";
row.addItem( entry );
entries.addItem( row );
row = new ArrayCollection();
entry = new SimpleScheduleEntry();
entry.startDate = DateUtil.setTime( new Date(), DateUtil.HOUR_IN_MILLISECONDS * 13 );
entry.endDate = new Date( entry.startDate.getTime() + DateUtil.HOUR_IN_MILLISECONDS * 5 );
entry.label = "Our third entry!";
row.addItem( entry );
entries.addItem( row );
dataProvider = entries;
}
]]>
</mx:Script>
<controls:ScheduleViewer id="scheduleViewer"
width="600" height="400"
dataProvider="{ dataProvider }"
startDate="{ startDate }" endDate="{ endDate }"
entryRenderer="com.adobe.ac.controls.scheduleClasses.renderers.SolidScheduleEntryRenderer"
entryLayout="com.adobe.ac.controls.scheduleClasses.layout.SimpleLayout"
/>
</mx:Application>
