Merge branch 'new_devel' into 11-Collaboration

Former-commit-id: 6ae33324f3 [formerly b8df9f46e4] [formerly 395ae5ae63 [formerly a441dcd259dbf3ecd77464d1bd0cbe1f4cdb1cb6]]
Former-commit-id: 395ae5ae63
Former-commit-id: 5b943096c5
This commit is contained in:
Roger Ferrel 2012-04-03 15:29:53 -05:00
commit 4b49ba50a7
9 changed files with 806 additions and 184 deletions

View file

@ -43,10 +43,13 @@ import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException; import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence.Type; import com.raytheon.uf.viz.collaboration.comm.identity.IPresence.Type;
import com.raytheon.uf.viz.collaboration.comm.identity.ISession;
import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession; import com.raytheon.uf.viz.collaboration.comm.identity.ISharedDisplaySession;
import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession; import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
import com.raytheon.uf.viz.collaboration.comm.identity.event.ITextMessageEvent;
import com.raytheon.uf.viz.collaboration.comm.identity.event.IVenueInvitationEvent; import com.raytheon.uf.viz.collaboration.comm.identity.event.IVenueInvitationEvent;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID; import com.raytheon.uf.viz.collaboration.comm.identity.user.IQualifiedID;
import com.raytheon.uf.viz.collaboration.comm.provider.TextMessage;
import com.raytheon.uf.viz.collaboration.comm.provider.session.SessionManager; import com.raytheon.uf.viz.collaboration.comm.provider.session.SessionManager;
import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditor; import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditor;
import com.raytheon.uf.viz.collaboration.ui.login.LoginData; import com.raytheon.uf.viz.collaboration.ui.login.LoginData;
@ -56,6 +59,7 @@ import com.raytheon.uf.viz.collaboration.ui.role.DataProviderEventController;
import com.raytheon.uf.viz.collaboration.ui.role.ParticipantEventController; import com.raytheon.uf.viz.collaboration.ui.role.ParticipantEventController;
import com.raytheon.uf.viz.collaboration.ui.role.SessionLeaderEventController; import com.raytheon.uf.viz.collaboration.ui.role.SessionLeaderEventController;
import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView; import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.VizApp;
/** /**
@ -220,6 +224,15 @@ public class CollaborationDataManager {
if (isConnected()) { if (isConnected()) {
// Register handlers and events for the new manager. // Register handlers and events for the new manager.
manager.registerEventHandler(this); manager.registerEventHandler(this);
try {
ISession p2pSession = manager.getPeerToPeerSession();
p2pSession.registerEventHandler(this);
} catch (CollaborationException e) {
// TODO Auto-generated catch block. Please revise as
// appropriate.
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
wbListener = new IWorkbenchListener() { wbListener = new IWorkbenchListener() {
@Override @Override
@ -231,6 +244,16 @@ public class CollaborationDataManager {
@Override @Override
public void postShutdown(IWorkbench workbench) { public void postShutdown(IWorkbench workbench) {
if (manager != null) { if (manager != null) {
try {
ISession p2pSession = manager
.getPeerToPeerSession();
p2pSession.unRegisterEventHandler(this);
} catch (CollaborationException e) {
// TODO Auto-generated catch block. Please
// revise as appropriate.
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
manager.unRegisterEventHandler(this); manager.unRegisterEventHandler(this);
manager.closeManager(); manager.closeManager();
manager = null; manager = null;
@ -463,6 +486,49 @@ public class CollaborationDataManager {
}); });
} }
/**
* This takes a peer to peer message and displays it in the proper view.
*
* @param messageEvent
*/
@Subscribe
public void peer2peerMessage(ITextMessageEvent messageEvent) {
final TextMessage message = messageEvent.getMessage();
// System.out.println("p2pMsg from: " + message.getFrom().getFQName());
// System.out.println("p2pMsgt body: " + message.getBody());
VizApp.runAsync(new Runnable() {
@Override
public void run() {
String id = message.getFrom().getFQName();
for (IViewReference ref : PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
.getViewReferences()) {
if (id.equals(ref.getSecondaryId())) {
PeerToPeerView p2pView = (PeerToPeerView) ref
.getView(false);
p2pView.appendMessage(message);
return;
}
}
try {
PeerToPeerView p2pView = (PeerToPeerView) PlatformUI
.getWorkbench()
.getActiveWorkbenchWindow()
.getActivePage()
.showView(PeerToPeerView.ID, id,
IWorkbenchPage.VIEW_ACTIVATE);
p2pView.appendMessage(message);
} catch (PartInitException e) {
// TODO Auto-generated catch block. Please revise as
// appropriate.
statusHandler.handle(Priority.PROBLEM,
e.getLocalizedMessage(), e);
}
}
});
}
public String joinCollaborationSession(String venueName, String sessionId) { public String joinCollaborationSession(String venueName, String sessionId) {
String result = sessionId; String result = sessionId;
if (sessionsMap.get(sessionId) == null) { if (sessionsMap.get(sessionId) == null) {

View file

@ -0,0 +1,227 @@
package com.raytheon.uf.viz.collaboration.ui;
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 3, 2012 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class ChangePasswordDialog extends CaveSWTDialog {
private Label userLabel;
private Text passwordTF;
private Text verifyPasswordTF;
public ChangePasswordDialog(Shell parentShell) {
super(parentShell);
setText("Change Password");
}
private Control createDialogArea(Composite parent) {
CollaborationDataManager manager = CollaborationDataManager
.getInstance();
String user = manager.getLoginId();
Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new GridLayout(2, false));
// body.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL
// | GridData.HORIZONTAL_ALIGN_FILL));
Label label = null;
GridData gd = null;
userLabel = new Label(body, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.horizontalSpan = 2;
userLabel.setLayoutData(gd);
userLabel.setText(user);
label = new Label(body, SWT.NONE);
label.setText("New Password: ");
passwordTF = new Text(body, SWT.BORDER | SWT.PASSWORD);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
passwordTF.setLayoutData(gd);
label = new Label(body, SWT.NONE);
label.setText("Verify Password: ");
verifyPasswordTF = new Text(body, SWT.BORDER | SWT.PASSWORD);
verifyPasswordTF.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
true));
return body;
}
@Override
protected void initializeComponents(Shell shell) {
shell.setLayout(new GridLayout(1, false));
createDialogArea(shell);
createButtonBar(shell);
}
private void createButtonBar(Composite parent) {
GridData gd = null;
Composite bar = new Composite(parent, SWT.NONE);
// set up to center buttons.
bar.setLayout(new GridLayout(0, true));
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
bar.setLayoutData(gd);
createButton(bar, IDialogConstants.OK_ID, "Change", true);
createButton(bar, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);
}
@Override
protected void preOpened() {
super.preOpened();
}
/**
* Creates a new button with the given id.
* <p>
* The <code>Dialog</code> implementation of this framework method creates a
* standard push button, registers it for selection events including button
* presses, and registers default buttons with its shell. The button id is
* stored as the button's client data. If the button id is
* <code>IDialogConstants.CANCEL_ID</code>, the new button will be
* accessible from <code>getCancelButton()</code>. If the button id is
* <code>IDialogConstants.OK_ID</code>, the new button will be accesible
* from <code>getOKButton()</code>. Note that the parent's layout is assumed
* to be a <code>GridLayout</code> and the number of columns in this layout
* is incremented. Subclasses may override.
* </p>
*
* @param parent
* the parent composite
* @param id
* the id of the button (see <code>IDialogConstants.*_ID</code>
* constants for standard dialog button ids)
* @param label
* the label from the button
* @param defaultButton
* <code>true</code> if the button is to be the default button,
* and <code>false</code> otherwise
*
* @return the new button
*
* @see #getCancelButton
* @see #getOKButton()
*/
protected Button createButton(Composite parent, int id, String label,
boolean defaultButton) {
// increment the number of columns in the button bar
((GridLayout) parent.getLayout()).numColumns++;
Button button = new Button(parent, SWT.PUSH);
button.setText(label);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.minimumWidth = 70;
button.setLayoutData(gd);
button.setData(new Integer(id));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Integer val = (Integer) event.widget.getData();
if (val != IDialogConstants.OK_ID) {
setReturnValue(null);
ChangePasswordDialog.this.getShell().dispose();
} else {
Text focusField = null;
List<String> errorMessages = new ArrayList<String>();
String password = passwordTF.getText();
String verifyPassword = verifyPasswordTF.getText();
if (password.length() == 0) {
errorMessages.add("Must enter new password.");
focusField = passwordTF;
verifyPasswordTF.setText("");
} else if (verifyPassword.length() == 0) {
errorMessages.add("Enter password again to verify.");
focusField = verifyPasswordTF;
} else if (password.equals(verifyPassword) == false) {
errorMessages
.add("New and verified password do not match.");
errorMessages.add("Enter them again.");
focusField = passwordTF;
verifyPasswordTF.setText("");
}
if (focusField == null) {
setReturnValue(password);
ChangePasswordDialog.this.getShell().dispose();
} else {
StringBuilder sb = new StringBuilder();
String prefix = "";
for (String msg : errorMessages) {
sb.append(prefix).append(msg);
prefix = "\n";
}
MessageBox messageBox = new MessageBox(event.widget
.getDisplay().getActiveShell(), SWT.ERROR);
messageBox.setText("Change Password Error");
messageBox.setMessage(sb.toString());
messageBox.open();
event.doit = false;
setReturnValue(null);
focusField.setFocus();
focusField.selectAll();
}
}
}
});
if (defaultButton) {
Shell shell = parent.getShell();
if (shell != null) {
shell.setDefaultButton(button);
}
}
return button;
}
}

View file

@ -28,8 +28,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuCreator;
import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.IToolBarManager;
@ -73,6 +71,7 @@ import org.osgi.framework.Bundle;
import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence; import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence.Type; import com.raytheon.uf.viz.collaboration.comm.identity.IPresence.Type;
import com.raytheon.uf.viz.collaboration.comm.identity.ISession; import com.raytheon.uf.viz.collaboration.comm.identity.ISession;
@ -90,6 +89,8 @@ import com.raytheon.uf.viz.collaboration.data.CollaborationUser;
import com.raytheon.uf.viz.collaboration.data.LoginUser; import com.raytheon.uf.viz.collaboration.data.LoginUser;
import com.raytheon.uf.viz.collaboration.data.SessionGroup; import com.raytheon.uf.viz.collaboration.data.SessionGroup;
import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditor; import com.raytheon.uf.viz.collaboration.ui.editor.CollaborationEditor;
import com.raytheon.uf.viz.collaboration.ui.login.ChangeStatusDialog;
import com.raytheon.uf.viz.collaboration.ui.login.LoginData;
import com.raytheon.uf.viz.collaboration.ui.session.AbstractSessionView; import com.raytheon.uf.viz.collaboration.ui.session.AbstractSessionView;
import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView; import com.raytheon.uf.viz.collaboration.ui.session.CollaborationSessionView;
import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView; import com.raytheon.uf.viz.collaboration.ui.session.PeerToPeerView;
@ -157,13 +158,11 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
private Action removeUserAction; private Action removeUserAction;
private Action changeMessageAction; private Action changeStatusAction;
private Action changePasswordAction; private Action changePasswordAction;
private Action changeStatusAction; // private Action refreshActiveSessionsAction;
private Action refreshActiveSessionsAction;
private Action collapseAllAction; private Action collapseAllAction;
@ -227,13 +226,15 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
String sessionId = getId(); String sessionId = getId();
IVenueSession session = CollaborationDataManager.getInstance() IVenueSession session = CollaborationDataManager.getInstance()
.getSession(sessionId); .getSession(sessionId);
String roomName = session.getVenue().getInfo()
.getVenueDescription();
List<String> ids = new ArrayList<String>(); List<String> ids = new ArrayList<String>();
for (CollaborationUser user : getSelectedUsers()) { for (CollaborationUser user : getSelectedUsers()) {
// TODO not add to list if user is already in the session.
String id = user.getId(); String id = user.getId();
if (!ids.contains(id)) { System.out.println("Add Selected User: " + id);
System.out.println("Add Selected User: " + id); ids.add(id);
ids.add(id);
}
} }
IVenueInfo info = session.getVenue().getInfo(); IVenueInfo info = session.getVenue().getInfo();
System.out.println("room: " + info.getVenueName()); System.out.println("room: " + info.getVenueName());
@ -315,24 +316,24 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
} }
}; };
changeMessageAction = new Action("Change Message...") { changeStatusAction = new Action("Change Status...") {
public void run() { public void run() {
System.out.println("Change message"); changeStatus();
}; };
}; };
changePasswordAction = new Action("Change password...") { changePasswordAction = new Action("Change password...") {
public void run() { public void run() {
System.out.println("Change password here"); changePassword();
}; };
}; };
changeStatusAction = new Action("Change Status", // changeStatusAction = new Action("Change Status",
Action.AS_DROP_DOWN_MENU) { // Action.AS_DROP_DOWN_MENU) {
public void run() { // public void run() {
System.out.println("Change Status here to: " + getId()); // System.out.println("Change Status here to: " + getId());
}; // };
}; // };
// refreshActiveSessionsAction = new Action("Refresh") { // refreshActiveSessionsAction = new Action("Refresh") {
// public void run() { // public void run() {
@ -353,30 +354,30 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
collapseAllAction.setImageDescriptor(IconUtil.getImageDescriptor( collapseAllAction.setImageDescriptor(IconUtil.getImageDescriptor(
bundle, "collapseall.gif")); bundle, "collapseall.gif"));
IMenuCreator creator = new IMenuCreator() { // IMenuCreator creator = new IMenuCreator() {
//
Menu menu; // Menu menu;
//
@Override // @Override
public Menu getMenu(Menu parent) { // public Menu getMenu(Menu parent) {
menu = new Menu(parent); // menu = new Menu(parent);
fillStatusMenu(menu); // fillStatusMenu(menu);
return menu; // return menu;
} // }
//
@Override // @Override
public Menu getMenu(Control parent) { // public Menu getMenu(Control parent) {
menu = new Menu(parent); // menu = new Menu(parent);
fillStatusMenu(menu); // fillStatusMenu(menu);
return menu; // return menu;
} // }
//
@Override // @Override
public void dispose() { // public void dispose() {
menu.dispose(); // menu.dispose();
} // }
}; // };
changeStatusAction.setMenuCreator(creator); // changeStatusAction.setMenuCreator(creator);
removeGroupAction = new Action("Remove Group") { removeGroupAction = new Action("Remove Group") {
public void run() { public void run() {
@ -388,6 +389,45 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
}; };
} }
private void changePassword() {
System.out.println("Change password here");
ChangePasswordDialog dialog = new ChangePasswordDialog(Display
.getCurrent().getActiveShell());
dialog.open();
Object result = dialog.getReturnValue();
if (result != null) {
char[] password = result.toString().toCharArray();
SessionManager sessionManager = CollaborationDataManager
.getInstance().getSessionManager();
try {
sessionManager.getAccountManager().changePassword(password);
} catch (CollaborationException e) {
// TODO Auto-generated catch block. Please revise as
// appropriate.
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
}
}
}
private void changeStatus() {
ChangeStatusDialog dialog = new ChangeStatusDialog(Display.getCurrent()
.getActiveShell());
dialog.open();
LoginData loginData = (LoginData) dialog.getReturnValue();
if (loginData != null) {
LoginUser loginUser = getLoginUser();
loginUser.setMode(loginData.getMode());
loginUser.setStatusMessage(loginData.getModeMessage());
usersTreeViewer.refresh(loginUser, true);
System.err.println("send mode change here: "
+ loginData.getMode().toString() + ", Message: \""
+ loginData.getModeMessage() + "\"");
}
}
/** /**
* This displays a warning dialog then closes all collaboration views and * This displays a warning dialog then closes all collaboration views and
* disconnects from the server. * disconnects from the server.
@ -456,22 +496,22 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
} }
private void fillStatusMenu(Menu menu) { // private void fillStatusMenu(Menu menu) {
for (IPresence.Mode type : CollaborationUtils.statusModes) { // for (IPresence.Mode type : CollaborationUtils.statusModes) {
Action action = new Action(type.getMode()) { // Action action = new Action(type.getMode()) {
public void run() { // public void run() {
changeStatusAction.setId(getId()); // changeStatusAction.setId(getId());
changeStatusAction.run(); // changeStatusAction.run();
}; // };
}; // };
action.setId(type.name()); // action.setId(type.name());
ActionContributionItem item = new ActionContributionItem(action); // ActionContributionItem item = new ActionContributionItem(action);
action.setImageDescriptor(IconUtil.getImageDescriptor(Activator // action.setImageDescriptor(IconUtil.getImageDescriptor(Activator
.getDefault().getBundle(), type.name().toLowerCase() // .getDefault().getBundle(), type.name().toLowerCase()
+ ".gif")); // + ".gif"));
item.fill(menu, -1); // item.fill(menu, -1);
} // }
} // }
private void createToolbar() { private void createToolbar() {
IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager(); IToolBarManager mgr = getViewSite().getActionBars().getToolBarManager();
@ -500,8 +540,8 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
mgr.add(addUserAction); mgr.add(addUserAction);
mgr.add(selectGroups); mgr.add(selectGroups);
mgr.add(new Separator()); mgr.add(new Separator());
// mgr.add(changeStatusAction);
mgr.add(changeStatusAction); mgr.add(changeStatusAction);
mgr.add(changeMessageAction);
mgr.add(changePasswordAction); mgr.add(changePasswordAction);
mgr.add(new Separator()); mgr.add(new Separator());
if (CollaborationDataManager.getInstance().isConnected()) { if (CollaborationDataManager.getInstance().isConnected()) {
@ -1043,6 +1083,17 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
} }
} }
private LoginUser getLoginUser() {
LoginUser loginUser = null;
for (CollaborationNode node : topLevel.getChildren()) {
if (node instanceof LoginUser) {
loginUser = (LoginUser) node;
break;
}
}
return loginUser;
}
/** /**
* @return * @return
*/ */
@ -1051,7 +1102,7 @@ public class CollaborationGroupView extends ViewPart implements IPartListener {
} }
/** /**
* Get the list of selected users that have a Type of AVAILABLE. * Get a unique set of selected users that have a Type of AVAILABLE.
* *
* @return * @return
*/ */

View file

@ -0,0 +1,212 @@
package com.raytheon.uf.viz.collaboration.ui.login;
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import com.raytheon.uf.viz.collaboration.comm.identity.IPresence;
import com.raytheon.uf.viz.collaboration.ui.CollaborationUtils;
import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
/**
* Change the user Mode Status and the optional message.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Apr 3, 2012 rferrel Initial creation
*
* </pre>
*
* @author rferrel
* @version 1.0
*/
public class ChangeStatusDialog extends CaveSWTDialog {
private Label userLabel;
private Combo statusCombo;
private Text messageTF;
private LoginData loginData;
public ChangeStatusDialog(Shell parentShell) {
super(parentShell, SWT.DIALOG_TRIM);
setText("Collaboration Server Log On");
}
private Control createDialogArea(Composite parent) {
GridData gd = null;
Composite body = new Composite(parent, SWT.NONE);
body.setLayout(new GridLayout(2, false));
Label label = null;
userLabel = new Label(body, SWT.NONE);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.horizontalSpan = 2;
userLabel.setLayoutData(gd);
userLabel.setText("");
label = new Label(body, SWT.NONE);
label.setText("Status: ");
statusCombo = new Combo(body, SWT.DEFAULT);
for (IPresence.Mode mode : CollaborationUtils.statusModes) {
statusCombo.add(mode.getMode());
}
label = new Label(body, SWT.NONE);
label.setText("Message: ");
messageTF = new Text(body, SWT.BORDER);
gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.minimumWidth = 200;
messageTF.setLayoutData(gd);
return body;
}
@Override
protected void initializeComponents(Shell shell) {
shell.setLayout(new GridLayout(1, false));
createDialogArea(shell);
createButtonBar(shell);
}
private void createButtonBar(Composite parent) {
GridData gd = null;
Composite bar = new Composite(parent, SWT.NONE);
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
bar.setLayout(new GridLayout(0, true));
bar.setLayoutData(gd);
createButton(bar, IDialogConstants.OK_ID, "Send", true);
createButton(bar, IDialogConstants.CANCEL_ID,
IDialogConstants.CANCEL_LABEL, false);
}
@Override
protected void preOpened() {
super.preOpened();
this.loginData = LoginDialog.openUserLoginData();
userLabel.setText(loginData.getAccount());
statusCombo.select(CollaborationUtils.statusModesIndex(loginData
.getMode()));
statusCombo.select(CollaborationUtils.statusModesIndex(loginData
.getMode()));
messageTF.setText(loginData.getModeMessage());
messageTF.selectAll();
statusCombo.setFocus();
}
/**
* Creates a new button with the given id.
* <p>
* The <code>Dialog</code> implementation of this framework method creates a
* standard push button, registers it for selection events including button
* presses, and registers default buttons with its shell. The button id is
* stored as the button's client data. If the button id is
* <code>IDialogConstants.CANCEL_ID</code>, the new button will be
* accessible from <code>getCancelButton()</code>. If the button id is
* <code>IDialogConstants.OK_ID</code>, the new button will be accesible
* from <code>getOKButton()</code>. Note that the parent's layout is assumed
* to be a <code>GridLayout</code> and the number of columns in this layout
* is incremented. Subclasses may override.
* </p>
*
* @param parent
* the parent composite
* @param id
* the id of the button (see <code>IDialogConstants.*_ID</code>
* constants for standard dialog button ids)
* @param label
* the label from the button
* @param defaultButton
* <code>true</code> if the button is to be the default button,
* and <code>false</code> otherwise
*
* @return the new button
*
* @see #getCancelButton
* @see #getOKButton()
*/
protected Button createButton(Composite parent, int id, String label,
boolean defaultButton) {
// increment the number of columns in the button bar
((GridLayout) parent.getLayout()).numColumns++;
Button button = new Button(parent, SWT.PUSH);
button.setText(label);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
gd.minimumWidth = 70;
button.setLayoutData(gd);
button.setData(new Integer(id));
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
Integer val = (Integer) event.widget.getData();
if (val != IDialogConstants.OK_ID) {
setReturnValue(null);
} else {
boolean modified = false;
IPresence.Mode mode = CollaborationUtils.statusModes[statusCombo
.getSelectionIndex()];
if (mode != loginData.getMode()) {
modified = true;
}
String modeMessage = messageTF.getText().trim();
if (modeMessage.equals(loginData.getModeMessage()) == false) {
modified = true;
}
if (modified) {
loginData.setMode(mode);
loginData.setModeMessage(modeMessage);
LoginDialog.saveUserLoginData(loginData);
setReturnValue(loginData);
} else {
setReturnValue(null);
}
}
ChangeStatusDialog.this.getShell().dispose();
}
});
if (defaultButton) {
Shell shell = parent.getShell();
if (shell != null) {
shell.setDefaultButton(button);
}
}
return button;
}
}

View file

@ -232,7 +232,7 @@ public class LoginDialog extends CaveSWTDialog {
@Override @Override
protected void preOpened() { protected void preOpened() {
super.preOpened(); super.preOpened();
initLoginData(); this.loginData = LoginDialog.openUserLoginData();
userTF.setText(loginData.getUser()); userTF.setText(loginData.getUser());
serverTF.setText(loginData.getServer()); serverTF.setText(loginData.getServer());
@ -341,7 +341,7 @@ public class LoginDialog extends CaveSWTDialog {
loginData.setModeMessage(modeMessage); loginData.setModeMessage(modeMessage);
} }
if (doSaveLoginData) { if (doSaveLoginData) {
saveLoginData(); LoginDialog.saveUserLoginData(loginData);
} }
// loginData = new LoginData(user, server, password, // loginData = new LoginData(user, server, password,
@ -378,8 +378,8 @@ public class LoginDialog extends CaveSWTDialog {
return button; return button;
} }
private void initLoginData() { public static LoginData openUserLoginData() {
loginData = null; LoginData loginData = null;
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
File fname = pm.getStaticFile(LOGIN_FILE_NAME); File fname = pm.getStaticFile(LOGIN_FILE_NAME);
try { try {
@ -393,9 +393,10 @@ public class LoginDialog extends CaveSWTDialog {
loginData = new LoginData(); loginData = new LoginData();
} }
} }
return loginData;
} }
private void saveLoginData() { public static void saveUserLoginData(LoginData loginData) {
try { try {
LocalizationFile lFile = getFile(LOGIN_FILE_NAME); LocalizationFile lFile = getFile(LOGIN_FILE_NAME);
File file = lFile.getFile(false); File file = lFile.getFile(false);
@ -418,7 +419,7 @@ public class LoginDialog extends CaveSWTDialog {
* @return lFile * @return lFile
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
private LocalizationFile getFile(String filename) private static LocalizationFile getFile(String filename)
throws FileNotFoundException { throws FileNotFoundException {
IPathManager pm = PathManagerFactory.getPathManager(); IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext context = pm.getContext( LocalizationContext context = pm.getContext(

View file

@ -19,11 +19,16 @@
**/ **/
package com.raytheon.uf.viz.collaboration.ui.session; package com.raytheon.uf.viz.collaboration.ui.session;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.FocusListener;
@ -40,6 +45,9 @@ import org.eclipse.ui.IPartListener;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.part.ViewPart;
import com.raytheon.uf.viz.collaboration.comm.identity.IMessage;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.ui.Activator; import com.raytheon.uf.viz.collaboration.ui.Activator;
import com.raytheon.uf.viz.core.icon.IconUtil; import com.raytheon.uf.viz.core.icon.IconUtil;
import com.raytheon.viz.ui.perspectives.VizPerspectiveListener; import com.raytheon.viz.ui.perspectives.VizPerspectiveListener;
@ -222,6 +230,104 @@ public abstract class AbstractSessionView extends ViewPart implements
return message; return message;
} }
/**
* Append the message into the message text field.
*
* @param message
*/
public void appendMessage(IMessage message) {
String fqName = message.getFrom().getFQName();
String name = message.getFrom().getName();
long timestamp = message.getTimeStamp();
String body = message.getBody();
appendMessage(fqName, name, timestamp, body);
}
public void appendMessage(String fqName, String name, long timestamp,
String body) {
// String fqName = message.getFrom().getFQName();
// String name = message.getFrom().getName();
if (name == null) {
name = fqName.substring(0, fqName.indexOf("@"));
}
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(timestamp);
String time = String.format("%1$tI:%1$tM:%1$tS %1$Tp", cal);
StringBuilder sb = new StringBuilder();
if (messagesText.getCharCount() != 0) {
sb.append("\n");
}
sb.append("(").append(time).append(") ");
int offset = sb.length();
sb.append(name).append(": ").append(body);
// here is the place to put the font and color changes for keywords
// read in localization file once and then don't read in again, per
// chat room?
Collection<String> alertWords = findAlertWords(sb,
offset + name.length() + 2);
List<StyleRange> ranges = new ArrayList<StyleRange>();
if (alertWords != null) {
for (String keyword : alertWords) {
if (sb.toString().toLowerCase().contains(keyword.toLowerCase())) {
StyleRange keywordRange = new StyleRange(
messagesText.getCharCount()
+ sb.toString().toLowerCase()
.indexOf(keyword.toLowerCase()),
keyword.length(), null, null, SWT.BOLD | SWT.ITALIC);
ranges.add(keywordRange);
}
}
}
ParticipantRole[] roles = getRoles(fqName);
Color color = SessionColorAdvisor.getColor(roles, fqName
.equals(CollaborationDataManager.getInstance().getLoginId()));
StyleRange range = new StyleRange(messagesText.getCharCount() + offset,
name.length() + 1, color, null, SWT.BOLD);
messagesText.append(sb.toString());
messagesText.setStyleRange(range);
for (StyleRange newRange : ranges) {
messagesText.setStyleRange(newRange);
}
messagesText.setTopIndex(messagesText.getLineCount() - 1);
// room for other fun things here, such as sounds and such
executeSightsSounds();
}
/**
* Find keys words in body of message starting at offset. /**
*
* @param builder
* @param offset
* @return alertWords
*/
protected Collection<String> findAlertWords(StringBuilder builder,
int offset) {
return null;
}
/**
* Returns a list of Participant roles the user is assigned for the session.
* This sets up a default list of user as a PARTICIPANT.
*
* @param userId
* @return roles
*/
protected ParticipantRole[] getRoles(String userId) {
return new ParticipantRole[] { ParticipantRole.PARTICIPANT };
}
/**
* Place holder must override to do something.
*/
protected void executeSightsSounds() {
// placeholder for future things
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View file

@ -20,6 +20,9 @@ package com.raytheon.uf.viz.collaboration.ui.session;
* further licensing information. * further licensing information.
**/ **/
import java.util.Collection;
import java.util.List;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem; import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.IMenuCreator; import org.eclipse.jface.action.IMenuCreator;
@ -32,7 +35,9 @@ import org.eclipse.ui.IWorkbenchPart;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException; import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession; import com.raytheon.uf.viz.collaboration.comm.identity.IVenueSession;
import com.raytheon.uf.viz.collaboration.comm.identity.info.IVenueInfo; import com.raytheon.uf.viz.collaboration.comm.identity.info.IVenueInfo;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager; import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.data.CollaborationUser;
/** /**
* TODO Add Description * TODO Add Description
@ -126,6 +131,43 @@ public class CollaborationSessionView extends SessionView {
return COLLABORATION_SESSION_IMAGE_NAME; return COLLABORATION_SESSION_IMAGE_NAME;
} }
/*
* (non-Javadoc)
*
* @see
* com.raytheon.uf.viz.collaboration.ui.session.AbstractSessionView#getRoles
* (java.lang.String)
*/
@SuppressWarnings("unchecked")
@Override
protected ParticipantRole[] getRoles(String userId) {
for (CollaborationUser u : ((List<CollaborationUser>) usersTable
.getInput())) {
if (userId.equals(u.getId())) {
return u.getRoles();
}
}
return new ParticipantRole[] { ParticipantRole.PARTICIPANT };
}
@Override
protected Collection<String> findAlertWords(StringBuilder builder,
int offset) {
// TODO
// 1) if needed read in localized list of key words/sounds
// 2) search builder starting at offset for key works. besides the key
// words found may also want to return the location(s) of where they are
// found along with the sound to used.
return super.findAlertWords(builder, offset);
}
@Override
protected void executeSightsSounds() {
// TODO From the alert words found determine what sound to play and for
// how long?
super.executeSightsSounds();
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View file

@ -29,7 +29,6 @@ import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority; import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException; import com.raytheon.uf.viz.collaboration.comm.identity.CollaborationException;
import com.raytheon.uf.viz.collaboration.comm.identity.IPeerToPeer; import com.raytheon.uf.viz.collaboration.comm.identity.IPeerToPeer;
import com.raytheon.uf.viz.collaboration.comm.identity.ISession;
import com.raytheon.uf.viz.collaboration.comm.identity.listener.IMessageListener; import com.raytheon.uf.viz.collaboration.comm.identity.listener.IMessageListener;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager; import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
@ -165,32 +164,42 @@ public class PeerToPeerView extends AbstractSessionView {
// Get any open session to send peer-to-peer message // Get any open session to send peer-to-peer message
IPeerToPeer p2p = null; IPeerToPeer p2p = null;
try { try {
p2p = (IPeerToPeer) CollaborationDataManager.getInstance().getSessionManager().getPeerToPeerSession(); p2p = (IPeerToPeer) CollaborationDataManager.getInstance()
.getSessionManager().getPeerToPeerSession();
} catch (CollaborationException e) { } catch (CollaborationException e) {
// TODO Auto-generated catch block. Please revise as appropriate. // TODO Auto-generated catch block. Please revise as
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); // appropriate.
statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(),
e);
} }
if(p2p != null) { if (p2p != null) {
p2p.sendPeerToPeer(toUser, message); p2p.sendPeerToPeer(toUser, message);
// TODO need to put the message in messag text field here.
CollaborationDataManager manager = CollaborationDataManager
.getInstance();
String fqName = manager.getLoginId();
String name = null;
long timestamp = System.currentTimeMillis();
appendMessage(fqName, name, timestamp, message);
} }
// ISession session = CollaborationDataManager.getInstance() // ISession session = CollaborationDataManager.getInstance()
// .getSession(null); // .getSession(null);
// if (session != null) { // if (session != null) {
// session.sendTextMessage(toUser, message); // session.sendTextMessage(toUser, message);
// } else { // } else {
// try { // try {
// session = CollaborationDataManager.getInstance() // session = CollaborationDataManager.getInstance()
// .getSessionManager().createPeerToPeerSession(); // .getSessionManager().createPeerToPeerSession();
// // session.sendTextMessage(toUser, message); // // session.sendTextMessage(toUser, message);
// // session.close(); // // session.close();
// } catch (CollaborationException e) { // } catch (CollaborationException e) {
// // TODO Auto-generated catch block. Please revise as // // TODO Auto-generated catch block. Please revise as
// // appropriate. // // appropriate.
// statusHandler.handle(Priority.PROBLEM, // statusHandler.handle(Priority.PROBLEM,
// e.getLocalizedMessage(), e); // e.getLocalizedMessage(), e);
// } // }
// } // }
} }
} }

View file

@ -21,7 +21,6 @@ package com.raytheon.uf.viz.collaboration.ui.session;
**/ **/
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
@ -35,11 +34,9 @@ import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter; import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Point;
@ -71,7 +68,6 @@ import com.raytheon.uf.viz.collaboration.comm.identity.info.IVenueInfo;
import com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueParticipant; import com.raytheon.uf.viz.collaboration.comm.identity.user.IVenueParticipant;
import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole; import com.raytheon.uf.viz.collaboration.comm.identity.user.ParticipantRole;
import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager; import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager;
import com.raytheon.uf.viz.collaboration.data.CollaborationKeywords;
import com.raytheon.uf.viz.collaboration.data.CollaborationUser; import com.raytheon.uf.viz.collaboration.data.CollaborationUser;
import com.raytheon.uf.viz.core.VizApp; import com.raytheon.uf.viz.core.VizApp;
@ -99,7 +95,7 @@ public class SessionView extends AbstractSessionView {
public static final String ID = "com.raytheon.uf.viz.collaboration.SessionView"; public static final String ID = "com.raytheon.uf.viz.collaboration.SessionView";
private TableViewer usersTable; protected TableViewer usersTable;
protected String sessionId; protected String sessionId;
@ -202,7 +198,7 @@ public class SessionView extends AbstractSessionView {
@Override @Override
public void run() { public void run() {
addMessage(msg); appendMessage(msg);
} }
}); });
} }
@ -402,94 +398,6 @@ public class SessionView extends AbstractSessionView {
} }
} }
// @SuppressWarnings("unchecked")
// public void addUser(CollaborationUser user) {
// List<CollaborationUser> list = (List<CollaborationUser>) usersTable
// .getInput();
// list.add(user);
// }
//
// @SuppressWarnings("unchecked")
// public void clearUsers() {
// List<CollaborationUser> list = (List<CollaborationUser>) usersTable
// .getInput();
// list.clear();
// ;
// }
//
// @SuppressWarnings("unchecked")
// public void removeUser(CollaborationUser user) {
// List<CollaborationUser> list = (List<CollaborationUser>) usersTable
// .getInput();
// list.remove(user);
// }
public void addMessage(IMessage message) {
String name = message.getFrom().getFQName();
String user = message.getFrom().getName();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(message.getTimeStamp());
String time = String.format("%1$tI:%1$tM:%1$tS %1$Tp", cal);
StringBuilder sb = new StringBuilder();
if (messagesText.getCharCount() != 0) {
sb.append("\n");
}
int offset = 0;
sb.append("(").append(time).append(") ");
offset = sb.length();
sb.append(user).append(": ").append(message.getBody());
// here is the place to put the font and color changes for keywords
// read in localization file once and then don't read in again, per
// chat room?
List<String> keywords = CollaborationKeywords.parseKeywords();
List<StyleRange> ranges = new ArrayList<StyleRange>();
if (keywords != null) {
for (String keyword : keywords) {
if (sb.toString().toLowerCase().contains(keyword.toLowerCase())) {
StyleRange keywordRange = new StyleRange(
messagesText.getCharCount()
+ sb.toString().toLowerCase()
.indexOf(keyword.toLowerCase()),
keyword.length(), null, null, SWT.BOLD | SWT.ITALIC);
ranges.add(keywordRange);
}
}
}
ParticipantRole[] type = null;
for (CollaborationUser u : (List<CollaborationUser>) usersTable
.getInput()) {
if (name.equals(u.getId())) {
type = u.getRoles();
break;
}
}
Color color = SessionColorAdvisor.getColor(type, name
.equals(CollaborationDataManager.getInstance().getLoginId()));
StyleRange range = new StyleRange(messagesText.getCharCount() + offset,
user.length() + 1, color, null, SWT.BOLD);
messagesText.append(sb.toString());
messagesText.setStyleRange(range);
for (StyleRange newRange : ranges) {
messagesText.setStyleRange(newRange);
}
messagesText.setTopIndex(messagesText.getLineCount() - 1);
// room for other fun things here, such as sounds and such
executeSightsSounds();
}
/**
*
*/
private void executeSightsSounds() {
// TODO Auto-generated method stub
// placeholder for future things
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *