From 3f325138348a6349ddc4ca6bb26e1ab329b5b773 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Fri, 14 Feb 2014 14:11:09 +0000 Subject: [PATCH] fixed paste on replies method git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/news-feed@91611 82a268e6-3cf1-43bd-a215-b396298e98cf --- .classpath | 2 +- .settings/org.eclipse.wst.common.component | 3 -- pom.xml | 1 + .../client/templates/AddCommentTemplate.java | 30 ++++++++++++++----- .../client/templates/SingleComment.java | 2 ++ .../client/templates/TweetTemplate.java | 24 +++++++++++---- .../user/newsfeed/server/NewsServiceImpl.java | 8 ++--- 7 files changed, 49 insertions(+), 21 deletions(-) diff --git a/.classpath b/.classpath index 44c5f88..f846250 100644 --- a/.classpath +++ b/.classpath @@ -28,7 +28,7 @@ - + diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component index 92202a8..b0c273d 100644 --- a/.settings/org.eclipse.wst.common.component +++ b/.settings/org.eclipse.wst.common.component @@ -4,9 +4,6 @@ - - uses - uses diff --git a/pom.xml b/pom.xml index 2096ee0..2cda5a0 100644 --- a/pom.xml +++ b/pom.xml @@ -87,6 +87,7 @@ org.gcube.portlets.widgets user-selection-dialog [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + compile org.gcube.portlets.widgets diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/AddCommentTemplate.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/AddCommentTemplate.java index 567389c..88b4e93 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/AddCommentTemplate.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/AddCommentTemplate.java @@ -12,6 +12,7 @@ import com.google.gwt.event.shared.HandlerManager; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.Event; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.Composite; @@ -34,7 +35,7 @@ public class AddCommentTemplate extends Composite{ private boolean isEditing = false; private HTMLPanel commentPanel; private Comment toEdit; - + interface CommentTemplateUiBinder extends UiBinder { } /** @@ -72,17 +73,32 @@ public class AddCommentTemplate extends Composite{ mainPanel.setStyleName("single-comment"); commentTextArea.addStyleName("dark-color"); } - + @UiField HTMLPanel mainPanel; @UiField Image avatarImage; @UiField TextArea commentTextArea; @UiField Button submitButton; @UiField Button cancelButton; - + public void setFocus() { commentTextArea.setFocus(true); } - + + /** + * paste event overridden + */ + public void onBrowserEvent(Event event) { + super.onBrowserEvent(event); + switch (event.getTypeInt()) { + case Event.ONPASTE: + if (commentTextArea.getText().equals(COMMENT_TEXT) || commentTextArea.getText().equals(ERROR_UPDATE_TEXT) ) { + commentTextArea.setText(""); + commentTextArea.addStyleName("dark-color"); + commentTextArea.removeStyleName("error"); + } + } + } + @UiHandler("submitButton") void onSubmitClick(ClickEvent e) { String userComment = commentTextArea.getText().trim(); @@ -104,7 +120,7 @@ public class AddCommentTemplate extends Composite{ this.getWidget().setVisible(false); owner.setCommentingDisabled(false); } - + /** * called when pasting. it tries to avoid pasting long non spaced strings * @param linkToCheck @@ -122,7 +138,7 @@ public class AddCommentTemplate extends Composite{ } return true; } - + @UiHandler("cancelButton") void onCancelClick(ClickEvent e) { this.getWidget().setVisible(false); @@ -143,7 +159,7 @@ public class AddCommentTemplate extends Composite{ commentTextArea.removeStyleName("error"); } } - + @UiHandler("commentTextArea") void onCommentKeyPress(KeyPressEvent e) { if (commentTextArea.getText().equals(COMMENT_TEXT) || commentTextArea.getText().equals(ERROR_UPDATE_TEXT) ) { diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SingleComment.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SingleComment.java index 1689769..1cdd388 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SingleComment.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/SingleComment.java @@ -14,6 +14,7 @@ import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.uibinder.client.UiBinder; import com.google.gwt.uibinder.client.UiField; import com.google.gwt.uibinder.client.UiHandler; +import com.google.gwt.user.client.Event; import com.google.gwt.user.client.ui.Composite; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.HTMLPanel; @@ -44,6 +45,7 @@ public class SingleComment extends Composite { public SingleComment(Comment toShow, TweetTemplate owner, boolean isUsers) { initWidget(uiBinder.createAndBindUi(this)); + sinkEvents(Event.ONPASTE); this.owner = owner; this.isUsers = isUsers; this.myComment = toShow; diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/TweetTemplate.java b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/TweetTemplate.java index e151849..5433106 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/TweetTemplate.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/client/templates/TweetTemplate.java @@ -116,6 +116,7 @@ public class TweetTemplate extends Composite { public TweetTemplate(boolean displaySingle, UserInfo myUserInfo, EnhancedFeed myFeed, HandlerManager eventBus) { initWidget(uiBinder.createAndBindUi(this)); this.myUserInfo = myUserInfo; + this.myFeed = myFeed; isAppFeed = myFeed.getFeed().isApplicationFeed(); Feed feed = myFeed.getFeed(); @@ -125,11 +126,14 @@ public class TweetTemplate extends Composite { this.eventBus = eventBus; this.isUsers = myFeed.isUsers(); myComments = new ArrayList(); - closeImage.setStyleName("closeImage"); - if (isUsers) { + + if (isUsers || myUserInfo.isAdmin()) { closeImage.setStyleName("closeImage"); - closeImage.setTitle("Delete"); + closeImage.setTitle(myUserInfo.isAdmin() ? "Delete (Administrator Mode)" : "delete"); + } else { + closeImage.removeFromParent(); } + openImage.setStyleName("openImage"); openImage.setTitle("Open this feed separately"); //show if the user has already liked this @@ -159,8 +163,11 @@ public class TweetTemplate extends Composite { else { // messageSeparator.setVisible(false); contentArea.setHTML(""+feed.getFullName()+" " + feedText); - closeImage.setTitle("Delete this Application feed (Administrator Only)"); if (isAppFeed) { + if (myUserInfo.isAdmin()) + closeImage.setTitle("Delete this Application feed (Administrator Only)"); + else + closeImage.removeFromParent(); try{ String vreName = feed.getVreid().substring(feed.getVreid().lastIndexOf("/")+1); messageArea.setHTML(" go App [" +vreName + "]"); @@ -228,15 +235,20 @@ public class TweetTemplate extends Composite { @UiHandler("contentArea") public void onHover(MouseOverEvent event) { - if (isUsers) + if (isUsers) { closeImage.addStyleName("uiCloseButton"); + GWT.log("this belong to user"); + } openImage.addStyleName("uiOpenButton"); } @UiHandler("closeImage") void onDeleteFeedClick(ClickEvent e) { - if (isUsers) + if (isUsers || myUserInfo.isAdmin()) eventBus.fireEvent(new DeleteFeedEvent(this)); + else { + GWT.log("not belong to user"); + } } @UiHandler("openImage") diff --git a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java index 5b6e77a..b4141b1 100644 --- a/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java +++ b/src/main/java/org/gcube/portlets/user/newsfeed/server/NewsServiceImpl.java @@ -78,7 +78,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService private boolean withinPortal = false; - private final static int MAX_FEEDS_NO = 30; + private final static int MAX_FEEDS_NO = 45; public void init() { store = new DBCassandraAstyanaxImpl(); @@ -98,8 +98,8 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService if (user == null) { _log.warn("USER IS NULL setting testing user and Running OUTSIDE PORTAL"); user = "test.user"; - user = "massimiliano.assante"; - SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube"); +// user = "massimiliano.assante"; +// SessionManager.getInstance().getASLSession(sessionID, user).setScope("/gcube"); } else { withinPortal = true; @@ -128,7 +128,7 @@ public class NewsServiceImpl extends RemoteServiceServlet implements NewsService ThemeDisplay themeDisplay = (ThemeDisplay) this.getThreadLocalRequest().getSession().getAttribute(WebKeys.THEME_DISPLAY); String accountURL = themeDisplay.getURLMyAccount().toString(); - UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, false, null); + UserInfo userInfo = new UserInfo(username, fullName, thumbnailURL, user.getEmailAddress(), accountURL, true, isAdmin(), null); UserSettings toReturn = new UserSettings(userInfo, getFeedsRefreshTimeInMillis(), session.getScopeName(), getVRELabel(), isInfrastructureScope()); setUserSettingsInSession(toReturn); return toReturn;