/**
*
*/
package com.waxayaz.TomcatMI.ui.components;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Image;
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.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import com.waxayaz.TomcatMI.core.domains.TomcatInstance;
import com.waxayaz.TomcatMI.core.enums.InstanceStatus;
import com.waxayaz.TomcatMI.ui.MainWindow;
import com.waxayaz.TomcatMI.ui.components.instanceConfig.InstanceConfigTabPane;
/**
* @author Waxayaz
*
*/
public class InstanceTab {
/**
*
*/
private static final long serialVersionUID = 6560860893517181926L;
private TomcatInstance instance;
private CTabItem tabItem;
private Composite contentPane;
private CTabFolder parent;
//private InstanceConfigTabPane configTabPane;
public InstanceTab(CTabFolder parent, Display display, final TomcatInstance instance) {
this.parent = parent;
this.instance = instance;
// Build TabItem
tabItem = new CTabItem(parent, SWT.CLOSE);
if(instance != null)
tabItem.setText(" "+instance.getName()+" ");
else
tabItem.setText("Tab "+parent.getItemCount());
tabItem.setImage(new Image(display, "res/images/TomcatInstance.png"));
// Build UI
buildTab(parent);
}
private void buildTab(CTabFolder parent) {
contentPane = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.numColumns = 1;
contentPane.setLayout(layout);
tabItem.setControl(contentPane);
//panel.setEnabled(false);
///////////////////////////////////////////////////////
// HEADER
Composite header = new Composite(contentPane, SWT.BORDER);
GridLayout headerLayout = new GridLayout();
headerLayout.numColumns = 2;
header.setLayout(headerLayout);
GridData headerData = new GridData();
headerData.grabExcessHorizontalSpace = true;
headerData.horizontalAlignment = GridData.FILL;
header.setLayoutData(headerData);
// Display Image
Image img = new Image(MainWindow.display, "res/images/tomcat_logo.gif");
Label lbl = new Label(header, SWT.NONE);
lbl.setImage(img);
header.setBackground(MainWindow.display.getSystemColor(SWT.COLOR_WHITE));
Composite c = new Composite(header, SWT.NONE);
GridLayout cLayout = new GridLayout();
cLayout.numColumns = 1;
cLayout.verticalSpacing = 5;
c.setLayout(cLayout);
c.setBackground(MainWindow.display.getSystemColor(SWT.COLOR_WHITE));
// Display Instance Name
Label lblTitle = new Label(c, SWT.NONE);
lblTitle.setFont(new Font(MainWindow.display, "Arial", 30, SWT.BOLD));
lblTitle.setText(instance.getName());
lblTitle.setBackground(MainWindow.display.getSystemColor(SWT.COLOR_WHITE));
// Display Tomcat Version
Label lblVersion = new Label(c, SWT.NONE);
lblVersion.setFont(new Font(MainWindow.display, "Arial", 9, SWT.ITALIC));
lblVersion.setText(" Apache Tomcat v"+instance.getTomcatVersion());
lblVersion.setBackground(MainWindow.display.getSystemColor(SWT.COLOR_WHITE));
////////////////////////////////////////////////////////
// SPLIT PANE
SashForm splitPane = new SashForm(contentPane, SWT.HORIZONTAL);
GridData splitData = new GridData();
splitData.horizontalAlignment = GridData.FILL;
splitData.verticalAlignment = GridData.FILL;
splitData.grabExcessHorizontalSpace = true;
splitData.grabExcessVerticalSpace = true;
splitPane.setLayoutData(splitData);
//////////////////////////////////////////////////////
// INFORMATIONS
Group groupInfos = new Group(splitPane, SWT.NONE);
groupInfos.setText("Informations about instance");
groupInfos.setBackground(MainWindow.display.getSystemColor(SWT.COLOR_WHITE));
groupInfos.setLayout(new GridLayout());
// Status Container
Composite statusPanel = new Composite(groupInfos, SWT.NONE);
GridData fillBothData = new GridData(GridData.FILL_BOTH);
statusPanel.setLayoutData(fillBothData);
statusPanel.setBackground(groupInfos.getBackground());
GridLayout statusPanelLayout = new GridLayout();
statusPanelLayout.numColumns = 2;
statusPanelLayout.verticalSpacing = 5;
statusPanelLayout.marginTop = 5;
statusPanel.setLayout(statusPanelLayout);
statusPanel.setLayoutData(headerData);
// Status Image
Label statusImage = new Label(statusPanel, SWT.NONE);
statusImage.setBackground(statusPanel.getBackground());
Image statusImg = new Image(MainWindow.display, "res/images/"+instance.getStatus().toString()+".png");
statusImage.setImage(statusImg);
// Status Label
Label lblStatus = new Label(statusPanel, SWT.NONE);
lblStatus.setText(" "+instance.getStatus().toString());
lblStatus.setBackground(statusPanel.getBackground());
lblStatus.setFont(new Font(MainWindow.display, "Arial", 16, SWT.BOLD));
// Start/Stop Instance LINK
GridData linksData = new GridData(GridData.FILL_HORIZONTAL);
linksData.horizontalSpan = 2;
if(instance.getStatus().equals(InstanceStatus.STOPPED)) {
Link linkStart = new Link(statusPanel, SWT.NONE);
linkStart.setText("<a>Start</a> tomcat instance.");
linkStart.setBackground(statusPanel.getBackground());
linkStart.setLayoutData(linksData);
linkStart.addListener(SWT.Selection, new Listener() {
// START Instance
public void handleEvent(Event event) {
instance.setStatus(InstanceStatus.STARTED);
redraw();
}
});
} else {
Link linkStop = new Link(statusPanel, SWT.NONE);
linkStop.setText("<a>Stop</a> tomcat instance.");
linkStop.setBackground(statusPanel.getBackground());
linkStop.setLayoutData(linksData);
linkStop.addListener(SWT.Selection, new Listener() {
// STOP Instance
public void handleEvent(Event event) {
instance.setStatus(InstanceStatus.STOPPED);
redraw();
}
});
}
///////////////////////////////////////////////////////
// INSTANCE CONFIG PANEL
new InstanceConfigTabPane(splitPane, instance);
// Set SplitPane panels Sizes in percent
splitPane.setWeights(new int[]{25, 75});
}
public TomcatInstance getInstance() {
return instance;
}
public CTabItem getTabItem() {
return tabItem;
}
public void redraw() {
contentPane.dispose();
buildTab(parent);
contentPane.layout(true);
}
}