|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.ItemContext
public class ItemContext
This item is a helper class for client applications when they need to store information about the current context for plugins that needs to find out the current context of the running client application. It is optional to use this class and it is recommended that plugins and client applications that expects to find context information also can handle situations without any context information. Some of the settings in this objects are saved in the database, some not.
Typical example for using this class are:
A client application storing list/table settings
SessionControl sc = ... ItemContext current = sc.getCurrentContext(Item.SAMPLE); current.setRowsPerPage(50); current.setPage(0); current.setSortProperty("name"); current.setSortDirection(SortDirection.DESC); current.setPropertyFilter( new PropertyFilter("name", Operator.LIKE, "Nicklas%", Type.STRING) ); ItemQuery query = Sample.getQuery(); current.configureQuery(query, true); // The query will now return the 50 first samples with a // a name starting with 'Nicklas' sorted in descending order
A client application using filter information when creating new items
SessionControl sc = ... DbControl dc = sc.newDbControl(); ItemContext current = sc.getCurrentContext(Item.SAMPLE); Sample sample = Sample.getNew(dc); if (current.getPropertyValue("name") != null) { sample.setName(current.getPropertyValue("name")); } // The name is now 'Nicklas%'
Plugin finds out which items in a list has been selected
SessionControl sc = ... ItemContext current = sc.getCurrentContext(Item.SAMPLE); ItemQuery query = Sample.getQuery(); Set selected = current.getSelected(); if (selected != null && selected.size() > 0) { query.restrict( Restrictions.in(Hql.property("id"), Expressions.parameter("selected", selected, Type.INT)) ); ) // The query will now return the selected items only
An import plugin asks client application for a file with a specific file type
public RequestInformation getRequestInformation(GuiContext context, String command) throws BaseException { RequestInformation requestInformation = null; if (command.equals(Request.COMMAND_CONFIGURE_PLUGIN)) { requestInformation = getConfigurePluginParameters(context); } else if (command.equals(Request.COMMAND_CONFIGURE_JOB)) { requestInformation = getConfigureJobParameters(context); ItemContext fileContext = sc.getCurrentContext(Item.FILE); fileContext.setPropertyFilter(FileType.getPropertyFilter(FileType.REPORTER)); } return requestInformation; }
SessionControl.getCurrentContext(Item)
,
SessionControl.saveCurrentContextAs(Item, String, boolean, boolean)
Nested Class Summary | |
---|---|
(package private) static class |
ItemContext.PropertyFilterPair
Holds a pair of filter. |
static class |
ItemContext.SortDirection
Enumeration used to specify the sort direction. |
Field Summary | |
---|---|
private static JepFunction |
ch
|
private int |
contextId
|
static String |
DEFAULT_NAME
This is the name of the default context which is automatically saved when a user is logging out. |
private Set<Include> |
include
|
private int |
itemId
|
private Item |
itemType
|
private String |
message
|
private String |
name
|
private Map<String,Object> |
objects
|
private int |
page
|
private Permission |
permission
|
private Map<String,ItemContext.PropertyFilterPair> |
propertyFilters
|
private Query |
query
|
private static JepFunction |
raw
|
private static JepFunction |
rawCh
|
private static JepFunction |
rep
|
private int |
rowsPerPage
|
private Set<Integer> |
selected
|
private Map<String,String> |
settings
|
private ItemContext.SortDirection |
sortDirection
|
private String |
sortProperty
|
private String |
subContext
|
Constructor Summary | |
---|---|
ItemContext(ContextData context)
Create a new context from a loaded database object. |
|
ItemContext(Item itemType,
String subContext,
String name)
Create a new empty context. |
|
ItemContext(String sortProperty,
ItemContext.SortDirection sortDirection,
int rowsPerPage,
int page)
Create a new context. |
Method Summary | |
---|---|
void |
clearAllRecent()
Clear all recently used values lists. |
void |
clearRecent(Item itemType)
Clear the recently used items list from items of the specified type. |
void |
clearRecent(Item itemType,
String subList)
Clear the recently used items sublist from items of the specified type. |
void |
clearRecent(String key)
Clear the recently used values list. |
void |
configureQuery(DbControl dc,
DynamicQuery query,
List<String> selectionList)
Use the settings in this context to configure a dynamic query. |
void |
configureQuery(DbControl dc,
EntityQuery query,
boolean autoLeftJoin)
Use the settings in this context to configure a query. |
void |
configureQuery(EntityQuery query,
boolean autoLeftJoin)
Deprecated. Use configureQuery(DbControl, EntityQuery, boolean) instead |
(package private) void |
copyFrom(ItemContext other,
boolean forceAll)
Copy settings from another context to this context. |
void |
filterOnSelectedItems(EntityQuery query)
Add a filter to the given query that restricts it to only return items that have been selected. |
int |
getContextId()
Get the database ID of this context. |
(package private) ContextData |
getData(String name,
UserData user,
ClientData client,
boolean isPublic)
Create a new database context object from this context. |
static Expression |
getDynamicExpression(DbControl dc,
String propertyDef)
Create an Expression from a string. |
static Select |
getDynamicSelect(DbControl dc,
String propertyDef)
Same as getDynamicExpression(DbControl, String) but generates
a select object instead. |
Restriction |
getFilterRestriction(String property,
DbControl dc,
EntityQuery query)
Create a restriction from a property filter. |
int |
getId()
Get the ID of the current item in this context. |
Set<Include> |
getInclude()
Get a Set object to specify Include options for
a query. |
Permission |
getItemPermission()
The permission the logged in user must have for items returned by a query. |
Item |
getItemType()
Get the type of item this object is storing context for. |
String |
getMessage()
Get a message that should be displayed by a client application as soon as it is appropriate to do so. |
String |
getName()
Get the name of this context. |
int |
getNumPropertyFilters()
Get the number of property filters stored in this context. |
int |
getNumRecent(Item itemType)
Get the number of recently used items in the list. |
int |
getNumRecent(Item itemType,
String subList)
Get the number of recently used items in a list with a sublist. |
int |
getNumRecent(String key)
Get the number of recently used value in the list. |
Object |
getObject(String name)
Get an object. |
int |
getPage()
Get the current table page. |
PropertyFilter |
getPropertyFilter(String property)
Get a filter for a property. |
Collection<PropertyFilter> |
getPropertyFilters()
Get a collection of all property filters stored in this context. |
Object |
getPropertyObject(String property)
|
String |
getPropertyValue(String property)
Get the value of a property filter. |
Query |
getQuery()
|
List<? extends BasicItem> |
getRecent(DbControl dc,
Item itemType)
Get all recently used items of the specified type. |
BasicItem |
getRecent(DbControl dc,
Item itemType,
int index)
|
List<? extends BasicItem> |
getRecent(DbControl dc,
Item itemType,
String subList)
Get all recently used items of the specified type in a given sublist. |
BasicItem |
getRecent(DbControl dc,
Item itemType,
String subList,
int index)
|
List<String> |
getRecent(String key)
Get all recently used values for the specified key. |
String |
getRecent(String key,
int index)
|
private String |
getRecentSettingName(String key)
|
int |
getRowsPerPage()
Get the number of rows the current table page is displaying. |
Set<Integer> |
getSelected()
Get a Set object to specify the ID:s of all items that are
currently selected. |
String |
getSetting(String name)
Get a value. |
ItemContext.SortDirection |
getSortDirection()
If the items are sorted in ascending or descending order. |
Order |
getSortOrder()
Get the current sort property as an Order instance. |
String |
getSortProperty()
Get the name of the property the current listing is sorted by. |
String |
getSubContext()
Get the sub-context name of this context. |
private List<? extends BasicItem> |
loadRecent(DbControl dc,
Item itemType,
String key)
|
private BasicItem |
loadRecent(DbControl dc,
Item itemType,
String key,
int index)
|
void |
removeAllPropertyFilters()
Remove all property filter from this context. |
void |
removeAllTemporaryFilters()
Remove all temporary filters. |
Object |
removeObject(String name)
Remove a value. |
void |
removePropertyFilter(String property)
Remove a property filter. |
String |
removeSetting(String name)
Remove a value. |
void |
removeTemporaryFilter(String property)
Remote a temporary filter for the given property. |
void |
setId(int id)
Set the ID of the current item in this context. |
void |
setItemPermission(Permission permission)
Specify the permission the logged in user must have for items returned by a query. |
void |
setMessage(String message)
Set a message to be displayed by a client application as soon as it is appropriate to do so. |
Object |
setObject(String name,
Object value)
Set a value. |
void |
setPage(int page)
Set the current table page. |
void |
setPropertyFilter(PropertyFilter filter)
Set a property filter. |
void |
setQuery(Query query)
|
void |
setRecent(BasicItem item,
int maxInList)
Add an item to the "recently used items" list. |
void |
setRecent(BasicItem item,
String subList,
int maxInList)
Add an item to the "recently used items" list. |
private void |
setRecent(String key,
List<String> recent)
|
void |
setRecent(String key,
String value,
int maxInList)
Add a value to the list of recently used values for the specified key. |
void |
setRowsPerPage(int rowsPerPage)
Set the number of rows the current table page should show. |
String |
setSetting(String name,
String value)
Set a value. |
void |
setSortDirection(ItemContext.SortDirection sortDirection)
Set the sort direction (ascending or descending) of the current listing. |
void |
setSortProperty(String sortProperty)
Set the name of the property that the current listing is sorted by. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String DEFAULT_NAME
private static final JepFunction ch
private static final JepFunction rawCh
private static final JepFunction raw
private static final JepFunction rep
private final String name
private final Item itemType
private final String subContext
private int contextId
private int itemId
private Set<Integer> selected
private int rowsPerPage
private int page
private String sortProperty
private String message
private ItemContext.SortDirection sortDirection
private Set<Include> include
private Permission permission
private Map<String,ItemContext.PropertyFilterPair> propertyFilters
private Map<String,String> settings
private Map<String,Object> objects
private Query query
Constructor Detail |
---|
public ItemContext(String sortProperty, ItemContext.SortDirection sortDirection, int rowsPerPage, int page)
sortProperty
- The property used to sort a listsortDirection
- If the items should be sorted in ascending or descending orderrowsPerPage
- The number of rows to display on a single pagepage
- The page number of the currently displayed page, starting at 0ItemContext(Item itemType, String subContext, String name)
ItemContext(ContextData context)
Method Detail |
---|
ContextData getData(String name, UserData user, ClientData client, boolean isPublic)
name
- The name to use, or null if the current name should be useduser
- The user that should own the context objectclient
- The client application currently in useisPublic
- If the context should be public or notpublic Item getItemType()
public String getSubContext()
public String getName()
public int getContextId()
public int getId()
public void setId(int id)
id
- The ID of the item, or 0 if no item is currentpublic int getRowsPerPage()
public void setRowsPerPage(int rowsPerPage)
rowsPerPage
- The number of rows to show on a pagepublic int getPage()
public void setPage(int page)
page
- The number of the page, starting at 0public String getSortProperty()
public void setSortProperty(String sortProperty)
sortProperty
- The name of the propertypublic ItemContext.SortDirection getSortDirection()
public void setSortDirection(ItemContext.SortDirection sortDirection)
sortDirection
- The sort directionpublic Order getSortOrder()
Order
instance.
If multiple properties are used for sorting, this method only
returns the first property.
public String getMessage()
configureQuery(EntityQuery, boolean)
sets an error message if it couldn't configure the query for some reason.
public void setMessage(String message)
configureQuery(EntityQuery, boolean)
sets an error message if it couldn't configure the query for some reason.
This property is not stored in the database.
message
- The messagepublic Set<Include> getInclude()
Set
object to specify Include
options for
a query. This property is stored in the database.
EntityQuery
public void setItemPermission(Permission permission)
EntityQuery.setItemPermission(Permission)
public Permission getItemPermission()
EntityQuery.getItemPermission()
public Set<Integer> getSelected()
Set
object to specify the ID:s of all items that are
currently selected. This property is not stored in the database.
public void setPropertyFilter(PropertyFilter filter)
filter
- The new property filterPropertyFilter.isTemporary()
public PropertyFilter getPropertyFilter(String property)
property
- The name of the property
PropertyFilter
object or
null if no filter existspublic Collection<PropertyFilter> getPropertyFilters()
public int getNumPropertyFilters()
public String getPropertyValue(String property)
getPropertyFilter(property).getValue()
but also handles the case of a non-existing filter for the
specfied property.
property
- The name of the property
public void removePropertyFilter(String property)
property
- The name of the propertypublic void removeTemporaryFilter(String property)
property
- The name of the propertypublic Object getPropertyObject(String property)
public void removeAllPropertyFilters()
public void removeAllTemporaryFilters()
public Restriction getFilterRestriction(String property, DbControl dc, EntityQuery query)
property
- The propertydc
- A DbControl that should be used if database access is neededquery
- The query that the filter is going to be used in (can be
null for most properties)
public void setRecent(BasicItem item, int maxInList)
maxInList
items.
Note! The lists are stored as string of colon-separated ID:s in
the setting given by the item type. For example the recently used
protocols are found in the setting:
getSetting("PROTOCOL.recent")
. Client code is advised to
not change these settings.
item
- The item to addmaxInList
- The maximum number of items in the listpublic void setRecent(BasicItem item, String subList, int maxInList)
maxInList
items.
Note! The lists are stored as string of colon-separated ID:s in
the setting given by the item type and sublist name. For example the
recently used protocols are found in the setting:
getSetting("PROTOCOL.subList.recent")
. Client code is advised to
not change these settings.
item
- The item to addsubList
- The sublistmaxInList
- The maximum number of items in the listpublic void setRecent(String key, String value, int maxInList)
maxInList
values. If the value is already in the list
it is moved to the front of the list.
Note! The lists are stored as string of colon-separated ID:s in
the setting given by the key. For example, if key is "RAWDATATYPE",
the recently used values are found in the setting:
getSetting("RAWDATATYPE.recent")
. Client code is advised to
not change these settings.
key
- The key to the listvalue
- The value to addmaxInList
- The maximum number of values in the listpublic int getNumRecent(Item itemType)
itemType
- The type of itemspublic int getNumRecent(Item itemType, String subList)
itemType
- The type of itemssubList
- The name of the sublistpublic int getNumRecent(String key)
key
- The key to the listpublic List<? extends BasicItem> getRecent(DbControl dc, Item itemType)
getNumRecent(Item)
may return a larger number than what is actually returned in this
list.
dc
- The DbControl used to access the databaseitemType
- The type of items
public List<? extends BasicItem> getRecent(DbControl dc, Item itemType, String subList)
getNumRecent(Item)
may return a larger number than what is actually returned in this
list.
dc
- The DbControl used to access the databaseitemType
- The type of itemssubList
- The name of the sublist
private List<? extends BasicItem> loadRecent(DbControl dc, Item itemType, String key)
public BasicItem getRecent(DbControl dc, Item itemType, int index)
public BasicItem getRecent(DbControl dc, Item itemType, String subList, int index)
private BasicItem loadRecent(DbControl dc, Item itemType, String key, int index)
public List<String> getRecent(String key)
setRecent(String, String, int)
instead.
key
- The key to the list
public String getRecent(String key, int index)
public void clearRecent(Item itemType)
itemType
- The type of itemspublic void clearRecent(Item itemType, String subList)
itemType
- The type of itemssubList
- The name of the sublistpublic void clearRecent(String key)
key
- The key to the listpublic void clearAllRecent()
private String getRecentSettingName(String key)
private void setRecent(String key, List<String> recent)
public String getSetting(String name)
name
- The name of the value
setSetting(String, String)
public String setSetting(String name, String value)
name
- The name of the valuevalue
- The value
getSetting(String)
public String removeSetting(String name)
name
- The name of the value
public Object getObject(String name)
name
- The name of the value
setObject(String, Object)
public Object setObject(String name, Object value)
name
- The name of the valuevalue
- The value
getObject(String)
public Object removeObject(String name)
name
- The name of the value
public Query getQuery()
public void setQuery(Query query)
public void configureQuery(EntityQuery query, boolean autoLeftJoin) throws BaseException
configureQuery(DbControl, EntityQuery, boolean)
instead
BaseException
public void configureQuery(DbControl dc, EntityQuery query, boolean autoLeftJoin) throws BaseException
Query.setReturnTotalCount(boolean)
is set to true.
Query.setFirstResult(int)
and Query.setMaxResults(int)
is set using getPage()
and getRowsPerPage()
settings.
getSortProperty()
and getSortDirection()
is
used to sort the query. If the sort property starts with a dollar ($)
sign it is interpreted as a alias.property
value, ignoring
the root alias of the query. The sort property may contain multiple properties
if they are separated by a comma.
getInclude()
is used to set EntityQuery.include(Include[])
or @link EntityQuery#exclude(Include[])} options.
Restriction
:s to the
query.
dc
- The DbControl that will be used to execute the queryquery
- The query to configureautoLeftJoin
- If true, and the sort property and filters are checked
for associations to other items, which are automatically left joined to
the query (instead of the hibernate default of inner join) (this feature
is experimental)
BaseException
- If configuring the query fails.void copyFrom(ItemContext other, boolean forceAll)
forceAll
parameter is set.
public void filterOnSelectedItems(EntityQuery query)
query
- The query to filterpublic void configureQuery(DbControl dc, DynamicQuery query, List<String> selectionList) throws BaseException
AbstractQuery.setReturnTotalCount(boolean)
is set to true.
AbstractQuery.setFirstResult(int)
and AbstractQuery.setMaxResults(int)
is set using getPage()
and getRowsPerPage()
settings.
dc
- A DbControl to use if the database needs to be accessedquery
- The query to configureselectionList
- A list of expression that we want to select
from the query
BaseException
- If the configuring the query fails.public static Expression getDynamicExpression(DbControl dc, String propertyDef)
Expression
from a string. If the string starts with:
Dynamic.column(VirtualColumn)
to create the expression
for VirtualColumn.channelRaw(int)
Dynamic.rawData(String)
to create the expression.
Dynamic.reporter(String)
to create the expression.
Dynamic.extraValue(ExtraValue)
to create the expression and
DynamicSpotQuery.joinExtraValue(ExtraValue, JoinType)
to automatically
join the extra values.
Jep.formulaToExpression(String, JepFunction[])
method.
Dynamic.column(VirtualColumn)
method:
VirtualColumn.POSITION
VirtualColumn.COLUMN
dc
- A DbControl to use if the database needs to be accessedpropertyDef
- The string to use for creating the expression.
public static Select getDynamicSelect(DbControl dc, String propertyDef)
getDynamicExpression(DbControl, String)
but generates
a select object instead.
dc
- DbControl used to access the databasepropertyDef
- The string to use for creating the expression.
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |