From ece09a1f5ce90f734dfa16067efb41a4b334d56b Mon Sep 17 00:00:00 2001
From: srosse <none@none>
Date: Tue, 31 Jul 2012 17:08:31 +0200
Subject: [PATCH] OO-291: fine tuning of the wording to access an open group

---
 .../ui/main/AccessActionColumnDescriptor.java | 95 +++++++++++++++++++
 .../org/olat/group/ui/main/BGTableItem.java   | 36 +++++--
 .../main/BusinessGroupTableModelWithType.java |  5 +-
 .../ui/main/OpenBusinessGroupsController.java |  2 +-
 .../ui/main/_i18n/LocalStrings_de.properties  |  3 +
 5 files changed, 132 insertions(+), 9 deletions(-)
 create mode 100644 src/main/java/org/olat/group/ui/main/AccessActionColumnDescriptor.java

diff --git a/src/main/java/org/olat/group/ui/main/AccessActionColumnDescriptor.java b/src/main/java/org/olat/group/ui/main/AccessActionColumnDescriptor.java
new file mode 100644
index 00000000000..534a4ef52cf
--- /dev/null
+++ b/src/main/java/org/olat/group/ui/main/AccessActionColumnDescriptor.java
@@ -0,0 +1,95 @@
+/**
+ * <a href="http://www.openolat.org">
+ * OpenOLAT - Online Learning and Training</a><br>
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); <br>
+ * you may not use this file except in compliance with the License.<br>
+ * You may obtain a copy of the License at the
+ * <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
+ * <p>
+ * Unless required by applicable law or agreed to in writing,<br>
+ * software distributed under the License is distributed on an "AS IS" BASIS, <br>
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
+ * See the License for the specific language governing permissions and <br>
+ * limitations under the License.
+ * <p>
+ * Initial code contributed and copyrighted by<br>
+ * 12.10.2011 by frentix GmbH, http://www.frentix.com
+ * <p>
+ */
+package org.olat.group.ui.main;
+
+import static org.olat.group.ui.main.AbstractBusinessGroupListController.*;
+
+import org.olat.core.gui.components.table.DefaultColumnDescriptor;
+import org.olat.core.gui.render.Renderer;
+import org.olat.core.gui.render.StringOutput;
+import org.olat.core.gui.translator.Translator;
+import org.olat.group.model.BGMembership;
+
+/**
+ * 
+ * Description:<br>
+ * 
+ * <P>
+ * Initial Date:  11 oct. 2011 <br>
+ *
+ * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
+ */
+public class AccessActionColumnDescriptor extends DefaultColumnDescriptor {
+	
+	private final Translator translator;
+	
+	public AccessActionColumnDescriptor(final String headerKey, final int dataColumn, final Translator translator) {
+		super(headerKey, dataColumn, null, translator.getLocale());
+		this.translator = translator;
+	}
+
+	@Override
+	public String getAction(int row) {
+		int sortedRow = table.getSortedRow(row);
+		
+		Object memberObj = table.getTableDataModel().getValueAt(sortedRow, BusinessGroupTableModelWithType.Cols.role.ordinal());
+		if(memberObj instanceof BGMembership) {
+			//owner, participant, or in waiting list can leave
+			return TABLE_ACTION_LEAVE;
+		}
+		
+		Object wrapper = table.getTableDataModel().getValueAt(sortedRow, BusinessGroupTableModelWithType.Cols.wrapper.ordinal());
+		if(wrapper instanceof BGTableItem) {
+			BGTableItem item = (BGTableItem)wrapper;
+			if(item.isFull()) {
+				return null;
+			}
+			return TABLE_ACTION_ACCESS;
+		}
+		return null;
+	}
+
+	@Override
+	public void renderValue(StringOutput sb, int row, Renderer renderer) {
+		int sortedRow = table.getSortedRow(row);
+		Object memberObj = table.getTableDataModel().getValueAt(sortedRow, BusinessGroupTableModelWithType.Cols.role.ordinal());
+		if(memberObj instanceof BGMembership) {
+			switch((BGMembership)memberObj) {
+				case owner:
+				case participant:
+					sb.append(translator.translate("table.header.leave")); break;
+				case waiting:
+					sb.append(translator.translate("table.header.leave.waiting")); break;
+			}
+		} else {
+			Object wrapper = table.getTableDataModel().getValueAt(sortedRow, BusinessGroupTableModelWithType.Cols.wrapper.ordinal());
+			if(wrapper instanceof BGTableItem) {
+				BGTableItem item = (BGTableItem)wrapper;
+				if(item.isFull()) {
+					sb.append(translator.translate("table.header.group.full"));
+				} else if(item.isWaitingListEnabled()) {
+					sb.append(translator.translate("table.access.waitingList"));
+				} else {
+					sb.append(translator.translate("table.access"));
+				}
+			}
+		}
+	}
+}
diff --git a/src/main/java/org/olat/group/ui/main/BGTableItem.java b/src/main/java/org/olat/group/ui/main/BGTableItem.java
index 9a35d36fb09..4825a804175 100644
--- a/src/main/java/org/olat/group/ui/main/BGTableItem.java
+++ b/src/main/java/org/olat/group/ui/main/BGTableItem.java
@@ -89,6 +89,21 @@ public class BGTableItem {
 	public Integer getMaxParticipants() {
 		return businessGroup.getMaxParticipants();
 	}
+	
+	public boolean isWaitingListEnabled() {
+		return businessGroup.isWaitingListEnabled();
+	}
+	
+	public boolean isFull() {
+		Integer maxParticipants = businessGroup.getMaxParticipants();
+		if(maxParticipants == null || maxParticipants.intValue() <= 0) {
+			return false;
+		}
+		if(maxParticipants.intValue() <= getNumOfParticipants()) {
+			return true;
+		}
+		return false;
+	}
 
 	public String getBusinessGroupDescription() {
 		return businessGroupDescription;
@@ -172,18 +187,21 @@ public class BGTableItem {
 		private final String name;
 		private final Integer maxParticipants;
 		private int numOfParticipants;
+		private final boolean waitingListEnabled;
 		
 		public BGShort(BusinessGroup group) {
-			this.key = group.getKey();
-			this.name = group.getName().intern();
-			this.maxParticipants = group.getMaxParticipants();
+			key = group.getKey();
+			name = group.getName().intern();
+			maxParticipants = group.getMaxParticipants();
+			waitingListEnabled = group.getWaitingListEnabled() == null ? false : group.getWaitingListEnabled().booleanValue();
 		}
 		
 		public BGShort(BusinessGroupView group) {
-			this.key = group.getKey();
-			this.name = group.getName().intern();
-			this.maxParticipants = group.getMaxParticipants();
-			this.numOfParticipants = group.getNumOfParticipants();
+			key = group.getKey();
+			name = group.getName().intern();
+			maxParticipants = group.getMaxParticipants();
+			numOfParticipants = group.getNumOfParticipants();
+			waitingListEnabled = group.getWaitingListEnabled() == null ? false : group.getWaitingListEnabled().booleanValue();
 		}
 
 		@Override
@@ -213,6 +231,10 @@ public class BGTableItem {
 		public int getNumOfParticipants() {
 			return numOfParticipants;
 		}
+		
+		public boolean isWaitingListEnabled() {
+			return waitingListEnabled;
+		}
 
 		@Override
 		public int hashCode() {
diff --git a/src/main/java/org/olat/group/ui/main/BusinessGroupTableModelWithType.java b/src/main/java/org/olat/group/ui/main/BusinessGroupTableModelWithType.java
index 06a4c4c8a39..ea6a9b34593 100644
--- a/src/main/java/org/olat/group/ui/main/BusinessGroupTableModelWithType.java
+++ b/src/main/java/org/olat/group/ui/main/BusinessGroupTableModelWithType.java
@@ -125,6 +125,8 @@ public class BusinessGroupTableModelWithType extends DefaultTableDataModel<BGTab
 				}
 				return "&infin;";
 			}
+			case wrapper:
+				return wrapped;
 			default:
 				return "ERROR";
 		}
@@ -170,7 +172,8 @@ public class BusinessGroupTableModelWithType extends DefaultTableDataModel<BGTab
 		firstTime("table.header.firstTime"),
 		lastTime("table.header.lastTime"),
 		key("table.header.key"),
-		freePlaces("table.header.freePlaces");
+		freePlaces("table.header.freePlaces"),
+		wrapper("");
 		
 		private final String i18n;
 		
diff --git a/src/main/java/org/olat/group/ui/main/OpenBusinessGroupsController.java b/src/main/java/org/olat/group/ui/main/OpenBusinessGroupsController.java
index 8fd061787dc..b43c316abcb 100644
--- a/src/main/java/org/olat/group/ui/main/OpenBusinessGroupsController.java
+++ b/src/main/java/org/olat/group/ui/main/OpenBusinessGroupsController.java
@@ -83,7 +83,7 @@ public class OpenBusinessGroupsController extends AbstractBusinessGroupListContr
 		groupListCtr.addColumnDescriptor(new CustomRenderColumnDescriptor(Cols.accessTypes.i18n(), Cols.accessTypes.ordinal(), null, getLocale(), ColumnDescriptor.ALIGNMENT_LEFT, acRenderer));
 		CustomCellRenderer roleRenderer = new BGRoleCellRenderer(getLocale());
 		groupListCtr.addColumnDescriptor(new CustomRenderColumnDescriptor(Cols.role.i18n(), Cols.role.ordinal(), null, getLocale(),  ColumnDescriptor.ALIGNMENT_LEFT, roleRenderer));
-		groupListCtr.addColumnDescriptor(new DefaultColumnDescriptor(Cols.accessControlLaunch.i18n(), Cols.accessControlLaunch.ordinal(), TABLE_ACTION_ACCESS, getLocale()));
+		groupListCtr.addColumnDescriptor(new AccessActionColumnDescriptor(Cols.accessControlLaunch.i18n(), Cols.accessControlLaunch.ordinal(), getTranslator()));
 		return 8;
 	}
 	
diff --git a/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
index a97dbed8dab..09ced2e0736 100644
--- a/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
+++ b/src/main/java/org/olat/group/ui/main/_i18n/LocalStrings_de.properties
@@ -69,6 +69,8 @@ table.header.description=Beschreibung
 table.header.edit=\u00C4ndern
 table.header.lastUsage=Zuletzt
 table.header.leave=Verlassen
+table.header.leave.waiting=Verlassen
+table.header.group.full=Voll belegt
 table.header.mark=Favorit
 table.header.type=Typ
 table.header.resources=Kurs
@@ -78,6 +80,7 @@ table.header.lastTime=Zuletzt Besuch
 table.header.key=ID
 table.header.freePlaces=Plätze
 table.access=Belegen
+table.access.waitingList=Warteliste eintragen
 table.delete=Löschen
 table.email=Email versenden
 table.duplicate=Douplizieren
-- 
GitLab