Compare commits
5 Commits
25fa8addca
...
6508c02e9a
Author | SHA1 | Date |
---|---|---|
Massimiliano Assante | 6508c02e9a | |
Massimiliano Assante | 7115d7675e | |
Massimiliano Assante | bcc5f729ae | |
Massimiliano Assante | 024e218872 | |
Massimiliano Assante | d7ae2098b4 |
|
@ -29,7 +29,7 @@
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
|
|
|
@ -1,10 +1,22 @@
|
||||||
<ReleaseNotes>
|
<ReleaseNotes>
|
||||||
|
<Changeset component="portlets-widgets.pickitem-widget.1-3-0"
|
||||||
|
date="2018-03-19">
|
||||||
|
<Change>Enhanced information passed when an item is selected, now passing more info such as if the item is a group or not and the item id
|
||||||
|
</Change>
|
||||||
|
</Changeset>
|
||||||
|
<Changeset component="portlets-widgets.pickitem-widget.1-2-0"
|
||||||
|
date="2016-06-30">
|
||||||
|
<Change>Fix for Incident #4246, in some cases notification email
|
||||||
|
resulting from posts are "broken"</Change>
|
||||||
|
<Change>Fix for hashtags not allowing to use enter after picked one
|
||||||
|
</Change>
|
||||||
|
</Changeset>
|
||||||
<Changeset component="portlets-widgets.pickitem-widget.1-1-0"
|
<Changeset component="portlets-widgets.pickitem-widget.1-1-0"
|
||||||
date="2015-07-14">
|
date="2015-07-14">
|
||||||
<Change>Ported to GWT 2.7.0</Change>
|
<Change>Ported to GWT 2.7.0</Change>
|
||||||
<Change>Fix for Bug #320, Users tagging does not work if @ is in the
|
<Change>Fix for Bug #320, Users tagging does not work if @ is in the
|
||||||
middle of already typed text</Change>
|
middle of already typed text
|
||||||
|
</Change>
|
||||||
</Changeset>
|
</Changeset>
|
||||||
<Changeset component="portlets-widgets.pickitem-widget.1-0-0"
|
<Changeset component="portlets-widgets.pickitem-widget.1-0-0"
|
||||||
date="2013-10-21">
|
date="2013-10-21">
|
||||||
|
|
72
pom.xml
72
pom.xml
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<groupId>org.gcube.portlets.widgets</groupId>
|
<groupId>org.gcube.portlets.widgets</groupId>
|
||||||
<artifactId>pickitem-widget</artifactId>
|
<artifactId>pickitem-widget</artifactId>
|
||||||
<version>1.1.1-SNAPSHOT</version>
|
<version>2.0.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>gCube Pick Item Widget</name>
|
<name>gCube Pick Item Widget</name>
|
||||||
<description>
|
<description>
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
<gwtVersion>2.7.0</gwtVersion>
|
<gwtVersion>2.7.0</gwtVersion>
|
||||||
<distroDirectory>distro</distroDirectory>
|
<distroDirectory>distro</distroDirectory>
|
||||||
<maven.compiler.source>1.7</maven.compiler.source>
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
<maven.compiler.target>1.7</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
<webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory>
|
||||||
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -52,6 +52,36 @@
|
||||||
<version>${gwtVersion}</version>
|
<version>${gwtVersion}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.servlet</groupId>
|
||||||
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.portlet</groupId>
|
||||||
|
<artifactId>portlet-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.gcube.dvos</groupId>
|
||||||
|
<artifactId>usermanagement-core</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.liferay.portal</groupId>
|
||||||
|
<artifactId>portal-service</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.liferay.portal</groupId>
|
||||||
|
<artifactId>util-java</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<resources>
|
<resources>
|
||||||
|
@ -66,8 +96,8 @@
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.7</source>
|
<source>${maven.compiler.source}</source>
|
||||||
<target>1.7</target>
|
<target>${maven.compiler.target}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
@ -144,23 +174,23 @@
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- GWT Maven Plugin -->
|
<!-- GWT Maven Plugin -->
|
||||||
<!-- <plugin> -->
|
<!-- <plugin> -->
|
||||||
<!-- <groupId>org.codehaus.mojo</groupId> -->
|
<!-- <groupId>org.codehaus.mojo</groupId> -->
|
||||||
<!-- <artifactId>gwt-maven-plugin</artifactId> -->
|
<!-- <artifactId>gwt-maven-plugin</artifactId> -->
|
||||||
<!-- <version>2.5.1</version> -->
|
<!-- <version>2.5.1</version> -->
|
||||||
<!-- <executions> -->
|
<!-- <executions> -->
|
||||||
<!-- <execution> -->
|
<!-- <execution> -->
|
||||||
<!-- <goals> -->
|
<!-- <goals> -->
|
||||||
<!-- <goal>compile</goal> -->
|
<!-- <goal>compile</goal> -->
|
||||||
<!-- <goal>test</goal> -->
|
<!-- <goal>test</goal> -->
|
||||||
<!-- </goals> -->
|
<!-- </goals> -->
|
||||||
<!-- </execution> -->
|
<!-- </execution> -->
|
||||||
<!-- </executions> -->
|
<!-- </executions> -->
|
||||||
<!-- <configuration> -->
|
<!-- <configuration> -->
|
||||||
<!-- <runTarget>PickItem.html</runTarget> -->
|
<!-- <runTarget>PickItem.html</runTarget> -->
|
||||||
<!-- <hostedWebapp>${webappDirectory}</hostedWebapp> -->
|
<!-- <hostedWebapp>${webappDirectory}</hostedWebapp> -->
|
||||||
<!-- </configuration> -->
|
<!-- </configuration> -->
|
||||||
<!-- </plugin> -->
|
<!-- </plugin> -->
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package org.gcube.portlets.widgets.pickitem.client.dialog;
|
package org.gcube.portlets.widgets.pickitem.client.dialog;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages;
|
import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEvent;
|
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEvent;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEventHandler;
|
import org.gcube.portlets.widgets.pickitem.client.events.PickedItemEventHandler;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.oracle.UserOracle;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.oracle.UserSuggestion;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.uibinder.NoPhotoTemplate;
|
import org.gcube.portlets.widgets.pickitem.client.uibinder.NoPhotoTemplate;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.uibinder.SelectableItem;
|
import org.gcube.portlets.widgets.pickitem.client.uibinder.SelectableItem;
|
||||||
import org.gcube.portlets.widgets.pickitem.client.uibinder.WithPhotoTemplate;
|
import org.gcube.portlets.widgets.pickitem.client.uibinder.WithPhotoTemplate;
|
||||||
|
@ -55,7 +58,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
private int itemCursorIndexStart = -1;
|
private int itemCursorIndexStart = -1;
|
||||||
boolean handleNonCharKeys = false;
|
boolean handleNonCharKeys = false;
|
||||||
|
|
||||||
private final MultiWordSuggestOracle oracle = new MultiWordSuggestOracle();
|
private MultiWordSuggestOracle oracle;
|
||||||
|
|
||||||
private int displayIndexSelected;
|
private int displayIndexSelected;
|
||||||
|
|
||||||
|
@ -64,6 +67,8 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
private char triggerChar;
|
private char triggerChar;
|
||||||
private ArrayList<ItemBean> beans;
|
private ArrayList<ItemBean> beans;
|
||||||
|
|
||||||
|
private String context; //e.g. /gcube/devNext/NextNext
|
||||||
|
|
||||||
//needed because is selected when it popups
|
//needed because is selected when it popups
|
||||||
private Widget first;
|
private Widget first;
|
||||||
private boolean hasPhoto;
|
private boolean hasPhoto;
|
||||||
|
@ -77,38 +82,56 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param triggerChar the 'single char' used to trigger the items list show, e.g. '@', '#' ....
|
* @param triggerChar the 'single char' used to trigger the items list show, e.g. '@', '#' ....
|
||||||
* @param the list of user to pick
|
* @param the list of user to pick as {@link ArrayList} of {@link ItemBean}
|
||||||
* @param eventBus the event bus on where the widget will fire the selected user event
|
* @param eventBus the event bus on where the widget will fire the selected user event
|
||||||
* @param widthInPixel the desired width (grater than 199 pixel)
|
* @param widthInPixel the desired width (grater than 199 pixel)
|
||||||
* @param hasPhoto tell of you have want to show photo for the item or not
|
|
||||||
* @param includeTriggerChar true if your suggestions start with the trigger char (e.g. #anHashTag triggered by #) false otherwise
|
|
||||||
*/
|
*/
|
||||||
public PickItemsDialog(char triggerChar, ArrayList<ItemBean> beans, final HandlerManager eventBus, int widthInPixel) {
|
public PickItemsDialog(char triggerChar, ArrayList<ItemBean> beans, final HandlerManager eventBus, int widthInPixel) {
|
||||||
super(true, false);
|
this(triggerChar, eventBus, widthInPixel, null);
|
||||||
if (widthInPixel < 200) {
|
|
||||||
throw new IllegalArgumentException("width must be greater than 199");
|
|
||||||
}
|
|
||||||
this.eventBus = eventBus;
|
|
||||||
this.triggerChar = triggerChar;
|
|
||||||
this.includeTriggerChar = false;
|
|
||||||
this.hasPhoto = false;
|
|
||||||
this.beans = beans;
|
this.beans = beans;
|
||||||
focusPanel.setWidth(widthInPixel+"px");
|
oracle = new MultiWordSuggestOracle(); //not async version
|
||||||
mainPanel.setWidth(widthInPixel+"px");
|
GWT.log("new constructor");
|
||||||
setWidth(widthInPixel+"px");
|
|
||||||
focusPanel.add(mainPanel);
|
|
||||||
setWidget(focusPanel);
|
|
||||||
setStyleName("pickDialog");
|
|
||||||
|
|
||||||
//add the user fill names to the oracle
|
//add the user fill names to the oracle
|
||||||
for (ItemBean bean : beans) {
|
for (ItemBean bean : beans) {
|
||||||
oracle.add(bean.getAlternativeName());
|
oracle.add(bean.getAlternativeName());
|
||||||
|
|
||||||
// if it is a team, set the avatar
|
// if it is a team, set the avatar
|
||||||
if(bean.isItemGroup())
|
if(bean.isItemGroup())
|
||||||
bean.setThumbnailURL(CssAndImages.INSTANCE.iconTeam().getURL());
|
bean.setThumbnailURL(CssAndImages.INSTANCE.iconTeam().getSafeUri().asString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this constructor for users, the list of the users is automatically loaded from the VRE passed in the context param
|
||||||
|
* Note that you must declare the pick item widget servlet in this case
|
||||||
|
* @param triggerChar the 'single char' used to trigger the items list show, e.g. '@', '#' ....
|
||||||
|
* @param eventBus the event bus on where the widget will fire the selected user event
|
||||||
|
* @param widthInPixel the desired width (grater than 199 pixel)
|
||||||
|
* @param context the context (VRE scope e.g. /gcube/devNext/NextNext) from where to load the users and groups
|
||||||
|
*/
|
||||||
|
public PickItemsDialog(char triggerChar, final HandlerManager eventBus, int widthInPixel, String context) {
|
||||||
|
super(true, false);
|
||||||
|
if (widthInPixel < 200) {
|
||||||
|
throw new IllegalArgumentException("width must be greater than 199");
|
||||||
|
}
|
||||||
|
this.context = context;
|
||||||
|
oracle = new UserOracle(context); //by default we use the async version;
|
||||||
|
this.eventBus = eventBus;
|
||||||
|
this.triggerChar = triggerChar;
|
||||||
|
this.includeTriggerChar = false;
|
||||||
|
this.hasPhoto = false;
|
||||||
|
this.beans = new ArrayList<>();
|
||||||
|
focusPanel.setWidth(widthInPixel+"px");
|
||||||
|
mainPanel.setWidth(widthInPixel+"px");
|
||||||
|
setWidth(widthInPixel+"px");
|
||||||
|
focusPanel.add(mainPanel);
|
||||||
|
setWidget(focusPanel);
|
||||||
|
setStyleName("pickDialog");
|
||||||
|
if (oracle instanceof UserOracle) {
|
||||||
|
UserOracle asyncOracle = (UserOracle) oracle;
|
||||||
|
asyncOracle.addContacts(getAllUsers());
|
||||||
|
}
|
||||||
|
|
||||||
//remove the first selected when hovering
|
//remove the first selected when hovering
|
||||||
focusPanel.addMouseOverHandler(new MouseOverHandler() {
|
focusPanel.addMouseOverHandler(new MouseOverHandler() {
|
||||||
|
@ -137,11 +160,17 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
eventBus.addHandler(PickedItemEvent.TYPE, new PickedItemEventHandler() {
|
eventBus.addHandler(PickedItemEvent.TYPE, new PickedItemEventHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onSelectedItem(PickedItemEvent event) {
|
public void onSelectedItem(PickedItemEvent event) {
|
||||||
GWT.log("GOT @ CAZZEVENT! "+ event.getSelectedItem().getAlternativeName());
|
GWT.log("GOT EVENT "+ event.getSelectedItem().getAlternativeName());
|
||||||
stopListening = true;
|
stopListening = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
//just used in devlopment
|
||||||
|
private List<ItemBean> getAllUsers() {
|
||||||
|
List<ItemBean> toReturn = new ArrayList<>();
|
||||||
|
toReturn.add(new ItemBean("id", "username", "Andrea Rossi Dev", "email"));
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* use if you have want to show a photo for the item or not, remember to provide it in {@link ItemBean} instances
|
* use if you have want to show a photo for the item or not, remember to provide it in {@link ItemBean} instances
|
||||||
*/
|
*/
|
||||||
|
@ -157,7 +186,9 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
|
|
||||||
private void handleMouseDown() {
|
private void handleMouseDown() {
|
||||||
SelectableItem ut = (SelectableItem) mainPanel.getWidget(displayIndexSelected);
|
SelectableItem ut = (SelectableItem) mainPanel.getWidget(displayIndexSelected);
|
||||||
eventBus.fireEvent(new PickedItemEvent(new ItemBean("id", "username", ut.getItemName(), "thumb"), this.triggerChar, itemCursorIndexStart, itemCursorIndexEnd));
|
ItemBean itemBean = new ItemBean(ut.getItemId(), "username", ut.getItemName(), "thumb");
|
||||||
|
itemBean.setItemGroup(ut.isGroup());
|
||||||
|
eventBus.fireEvent(new PickedItemEvent(itemBean, this.triggerChar, itemCursorIndexStart, itemCursorIndexEnd));
|
||||||
hide();
|
hide();
|
||||||
select(0); //RESET
|
select(0); //RESET
|
||||||
}
|
}
|
||||||
|
@ -214,6 +245,7 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
* @param currText the text being typed
|
* @param currText the text being typed
|
||||||
*/
|
*/
|
||||||
private boolean pickingUser(String currText) {
|
private boolean pickingUser(String currText) {
|
||||||
|
GWT.log("ci arriva");
|
||||||
if (currText.trim().length() > 0) {
|
if (currText.trim().length() > 0) {
|
||||||
if (includeTriggerChar)
|
if (includeTriggerChar)
|
||||||
showSuggestions(triggerChar+currText);
|
showSuggestions(triggerChar+currText);
|
||||||
|
@ -251,7 +283,9 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
ut = (SelectableItem) mainPanel.getWidget(0);
|
ut = (SelectableItem) mainPanel.getWidget(0);
|
||||||
else
|
else
|
||||||
ut = (SelectableItem) mainPanel.getWidget(displayIndexSelected);
|
ut = (SelectableItem) mainPanel.getWidget(displayIndexSelected);
|
||||||
eventBus.fireEvent(new PickedItemEvent(new ItemBean("id", "username", ut.getItemName(), "thumb"), this.triggerChar, itemCursorIndexStart, itemCursorIndexEnd));
|
ItemBean itemBean = new ItemBean(ut.getItemId(), "username", ut.getItemName(), "thumb");
|
||||||
|
itemBean.setItemGroup(ut.isGroup());
|
||||||
|
eventBus.fireEvent(new PickedItemEvent(itemBean, this.triggerChar, itemCursorIndexStart, itemCursorIndexEnd));
|
||||||
hide();
|
hide();
|
||||||
select(0); //RESET
|
select(0); //RESET
|
||||||
}
|
}
|
||||||
|
@ -289,15 +323,21 @@ public class PickItemsDialog extends PopupPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ItemBean getUserModelBySuggestion(Suggestion suggestion) {
|
private ItemBean getUserModelBySuggestion(Suggestion suggestion) {
|
||||||
|
if (suggestion instanceof UserSuggestion) {
|
||||||
|
UserSuggestion us = (UserSuggestion) suggestion;
|
||||||
|
return us.getUser();
|
||||||
|
} else { //the user were preloaded client side
|
||||||
for (ItemBean bean : beans) {
|
for (ItemBean bean : beans) {
|
||||||
if (suggestion.getReplacementString().compareTo(bean.getAlternativeName()) ==0)
|
if (suggestion.getReplacementString().compareTo(bean.getAlternativeName()) ==0)
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
return new ItemBean("no-match","no-match","no-match","no-match");
|
return new ItemBean("no-match","no-match","no-match","no-match");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Widget getUserTemplate(ItemBean user, int displayIndex, boolean hasPhoto) {
|
private Widget getUserTemplate(ItemBean user, int displayIndex, boolean hasPhoto) {
|
||||||
if (hasPhoto)
|
if (hasPhoto)
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.client.oracle;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.rpc.PickItemService;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.rpc.PickItemServiceAsync;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.GWT;
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
import com.google.gwt.user.client.ui.MultiWordSuggestOracle;
|
||||||
|
|
||||||
|
public class UserOracle extends MultiWordSuggestOracle{
|
||||||
|
private final PickItemServiceAsync pickuserService = GWT.create(PickItemService.class);
|
||||||
|
|
||||||
|
private List<ItemBean> contacts = new LinkedList<>();
|
||||||
|
private String context;
|
||||||
|
|
||||||
|
public UserOracle(String context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addContacts(List<ItemBean> users) {
|
||||||
|
for (ItemBean bean : users) {
|
||||||
|
// if it is a team, set the avatar
|
||||||
|
if(bean.isItemGroup())
|
||||||
|
bean.setThumbnailURL(CssAndImages.INSTANCE.iconTeam().getSafeUri().asString());
|
||||||
|
contacts.add(bean);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void requestSuggestions(final Request request, final Callback callback) {
|
||||||
|
final Response resp = new Response();
|
||||||
|
if(contacts.isEmpty()){
|
||||||
|
callback.onSuggestionsReady(request, resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String text = request.getQuery();
|
||||||
|
text = text.toLowerCase();
|
||||||
|
|
||||||
|
final List<UserSuggestion> list = new ArrayList<>();
|
||||||
|
pickuserService.searchEntities(text, context, new AsyncCallback<ArrayList<ItemBean>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Throwable arg0) {
|
||||||
|
GWT.log("error");
|
||||||
|
callback.onSuggestionsReady(request, resp);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuccess(ArrayList<ItemBean> results) {
|
||||||
|
for (ItemBean contact : results){
|
||||||
|
list.add(new UserSuggestion(contact));
|
||||||
|
}
|
||||||
|
resp.setSuggestions(list);
|
||||||
|
callback.onSuggestionsReady(request, resp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.client.oracle;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
import com.google.gwt.user.client.ui.SuggestOracle;
|
||||||
|
|
||||||
|
public class UserSuggestion implements SuggestOracle.Suggestion {
|
||||||
|
|
||||||
|
private ItemBean user;
|
||||||
|
|
||||||
|
public UserSuggestion(ItemBean user) {
|
||||||
|
this.user = user;
|
||||||
|
if (user.isItemGroup())
|
||||||
|
user.setThumbnailURL(CssAndImages.INSTANCE.iconTeam().getSafeUri().asString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayString() {
|
||||||
|
return user.getAlternativeName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getReplacementString() {
|
||||||
|
return user.getAlternativeName();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemBean getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.client.rpc;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
import com.google.gwt.user.client.rpc.RemoteService;
|
||||||
|
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
||||||
|
@RemoteServiceRelativePath("pickItemServlet")
|
||||||
|
public interface PickItemService extends RemoteService {
|
||||||
|
ArrayList<ItemBean> searchEntities(String keyword, String vreContext);
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.client.rpc;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
|
||||||
|
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||||
|
|
||||||
|
public interface PickItemServiceAsync {
|
||||||
|
|
||||||
|
void searchEntities(String keyword, String vreContext, AsyncCallback<ArrayList<ItemBean>> callback);
|
||||||
|
|
||||||
|
}
|
|
@ -28,14 +28,16 @@ public class NoPhotoTemplate extends Composite implements SelectableItem {
|
||||||
FocusPanel focusDiv;
|
FocusPanel focusDiv;
|
||||||
@UiField
|
@UiField
|
||||||
HTML contentArea;
|
HTML contentArea;
|
||||||
|
private String id;
|
||||||
|
private boolean isGroup;
|
||||||
|
|
||||||
public NoPhotoTemplate(PickItemsDialog owner, ItemBean user, int displayIndex) {
|
public NoPhotoTemplate(PickItemsDialog owner, ItemBean user, int displayIndex) {
|
||||||
initWidget(uiBinder.createAndBindUi(this));
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
currDisplayIndex = displayIndex;
|
currDisplayIndex = displayIndex;
|
||||||
contentArea.setHTML(user.getAlternativeName());
|
contentArea.setHTML(user.getAlternativeName());
|
||||||
|
this.id = user.getId();
|
||||||
|
this.isGroup = user.isItemGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@UiHandler("focusDiv")
|
@UiHandler("focusDiv")
|
||||||
|
@ -47,6 +49,13 @@ public class NoPhotoTemplate extends Composite implements SelectableItem {
|
||||||
public String getItemName() {
|
public String getItemName() {
|
||||||
return contentArea.getText();
|
return contentArea.getText();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String getItemId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isGroup() {
|
||||||
|
return this.isGroup;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.gcube.portlets.widgets.pickitem.client.uibinder;
|
package org.gcube.portlets.widgets.pickitem.client.uibinder;
|
||||||
|
|
||||||
public interface SelectableItem {
|
public interface SelectableItem {
|
||||||
|
String getItemId();
|
||||||
String getItemName();
|
String getItemName();
|
||||||
|
boolean isGroup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,9 @@ public class WithPhotoTemplate extends Composite implements SelectableItem {
|
||||||
@UiField
|
@UiField
|
||||||
HTML contentArea;
|
HTML contentArea;
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private boolean isGroup;
|
||||||
|
|
||||||
public WithPhotoTemplate(PickItemsDialog owner, ItemBean user, int displayIndex) {
|
public WithPhotoTemplate(PickItemsDialog owner, ItemBean user, int displayIndex) {
|
||||||
initWidget(uiBinder.createAndBindUi(this));
|
initWidget(uiBinder.createAndBindUi(this));
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
|
@ -40,7 +43,8 @@ public class WithPhotoTemplate extends Composite implements SelectableItem {
|
||||||
|
|
||||||
avatarImage.setPixelSize(30, 30);
|
avatarImage.setPixelSize(30, 30);
|
||||||
contentArea.setHTML(user.getAlternativeName());
|
contentArea.setHTML(user.getAlternativeName());
|
||||||
|
this.id = user.getId();
|
||||||
|
this.isGroup = user.isItemGroup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,4 +57,12 @@ public class WithPhotoTemplate extends Composite implements SelectableItem {
|
||||||
public String getItemName() {
|
public String getItemName() {
|
||||||
return contentArea.getText();
|
return contentArea.getText();
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String getItemId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean isGroup() {
|
||||||
|
return this.isGroup;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
package org.gcube.portlets.widgets.pickitem.server;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.bundle.CssAndImages;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.client.rpc.PickItemService;
|
||||||
|
import org.gcube.portlets.widgets.pickitem.shared.ItemBean;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException;
|
||||||
|
import org.gcube.vomanagement.usermanagement.exception.UserRetrievalFault;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||||
|
import org.gcube.vomanagement.usermanagement.util.ManagementUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
|
import com.liferay.portal.kernel.dao.orm.QueryUtil;
|
||||||
|
import com.liferay.portal.kernel.util.OrderByComparator;
|
||||||
|
import com.liferay.portal.kernel.util.OrderByComparatorFactoryUtil;
|
||||||
|
import com.liferay.portal.model.Team;
|
||||||
|
import com.liferay.portal.model.User;
|
||||||
|
import com.liferay.portal.service.TeamLocalServiceUtil;
|
||||||
|
import com.liferay.portal.service.UserLocalServiceUtil;
|
||||||
|
|
||||||
|
@SuppressWarnings("serial")
|
||||||
|
public class PickItemServiceImpl extends RemoteServiceServlet implements PickItemService {
|
||||||
|
private static final Logger _log = LoggerFactory.getLogger(PickItemServiceImpl.class);
|
||||||
|
//this map is used as cache containing the association between a context and a GroupId so that we don't ask everytime.
|
||||||
|
private static HashMap<String, Long> contextToGroupIdMap = new HashMap<>();
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return true if you're running into the portal, false if in development
|
||||||
|
*/
|
||||||
|
private boolean isWithinPortal() {
|
||||||
|
try {
|
||||||
|
UserLocalServiceUtil.getService();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (com.liferay.portal.kernel.bean.BeanLocatorException ex) {
|
||||||
|
_log.trace("Development Mode ON");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getGroupIdFromContext(String context) {
|
||||||
|
if (contextToGroupIdMap.containsKey(context))
|
||||||
|
return contextToGroupIdMap.get(context);
|
||||||
|
try {
|
||||||
|
long groupId = new LiferayGroupManager().getGroupIdFromInfrastructureScope(context);
|
||||||
|
contextToGroupIdMap.put(context, new Long(groupId));
|
||||||
|
return groupId;
|
||||||
|
} catch (IllegalArgumentException | UserManagementSystemException | GroupRetrievalFault e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArrayList<ItemBean> searchEntities(String keyword, String context) {
|
||||||
|
ArrayList<ItemBean> toReturn = new ArrayList<>();
|
||||||
|
if (isWithinPortal()) {
|
||||||
|
OrderByComparator comparator = OrderByComparatorFactoryUtil.create("User_", "screenname", true);
|
||||||
|
LinkedHashMap<String, Object> params = new LinkedHashMap<>();
|
||||||
|
long currentGroupId = getGroupIdFromContext(context);
|
||||||
|
params.put("usersGroups", currentGroupId);
|
||||||
|
try {
|
||||||
|
_log.debug("Searching " + keyword + " on " + context);
|
||||||
|
List<User> usersByGroup = UserLocalServiceUtil.search(
|
||||||
|
ManagementUtils.getCompany().getCompanyId(), keyword, 0, params, QueryUtil.ALL_POS, QueryUtil.ALL_POS, comparator);
|
||||||
|
for (User user : usersByGroup) {
|
||||||
|
toReturn.add(new ItemBean(""+user.getUserId(), user.getScreenName(), user.getFullName(), getUserImagePortraitUrlLocal(user.getScreenName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
OrderByComparator teamComparator = OrderByComparatorFactoryUtil.create("team", "name", true);
|
||||||
|
List<Team> teams = TeamLocalServiceUtil.search(currentGroupId, keyword, "", null, QueryUtil.ALL_POS, QueryUtil.ALL_POS, teamComparator);
|
||||||
|
for (Team team : teams) {
|
||||||
|
ItemBean iBean = new ItemBean(team.getTeamId()+"", team.getName());
|
||||||
|
iBean.setItemGroup(true);
|
||||||
|
toReturn.add(iBean);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else { //development
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
toReturn.add(new ItemBean("id", "andrea.rossi", "Andrea Rossi", "email"));
|
||||||
|
if (i % 2 == 0)
|
||||||
|
toReturn.add(new ItemBean(""+i, "username"+i, "userGetFullname()"+i, "user.getEmail()"+i));
|
||||||
|
else {
|
||||||
|
ItemBean groupBean = new ItemBean("idG"+i, "Group "+i);
|
||||||
|
groupBean.setItemGroup(true);
|
||||||
|
toReturn.add(new ItemBean(""+i, "Group "+i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return toReturn;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* this method is needed because user images portrait change id depending on the portal instance
|
||||||
|
* e.g. a post made from iMarine portal would not show the avatarIMage in D4Science.org
|
||||||
|
* @param screenname
|
||||||
|
* @return the url of the image portrait for this portal instance
|
||||||
|
*/
|
||||||
|
private String getUserImagePortraitUrlLocal(String screenName) {
|
||||||
|
if (! isWithinPortal()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
String thumbnailURL = "";
|
||||||
|
try {
|
||||||
|
thumbnailURL = new LiferayUserManager().getUserByUsername(screenName).getUserAvatarURL();
|
||||||
|
} catch (UserManagementSystemException | UserRetrievalFault e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return thumbnailURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue