diff options
author | Simon Rettberg | 2015-07-08 19:39:35 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-07-08 19:39:35 +0200 |
commit | 8d6cd17c330388aa13fd7c39802c7400d85f972c (patch) | |
tree | 5f2c5856f58b1454e24dc16fad10751dfe9d087b /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java | |
parent | oops (diff) | |
download | tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.tar.gz tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.tar.xz tutor-module-8d6cd17c330388aa13fd7c39802c7400d85f972c.zip |
[client] Redo package structure, add comments/TODOs, rename GUI classes
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java | 369 |
1 files changed, 369 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java new file mode 100644 index 00000000..99d97eac --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java @@ -0,0 +1,369 @@ +package org.openslx.dozmod.gui.window.layout; + + +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 org.openslx.dozmod.gui.helper.GuiManager; +import org.openslx.dozmod.gui.helper.TableHelper; +import org.openslx.dozmod.gui.wizard.ImageWizard; + +public abstract class ImageListWindowLayout 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 ImageListWindowLayout(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); + + TableHelper.createImageTableColumns(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(); + } + }); + + + } +} |