Skip to content

Commit

Permalink
Send message dialog esthetic changed
Browse files Browse the repository at this point in the history
+ Allow send the same message to many people (~ brodcast)
  • Loading branch information
Christophe authored and Christophe committed Mar 8, 2012
1 parent 3897865 commit dac728f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 18 deletions.
1 change: 0 additions & 1 deletion .classpath
Expand Up @@ -4,6 +4,5 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="E:/git/epomodoro/lib/jgroups-3.1.0.Alpha3.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion plugin.xml
Expand Up @@ -49,7 +49,7 @@
<page
class="net.mornati.epomodoro.preference.PomodoroPreferencePage"
id="epomodoro.Preferences"
name="Pomodoro Preferences">
name="ePomodoro">
</page>
</extension>
<extension
Expand Down
69 changes: 53 additions & 16 deletions src/net/mornati/epomodoro/handlers/SendMessageHandler.java
@@ -1,45 +1,82 @@
package net.mornati.epomodoro.handlers;

import java.util.Iterator;
import java.util.List;

import net.mornati.epomodoro.Activator;
import net.mornati.epomodoro.communication.Communication;
import net.mornati.epomodoro.communication.TextMessage;
import net.mornati.epomodoro.communication.TimerMessage;
import net.mornati.epomodoro.dialogs.MessageDialog;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.jface.dialogs.IInputValidator;
import org.eclipse.jface.dialogs.InputDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Display;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.jgroups.Address;

public class SendMessageHandler extends AbstractHandler implements IHandler {

private static final IInputValidator NON_EMPTY_VALIDATOR=new IInputValidator() {
@Override
public String isValid(String newText) {
return newText.isEmpty() ? "You must enter a message text" : null;
}
};

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection selection=HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
IWorkbenchWindow window=HandlerUtil.getActiveWorkbenchWindow(event);
ISelection selection=window.getActivePage().getSelection();
if (selection != null & selection instanceof IStructuredSelection) {
IStructuredSelection strucSelection=(IStructuredSelection) selection;
for (Iterator<Object> iterator=strucSelection.iterator(); iterator.hasNext();) {
Object element=iterator.next();
if (element instanceof TimerMessage) {
TimerMessage message=(TimerMessage) element;
Address source=message.getSourceAddress();
try {
MessageDialog dialog=new MessageDialog(Display.getDefault().getActiveShell(), "Write message for " + message.getSender());
String textToSend=dialog.open();
if (textToSend != null && !textToSend.equals("")) {
if (!strucSelection.isEmpty()) {
String senders=null;
for (TimerMessage timeMessage : (List<TimerMessage>) strucSelection.toList()) {
if (senders == null)
senders=timeMessage.getSender();
else
senders+=", " + timeMessage.getSender();
}
// See http://bingjava.appspot.com/model?id=752002
InputDialog dialog=new InputDialog(window.getShell(), "Write message to " + senders, "Enter your message here:", "", NON_EMPTY_VALIDATOR) {
/**
* Override this method to make the text field multilined and give it a scroll bar. But...
*/
@Override
protected int getInputTextStyle() {
return SWT.MULTI | SWT.BORDER | SWT.V_SCROLL;
}

/**
* ...it still is just one line high. This hack is not very nice, but at least it gets the job done... ;o)
*/
@Override
protected Control createDialogArea(Composite parent) {
Control res=super.createDialogArea(parent);
((GridData) this.getText().getLayoutData()).heightHint=100;
return res;
}
};
if (dialog.open() == Window.OK) {
for (TimerMessage message : (List<TimerMessage>) strucSelection.toList()) {
Address source=message.getSourceAddress();
try {
TextMessage msg=(TextMessage) Communication.createMessage(TextMessage.class);
msg.setMessage(textToSend);
msg.setMessage(dialog.getValue());
Activator.getDefault().getCommunication().sendMessage(msg, source);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Expand Down

0 comments on commit dac728f

Please sign in to comment.