summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-17 17:20:38 +0200
committerSimon Rettberg2015-07-17 17:20:38 +0200
commit7844be5e4d74612e9aff44c5aab09d4f6e5d2631 (patch)
tree2605abdf19b146b22feda18a3256e3e031c677eb /dozentenmodul/src/main/java
parent[client] first steps in ImagePermissions page (diff)
downloadtutor-module-7844be5e4d74612e9aff44c5aab09d4f6e5d2631.tar.gz
tutor-module-7844be5e4d74612e9aff44c5aab09d4f6e5d2631.tar.xz
tutor-module-7844be5e4d74612e9aff44c5aab09d4f6e5d2631.zip
[client] Add image details window
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java27
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java18
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java82
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/SwtUtil.java51
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java107
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java38
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java124
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java42
8 files changed, 458 insertions, 31 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
index 42fbf165..57103748 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java
@@ -33,6 +33,7 @@ public class Gui {
/**
* Center the given shell on the {@link Monitor} it is displayed on.
+ * WARNING: Seems broken on Linux, SWT only sees the primary monitor.
*
* @param shell Some shell
*/
@@ -46,6 +47,24 @@ public class Gui {
}
/**
+ * Take a shell and center it relative to another shell
+ *
+ * @param parent Parent shell, used as reference
+ * @param shellToCenter The shell that should be repositioned
+ */
+ public static void centerShellOverShell(Shell parent, Shell shellToCenter) {
+ Rectangle bounds = parent.getBounds();
+ Rectangle rect = shellToCenter.getBounds();
+ int x = bounds.x + (bounds.width - rect.width) / 2;
+ int y = bounds.y + (bounds.height - rect.height) / 2;
+ if (x < bounds.x)
+ x = bounds.x;
+ if (y < bounds.y)
+ y = bounds.y;
+ shellToCenter.setLocation(x, y);
+ }
+
+ /**
* Make sure the given shell fits the {@link Monitor} it is displayed on.
*
* @param shell Some shell
@@ -90,14 +109,18 @@ public class Gui {
* @return the {@link Monitor}
*/
public static Monitor getMonitorFromPoint(Point point, boolean defaultToPrimary) {
+ LOGGER.debug("Finding monitor for point " + point.toString());
Monitor[] monitors = display.getMonitors();
for (Monitor monitor : monitors) {
Rectangle bounds = monitor.getBounds();
+ LOGGER.debug("Checking monitor " + bounds.toString());
if (bounds.contains(point))
return monitor;
}
- if (defaultToPrimary)
+ if (defaultToPrimary) {
+ LOGGER.debug("Defaulting to promary...");
return display.getPrimaryMonitor();
+ }
return null;
}
@@ -113,6 +136,7 @@ public class Gui {
// Make sure rectangle is in bounds. This is not completely accurate
// in case there are multiple monitors that have different resolutions.
Rectangle bounds = display.getBounds();
+ LOGGER.debug("Display bounds are " + bounds.toString() + ", rect is " + rect.toString());
if (rect.x + rect.width >= bounds.x + bounds.width) {
rect.width -= (rect.x + rect.width) - (bounds.x + bounds.width);
if (rect.width < 1)
@@ -131,6 +155,7 @@ public class Gui {
rect.height -= bounds.y - rect.y;
rect.y = bounds.y;
}
+ LOGGER.debug("After correction: " + rect.toString());
// Now just use the same code as *FromPoint by using the rectangle's center
return getMonitorFromPoint(new Point(rect.x + rect.width / 2, rect.y + rect.height / 2),
defaultToPrimary);
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
index e048a135..bcf2b738 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
@@ -80,8 +80,10 @@ public abstract class MainWindow {
* @param modal modal mode - other windows will be blocked until this popup
* is closed
* @param noclose don't allow closing the popup via the (X) in the title bar
+ * @return The composite that is opened as a popup, or <code>null</code> on
+ * error
*/
- public static void openPopup(Class<? extends Composite> clazz, boolean modal, boolean noclose) {
+ public static <T extends Composite> T openPopup(Class<T> clazz, boolean modal, boolean noclose) {
int style = SWT.TITLE | SWT.BORDER | SWT.RESIZE;
if (modal)
style |= SWT.APPLICATION_MODAL;
@@ -90,14 +92,14 @@ public abstract class MainWindow {
Shell dialogShell = Gui.newShell(mainShell, style);
// populate dialogShell
dialogShell.setLayout(new GridLayout(1, false));
- Constructor<?> con = null;
+ final T comp;
try {
- con = clazz.getConstructor(Shell.class);
- con.newInstance(dialogShell);
+ Constructor<T> con = clazz.getConstructor(Shell.class);
+ comp = con.newInstance(dialogShell);
} catch (Exception e1) {
Gui.showMessageBox(mainShell, "Cannot show popup " + clazz.getName(), MessageType.DEBUG, LOGGER,
e1);
- return;
+ return null;
}
if (noclose) {
@@ -114,7 +116,13 @@ public abstract class MainWindow {
dialogShell.layout();
dialogShell.pack();
Gui.limitShellSize(dialogShell);
+ Gui.centerShellOverShell(mainShell, dialogShell);
dialogShell.open();
+ return comp;
+ }
+
+ public static void centerShell(Shell shell) {
+ Gui.centerShellOverShell(mainShell, shell);
}
/**
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java
new file mode 100644
index 00000000..c4ad4dd5
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java
@@ -0,0 +1,82 @@
+package org.openslx.dozmod.gui.control;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.SwtUtil;
+import org.openslx.dozmod.util.FormatHelper;
+
+/**
+ * A label for displaying a {@link UserInfo} object. Supports a callback event
+ * for when the users clicks the label.
+ */
+public class PersonLabel {
+
+ private final Label label;
+
+ private UserInfo user = null;
+
+ private PersonLabelClickEvent callback = null;
+
+ public PersonLabel(Composite parent, int style) {
+ label = new Label(parent, style);
+ label.setForeground(Gui.display.getSystemColor(SWT.COLOR_LINK_FOREGROUND));
+ label.addMouseListener(new MouseListener() {
+ @Override
+ public void mouseUp(MouseEvent e) {
+ if (user != null && callback != null && e.button == 1 && label.getBounds().contains(e.x, e.y)) {
+ callback.clicked(user);
+ }
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ }
+ });
+ }
+
+ /**
+ * Set the callback to call when the user clicks this label using the left
+ * mouse button. Only called if a user is set.
+ *
+ * @param cb The {@link PersonLabelClickEvent} to call
+ */
+ public void setCallback(PersonLabelClickEvent cb) {
+ this.callback = cb;
+ }
+
+ /**
+ * Set layout data of this label.
+ */
+ public void setLayoutData(Object layoutData) {
+ label.setLayoutData(layoutData);
+ }
+
+ /**
+ * Set the user to display.
+ */
+ public void setUser(UserInfo user) {
+ this.user = user;
+ if (user == null) {
+ label.setText("");
+ } else {
+ label.setText(SwtUtil.replaceMnemonics(FormatHelper.userName(user)));
+ }
+ }
+
+ /**
+ * The callback for when this label contains a user and gets clicked.
+ */
+ public static interface PersonLabelClickEvent {
+ public void clicked(UserInfo user);
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/SwtUtil.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/SwtUtil.java
new file mode 100644
index 00000000..495b94a3
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/SwtUtil.java
@@ -0,0 +1,51 @@
+package org.openslx.dozmod.gui.helper;
+
+import org.eclipse.swt.layout.GridData;
+
+public class SwtUtil {
+
+ /**
+ * Replace '&'-character by '&&', which prevents it from acting as a
+ * mnemonic in most controls. For convenience, it turns a <code>null</code>
+ * input into the empty string.
+ *
+ * @param input Input string to escape
+ * @return Escaped string
+ */
+ public static String replaceMnemonics(String input) {
+ if (input == null || input.isEmpty())
+ return "";
+ if (input.indexOf('&') == -1)
+ return input;
+ return input.replace("&", "&&");
+ }
+
+ /**
+ * Helper for creating a GridData instance with horizontal span in one call.
+ *
+ * @param horizontalAlignment how control will be positioned horizontally
+ * within a cell,
+ * one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or
+ * SWT.RIGHT), or SWT.FILL
+ * @param verticalAlignment how control will be positioned vertically within
+ * a cell,
+ * one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or
+ * SWT.BOTTOM), or SWT.FILL
+ * @param grabExcessHorizontalSpace whether cell will be made wide enough to
+ * fit the remaining horizontal space
+ * @param grabExcessVerticalSpace whether cell will be made high enough to
+ * fit the remaining vertical space
+ * @param horizontalSpan specifies the number of column cells that the
+ * control
+ * will take up.
+ * @return {@link GridData} instance
+ */
+ public static GridData gridData(int horizontalAlignment, int verticalAlignment,
+ boolean grabExcessHorizontalSpace, boolean grabExcessVerticalSpace, int horizontalSpan) {
+ GridData gd = new GridData(horizontalAlignment, verticalAlignment, grabExcessHorizontalSpace,
+ grabExcessVerticalSpace);
+ gd.horizontalSpan = horizontalSpan;
+ return gd;
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
new file mode 100644
index 00000000..22f3297c
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
@@ -0,0 +1,107 @@
+package org.openslx.dozmod.gui.window;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Shell;
+import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
+import org.openslx.bwlp.thrift.iface.OperatingSystem;
+import org.openslx.bwlp.thrift.iface.Virtualizer;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.MainWindow;
+import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.gui.helper.SwtUtil;
+import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout;
+import org.openslx.dozmod.thrift.MetaDataCache;
+import org.openslx.dozmod.thrift.Session;
+import org.openslx.dozmod.thrift.UserCache;
+import org.openslx.dozmod.util.FormatHelper;
+import org.openslx.thrifthelper.ThriftManager;
+import org.openslx.util.QuickTimer;
+import org.openslx.util.QuickTimer.Task;
+
+public class ImageDetailsWindow extends ImageDetailsWindowLayout {
+
+ private static final Logger LOGGER = Logger.getLogger(ImageDetailsWindow.class);
+
+ private final ImageDetailsWindow me = this;
+
+ private ImageDetailsRead image = null;
+
+ public ImageDetailsWindow(Shell parent) {
+ super(parent);
+
+ // Close button closes window
+ btnClose.addSelectionListener(new SelectionListener() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ getShell().dispose();
+ }
+
+ @Override
+ public void widgetDefaultSelected(SelectionEvent e) {
+ }
+ });
+ }
+
+ public void setImage(final String imageBaseId) {
+ QuickTimer.scheduleOnce(new Task() {
+ @Override
+ public void fire() {
+ Exception error = null;
+ try {
+ synchronized (me) {
+ if (image != null)
+ return;
+ image = ThriftManager.getSatClient().getImageDetails(Session.getSatelliteToken(),
+ imageBaseId);
+ }
+ } catch (Exception e) {
+ error = e;
+ }
+ // Just prime the cache...
+ MetaDataCache.getOperatingSystems();
+ MetaDataCache.getVirtualizers();
+ final Exception e = error;
+ Gui.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ if (e != null || image == null) {
+ MainWindow.showMessageBox("Konnte Daten des Images nicht abrufen",
+ MessageType.ERROR, LOGGER, e);
+ getShell().dispose();
+ } else {
+ fill();
+ }
+ }
+ });
+ }
+ });
+ }
+
+ private void fill() {
+ if (isDisposed() || image == null)
+ return;
+ lblTitle.setText(SwtUtil.replaceMnemonics(image.getImageName()));
+ lblDescription.setText(SwtUtil.replaceMnemonics(image.getDescription()));
+ lblOwner.setUser(UserCache.find(image.getOwnerId()));
+ lblUpdater.setUser(UserCache.find(image.getUpdaterId()));
+ lblCreateTime.setText(FormatHelper.longDate(image.getCreateTime()));
+ lblUpdateTime.setText(FormatHelper.longDate(image.getUpdateTime()));
+ List<OperatingSystem> osList = MetaDataCache.getOperatingSystems();
+ cboOperatingSystem.setInput(osList);
+ OperatingSystem os = MetaDataCache.getOsById(image.getOsId());
+ if (os != null) {
+ cboOperatingSystem.setSelection(new StructuredSelection(os), true);
+ }
+ Virtualizer virt = MetaDataCache.getVirtualizerById(image.getVirtId());
+ if (virt != null)
+ lblVirtualizer.setText(virt.getVirtName());
+ getShell().pack();
+ MainWindow.centerShell(getShell());
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
index 340ba425..43c6eb98 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
@@ -3,6 +3,8 @@ package org.openslx.dozmod.gui.window;
import java.util.List;
import org.apache.log4j.Logger;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@@ -64,31 +66,31 @@ public class ImageListWindow extends ImageListWindowLayout {
tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
@Override
public void selectionChanged(SelectionChangedEvent event) {
- IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
- ImageSummaryRead selectedElement = (ImageSummaryRead) selection.getFirstElement();
- if (selectedElement == null)
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ ImageSummaryRead image = (ImageSummaryRead) selection.getFirstElement();
+ if (image == null)
return;
// -- Set details --
// set the image name
- setFieldText(imageSelectedNameLabel, selectedElement.getImageName());
+ setFieldText(imageSelectedNameLabel, image.getImageName());
// set the image
- setFieldText(idInfo, selectedElement.getImageBaseId());
+ setFieldText(idInfo, image.getImageBaseId());
// set the current version of the image
- setFieldText(versionInfo, selectedElement.getCurrentVersionId());
+ setFieldText(versionInfo, image.getCurrentVersionId());
// set the time, the image has last been updated
- lastUpdateInfo.setText(FormatHelper.shortDate(selectedElement.getUpdateTime()));
+ lastUpdateInfo.setText(FormatHelper.shortDate(image.getUpdateTime()));
// info about the image permissions
- ImagePermissions perms = selectedElement.getUserPermissions();
+ ImagePermissions perms = image.getUserPermissions();
if (perms == null)
- perms = selectedElement.getDefaultPermissions();
+ perms = image.getDefaultPermissions();
if (perms != null)
setFieldText(permissionInfo, perms.toString());
// the owner id of the selected image
- UserInfo user = UserCache.find(selectedElement.getOwnerId());
+ UserInfo user = UserCache.find(image.getOwnerId());
setFieldText(ownerInfo, FormatHelper.userName(user));
// set the template info
- if (selectedElement.isTemplate) {
+ if (image.isTemplate) {
templateInfo.setText("ja");
} else {
templateInfo.setText("Nein");
@@ -104,6 +106,20 @@ public class ImageListWindow extends ImageListWindowLayout {
}
});
+ // Double click entry -> open details window
+ tableViewer.addDoubleClickListener(new IDoubleClickListener() {
+ @Override
+ public void doubleClick(DoubleClickEvent event) {
+ IStructuredSelection selection = (IStructuredSelection) event.getSelection();
+ ImageSummaryRead image = (ImageSummaryRead) selection.getFirstElement();
+ if (image == null)
+ return;
+ ImageDetailsWindow popup = MainWindow.openPopup(ImageDetailsWindow.class, true, false);
+ if (popup != null)
+ popup.setImage(image.getImageBaseId());
+ }
+ });
+
newButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java
new file mode 100644
index 00000000..fba210ec
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java
@@ -0,0 +1,124 @@
+package org.openslx.dozmod.gui.window.layout;
+
+import org.eclipse.jface.resource.FontDescriptor;
+import org.eclipse.jface.resource.JFaceResources;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ComboViewer;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+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;
+import org.openslx.bwlp.thrift.iface.OperatingSystem;
+import org.openslx.dozmod.gui.control.PersonLabel;
+import org.openslx.dozmod.gui.helper.SwtUtil;
+
+public abstract class ImageDetailsWindowLayout extends Composite {
+
+ protected final Label lblTitle;
+
+ protected final Label lblDescription;
+
+ protected final Label lblCreateTime;
+
+ protected final Label lblUpdateTime;
+
+ protected final PersonLabel lblOwner;
+
+ protected final PersonLabel lblUpdater;
+
+ protected final ComboViewer cboOperatingSystem;
+
+ protected final Label lblVirtualizer;
+
+ protected final ComboViewer cboShareMode;
+
+ protected final Button btnClose;
+
+ // TODO: IsTemplate, Permissions, ...
+
+ public ImageDetailsWindowLayout(Shell parent) {
+ super(parent, SWT.NONE);
+ this.setLayout(new GridLayout(2, false));
+ this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+ // Title label
+ lblTitle = new Label(this, SWT.NONE);
+ FontData[] fonts = FontDescriptor.copy(JFaceResources.getFontRegistry().getFontData(
+ JFaceResources.DEFAULT_FONT));
+ for (FontData f : fonts) {
+ f.setHeight(f.getHeight() * 2);
+ }
+ final Font titleFont = new Font(getDisplay(), fonts);
+ lblTitle.setFont(titleFont);
+ GridData gdTitle = SwtUtil.gridData(SWT.LEFT, SWT.FILL, true, false, 2);
+ gdTitle.minimumWidth = 600;
+ gdTitle.minimumHeight = 20;
+ lblTitle.setLayoutData(gdTitle);
+
+ // Create a horizontal separator
+ Label separator = new Label(this, SWT.HORIZONTAL | SWT.SEPARATOR);
+ separator.setLayoutData(SwtUtil.gridData(SWT.FILL, SWT.FILL, true, false, 2));
+
+ // Description
+ lblDescription = new Label(this, SWT.BORDER);
+ lblDescription.setLayoutData(SwtUtil.gridData(SWT.FILL, SWT.FILL, true, false, 2));
+
+ // Owner
+ new Label(this, SWT.NONE).setText("Besitzer");
+ lblOwner = new PersonLabel(this, SWT.NONE);
+
+ // Creation time
+ new Label(this, SWT.NONE).setText("Erstellt");
+ lblCreateTime = new Label(this, SWT.NONE);
+
+ // Updater
+ new Label(this, SWT.NONE).setText("Geändert durch");
+ lblUpdater = new PersonLabel(this, SWT.NONE);
+
+ // Update time
+ new Label(this, SWT.NONE).setText("Änderungszeitpunkt");
+ lblUpdateTime = new Label(this, SWT.NONE);
+
+ // OS list
+ new Label(this, SWT.NONE).setText("Betriebssystem");
+ cboOperatingSystem = new ComboViewer(this, SWT.DROP_DOWN | SWT.READ_ONLY);
+ cboOperatingSystem.setContentProvider(ArrayContentProvider.getInstance());
+ cboOperatingSystem.setLabelProvider(new LabelProvider() {
+ @Override
+ public String getText(Object element) {
+ return ((OperatingSystem) element).getOsName();
+ }
+ });
+
+ // Virtualizer
+ new Label(this, SWT.NONE).setText("Virtualizer");
+ lblVirtualizer = new Label(this, SWT.NONE);
+
+ // Share mode
+ new Label(this, SWT.NONE).setText("Freigabemodus");
+ cboShareMode = new ComboViewer(this, SWT.DROP_DOWN | SWT.READ_ONLY);
+
+ // Close button
+ btnClose = new org.eclipse.swt.widgets.Button(this, SWT.PUSH | SWT.RIGHT | SWT.DOWN);
+ btnClose.setText("Schließen");
+ btnClose.setLayoutData(SwtUtil.gridData(SWT.RIGHT, SWT.BOTTOM, false, false, 2));
+
+ //
+ // Dispose of stuff we allocated
+ this.addDisposeListener(new DisposeListener() {
+ @Override
+ public void widgetDisposed(DisposeEvent e) {
+ titleFont.dispose();
+ }
+ });
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java
index 00dd7905..f71d2a0d 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/MetaDataCache.java
@@ -10,15 +10,16 @@ import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.GenericDataCache;
public class MetaDataCache {
-
+
private static final Logger LOGGER = Logger.getLogger(MetaDataCache.class);
-
+
/**
* How long to cache data.
*/
private static final int CACHE_TIME_MS = 60 * 60 * 1000;
-
- private static final GenericDataCache<List<OperatingSystem>> osCache = new GenericDataCache<List<OperatingSystem>>(CACHE_TIME_MS) {
+
+ private static final GenericDataCache<List<OperatingSystem>> osCache = new GenericDataCache<List<OperatingSystem>>(
+ CACHE_TIME_MS) {
@Override
protected List<OperatingSystem> update() throws TException {
try {
@@ -29,8 +30,9 @@ public class MetaDataCache {
return ThriftManager.getMasterClient().getOperatingSystems();
}
};
-
- private static final GenericDataCache<List<Virtualizer>> virtualizerCache = new GenericDataCache<List<Virtualizer>>(CACHE_TIME_MS) {
+
+ private static final GenericDataCache<List<Virtualizer>> virtualizerCache = new GenericDataCache<List<Virtualizer>>(
+ CACHE_TIME_MS) {
@Override
protected List<Virtualizer> update() throws TException {
try {
@@ -41,33 +43,45 @@ public class MetaDataCache {
return ThriftManager.getMasterClient().getVirtualizers();
}
};
-
+
/**
* Get all known/valid operating systems an image can be marked as.
- *
+ *
* @return
*/
public static List<OperatingSystem> getOperatingSystems() {
return osCache.get();
}
-
- public static OperatingSystem getOsById(int id){
+
+ public static OperatingSystem getOsById(int id) {
List<OperatingSystem> list = getOperatingSystems();
if (list == null)
return null;
for (OperatingSystem os : list) {
- if (os.getOsId() == id) return os;
+ if (os.getOsId() == id)
+ return os;
}
return null;
}
-
+
/**
* Get all supported virtualizers an image can be declared to be run as.
- *
+ *
* @return
*/
public static List<Virtualizer> getVirtualizers() {
return virtualizerCache.get();
}
-
+
+ public static Virtualizer getVirtualizerById(String virtId) {
+ List<Virtualizer> list = getVirtualizers();
+ if (list == null)
+ return null;
+ for (Virtualizer virt : list) {
+ if (virt.getVirtId().equals(virtId))
+ return virt;
+ }
+ return null;
+ }
+
} \ No newline at end of file