package org.openslx.dozmod.gui.window.layout;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.GridBagLayout;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import org.apache.log4j.Logger;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
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.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.Text;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.CompositePage;
import org.openslx.dozmod.gui.helper.ResizeColumnListener;
import org.openslx.dozmod.gui.helper.TableRenderer;
public abstract class ImageListWindowLayout extends CompositePage {
private final static Logger LOGGER = Logger.getLogger(ImageListWindowLayout.class);
protected String infoTitleString = "Übersicht Virtuelle Maschinen";
protected String newButtonLabel = "Neu";
protected String editButtonLabel = "Bearbeiten";
protected String deleteButtonLabel = "Löschen";
protected String downloadButtonLabel = "Download";
protected String backButtonLabel = "Zurück";
protected String tableGroupLabel = "Images";
protected String vmInfoGroupLabel = "Detailinformationen";
protected String filterGroupLabel = "Filter";
// buttons
protected Button newButton;
protected Button deleteButton;
protected Button downloadButton;
protected Button backButton;
// imageDetail texts
protected Text imageSelectedNameLabel;
protected Text idInfo;
protected Text versionInfo;
protected Text lastUpdateInfo;
protected Text permissionInfo;
protected Text ownerInfo;
protected Text templateInfo;
protected final Text searchTextField;
protected JTable jtable;
protected String infoTextString = "Hier können Sie Virtuelle Maschinen hochladen, herunterladen, bearbeiten und löschen.";
public ImageListWindowLayout() {
super(new GridBagLayout());
// the layout and layoutData of the ImageListWindow
this.setLayout(new GridLayout(2, false));
this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
// -- info group with title and text --
Composite infoComposite = new Composite(this, SWT.BORDER);
infoComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
// layout for the items of the group
infoComposite.setLayout(new GridLayout(1, false));
// title of the info group in bold
Label infoTitle = new Label(infoComposite, SWT.NONE);
infoTitle.setText(infoTitleString);
// set the fond
FontData fontData = infoTitle.getFont().getFontData()[0];
final Font titleFont = new Font(Gui.display, new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD));
infoTitle.setFont(titleFont);
// the infotext
Label infoText = new Label(infoComposite, SWT.NONE);
infoText.setText(infoTextString);
// -- end group of title --
// -- group for the table --
final Group tableGroup = new Group(this, SWT.BORDER);
tableGroup.setText(tableGroupLabel);
GridData tgLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
tgLayoutData.minimumWidth = 400;
tgLayoutData.widthHint = 800;
tableGroup.setLayoutData(tgLayoutData);
tableGroup.setLayout(new GridLayout());
// -- group for the filter --
Group filterGroup = new Group(tableGroup, SWT.BORDER);
filterGroup.setText(filterGroupLabel);
GridData fgGridData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
fgGridData.minimumWidth = 400;
fgGridData.widthHint = 800;
filterGroup.setLayoutData(fgGridData);
filterGroup.setLayout(new GridLayout());
// filter text field
searchTextField = new Text(filterGroup, SWT.BORDER);
searchTextField.setMessage("Name, Verantwortlicher, OS");
// -- end group of filter --
// table composite to embed the swing table
final Composite comp = new Composite(tableGroup, SWT.NO_BACKGROUND | SWT.EMBEDDED);
comp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
final Frame frame = SWT_AWT.new_Frame(comp);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
System.setProperty("sun.awt.noerasebackground", "true");
// auto-resize-on-scroll http://stackoverflow.com/questions/17858132/automatically-adjust-jtable-column-to-fit-content
JPanel panel = new JPanel(new BorderLayout());
frame.add(panel);
JRootPane root = new JRootPane();
panel.add(root);
java.awt.Container contentPane = root.getContentPane();
// init table
jtable = new JTable();
jtable.setShowGrid(false);
jtable.setCellSelectionEnabled(false);
jtable.createDefaultColumnsFromModel();
jtable.setAutoCreateRowSorter(true);
jtable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
jtable.getTableHeader().setReorderingAllowed(false);
jtable.setDefaultRenderer(Object.class, new TableRenderer());
jtable.setRowSelectionAllowed(true);
jtable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// jtable.setFont(new java.awt.Font("URW Gothic", java.awt.Font.PLAIN, 12));
new ResizeColumnListener(jtable);
JScrollPane scrollPane = new JScrollPane(jtable);
contentPane.setLayout(new BorderLayout());
contentPane.add(scrollPane);
}
});
// create, modify, download and delete buttons
Composite buttonComposite = new Composite(tableGroup, SWT.NONE);
GridData buttonCompositeGridData = new GridData(SWT.FILL, SWT.FILL, true, false);
buttonCompositeGridData.minimumWidth = 200;
buttonComposite.setLayoutData(buttonCompositeGridData);
buttonComposite.setLayout(new RowLayout());
newButton = new Button(buttonComposite, SWT.PUSH);
newButton.setText(newButtonLabel);
deleteButton = new Button(buttonComposite, SWT.PUSH);
deleteButton.setText(deleteButtonLabel);
downloadButton = new Button(buttonComposite, SWT.PUSH);
downloadButton.setText(downloadButtonLabel);
backButton = new Button(buttonComposite, SWT.PUSH);
backButton.setText(backButtonLabel);
// -- end group for table --
// -- group for details of selected image --
final Group vmInfoGroup = new Group(this, SWT.BORDER);
vmInfoGroup.setText(vmInfoGroupLabel);
final GridData igGridData = new GridData(SWT.FILL, SWT.FILL, true, false);
igGridData.widthHint = 300;
vmInfoGroup.setLayoutData(igGridData);
vmInfoGroup.setLayout(new GridLayout(2, false));
// image name info
imageSelectedNameLabel = createCaptionAndTextfield("Image Name:", vmInfoGroup);
idInfo = createCaptionAndTextfield("ID:", vmInfoGroup);
versionInfo = createCaptionAndTextfield("Version:", vmInfoGroup);
lastUpdateInfo = createCaptionAndTextfield("Letztes Update:", vmInfoGroup);
permissionInfo = createCaptionAndTextfield("Berechtigungen:", vmInfoGroup);
ownerInfo = createCaptionAndTextfield("Besitzer:", vmInfoGroup);
templateInfo = createCaptionAndTextfield("Vorlage:", vmInfoGroup);
// -- end group of details --
// Dispose of stuff we allocated
this.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
titleFont.dispose();
}
});
}
public Text createCaptionAndTextfield(String captionString, Group group) {
Label caption = new Label(group, SWT.NONE);
Text textField = new Text(group, SWT.READ_ONLY);
caption.setText(captionString);
caption.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
gridData.minimumWidth = 180;
textField.setLayoutData(gridData);
return textField;
}
}