package ee.ut.cs.rum.workspaces.internal.ui.workspace;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabItem;
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.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;

import ee.ut.cs.rum.database.domain.Workspace;
import ee.ut.cs.rum.workspaces.internal.ui.task.TasksTableViewer;
import ee.ut.cs.rum.workspaces.internal.ui.task.newtask.NewTaskDetails;

public class WorkspaceDetailsTabContents extends Composite {
	private static final long serialVersionUID = 1649148279320216160L;

	private Workspace workspace;
	private TasksTableViewer tasksTableViewer;

	WorkspaceDetailsTabContents(WorkspaceTabFolder workspaceTabFolder, Composite workspaceContainer, Workspace workspace) {
		super(workspaceTabFolder, SWT.NONE);

		this.workspace=workspace;

		this.setLayout(new GridLayout(2, false));
		this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

		Label l = new Label(this, SWT.BORDER);
		if (workspace.getName()!=null) {
			l.setText(workspace.getName());
		}
		l.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		((GridData) l.getLayoutData()).horizontalSpan=((GridLayout) this.getLayout()).numColumns;
		
		l = new Label(this, SWT.BORDER);
		if (workspace.getDescription()!=null) {
			l.setText(workspace.getDescription());
		}
		l.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
		((GridData) l.getLayoutData()).horizontalSpan=((GridLayout) this.getLayout()).numColumns;
		

		tasksTableViewer = new TasksTableViewer(this, workspaceTabFolder);
		((GridData) tasksTableViewer.getTable().getLayoutData()).horizontalSpan=((GridLayout) this.getLayout()).numColumns;
		
		Button refreshTasksTableButton = new Button(this, SWT.PUSH);
		refreshTasksTableButton.setText("Refresh table");
		refreshTasksTableButton.setLayoutData(new GridData(SWT.LEFT, SWT.BOTTOM, true, false));
		
		Button addTaskDialogueButton = new Button(this, SWT.PUSH);
		addTaskDialogueButton.setText("Add task");
		addTaskDialogueButton.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));

		addTaskDialogueButton.addListener(SWT.Selection, new Listener() {
			private static final long serialVersionUID = 1L;

			@Override
			public void handleEvent(Event arg0) {
				CTabItem cTabItem = null;

				for (CTabItem c : workspaceTabFolder.getItems()) {
					if (c.getControl().getClass() == NewTaskDetails.class) {
						cTabItem = c;
						workspaceTabFolder.setSelection(c);
					}
				}

				if (cTabItem == null) {
					cTabItem = new CTabItem (workspaceTabFolder, SWT.CLOSE);
					cTabItem.setText ("New task");
					cTabItem.setControl(new NewTaskDetails(workspaceTabFolder));
					workspaceTabFolder.setSelection(cTabItem);
				}
			}
		});
	}

	public Workspace getWorkspace() {
		return workspace;
	}

	public TasksTableViewer getTasksTableViewer() {
		return tasksTableViewer;
	}

}

@@ -47,24 +47,50 @@
 rkspace;%0D%0A%0D%0A
+import java.util.List;%0D%0A%0D%0A
 import org.e
@@ -472,25 +472,115 @@
 .domain.
-Workspace
+Task;%0D%0Aimport ee.ut.cs.rum.database.domain.Workspace;%0D%0Aimport ee.ut.cs.rum.database.util.TaskAccess
 ;%0D%0Aimpor
@@ -2215,24 +2215,382 @@
 lse));%0D%0A%09%09%0D%0A
+%09%09refreshTasksTableButton.addListener(SWT.Selection, new Listener() %7B%0D%0A%09%09%09private static final long serialVersionUID = -4798041339203828187L;%0D%0A%0D%0A%09%09%09@Override%0D%0A%09%09%09public void handleEvent(Event arg0) %7B%0D%0A%09%09%09%09List%3CTask%3E workspaceTasks = TaskAccess.getWorkspaceTasksDataFromDb(workspace.getId());%0D%0A%09%09%09%09tasksTableViewer.setInput(workspaceTasks);%0D%0A%09%09%09%7D%0D%0A%09%09%7D);%0D%0A%09%09%0D%0A
 %09%09Button add
@@ -2635,24 +2635,24 @@
 SWT.PUSH);%0D%0A
-
 %09%09addTaskDia
@@ -2895,17 +2895,36 @@
 onUID = 
-1
+-7320478204056667508
 L;%0D%0A%0D%0A%09%09

Refresh tasks table on buttonclick