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/gui | |
| 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/gui')
12 files changed, 0 insertions, 1672 deletions
diff --git a/dozentenmodul/src/main/java/gui/GuiManager.java b/dozentenmodul/src/main/java/gui/GuiManager.java deleted file mode 100644 index 4df4b6a0..00000000 --- a/dozentenmodul/src/main/java/gui/GuiManager.java +++ /dev/null @@ -1,147 +0,0 @@ -package gui; - -import org.apache.log4j.Logger; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.MenuItem; -import org.eclipse.swt.widgets.MessageBox; -import org.eclipse.swt.widgets.Monitor; -import org.eclipse.swt.widgets.Shell; -import org.openslx.thrifthelper.ThriftManager; -import org.openslx.thrifthelper.ThriftManager.ErrorCallback; - -public abstract class GuiManager { - - private final static Logger LOGGER = Logger.getLogger(GuiManager.class); - - static Shell mainShell; - static Composite contentComposite; - static Display display; - - static final int THRIFT_ERROR_RETRY_COUNT = 3; - static final String THRIFT_ERROR = "Lost connection to the masterserver. Click OK to retry."; - static final String THRIFT_FINAL_ERROR = "Could not re-establish connection to the masterserver after " - + THRIFT_ERROR_RETRY_COUNT + " tries. Contact an administrator/developer. Exiting application."; - - /** - * Add a new composite with content to the main Shell - * @param The composite to add, should be a GUI - */ - public static void addContent( Composite contentComposite ){ - removeContent(); - - GuiManager.contentComposite = contentComposite; - - // sets the starting preferred size. - GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - gridData.widthHint = 800; - gridData.heightHint = 600; - contentComposite.setLayoutData(gridData); - mainShell.setMinimumSize(850, 650); - mainShell.layout(); - - } - - /** - * Remove the current content of the main shell - */ - private static void removeContent() { - if(contentComposite != null) { - GuiManager.contentComposite.dispose(); - - } - } - - // TODO use showMessageBox - public static void showMessage(final String message, final int style) { - MessageBox msgBox = new MessageBox(mainShell, style); - msgBox.setText("Information"); - msgBox.setMessage(message); - int ret = msgBox.open(); - LOGGER.info("Message box return value: " + ret); - } - - public static Display getDisplay(){ - return display; - } - - public static void initGui() { - display = new Display(); - mainShell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER); - - // setup global thrift connection error handler before anything else - // Set master server to use (TODO: make configurable via command line) - ThriftManager.setMasterServerAddress( "bwlp-masterserver.ruf.uni-freiburg.de" ); - - // Set up thrift error message displaying - ThriftManager.setErrorCallback(new ErrorCallback() { - - @Override - public boolean thriftError(int failCount, String method, Throwable t) { - // first check if we failed 3 reconnects, if so just let the user know - // that we are closing the application due to connection problems. - MessageBox msgBox = new MessageBox(mainShell, SWT.ICON_ERROR); - msgBox.setText("Critical error"); - if (failCount > THRIFT_ERROR_RETRY_COUNT) { - msgBox.setMessage(THRIFT_FINAL_ERROR); - return false; - } else { - msgBox.setMessage(THRIFT_ERROR); - return true; - } - } - }); - - Menu menuBar = new Menu(mainShell, SWT.BAR); - MenuItem cascadeFileMenu = new MenuItem(menuBar, SWT.CASCADE); - cascadeFileMenu.setText("&File"); - - Menu fileMenu = new Menu(mainShell, SWT.DROP_DOWN); - cascadeFileMenu.setMenu(fileMenu); - - MenuItem exitItem = new MenuItem(fileMenu, SWT.PUSH); - exitItem.setText("&Exit"); - exitItem.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - mainShell.getDisplay().dispose(); - System.exit(0); - } - }); - - mainShell.setText("bwSuite"); - mainShell.setMenuBar(menuBar); - - // Set layout for the mainshell, items added to the shell should get a gridData - mainShell.setLayout(new GridLayout(1, true)); - - addContent(new gui.core.LoginGUI(mainShell)); - - // center the window on the primary monitor - Monitor primary = display.getPrimaryMonitor(); - Rectangle bounds = primary.getBounds(); - Rectangle rect = mainShell.getBounds(); - - int x = bounds.x + (bounds.width - rect.width) / 2; - int y = bounds.y + (bounds.height - rect.height) / 2; - - mainShell.setLocation(x, y); - - mainShell.pack(); - mainShell.open(); - - LOGGER.info("GUI initialised."); - - while (!mainShell.isDisposed()) { - if (!display.readAndDispatch()) - display.sleep(); - } - } -} diff --git a/dozentenmodul/src/main/java/gui/controls/BlockProgressBar.java b/dozentenmodul/src/main/java/gui/controls/BlockProgressBar.java deleted file mode 100644 index 94fd9ffd..00000000 --- a/dozentenmodul/src/main/java/gui/controls/BlockProgressBar.java +++ /dev/null @@ -1,153 +0,0 @@ -package gui.controls; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -import org.eclipse.swt.widgets.Canvas; -import org.eclipse.swt.widgets.Composite; -import org.openslx.thrifthelper.TransferStatusWrapper; - -public class BlockProgressBar extends Canvas { - - private final Color white, blue, black; - - private final Color[] blockColors = new Color[5]; - - private final TransferStatusWrapper blocks = new TransferStatusWrapper(null); - - private boolean simpleMode = true; - - public BlockProgressBar(Composite parent) { - super(parent, SWT.NO_BACKGROUND); - setupListeners(); - white = getDisplay().getSystemColor(SWT.COLOR_WHITE); - blue = getDisplay().getSystemColor(SWT.COLOR_BLUE); - black = getDisplay().getSystemColor(SWT.COLOR_BLACK); - // 0 = complete, 1 = missing, 2 = uploading, 3 = queued for copying, 4 = copying - blockColors[0] = black; - blockColors[1] = getDisplay().getSystemColor(SWT.COLOR_RED); - blockColors[2] = getDisplay().getSystemColor(SWT.COLOR_YELLOW); - blockColors[3] = blue; - blockColors[4] = getDisplay().getSystemColor(SWT.COLOR_GREEN); - } - - public void setStatus(byte[] blocks) { - this.blocks.setBlocks(blocks); - this.redraw(); - } - - private void setupListeners() { - final BlockProgressBar me = this; - // Paint listener - this.addPaintListener(new PaintListener() { - @Override - public void paintControl(PaintEvent e) { - me.draw(e); - } - }); - - this.addMouseListener(new MouseListener() { - - @Override - public void mouseUp(MouseEvent e) { - } - - @Override - public void mouseDown(MouseEvent e) { - } - - @Override - public void mouseDoubleClick(MouseEvent e) { - me.toggleMode(); - } - }); - } - - private void toggleMode() { - simpleMode = !simpleMode; - this.redraw(); - } - - private void draw(PaintEvent e) { - if (blocks.isEmpty()) { - // No valid block data, draw white window - e.gc.setBackground(white); - e.gc.fillRectangle(e.x, e.y, e.width, e.height); - } else if (simpleMode) { - drawSimple(e); - } else { - drawDetailed(e); - } - } - - private void drawSimple(PaintEvent e) { - final Rectangle a = this.getClientArea(); - final float width = a.width - 2; - final float complete = blocks.getComplete(); - final float doneWidth = width * complete; - e.gc.setBackground(blue); - e.gc.fillRectangle(a.x, a.y, (int) doneWidth, a.height); - e.gc.setBackground(white); - e.gc.fillRectangle(a.x + (int) doneWidth, a.y, (int) (width - doneWidth), a.height); - final String progress = (int) (complete * 100) + "%"; - Point textExtent = e.gc.textExtent(progress, SWT.DRAW_TRANSPARENT); - final int textX = a.x + (a.width - textExtent.x) / 2; - final int textY = a.y + (a.height - textExtent.y) / 2; - e.gc.setForeground(white); - e.gc.drawText(progress, textX - 1, textY - 1, true); - e.gc.drawText(progress, textX + 1, textY + 1, true); - e.gc.setForeground(black); - e.gc.drawText(progress, textX, textY, true); - } - - private void drawDetailed(PaintEvent e) { - final int blockCount = blocks.getBlockCount(); - // Calculate display mode - final Rectangle a = this.getClientArea(); - final float width = a.width - 2; - float blockWidth = width / blockCount; - int rows = 1; - while (blockWidth * rows < 6 && a.height / rows > 8) { - rows++; - } - blockWidth *= rows; - final float blockHeight; - final float blockHeightVisible; - if (rows == 1) { - blockHeightVisible = blockHeight = a.height; - } else { - blockHeight = (a.height + 2) / rows; - blockHeightVisible = blockHeight - 2; - } - // Draw - float x = a.x, y = a.y; - for (byte block : blocks.getBlocks()) { - if (block >= 0 && block < blockColors.length) { - e.gc.setBackground(blockColors[block]); - } else { - e.gc.setBackground(white); - } - e.gc.fillRectangle((int) x, (int) y, (int) (x + blockWidth) - (int) x, - (int) (y + blockHeightVisible) - (int) y); - x += blockWidth; - if (x + 0.5 > a.width) { - e.gc.setBackground(white); - e.gc.fillRectangle(a.x, (int) (y + blockHeightVisible), a.width, 2); - x = a.x; - y += blockHeight; - } - } - // If we're multiline and have an odd number of blocks, there might be some remaining space - draw white - if (x + 0.5 < a.width) { - e.gc.setBackground(white); - e.gc.fillRectangle((int) x, (int) y, (int) (x + blockWidth) - (int) x, - (int) (y + blockHeightVisible) - (int) y); - } - } - -} diff --git a/dozentenmodul/src/main/java/gui/core/DisclaimerComposite.java b/dozentenmodul/src/main/java/gui/core/DisclaimerComposite.java deleted file mode 100644 index c4d48a60..00000000 --- a/dozentenmodul/src/main/java/gui/core/DisclaimerComposite.java +++ /dev/null @@ -1,87 +0,0 @@ -package gui.core; - -import org.eclipse.swt.SWT; -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.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - - -public class DisclaimerComposite extends Composite { - - private final String notice = "Bitte lesen und bestätigen Sie folgende rechtliche Hinweise"; - private final String disclaimer = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. \n\n" - + "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. \n\n" - + "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\n" - + "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.\n\n" - + "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.\n\n" - + "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.\n\n" - + "Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus.\n\n" - + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.\n\n" - + "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.\n\n" - + "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.\n\n" - + "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo"; - - private final String checkboxText = "Ja, ich aktzeptiere die Vereinbarung. Benachrichtigung nicht mehr anzeigen."; - - private final String title = "bwLehrpool Suite"; - private final String noticeLabel = "Hinweis"; - - // Buttons - protected Button agreeBox; - Button continueButton; - - public DisclaimerComposite(final Shell mainShell) { - super(mainShell, SWT.NONE); - - - mainShell.setText(title); - - // layout of this composite - this.setLayout(new GridLayout(1, true)); - - - // information to read the disclaimer at the beginning of the window. - Group noticeGroup = new Group(this, SWT.NONE); - noticeGroup.setLayout(new GridLayout()); - GridData gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); - noticeGroup.setLayoutData(gridData); - noticeGroup.setText(noticeLabel); - - Label noticeLabel = new Label(noticeGroup, SWT.NONE); - noticeLabel.setText(notice); - - - // the disclaimer text box with scrolling functionality - Text disclaimerText = new Text(this, SWT.READ_ONLY | SWT.WRAP| SWT.MULTI | SWT.V_SCROLL | SWT.BORDER); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - gridData.widthHint = 900; - gridData.heightHint = 600; - disclaimerText.setLayoutData(gridData); - disclaimerText.setText(disclaimer); - - - // checkbox for acknowledging the disclaimer - Composite checkboxComposite = new Composite(this, SWT.BORDER); - checkboxComposite.setLayout(new GridLayout()); - gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); - - checkboxComposite.setLayoutData(gridData); - - agreeBox = new Button(checkboxComposite, SWT.CHECK); - agreeBox.setText(checkboxText); - - - continueButton = new Button(this, SWT.PUSH); - continueButton.setText("Weiter"); - continueButton.setEnabled(false); - - gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); - gridData.horizontalAlignment = SWT.RIGHT; - continueButton.setLayoutData(gridData); - } -} diff --git a/dozentenmodul/src/main/java/gui/core/DisclaimerGUI.java b/dozentenmodul/src/main/java/gui/core/DisclaimerGUI.java deleted file mode 100644 index 5a53150e..00000000 --- a/dozentenmodul/src/main/java/gui/core/DisclaimerGUI.java +++ /dev/null @@ -1,44 +0,0 @@ -package gui.core; - -import gui.GuiManager; - -import org.apache.log4j.Logger; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Shell; - -import config.Config; - -public class DisclaimerGUI extends DisclaimerComposite{ - - private final static Logger LOGGER = Logger.getLogger(DisclaimerGUI.class); - - public DisclaimerGUI(final Shell mainShell) { - super(mainShell); - - // function for agreement checkbox - agreeBox.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - continueButton.setEnabled(!continueButton.isEnabled()); - } - }); - - // function for continue button - continueButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - // save the agreement to config - if (!Config.setDisclaimerAgreement(true)) - LOGGER.error("Could not set the agreement to the disclaimer in '" + Config.getPath() + "'!"); - Config.store(); - // now check the config to see if the user has agreed to vmware stuff - if (!Config.getVmwareLicenseAgreement()) - GuiManager.addContent(new VMWareInfoGUI(getShell())); - else - GuiManager.addContent(new MainWindowComposite(getShell())); - } - }); - } - -} diff --git a/dozentenmodul/src/main/java/gui/core/ImageWindowComposite.java b/dozentenmodul/src/main/java/gui/core/ImageWindowComposite.java deleted file mode 100644 index 6a024e3f..00000000 --- a/dozentenmodul/src/main/java/gui/core/ImageWindowComposite.java +++ /dev/null @@ -1,371 +0,0 @@ -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(); - } - }); - - - } -} diff --git a/dozentenmodul/src/main/java/gui/core/LoginComposite.java b/dozentenmodul/src/main/java/gui/core/LoginComposite.java deleted file mode 100644 index d4266adb..00000000 --- a/dozentenmodul/src/main/java/gui/core/LoginComposite.java +++ /dev/null @@ -1,171 +0,0 @@ -package gui.core; - -import gui.GuiManager; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -public class LoginComposite extends Composite { - - // TODO add ids to use for the authButtons group! - protected static enum LOGIN_TYPE { - BWIDM(0, "bwidm"), - BWLP(1, "bwlp"), - SAT(2, "sat"); - - private final int id; - private final String tag; - private LOGIN_TYPE(final int id, final String tag) { - this.id = id; - this.tag = tag; - } - public int getId() { return this.id; } - public String getTag() { return this.tag; } - - public static LOGIN_TYPE getEnum(String tag) { - switch(tag) { - case "bwidm": return LOGIN_TYPE.BWIDM; - case "bwlp": return LOGIN_TYPE.BWLP; - case "sat": return LOGIN_TYPE.SAT; - default: return null; - } - } - } - // authentication method to use for login attempts - protected LOGIN_TYPE loginType = null; - - private Image titleImage; - - - // textfields for the username/password - protected Text usernameText; - protected Text passwordText; - - // ComboBox/label for the IDP - protected final Combo idpCombo; - protected final Label idpText; - - // buttons - protected final Button loginButton; - protected final Button saveUsernameCheck; - protected final Button[] authButtons; - - private static final String title = "bwSuite - Login"; - private static final String authenticationGroupLabel = "Authentifizierungsart"; - - /** - * Create a new login composite - * - * @param mainShell - * The shell it should be added to - */ - public LoginComposite(final Shell mainShell) { - super(mainShell, SWT.NONE); - - // title for composite - mainShell.setText(title); - - // left authentication selection and right loginmask - GridLayout gridLayout = new GridLayout(2, true); - this.setLayout(gridLayout); - - // load the needed Picture - loadImage(); - - Label titlePicture = new Label(this, SWT.NONE); - titlePicture.setImage(titleImage); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - gridData.horizontalSpan = 2; - gridData.horizontalAlignment = SWT.CENTER; - titlePicture.setLayoutData(gridData); - - - // group for the authentication method. - // groups have borders and a title - Group authGroup = new Group(this, SWT.NONE); - authGroup.setText(authenticationGroupLabel); - gridLayout = new GridLayout(); - gridLayout.numColumns = 1; - authGroup.setLayout(gridLayout); - gridData = new GridData(GridData.FILL, GridData.FILL, false, false); - gridData.heightHint = 150; - authGroup.setLayoutData(gridData); - - // add the authentication method selection buttons - authButtons = new Button[3]; - authButtons[LOGIN_TYPE.BWIDM.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.BWIDM.id].setText("Authentifizierung über bwIDM"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.BWIDM.id].setLayoutData(gridData); - - authButtons[LOGIN_TYPE.BWLP.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.BWLP.id].setText("Test-Zugang mit festem Benutzernamen"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.BWLP.id].setLayoutData(gridData); - - authButtons[LOGIN_TYPE.SAT.id] = new Button(authGroup, SWT.RADIO); - authButtons[LOGIN_TYPE.SAT.id].setText("Direkte Verbindung zum Satelliten"); - gridData = new GridData(GridData.FILL, GridData.FILL, true, true); - authButtons[LOGIN_TYPE.SAT.id].setLayoutData(gridData); - - // group for the login mask - final Group loginGroup = new Group(this, SWT.NONE); - loginGroup.setText("Zugangsdaten"); - gridLayout = new GridLayout(); - gridLayout.numColumns = 2; - loginGroup.setLayout(gridLayout); - gridData = new GridData(GridData.FILL, GridData.CENTER, true, false); - gridData.heightHint = 150; - loginGroup.setLayoutData(gridData); - - idpText = new Label(loginGroup, SWT.NONE); - idpText.setText("IdP:"); - - idpCombo = new Combo(loginGroup, SWT.DROP_DOWN | SWT.READ_ONLY); - idpCombo.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, - false)); - - new Label(loginGroup, SWT.NONE).setText("Benutzername:"); - usernameText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER); - usernameText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, - true, false)); - - new Label(loginGroup, SWT.NONE).setText("Passwort:"); - passwordText = new Text(loginGroup, SWT.SINGLE | SWT.BORDER | SWT.PASSWORD); - passwordText.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, - true, false)); - // login button - loginButton = new Button(loginGroup, SWT.PUSH); - loginButton.setText("Login"); - saveUsernameCheck = new Button(loginGroup, SWT.CHECK); - saveUsernameCheck.setText("Benutzername speichern"); - - } - - private void loadImage() { - try { - // TODO use the ResourceLoader class to load the logo - // this way, we can be sure to get an image - // (since the ResourceLoader always returns an image, - // even if it cannot load the specified one). - titleImage = new Image(GuiManager.getDisplay(), getClass() - .getResourceAsStream("/img/Logo_bwLehrpool.png")); - ImageData imgData = titleImage.getImageData(); - imgData = imgData.scaledTo(imgData.width / 5, imgData.height / 5); - titleImage = new Image(GuiManager.getDisplay(), imgData); - } catch (Exception e) { - System.out.println("Cannot load image"); - System.out.println(e.getMessage()); - } - } -} diff --git a/dozentenmodul/src/main/java/gui/core/LoginGUI.java b/dozentenmodul/src/main/java/gui/core/LoginGUI.java deleted file mode 100644 index 795ccc4b..00000000 --- a/dozentenmodul/src/main/java/gui/core/LoginGUI.java +++ /dev/null @@ -1,331 +0,0 @@ -package gui.core; - -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.apache.log4j.Logger; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Shell; -import org.openslx.bwlp.dozmod.thrift.OrganizationCache; -import org.openslx.bwlp.thrift.iface.Organization; -import org.openslx.bwlp.thrift.iface.TAuthenticationException; -import org.openslx.bwlp.thrift.iface.UserInfo; -import org.openslx.thrifthelper.ThriftManager; - -import util.ShibbolethECP.ReturnCode; -import auth.BWIDMAuthenticator; -import auth.BWLPAuthenticator; -import auth.BaseAuthenticator.AuthenticatorCallback; -import config.Config; -import edu.kit.scc.dei.ecplean.ECPAuthenticationException; -import gui.GuiManager; - -/** - * @author Jonathan Bauer - * - */ -public class LoginGUI extends LoginComposite { - - private final static Logger LOGGER = Logger.getLogger(LoginGUI.class); - - // text constants - private final String NO_USERNAME = "Kein Benutzername angegeben!"; - private final String NO_PASSWORD = "Kein Passwort angegeben!"; - - // user input variables - private String username = null; - private String password = null; - - - /** - * Constructor doing the setup of the logical GUI functions - * Fetches the organization list for BWIDM logins and - * adds mouse/keyboard event listeners to various widgets. - * - * @param mainShell - */ - public LoginGUI(final Shell mainShell) { - // call the constructor of the superclass - super(mainShell); - - // entries in the combo - List<Organization> orgs = OrganizationCache.getAll(); - if (orgs == null) { - LOGGER.error("No organizations received from the cache."); - idpCombo.add("No entries"); - } - - // all fine, lets sort it - Collections.sort(orgs, new Comparator<Organization>() { - public int compare(Organization o1, Organization o2) { - return o1.getDisplayName().compareTo(o2.getDisplayName()); - } - }); - - // now check if we had a saved identity provider - String savedOrganizationId = Config.getIdentityProvider(); - // add only organizations which have an ECP URL to the combobox - for (Organization o : orgs) { - if (o.getEcpUrl() == null | o.getEcpUrl().isEmpty()) continue; - LOGGER.debug("Adding: " + o.toString()); - idpCombo.add(o.displayName); - idpCombo.setData(o.displayName, o); - if (savedOrganizationId != null && - !savedOrganizationId.isEmpty() && - savedOrganizationId.equals(o.getOrganizationId())) - // select the organization we just added, this seems kinda bad - is there a better way? - idpCombo.select(idpCombo.getItemCount() - 1); - //idpCombo.select(idpCombo.indexOf(savedOrganizationId)); this is probably not optimal... but safer - } - // if no organization was saved, none is selected, so select the first one in the combobox - if (idpCombo.getSelectionIndex() == -1) - idpCombo.select(0); - // check if we had saved an authentication method - String savedAuthMethod = Config.getAuthenticationMethod(); - if (savedAuthMethod != null && !savedAuthMethod.isEmpty()) { - LOGIN_TYPE savedLoginType = LOGIN_TYPE.getEnum(savedAuthMethod); - // if no valid LOGIN_TYPE was saved, just enable the BWIDM button - if (savedLoginType == null) { - authButtons[LOGIN_TYPE.BWIDM.getId()].setSelection(true); - loginType = LOGIN_TYPE.BWIDM; - } else { - authButtons[savedLoginType.getId()].setSelection(true); - loginType = savedLoginType; - idpText.setVisible(savedLoginType == LOGIN_TYPE.BWIDM); - idpCombo.setVisible(savedLoginType == LOGIN_TYPE.BWIDM); - } - } else { - // default value for LOGIN_TYPE is BWIDM - authButtons[LOGIN_TYPE.BWIDM.getId()].setSelection(true); - loginType = LOGIN_TYPE.BWIDM; - } - - - // finally check if we had a saved username - String savedUsername = Config.getUsername(); - if (savedUsername != null && !savedUsername.isEmpty()) { - usernameText.setText(savedUsername); - saveUsernameCheck.setSelection(true); - passwordText.setFocus(); - } else - usernameText.setFocus(); - - // actions of the login button - loginButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - doSaveConfig(); - doLogin(); - } - }); - - // for save username checkbox. - saveUsernameCheck.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - // clickedSaveUsernameCheck(); - } - }); - - // selecting the "Authentifizierung über bwIDM" radio button - authButtons[0].addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - idpText.setVisible(true); - idpCombo.setVisible(true); - loginType = LOGIN_TYPE.BWIDM; - } - }); - - // selecting the "Test-Zugang mit festem Benutzer" radio button - authButtons[1].addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - idpText.setVisible(false); - idpCombo.setVisible(false); - loginType = LOGIN_TYPE.BWLP; - } - }); - - authButtons[2].setEnabled(false); - // selecting the "Direkte Verbindung zum Satteliten" radio button - authButtons[2].addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - idpText.setVisible(false); - idpCombo.setVisible(false); - loginType = LOGIN_TYPE.SAT; - } - }); - - // add a key listener to the password field to trigger login - // when the user presses the ENTER key. - passwordText.addKeyListener(new KeyListener() { - - @Override - public void keyReleased(KeyEvent e) { - if (e.keyCode == SWT.CR) { - doSaveConfig(); - doLogin(); - } - } - @Override - public void keyPressed(KeyEvent e) {} - }); - } - - /** - * Saves various user choices to the config file. - * This gets triggered when the login button is activated. - */ - private void doSaveConfig() { - // first we need to check if the "Remember me" button is active - if (saveUsernameCheck.isEnabled()) { - // save username - String username = usernameText.getText(); - if (username != null && !username.isEmpty()) { - // all good, save it - if (!Config.setUsername(username)) - LOGGER.error("Could not save username '" + username + "' to '" + Config.getPath() + "'."); - } - } - // always save the authentication method and potentially the identity provider - if (!Config.setAuthenticationMethod(loginType.getTag())) - LOGGER.error("Could not save authentication method '" + loginType.getTag() + "' to '" + Config.getPath() + "'."); - // check if we are doing bwIDM authentication - if (loginType == LOGIN_TYPE.BWIDM) { - // save the selected identity provider - Organization selectedOrg = getSelectedOrganization(); - if (!Config.setIdentityProvider(selectedOrg.organizationId)) - LOGGER.error("Could not save the identity provider '" + selectedOrg.organizationId + "'!"); - } - // finalize by actually storing the config file - if (!Config.store()) - LOGGER.error("Could not save '" + Config.getPath() + "'!"); - } - /** - * Actually do the login using the username/password in the field using the - * authentication mechanism corresponding to the selected authButton - * @throws ECPAuthenticationException - */ - private void doLogin() { - // sanity check on loginType. - if (loginType == null) { - LOGGER.error("No login type set, a default should be set! Ignoring..."); - return; - } - // here we only check for the fields - username = usernameText.getText(); - password = passwordText.getText(); - // login clicked, lets first read the fields - if (username == null) { - // tell the GUIManager to show an error to the user - // TODO either popup or in the bottom status bar - GuiManager.showMessage(NO_USERNAME, SWT.ICON_ERROR); - return; - } - if (password == null) { - // tell the GUIManager to show an error to the user - // TODO either popup or in the bottom status bar - GuiManager.showMessage(NO_PASSWORD, SWT.ICON_ERROR); - return; - } - - // determine which organization was selected by the user. - Organization selectedOrg = getSelectedOrganization(); - - // now switch over the login types. - switch (loginType) { - case BWIDM: - BWIDMAuthenticator bwidmAuth = new BWIDMAuthenticator( - selectedOrg.getEcpUrl()); - try { - bwidmAuth.login(username, password, new AuthenticatorCallback() { - @Override - public void postLogin(ReturnCode returnCode, UserInfo user) { - // TODO finish this - // handle errors first - if (returnCode != ReturnCode.NO_ERROR && user == null) { - switch(returnCode) { - case IDP_ERROR: - GuiManager.showMessage("IdP Error", SWT.ICON_ERROR); - break; - default: - GuiManager.showMessage("Internal error!", SWT.ICON_ERROR); - break; - } - } else - postSuccessfulLogin(); - } - }); - } catch (TAuthenticationException e) { - //LOGGER.error("Authentication error, see trace: ", e); - GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR); - return; - } - break; - case BWLP: - LOGGER.info("bwlp"); - BWLPAuthenticator bwlpAuth = new BWLPAuthenticator(); - try { - bwlpAuth.login(username, password, new AuthenticatorCallback() { - @Override - public void postLogin(ReturnCode returnCode, UserInfo user) { - // handle errors first - if (returnCode != ReturnCode.NO_ERROR && user == null) { - LOGGER.error("BWLP login failed."); - GuiManager.showMessage("Login failed!", SWT.ICON_ERROR); - } - if (returnCode == ReturnCode.NO_ERROR && user != null) - postSuccessfulLogin(); - } - }); - } catch (TAuthenticationException e) { - GuiManager.showMessage(e.getMessage(), SWT.ICON_ERROR); - } - break; - case SAT: - LOGGER.warn("Direct satellite login is not yet supported."); - break; - default: - LOGGER.error("Unknown login type! Ignoring..."); - break; - } - return; - } - - /** - * Functions called by doLogin is the login process succeeded. - */ - private void postSuccessfulLogin() { - LOGGER.info(loginType.getTag() + " succeeded."); - - ThriftManager.setSatelliteAddress( "132.230.8.113" ); - - // now read the config to see if the user already agreed to the disclaimer - if (!Config.getDisclaimerAgreement()) - GuiManager.addContent(new DisclaimerGUI(getShell())); - else if (!Config.getVmwareLicenseAgreement()) - GuiManager.addContent(new VMWareInfoGUI(getShell())); - else - GuiManager.addContent(new MainWindowComposite(getShell())); - } - - /** - * @return the organization currently selected in the combobox for identity providers - */ - private final Organization getSelectedOrganization() { - // get the index of the selected item in the combobox - int selectionIndex = idpCombo.getSelectionIndex(); - if (selectionIndex == -1) { - LOGGER.error("No identity provider is selected in the combobox. There should be a default value!"); - return null; - } - return (Organization) idpCombo.getData(idpCombo.getItem(selectionIndex)); - } -} diff --git a/dozentenmodul/src/main/java/gui/core/MainWindowComposite.java b/dozentenmodul/src/main/java/gui/core/MainWindowComposite.java deleted file mode 100644 index fe24a610..00000000 --- a/dozentenmodul/src/main/java/gui/core/MainWindowComposite.java +++ /dev/null @@ -1,111 +0,0 @@ -package gui.core; - - - -import gui.GuiManager; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -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.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - - -public class MainWindowComposite extends Composite { - // text for info for the vms selection - protected String vmInfo = "Infotext VMs."; - - // text for the info for the lecture selection - protected String lecturesInfo = "Infotext Veranstaltungen."; - - // buttons - protected Button vmButton; - protected Button lecturesButton; - - public MainWindowComposite(final Shell mainShell) { - super(mainShell, SWT.NONE); - - this.setLayout(new GridLayout(2, true)); - - // group for the vm selection - Group vmGroup = new Group(this, SWT.NONE); - vmGroup.setLayout(new GridLayout()); - vmGroup.setText("VMs"); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - vmGroup.setLayoutData(gridData); - - vmButton = new Button(vmGroup, SWT.PUSH); - vmButton.setText("VM - Übersicht"); - gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true); - vmButton.setLayoutData(gridData); - - - Label vmInfoLabel = new Label(vmGroup, SWT.NONE); - vmInfoLabel.setText(vmInfo); - gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - vmInfoLabel.setLayoutData(gridData); - - - //g group for the lecture selection - Group lecturesGroup = new Group(this, SWT.NONE); - lecturesGroup.setLayout(new GridLayout()); - lecturesGroup.setText("Veranstaltungen"); - gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - lecturesGroup.setLayoutData(gridData); - - - - lecturesButton = new Button(lecturesGroup, SWT.PUSH); - lecturesButton.setText("Veranstanstaltungen"); - gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true); - lecturesButton.setLayoutData(gridData); - - Label lecturesInfoLabel = new Label(lecturesGroup, SWT.NONE); - lecturesInfoLabel.setText(lecturesInfo); - gridData = new GridData(SWT.FILL, SWT.FILL, true, true); - lecturesInfoLabel.setLayoutData(gridData); - - - // function for vmButton - vmButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - clickedVMButton(); - } - }); - - // function for lecturesButton - lecturesButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - clickedLecturesButton(); - } - }); - - } - - - - // - // logical functions for GUI - // - - /** - * function for the VMButton - */ - protected void clickedVMButton() { - GuiManager.addContent(new ImageWindowComposite(getShell())); - } - - /** - * function for the lecturesButton - */ - protected void clickedLecturesButton() { - System.out.println("lecturesButton clicked!"); - } -} diff --git a/dozentenmodul/src/main/java/gui/core/VMWareInfoComposite.java b/dozentenmodul/src/main/java/gui/core/VMWareInfoComposite.java deleted file mode 100644 index d385c60b..00000000 --- a/dozentenmodul/src/main/java/gui/core/VMWareInfoComposite.java +++ /dev/null @@ -1,90 +0,0 @@ -package gui.core; - -import gui.GuiManager; - -import org.eclipse.swt.SWT; -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.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; - - -public class VMWareInfoComposite extends Composite { - private final String title = "Hinweis VMWare Player"; - private final String infoText = "Für die Arbeit mit der bwLehrpool Suite wird zwingend ein VMWare Player benötigt. " - + "Diesen können Sie sich unter folgendem Link kostenfrei downloaden. " - + "Wenn Sie bereits den VMWare Player oder die VMWare Workstation installiert haben, können Sie diesen Hinweis ignorieren."; - - private final String checkboxText = "Ja, ich aktzeptiere die Vereinbarung. Benachrichtigung nicht mehr anzeigen."; - - private final String infoTitle = "bwLehrpool Suite"; - - protected Button windowsDLButton; - protected Button linuxDLButton; - protected Button readCheck; - protected Button continueButton; - - public VMWareInfoComposite(final Shell mainShell) { - super(mainShell, SWT.NONE); - - // set the title of the bar. - mainShell.setText(title); - - // layout for this composite - this.setLayout(new GridLayout(1, false)); - - // bold title at start. - Label titleLabel = new Label(this, SWT.NONE); - titleLabel.setText(infoTitle); - FontData fontData = titleLabel.getFont().getFontData()[0]; - Font font = new Font(GuiManager.getDisplay(), new FontData(fontData.getName(), fontData - .getHeight(), SWT.BOLD)); - titleLabel.setFont(font); - // TODO dispose of font? - - // infotext - Label infoLabel = new Label(this, SWT.NONE | SWT.WRAP); - infoLabel.setText(infoText); - GridData gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false); - infoLabel.setLayoutData(gridData); - - - // composite for the windows vmware-download button - Composite windowsComposite = new Composite(this, SWT.NONE); - windowsComposite.setLayout(new GridLayout()); - gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false); - windowsComposite.setLayoutData(gridData); - - new Label(windowsComposite, SWT.NONE).setText("Windows:"); - windowsDLButton = new Button(windowsComposite, SWT.PUSH); - windowsDLButton.setText("VMWare Player Herunterladen"); - - - // composite for the linux vmware-download button - Composite linuxComposite = new Composite(this, SWT.NONE); - linuxComposite.setLayout(new GridLayout()); - gridData = new GridData(GridData.FILL, GridData.BEGINNING, true, false); - linuxComposite.setLayoutData(gridData); - - new Label(windowsComposite, SWT.NONE).setText("Linux:"); - linuxDLButton = new Button(windowsComposite, SWT.PUSH); - linuxDLButton.setText("VMWare Player Herunterladen"); - - - - readCheck = new Button(this, SWT.CHECK); - readCheck.setText("Diese Benachrichtigung nicht mehr anzeigen."); - gridData = new GridData(GridData.BEGINNING, GridData.END, false, false); - readCheck.setLayoutData(gridData); - - continueButton = new Button(this, SWT.PUSH); - continueButton.setText("Weiter"); - gridData = new GridData(GridData.BEGINNING, GridData.END, false, false); - continueButton.setLayoutData(gridData); - - } -}
\ No newline at end of file diff --git a/dozentenmodul/src/main/java/gui/core/VMWareInfoGUI.java b/dozentenmodul/src/main/java/gui/core/VMWareInfoGUI.java deleted file mode 100644 index 74f6ad63..00000000 --- a/dozentenmodul/src/main/java/gui/core/VMWareInfoGUI.java +++ /dev/null @@ -1,56 +0,0 @@ -package gui.core; - -import gui.GuiManager; - -import org.apache.log4j.Logger; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.widgets.Shell; - -import config.Config; - -public class VMWareInfoGUI extends VMWareInfoComposite { - - private final static Logger LOGGER = Logger.getLogger(VMWareInfoGUI.class); - - public VMWareInfoGUI(final Shell mainShell) { - super(mainShell); - - // function for agreement checkbox - continueButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - if (!Config.setVmwareLicenseAgreement(true)) - LOGGER.error("Could not set the agreement to the vmware license in '" + Config.getPath() + "'!"); - Config.store(); - GuiManager.addContent(new MainWindowComposite(getShell())); - } - }); - - // actions of the login button - linuxDLButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - //clickedLinuxDLButton(); - } - }); - - // actions of the login button - windowsDLButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - //clickedWindowsDLButton(); - } - }); - - // actions of the login button - readCheck.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - //clickedReadCheckButton(); - } - }); - - } - -} diff --git a/dozentenmodul/src/main/java/gui/helper/ColumnSelector.java b/dozentenmodul/src/main/java/gui/helper/ColumnSelector.java deleted file mode 100644 index 45929614..00000000 --- a/dozentenmodul/src/main/java/gui/helper/ColumnSelector.java +++ /dev/null @@ -1,30 +0,0 @@ -package gui.helper; - -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; - -import javax.swing.AbstractButton; -import javax.swing.JTable; - -public class ColumnSelector implements ItemListener { - - private final JTable table; - private final Integer[] columns; - - public ColumnSelector(JTable table, Integer... columns) { - this.table = table; - this.columns = columns; - } - - public void itemStateChanged(ItemEvent e) { - if (!(e.getSource() instanceof AbstractButton)) - return; - Boolean checked = e.getStateChange() == ItemEvent.SELECTED; - for (int x = 0, y = table.getRowCount(); x < y; x++) { - for (Integer col : columns) { - table.setValueAt(checked, x, col); - } - } - } - -} diff --git a/dozentenmodul/src/main/java/gui/helper/VMColumns.java b/dozentenmodul/src/main/java/gui/helper/VMColumns.java deleted file mode 100644 index 9e73c307..00000000 --- a/dozentenmodul/src/main/java/gui/helper/VMColumns.java +++ /dev/null @@ -1,81 +0,0 @@ -package gui.helper; - -import org.eclipse.jface.viewers.ColumnLabelProvider; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.TableViewerColumn; -import org.eclipse.swt.SWT; -import org.openslx.bwlp.dozmod.thrift.MetaDataCache; -import org.openslx.bwlp.thrift.iface.ImageSummaryRead; -import org.openslx.bwlp.thrift.iface.OperatingSystem; -import org.openslx.bwlp.thrift.iface.UserInfo; - - -public final class VMColumns { - private VMColumns(){}; - - private static void createColumn(TableViewer table, String colName, int width, ColumnLabelProvider provider){ - TableViewerColumn col = new TableViewerColumn(table, SWT.NONE); - col.getColumn().setWidth(width); - col.getColumn().setText(colName); - col.setLabelProvider(provider); - - } - - /** - * create the columns for the table in the VM mainwindow - * @param table the tableViewer - */ - public static void createVMTableColumns(TableViewer table){ - createColumn(table, "Name", 150, new ColumnLabelProvider() { - @Override - public String getText(Object element) { - ImageSummaryRead image = (ImageSummaryRead) element; - return image.getImageName(); - } - }); - - - - createColumn(table, "OS", 90, new ColumnLabelProvider() { - @Override - public String getText(Object element) { - // TODO remove and uncomment when deploying - ImageSummaryRead image = (ImageSummaryRead) element; - //OperatingSystem os = MetaDataCache.getOsById(image.getOsId()); - - OperatingSystem os = null ; - if (os == null) { - return "Unknown"; - } else { - return os.getOsName(); - } - } - }); - - createColumn(table, "Verantwortlicher", 130, new ColumnLabelProvider() { - @Override - public String getText(Object element) { - ImageSummaryRead image = (ImageSummaryRead) element; - return image.getOwnerId(); - } - }); - - createColumn(table, "Letztes Update", 110, new ColumnLabelProvider() { - @Override - public String getText(Object element) { - ImageSummaryRead image = (ImageSummaryRead) element; - return String.valueOf(image.getUpdateTime()); - } - }); - - createColumn(table, "Größe", 80, new ColumnLabelProvider() { - @Override - public String getText(Object element) { - ImageSummaryRead image = (ImageSummaryRead) element; - return String.valueOf(image.getFileSize()); - } - }); - - - }; -} |
