dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #15772
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5807: Impl paging supportive methods
------------------------------------------------------------
revno: 5807
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-01-26 12:40:29 +0100
message:
Impl paging supportive methods
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nService.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/paging/Paging.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java 2012-01-22 09:58:04 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingService.java 2012-01-26 11:40:29 +0000
@@ -50,7 +50,7 @@
final String KEY_STYLE_DIRECTORY = "stylesheetDirectory";
final String KEY_MESSAGE_EMAIL_NOTIFICATION = "keyMessageEmailNotification";
final String KEY_MESSAGE_SMS_NOTIFICATION = "keyMessageSmsNotification";
- final String KEY_DB_LOCALE = "localeUserSetting";
+ final String KEY_DB_LOCALE = "keyLocaleUserSetting";
final int DEFAULT_CHARTS_IN_DASHBOARD = 4;
final List<Integer> DASHBOARD_CHARTS_TO_DISPLAY = Arrays.asList( 4, 6, 8 );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2012-01-22 12:16:48 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/DefaultI18nService.java 2012-01-26 11:40:29 +0000
@@ -280,6 +280,11 @@
return (Locale) userSettingService.getUserSetting( UserSettingService.KEY_DB_LOCALE );
}
+ public boolean currentLocaleIsBase()
+ {
+ return getCurrentLocale() == null;
+ }
+
public List<Locale> getAvailableLocales()
{
return locales;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nService.java 2012-01-22 09:58:04 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/i18n/I18nService.java 2012-01-26 11:40:29 +0000
@@ -74,5 +74,7 @@
Locale getCurrentLocale();
+ boolean currentLocaleIsBase();
+
List<Locale> getAvailableLocales();
}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/paging/Paging.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/paging/Paging.java 2011-04-02 12:26:50 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/paging/Paging.java 2012-01-26 11:40:29 +0000
@@ -27,6 +27,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
+
/**
* @author Quang Nguyen
*/
@@ -155,4 +163,59 @@
{
this.link = link;
}
+
+ // -------------------------------------------------------------------------
+ // Paging static utility methods
+ // -------------------------------------------------------------------------
+
+ public static <T extends IdentifiableObject> List<T> getObjectsBetweenByName( Collection<T> objects, String name, int first, int max )
+ {
+ final List<T> list = new ArrayList<T>();
+
+ if ( name != null )
+ {
+ for ( T object : objects )
+ {
+ if ( object != null && object.getName() != null && object.getName().toLowerCase().contains( name.toLowerCase() ) )
+ {
+ list.add( object );
+ }
+ }
+ }
+
+ Collections.sort( list, IdentifiableObjectNameComparator.INSTANCE );
+
+ int last = first + max;
+
+ return list.subList( first, last );
+ }
+
+ public static <T extends IdentifiableObject> List<T> getObjectsBetween( Collection<T> objects, int first, int max )
+ {
+ final List<T> list = new ArrayList<T>( objects );
+
+ Collections.sort( list, IdentifiableObjectNameComparator.INSTANCE );
+
+ int last = first + max;
+
+ return list.subList( first, last );
+ }
+
+ public static <T extends IdentifiableObject> int getCountByName( Collection<T> objects, String name )
+ {
+ int count = 0;
+
+ if ( name != null )
+ {
+ for ( IdentifiableObject object : objects )
+ {
+ if ( object != null && object.getName() != null && object.getName().toLowerCase().contains( name.toLowerCase() ) )
+ {
+ count++;
+ }
+ }
+ }
+
+ return count;
+ }
}