summaryrefslogtreecommitdiffstats
path: root/src/com/ibm/ServerWizard2/view/ErrataViewer.java
blob: 8c62cbc8fe85f987f05586d29326b561b4dc252b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.ibm.ServerWizard2.view;

import java.util.Vector;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.wb.swt.SWTResourceManager;

import com.ibm.ServerWizard2.model.Errata;

public class ErrataViewer extends Dialog {

	/**
	 * Create the dialog.
	 * 
	 * @param parentShell
	 */
	Vector<Errata> errata = new Vector<Errata>();
	private Table table;
	private StyledText styledText;
	
	public ErrataViewer(Shell parentShell, Vector<Errata> errata) {
		super(parentShell);
		this.errata = errata;
	}

	/**
	 * Create contents of the dialog.
	 * 
	 * @param parent
	 */
	@Override
	protected Control createDialogArea(Composite parent) {
		Composite container = (Composite) super.createDialogArea(parent);
		container.setLayout(new FillLayout(SWT.HORIZONTAL));

		table = new Table(container, SWT.CHECK | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
		table.setSize(100, 100);

		styledText = new StyledText(container, SWT.BORDER);
		styledText.setFont(SWTResourceManager.getFont("Courier New", 8, SWT.NORMAL));
		
		for (int i=errata.size()-1;i>=0;i--) {
			TableItem item = new TableItem(table, SWT.NONE);
			item.setText(errata.get(i).getId());
			item.setData(errata.get(i));
		}
		
		table.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent arg0) {
				if (table.getSelectionCount() > 0) {
					TableItem item = table.getSelection()[0];
					Errata e = (Errata) item.getData();
					styledText.setText(e.getDetail());
				}
			}
		});
		
		table.addListener (SWT.Selection, new Listener() {
			@Override
			public void handleEvent(Event event) {
				TableItem item = (TableItem) event.item;
				Errata e = (Errata) item.getData();
				if (item.getChecked()) {
					e.setApplied(true);
				} else {
					e.setApplied(false);
				}
			}
		});
		
		return container;
	}

	/**
	 * Create contents of the button bar.
	 * 
	 * @param parent
	 */
	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		Button button = createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
		createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
	}

	/**
	 * Return the initial size of the dialog.
	 */
	@Override
	protected Point getInitialSize() {
		return new Point(675, 377);
	}
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("Errata Viewer");
	}
}
OpenPOWER on IntegriCloud