⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 calendarmodelimpl.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006  Christopher Kohlhaas                                 |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/

package org.rapla.gui.internal.common;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.rapla.components.util.Assert;
import org.rapla.components.util.DateTools;
import org.rapla.components.xmlbundle.I18nBundle;
import org.rapla.entities.Named;
import org.rapla.entities.RaplaObject;
import org.rapla.entities.RaplaType;
import org.rapla.entities.User;
import org.rapla.entities.configuration.CalendarModelConfiguration;
import org.rapla.entities.domain.Allocatable;
import org.rapla.entities.domain.Appointment;
import org.rapla.entities.domain.AppointmentBlockArray;
import org.rapla.entities.domain.Reservation;
import org.rapla.entities.dynamictype.Classifiable;
import org.rapla.entities.dynamictype.Classification;
import org.rapla.entities.dynamictype.ClassificationFilter;
import org.rapla.entities.dynamictype.DynamicType;
import org.rapla.entities.dynamictype.DynamicTypeAnnotations;
import org.rapla.facade.ClientFacade;
import org.rapla.facade.Conflict;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;
import org.rapla.framework.RaplaLocale;

public class CalendarModelImpl implements CalendarSelectionModel
{

    Date startDate;
    Date endDate;
    Date selectedDate;
    ClassificationFilter[] filter = ClassificationFilter.CLASSIFICATIONFILTER_ARRAY;
    List selectedObjects = new ArrayList();
    String title;
    int columnSize = 100;
    ClientFacade m_facade;
    String selectedView;
    I18nBundle i18n;
    RaplaContext context;
    RaplaLocale raplaLocale;
    User user;
    Map optionMap = new HashMap();
    
    private CalendarModelImpl() {
    	
    }

    public CalendarModelImpl(RaplaContext sm) throws RaplaException {
        this.context = sm;
        this.raplaLocale = (RaplaLocale) sm.lookup(RaplaLocale.ROLE);
        i18n = (I18nBundle)sm.lookup(I18nBundle.ROLE + "/org.rapla.RaplaResources");
        m_facade = (ClientFacade) sm.lookup(ClientFacade.ROLE);
        if ( m_facade.isSessionActive()) {
            user = m_facade.getUser();
        }
        setSelectedDate( m_facade.today());
    }

    public void setUser( User user) {
        this.user = user;
    }

    public boolean setConfiguration(CalendarModelConfiguration config) throws RaplaException {
        boolean couldResolveAllEntities = true;
        selectedObjects = new ArrayList();
        // get filter
        title = config.getTitle();
        selectedView = config.getView();
        filter = config.getFilter();
        if ( config.getSelectedDate() != null) {
            setSelectedDate( config.getSelectedDate() );
        }
        if ( config.getStartDate() != null) {
            setStartDate( config.getStartDate() );
        }
        if ( config.getEndDate() != null) {
            setEndDate( config.getEndDate() );
        }
        selectedObjects.addAll( config.getSelected());
        setFilter( filter );
        //selectedObjects
        if (config.getOptionMap() != null )
        {
            optionMap = new HashMap(config.getOptionMap());
        } 
        else
        {
            optionMap = new HashMap();
        }
        return couldResolveAllEntities;
    }

    public User getUser() {
        return user;
    }

    public CalendarModelConfiguration createConfiguration() throws RaplaException {
        String viewName = selectedView;
        for (Iterator it = selectedObjects.iterator();it.hasNext();) {
            if ( it.next() instanceof Conflict) {
                throw new RaplaException("Storing the conflict view is not possible with Rapla.");
            }
        }

        Set selected = new HashSet( selectedObjects);
        return m_facade.newRaplaCalendarModel( m_facade.newRaplaMap(selected), filter, title, getStartDate(), getEndDate(), getSelectedDate(), viewName, m_facade.newRaplaMap(optionMap));
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#setFilter(org.rapla.entities.RaplaObject)
	 */
    public void setFilter(ClassificationFilter[] filter) {
        this.filter = filter;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#getSelectedDate()
	 */
    public Date getSelectedDate() {
        return selectedDate;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#setSelectedDate(java.util.Date)
	 */
    public void setSelectedDate(Date date) {
        if ( date == null)
            throw new IllegalStateException("Date can't be null");
        this.selectedDate = date;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#getStartDate()
	 */
    public Date getStartDate() {
        return startDate;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#setStartDate(java.util.Date)
	 */
    public void setStartDate(Date date) {
        this.startDate = date;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#getEndDate()
	 */
    public Date getEndDate() {
        return endDate;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#setEndDate(java.util.Date)
	 */
    public void setEndDate(Date date) {
        this.endDate = date;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#getTitle()
	 */
    public String getTitle() {
        return title;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#setTitle(java.lang.String)
	 */
    public void setTitle(String title) {
        this.title = title;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#setView(java.lang.String)
	 */
    public void setViewId(String view) {
        this.selectedView = view;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#getView()
	 */
    public String getViewId() {
        return this.selectedView;
    }

    /* (non-Javadoc)
	 * @see org.rapla.calendarview.CalendarModel#getNonEmptyTitle()
	 */
    public String getNonEmptyTitle() {
        if (getTitle() != null && getTitle().trim().length()>0)
            return getTitle();


        String types = "";
        /*
        String dateString = getRaplaLocale().formatDate(getSelectedDate());
        if  ( isListingAllocatables()) {
            try {
                Collection list = getSelectedObjectsAndChildren();
                if (list.size() == 1) {
                    Object obj = list.iterator().next();
                    if (!( obj instanceof DynamicType))
                    {
                        types = getI18n().format("allocation_view",getName( obj ),dateString);
                    }
                }

            } catch (RaplaException ex) {
            }
            if ( types == null )
                types = getI18n().format("allocation_view",  getI18n().getString("resources_persons"));
        } else if ( isListingReservations()) {
             types =  getI18n().getString("reservations");
        } else {
            types = "unknown";
        }
        */

        return types;
    }

    public String getName(Object object) {
        if (object == null)
            return "";
        if (object instanceof Named) {
            String name = ((Named) object).getName(getI18n().getLocale());
            return (name != null) ? name : "";
        }
        return object.toString();
    }

    public int getSize() {
        return columnSize;
    }

    public void setColumnSize(int columnSize) {
        this.columnSize = columnSize;
    }


    private Collection getFilteredAllocatables() throws RaplaException {
        List list = new ArrayList();
        Allocatable[] all = m_facade.getAllocatables();
        for (int i=0;i<all.length;i++) {
            if ( isInFilter( all[i]) ) {
                list.add( all[i]);
            }
        }
        return list;
    }

    private boolean isInFilter( Classifiable classifiable) {
        if ( filter.length == 0)
            return true;
        for ( int i=0;i< filter.length;i++)
        {
            if ( filter[i].matches( classifiable.getClassification())) {
                return true;
            }
        }
        return false;
    }

    public Collection getSelectedObjectsAndChildren() throws RaplaException
    {
        Assert.notNull(selectedObjects);

        ArrayList dynamicTypes = new ArrayList();
        for (Iterator it = selectedObjects.iterator();it.hasNext();)
        {
            Object obj = it.next();
            if (obj instanceof DynamicType) {
                dynamicTypes.add (obj);
            }
        }

        HashSet result = new HashSet();
        result.addAll( selectedObjects );
        
        boolean allAllocatablesSelected = selectedObjects.contains( ALLOCATABLES_ROOT);
        
        Collection filteredList = getFilteredAllocatables();
        for (Iterator it = filteredList.iterator();it.hasNext();)
        {
            Object oneSelectedItem =  it.next();
            if ( selectedObjects.contains(oneSelectedItem)) {
                continue;
            }
            if ( oneSelectedItem instanceof Classifiable ) {
                Classification classification = ((Classifiable)oneSelectedItem).getClassification();
                if ( classification == null)
                {
                	continue;
                }
                 if ( allAllocatablesSelected || dynamicTypes.contains(classification.getType()))
                 {
                    result.add( oneSelectedItem );
                    continue;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -