package artistmetrics.views;

import org.eclipse.swt.*;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.*;
import java.util.Calendar;


/**
 * This sample class demonstrates how to plug-in a new
 * workbench view. The view shows data obtained from the
 * model. The sample creates a dummy model on the fly,
 * but a real implementation would connect 		to the model
 * available either in this or another plug-in (e.g. the workspace).
 * The view is connectedT.RIGHT to the model using a content provider.
 * <p>
      }
 * The view uses a label provider to define how model
 * objects should be presented in the view. Each
 * view can present the same model objects using
 * different labels and icons, if needed. Alternatively,
 * a single label provider can be shared between views
 * in order to ensure that objects of the same type are
 * presented in the same way everywhere.
 * <p>
 */

public class AnonymousMessageGui extends ViewPart{

	private Button clear;
	private Button send;
	private Text Textlog;
	private Label message;
	private Label sent;

	/*
	 * The content provider class is responsible for
	 * providing objects to the view. It can wrap
	 * existing objects in adapters or simply return
	 * objects as-is. These objects may be sensitive
	 * to the current input of the view, or ignore
	 * it and always show the same content 
	 * (like Task List, for example).
	 */

	/**
	 * The constructor.
	 */

	public AnonymousMessageGui() {
	}

	/**
	 * This is a callback that will allow us
	 * to create the viewer and initialize it.
	 */
	public void createPartControl(Composite parent) {
        
		FormLayout layout = new FormLayout();
		parent.setLayout(layout);
		
		message = new Label(parent, SWT.PUSH);
		message.setText("Enter your message here:");
		FormData data = new FormData();
		data.width = 200;
		data.left = new FormAttachment(0, 0);
		data.top = new FormAttachment(0, 0);
		message.setLayoutData(data);
		
		sent = new Label(parent, SWT.PUSH | SWT.WRAP);
		
		clear = new Button(parent, SWT.PUSH);
		clear.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				Textlog.setText("");
			}
		});
		clear.setText("Clear");
		
		data = new FormData();
		data.width = 120;
		data.right = new FormAttachment(100, 0);
		data.top = new FormAttachment(message);
		clear.setLayoutData(data);
		
		send = new Button(parent, SWT.PUSH);
		send.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				if(Textlog.getText().length() == 0) {
					sent.setText("Message is blank!");
				}
				else {
					//send message off (to be implemented)
					Textlog.setText("");
					sent.setText("Message sent on " + Calendar.getInstance().getTime() + " - (not really working)");
				}
			}
		});
		send.setText("Send");
		data = new FormData();
		data.width = 120;
		data.right = new FormAttachment(100, 0);
		data.top = new FormAttachment(clear);
		send.setLayoutData(data);
		
		data = new FormData();
		data.width = 120;
		data.right = new FormAttachment(100,0);
		data.top = new FormAttachment(send);
		data.bottom = new FormAttachment(100,0);
		sent.setLayoutData(data);
		
		Textlog = new Text(parent, SWT.V_SCROLL | SWT.H_SCROLL);
		Textlog.setEditable(true);
		data = new FormData();
		data.left = new FormAttachment(0);
		data.right = new FormAttachment(send);
		data.bottom = new FormAttachment(100);
		data.top = new FormAttachment(message);
		Textlog.setLayoutData(data);


	}
	
	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
	}
}
