allocatableinfoui.java

来自「Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI」· Java 代码 · 共 114 行

JAVA
114
字号
/*--------------------------------------------------------------------------*
 | 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.view;

import java.util.ArrayList;
import java.util.Date;
import java.util.Collection;


import org.rapla.entities.User;
import org.rapla.entities.domain.Allocatable;
import org.rapla.entities.domain.Permission;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;

public class AllocatableInfoUI extends ClassificationInfoUI {
    public AllocatableInfoUI(RaplaContext sm) throws RaplaException {
        super(sm);
    }

    protected String getHTML(Object object,ViewTable controller) throws RaplaException{
        Allocatable allocatable = (Allocatable) object;
        StringBuffer buf = new StringBuffer();
        buf.append("<html>");
        insertClassification( allocatable, buf );
        insertPermissions( allocatable, buf );
        buf.append("</html>");
        return buf.toString();
    }

    void insertPermissions( Allocatable allocatable, StringBuffer buf ) {
        User user;
        Date today;
        try {
            user = getUser();
            today = getQuery().today();
        } catch (Exception ex) {
            return;
        }
        boolean firstPermission = true;
        if ( user.isAdmin() ) {
            return;
        }
        Permission[] permissions = allocatable.getPermissions();
        boolean everytime = false;
        for ( int i = 0; i < permissions.length; i++ ) {
            Permission permission = permissions[i];
            if ( permission.affectsUser ( user ) 
                    && permission.getMinAllowed( today ) == null
                    && permission.getMaxAllowed( today ) == null ) {
                everytime = true;
                break;
            }
        }
        
        for ( int i = 0; i < permissions.length; i++ ) {
            Permission permission = permissions[i];
            if ( permission.affectsUser( user ) ) {
                if ( firstPermission ) {
                    firstPermission = false;
                    buf.append( "<strong>" );
                    buf.append( getString( "allocatable_in_timeframe" ) );
                    buf.append( ":</strong>" );
                    buf.append("<br>");
                    if ( everytime ) {
                        buf.append( getString("everytime") );
                        break;
                    }
                }
                
                if ( permission.getMinAllowed( today ) != null ) {
                    Date date = permission.getMinAllowed( today );
                    buf.append( getRaplaLocale().formatDate( date ) );
                } else {
                    buf.append(getString("open"));
                }
                buf.append(" - ");
                if ( permission.getMaxAllowed( today ) != null ) {
                    Date date = permission.getMaxAllowed( today );
                    buf.append( getRaplaLocale().formatDate( date ) );
                } else {
                    buf.append(getString("open"));
                }
                buf.append("<br>");
            }
        }
    }

    public String getTooltip(Object object) {
        Allocatable allocatable = (Allocatable) object;
        StringBuffer buf = new StringBuffer();
        insertClassificationTitle( allocatable, buf );
        Collection att = new ArrayList();
        att.addAll(getClassificationAttributes(allocatable, false));
        createTable(att,buf);
        insertPermissions( allocatable, buf );
        return buf.toString();
    }



}

⌨️ 快捷键说明

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