summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/core/ImageWindowComposite.java
blob: 6a024e3f991b4000ea638f7a0bccd6ea5997a995 (plain) (blame)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
package gui.core;


import gui.GuiManager;
import gui.helper.VMColumns;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.LinkedList;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;

import wizards.ImageWizard;

public class ImageWindowComposite extends Composite {

	protected String infoTitleString = "Imageauswahl";
	protected String newButtonLabel = "Neu";
	protected String editButtonLabel = "Bearbeiten";
	protected String deleteButtonLabel = "Löschen";
	protected String downloadButtonLabel = "Download";
	protected String tableGroupLabel = "Images";
	protected String vmInfoGroupLabel = "Detailinformationen";
	
	
	// buttons
	protected Button newButton;
	protected Button deleteButton;
	protected Button editButton;
	protected Button downloadButton;
	
	// imageDetail texts
	protected Text imageSelectedNameLabel;
	protected Text idInfo;
	protected Text versionInfo;
	protected Text lastUpdateInfo;
	protected Text permissionInfo;
	protected Text ownerInfo;
	protected Text templateInfo;


	protected String infoTextString = "Hier können Sie images erstellen, bearbeiten und löschen.";

	public ImageWindowComposite(Composite mainShell) {
		super(mainShell, SWT.NONE);

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



		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.horizontalSpan = 2;
		Composite infoComposite = new Composite(this, SWT.BORDER);
		infoComposite.setLayoutData(gridData);
		infoComposite.setLayout(new GridLayout(1, false));



		Label infoTitle = new Label(infoComposite, SWT.NONE);
		infoTitle.setText(infoTitleString);
		FontData fontData = infoTitle.getFont().getFontData()[0];
		Font font = new Font(GuiManager.getDisplay(), new FontData(fontData.getName(), fontData
				.getHeight(), SWT.BOLD));
		infoTitle.setFont(font);

		Label infoText = new Label(infoComposite, SWT.NONE);
		infoText.setText(infoTextString);



		// group for the table
		Group tableGroup = new Group(this, SWT.BORDER);
		tableGroup.setText(tableGroupLabel);
		gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
		tableGroup.setLayoutData(gridData);
		tableGroup.setLayout(new GridLayout(3, true));

		// jface tableviewer on swt table
		Table vmTable = new Table(tableGroup, SWT.BORDER | SWT.V_SCROLL
				| SWT.H_SCROLL);
		gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
		gridData.horizontalSpan = 3;
		gridData.minimumWidth = 200;
		vmTable.setLayoutData(gridData);
		vmTable.setHeaderVisible(true);
		vmTable.setLinesVisible(true); 

		// TableViewer on the table
		final TableViewer tableViewer = new TableViewer(vmTable);
		tableViewer.setContentProvider(ArrayContentProvider.getInstance());



		// For testing
		ImageSummaryRead imageSummary = new ImageSummaryRead();
		imageSummary.setImageName("Windoof");
		imageSummary.setOsId(1);
		LinkedList<ImageSummaryRead> list = new LinkedList<>();
		imageSummary.setUserPermissions(new ImagePermissions(true, true, false, false));
		imageSummary.setUpdateTime(505050550);
		imageSummary.setOwnerId("2");
		imageSummary.setImageBaseId("8");
		imageSummary.setCurrentVersionId("8.12");
		list.add(imageSummary);

		ImageSummaryRead imageSummary2 = new ImageSummaryRead();
		imageSummary2.setImageName("Linuksch");
		imageSummary2.setOsId(2);
		list.add(imageSummary2);

		// The List to be displayed in the viewer
		tableViewer.setInput(list);

		VMColumns.createVMTableColumns(tableViewer);

		tableViewer.refresh();

		// create, modify, download and delete buttons	
		Composite buttonComposite = new Composite(tableGroup, SWT.NONE);
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.horizontalSpan = 4;
		gridData.minimumWidth = 200;
		buttonComposite.setLayoutData(gridData);
		buttonComposite.setLayout(new RowLayout());


		
		newButton = new Button(buttonComposite, SWT.PUSH);
		newButton.setText(newButtonLabel);

		editButton = new Button(buttonComposite, SWT.PUSH);
		editButton.setText(editButtonLabel);

		deleteButton = new Button(buttonComposite, SWT.PUSH);
		deleteButton.setText(deleteButtonLabel);

		downloadButton = new Button(buttonComposite, SWT.PUSH);
		downloadButton.setText(downloadButtonLabel);


		// group for the info of the clicked image in the tableViewer
		Group vmInfoGroup = new Group(this, SWT.BORDER);
		vmInfoGroup.setText(vmInfoGroupLabel);
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.minimumWidth = 300;
		vmInfoGroup.setLayoutData(gridData);
		vmInfoGroup.setLayout(new GridLayout(2, false));


		// image name info
		Label imageNameCaption = new Label(vmInfoGroup, SWT.NONE);
		imageSelectedNameLabel = new Text(vmInfoGroup, SWT.READ_ONLY);

		imageNameCaption.setText("Image Name:");
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.minimumWidth = 100;
		imageSelectedNameLabel.setLayoutData(gridData);

		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection)
						tableViewer.getSelection();
				ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
				String s = selectedElement.getImageName();
				if (s == null) {
					imageSelectedNameLabel.setText("Unknown");
				} else {
					imageSelectedNameLabel.setText(s);
				}
			}
		});


		// id info
		Label idInfoCaption = new Label(vmInfoGroup, SWT.NONE);
		idInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
		idInfoCaption.setText("ID:");
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.minimumWidth = 100;
		idInfo.setLayoutData(gridData);

		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection)
						tableViewer.getSelection();
				ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
				String s = selectedElement.getImageBaseId();
				if (s == null) {
					idInfo.setText("Unknown");
				} else {
					idInfo.setText(s);
				}
			}
		});
		//		imageSummary.get

		
		
		Label versionInfoCaption = new Label(vmInfoGroup, SWT.NONE);
		versionInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
		versionInfoCaption.setText("Version:");
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.minimumWidth = 100;
		versionInfo.setLayoutData(gridData);

		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection)
						tableViewer.getSelection();
				ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
				String s = selectedElement.getCurrentVersionId();
				if (s == null) {
					versionInfo.setText("Unknown");
				} else {
					versionInfo.setText(s);
				}
			}
		});


		Label lastUpdateInfoCaption = new Label(vmInfoGroup, SWT.NONE);
		lastUpdateInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
		lastUpdateInfoCaption.setText("Letztes Update:");
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.minimumWidth = 100;
		lastUpdateInfo.setLayoutData(gridData);

		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection)
						tableViewer.getSelection();
				ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
				long unixTimestamp = selectedElement.getUpdateTime();


				if (unixTimestamp == 0) {
					lastUpdateInfo.setText("Unknown");
				} else {
					Date date = new Date(unixTimestamp*1000L);
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
					String formattedDate = sdf.format(date);
					lastUpdateInfo.setText(formattedDate);
				}
			}
		});

		Label permissionInfoCaption = new Label(vmInfoGroup, SWT.NONE);
		permissionInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
		permissionInfoCaption.setText("Berechtigungen:");
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.minimumWidth = 100;
		permissionInfo.setLayoutData(gridData);

		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection)
						tableViewer.getSelection();
				ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
				ImagePermissions p =selectedElement.getUserPermissions();
				if (p != null){
					String s = p.toString();
					if (s == null) {
						permissionInfo.setText("Unknown");
					} else {
						permissionInfo.setText(s);
					}
				} else {
					permissionInfo.setText("Unknown");
				}

			}
		});


		Label ownerInfoCaption = new Label(vmInfoGroup, SWT.NONE);
		ownerInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
		ownerInfoCaption.setText("Besitzer ID:");
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.minimumWidth = 100;
		ownerInfo.setLayoutData(gridData);

		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection)
						tableViewer.getSelection();
				ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();

				String s = selectedElement.getOwnerId();

				if (s != null) {
					ownerInfo.setText(s);
				} else {
					ownerInfo.setText("Unknown");
				}

			}
		});

		Label templateCaption = new Label(vmInfoGroup, SWT.NONE);
		templateInfo = new Text(vmInfoGroup, SWT.READ_ONLY);
		templateCaption.setText("Vorlage:");
		gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
		gridData.minimumWidth = 100;
		templateInfo.setLayoutData(gridData);

		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection)
						tableViewer.getSelection();
				ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();

				if (selectedElement.isTemplate) {
					templateInfo.setText("ja");
				} else {
					templateInfo.setText("Nein");
				}
			}
		});


		newButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ImageWizard wizard = new ImageWizard(false);
				WizardDialog wd = new WizardDialog(getShell(), wizard);
				wd.open();
			}
		});

		editButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				ImageWizard wizard = new ImageWizard(true);
				WizardDialog wd = new WizardDialog(getShell(), wizard);
				wd.open();
			}
		});


	}
}