summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/gui/GuiManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/gui/GuiManager.java')
-rw-r--r--dozentenmodul/src/main/java/gui/GuiManager.java147
1 files changed, 0 insertions, 147 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();
- }
- }
-}