/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* 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; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: ResourceWrapper.java,v 1.5 2006/10/04 09:27:54 drmlipp Exp $
*
* $Log: ResourceWrapper.java,v $
* Revision 1.5 2006/10/04 09:27:54 drmlipp
* Using resource type information for display.
*
* Revision 1.4 2006/09/29 12:32:11 drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.3 2006/09/14 20:24:12 mlipp
* Improved.
*
* Revision 1.2 2006/09/13 13:55:16 drmlipp
* Proceeding with assignments display.
*
* Revision 1.1 2006/09/13 11:02:03 drmlipp
* Started assignments display.
*
*/
package de.danet.an.workflow.clients.mgmtportlets.process;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.faces.context.FacesContext;
import de.danet.an.util.jsf.JSFUtil;
import de.danet.an.workflow.api.GroupResource;
import de.danet.an.workflow.api.RoleResource;
import de.danet.an.workflow.api.UserResource;
import de.danet.an.workflow.omgcore.WfResource;
/**
* This class provides a wrapper around <code>WfResource</code> objects.
*
* @author Michael Lipp
*
*/
public class ResourceWrapper implements Serializable {
private String key;
private String name;
private String localizedType;
private boolean typed;
/**
* Create a new instance with all attributes initialized
* to defaults or the given values.
*
* @param resource
* @param resTypeMap resource bundle for looking up translations
* of type names.
*/
public ResourceWrapper(WfResource resource, ResourceBundle resTypeMap)
throws RemoteException {
super();
key = resource.resourceKey();
name = resource.resourceName();
typed = true;
if (resource instanceof UserResource) {
localizedType = resTypeMap.getString(UserResource.class.getName());
} else if (resource instanceof RoleResource) {
localizedType = resTypeMap.getString(RoleResource.class.getName());
} else if (resource instanceof GroupResource) {
localizedType = resTypeMap.getString(GroupResource.class.getName());
} else {
localizedType = resTypeMap.getString("resource.type.unknown");
typed = false;
}
}
/**
* Create a new instance with all attributes initialized
* to defaults or the given values. This constructor will use
* the default resource bundle for looking up translations
* of type names.
*
* @param resource
*/
public ResourceWrapper(WfResource resource) throws RemoteException {
this(resource, ResourceBundle.getBundle
("de.danet.an.workflow.clients.mgmtportlets.process.L10n",
JSFUtil.activeLocale(), ResourceWrapper.class.getClassLoader()));
}
/**
* Return the process management bean.
* @return the result
*/
protected ProcessMgmt processMgmt () {
FacesContext fc = FacesContext.getCurrentInstance();
return (ProcessMgmt)fc.getApplication()
.getVariableResolver().resolveVariable(fc, "processMgmt");
}
/**
* @return Returns the key.
*/
public String getKey() {
return key;
}
/**
* @return Returns the name.
*/
public String getName() {
return name;
}
/**
* @return Returns the typed.
*/
public boolean isTyped() {
return typed;
}
/**
* @return Returns the localizedType.
*/
public String getLocalizedType() {
return localizedType;
}
/**
* Select the resource
*/
public String showAssignments () {
processMgmt().setSelectedResourceKey(key);
return null;
}
/**
* Check if resource is selected.
* @return result
*/
public boolean isSelected () {
return processMgmt().getSelectedResourceKey() != null
&& processMgmt().getSelectedResourceKey().equals (key);
}
}
|