Issue #3040 - Fixed contact request and group name issues.

Change-Id: I7a430d4a443bdbcf7951ca9b6047b5cbda88238e

Former-commit-id: eed8c6cbba [formerly df05a79d63] [formerly f13ac7e1b9 [formerly badc9fa46aebe7f7da25c3a115294a37b30aa507]]
Former-commit-id: f13ac7e1b9
Former-commit-id: 222154d094
This commit is contained in:
Lee Venable 2014-04-23 18:22:39 -05:00
parent b8c0ae3f41
commit 421a4e4677
2 changed files with 184 additions and 47 deletions

View file

@ -25,11 +25,12 @@ import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
@ -48,6 +49,7 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* ------------ ---------- ----------- --------------------------
* Jun 27, 2012 bsteffen Initial creation
* Jan 24, 2014 2701 bclement removed local groups
* Apr 23, 2014 3040 lvenable Cleaned up dialog code/layout. Added check for group name.
*
* </pre>
*
@ -56,72 +58,122 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
*/
public class CreateGroupDialog extends CaveSWTDialog {
/** Name text field. */
private Text nameText;
/** New group name. */
private String newGroup = null;
/**
* Constructor.
*
* @param parentShell
* Parent shell.
*/
public CreateGroupDialog(Shell parentShell) {
super(parentShell, SWT.DIALOG_TRIM);
setText("Create Group");
}
@Override
protected Layout constructShellLayout() {
GridLayout mainLayout = new GridLayout(1, false);
return mainLayout;
}
@Override
protected Object constructShellLayoutData() {
return new GridData(SWT.FILL, SWT.DEFAULT, true, false);
}
@Override
protected void initializeComponents(Shell shell) {
Composite entryComp = new Composite(shell, SWT.NONE);
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
layout.center = true;
entryComp.setLayout(layout);
entryComp.setLayout(new GridLayout(2, false));
entryComp
.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true, false));
new Label(entryComp, SWT.NONE).setText("Group Name: ");
nameText = new Text(entryComp, SWT.BORDER);
nameText.setLayoutData(new RowData(100, SWT.DEFAULT));
nameText.setLayoutData(new GridData(150, SWT.DEFAULT));
nameText.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if (e.keyCode == SWT.CR || e.keyCode == SWT.KEYPAD_CR) {
finish();
handleOkAction();
}
}
});
/*
* Action buttons
*/
Composite buttonComp = new Composite(shell, SWT.NONE);
buttonComp.setLayoutData(new GridData(SWT.RIGHT, SWT.NONE, false,
false, 1, 1));
layout = new RowLayout(SWT.HORIZONTAL);
layout.pack = false;
buttonComp.setLayout(layout);
buttonComp.setLayout(new GridLayout(2, false));
buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.DEFAULT, true,
false));
GridData gd = new GridData(SWT.RIGHT, SWT.DEFAULT, true, false);
gd.widthHint = 75;
Button okButton = new Button(buttonComp, SWT.PUSH);
okButton.setText("OK");
okButton.setLayoutData(gd);
okButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
finish();
handleOkAction();
}
});
gd = new GridData(SWT.LEFT, SWT.DEFAULT, true, false);
gd.widthHint = 75;
Button cancelButton = new Button(buttonComp, SWT.PUSH);
cancelButton.setText("Cancel");
cancelButton.setLayoutData(gd);
cancelButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
close();
}
});
}
private void finish() {
/**
* Handle the OK action.
*/
private void handleOkAction() {
if (validGroupName() == false) {
return;
}
newGroup = nameText.getText();
CollaborationConnection.getConnection().getContactsManager()
.createGroup(newGroup);
close();
}
/**
* Check if there was something entered in the text field.
*
* @return True if there is text in the group name text field.
*/
private boolean validGroupName() {
if (nameText.getText().length() == 0) {
MessageBox mb = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
mb.setText("Invalid Name");
mb.setMessage("You have not entered a group name. Please enter one.");
mb.open();
return false;
}
return true;
}
/**
* Get the group name.
*
* @return The group name.
*/
public String getNewGroup() {
return newGroup;
}
}

View file

@ -34,6 +34,7 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Layout;
import org.eclipse.swt.widgets.Shell;
import org.jivesoftware.smack.RosterGroup;
@ -55,6 +56,9 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* Feb 13, 2014 2755 bclement roster addition now done in account manager, user input passed back
* Apr 07, 2014 2785 mpduff Changed to implement CaveSWTDialog
* Fix loading of groups
* Apr 23, 2014 3040 lvenable Cleaned up dialog code/layout. Allow the cancellation of the create
* group dialog without closing this dialog. Added capability to resize
* the group combo box if the names get too long.
*
* </pre>
*
@ -62,12 +66,19 @@ import com.raytheon.viz.ui.dialogs.CaveSWTDialog;
* @version 1.0
*/
public class SubRequestDialog extends CaveSWTDialog {
private final String NEW_GROUP = "New Group...";
/** User ID. */
private final String userid;
/** Combo listing all of the available groups. */
private Combo groupCbo;
/** Create group dialog. */
private CreateGroupDialog createGroupDlg;
/** Allow button. */
private Button allowBtn;
/**
* Constructor
*
@ -80,35 +91,70 @@ public class SubRequestDialog extends CaveSWTDialog {
setText("Contact Request");
}
@Override
protected Layout constructShellLayout() {
GridLayout mainLayout = new GridLayout(1, false);
return mainLayout;
}
@Override
protected Object constructShellLayoutData() {
return new GridData(SWT.FILL, SWT.DEFAULT, true, false);
}
@Override
protected void initializeComponents(Shell shell) {
GridLayout gl = new GridLayout(1, false);
GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
Composite mainComp = new Composite(shell, SWT.NONE);
GridLayout gl = new GridLayout(1, false);
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
mainComp.setLayout(gl);
mainComp.setLayoutData(gd);
/*
* Top Label
*/
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
Label msgLbl = new Label(mainComp, SWT.NONE);
msgLbl.setText(userid + " wants to add you to their contacts list.");
msgLbl.setText(userid + " wants to add you to a contacts list:");
msgLbl.setLayoutData(gd);
gl = new GridLayout(2, false);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
/*
* Group composite and controls.
*/
Composite groupComp = new Composite(mainComp, SWT.NONE);
gl = new GridLayout(3, false);
gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
groupComp.setLayout(gl);
groupComp.setLayoutData(gd);
gd = new GridData(SWT.RIGHT, SWT.DEFAULT, true, false);
gd = new GridData(SWT.DEFAULT, SWT.CENTER, false, true);
Label groupLbl = new Label(groupComp, SWT.NONE);
groupLbl.setText("Group: ");
groupLbl.setLayoutData(gd);
gd = new GridData(SWT.FILL, SWT.CENTER, true, true);
gd.minimumWidth = 130;
groupCbo = new Combo(groupComp, SWT.DROP_DOWN | SWT.READ_ONLY);
groupCbo.setItems(getGroupNames());
groupCbo.select(0);
groupCbo.setLayout(gl);
groupCbo.setLayoutData(gd);
gd = new GridData();
gd.horizontalIndent = 5;
Button newGroup = new Button(groupComp, SWT.PUSH);
newGroup.setText("New Group...");
newGroup.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleNewGroupAction();
}
});
addSeparator(mainComp);
/*
* Action buttons.
*/
gl = new GridLayout(2, false);
gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, false);
Composite btnComp = new Composite(mainComp, SWT.NONE);
@ -118,16 +164,21 @@ public class SubRequestDialog extends CaveSWTDialog {
int btnWidth = 75;
gd = new GridData(btnWidth, SWT.DEFAULT);
Button allowBtn = new Button(btnComp, SWT.PUSH);
allowBtn = new Button(btnComp, SWT.PUSH);
allowBtn.setText("Allow");
allowBtn.setLayoutData(gd);
allowBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
action(true);
handleAllowDenyAction(true);
}
});
// Disable the allow button if there are no items in the combo box.
if (groupCbo.getItemCount() == 0) {
allowBtn.setEnabled(false);
}
gd = new GridData(btnWidth, SWT.DEFAULT);
Button denyBtn = new Button(btnComp, SWT.PUSH);
denyBtn.setText("Deny");
@ -135,12 +186,14 @@ public class SubRequestDialog extends CaveSWTDialog {
denyBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
action(false);
handleAllowDenyAction(false);
}
});
}
/**
* Get the list of group names.
*
* @return list of existing group names
*/
private String[] getGroupNames() {
@ -157,28 +210,45 @@ public class SubRequestDialog extends CaveSWTDialog {
}
Collections.sort(groupList);
groupList.add(0, NEW_GROUP);
return groupList.toArray(new String[groupList.size()]);
}
/**
* Action handler.
*
* @param approved
* true if request approved, false if denied
* Handle adding a new group.
*/
private void action(boolean approved) {
if (approved) {
if (groupCbo.getSelectionIndex() == 0) {
// new group
CreateGroupDialog dialog = new CreateGroupDialog(Display
.getCurrent().getActiveShell());
dialog.open();
String group = dialog.getNewGroup();
setReturnValue(group);
} else {
private void handleNewGroupAction() {
if (createGroupDlg == null || createGroupDlg.isDisposed()) {
createGroupDlg = new CreateGroupDialog(Display.getCurrent()
.getActiveShell());
createGroupDlg.open();
String groupName = createGroupDlg.getNewGroup();
// If the group name is not null, add it to the combo and then
// select it.
if (groupName != null) {
allowBtn.setEnabled(true);
groupCbo.add(groupName, 0);
groupCbo.select(0);
shell.pack();
}
} else {
createGroupDlg.bringToTop();
}
}
/**
* Handle Allow/Deny action.
*
* @param allowRequest
* True if request allowed, false if denied
*/
private void handleAllowDenyAction(boolean allowRequest) {
if (allowRequest) {
if (groupCbo.getItemCount() != 0) {
setReturnValue(groupCbo.getItem(groupCbo.getSelectionIndex()));
} else {
}
} else {
setReturnValue(null);
@ -186,4 +256,19 @@ public class SubRequestDialog extends CaveSWTDialog {
close();
}
/**
* Add a line separator to the given composite.
*
* @param parentComp
* Parent composite.
*/
private void addSeparator(Composite parentComp) {
GridLayout gl = (GridLayout) parentComp.getLayout();
GridData gd = new GridData(SWT.FILL, SWT.DEFAULT, true, false);
gd.horizontalSpan = gl.numColumns;
Label sepLbl = new Label(parentComp, SWT.SEPARATOR | SWT.HORIZONTAL);
sepLbl.setLayoutData(gd);
}
}