/*
* Copyright 2011 Serbian Object Laboratories (SOL)
*
* Licensed under the GPL licence
*
* http://www.gnu.org/licenses/gpl.html
*/
package companyorganization;
import rs.sol.soloist.client.common.GUIFeatureNames;
import rs.sol.soloist.helpers.init.DefaultContextInit;
import rs.sol.soloist.helpers.init.Initializer;
import rs.sol.soloist.helpers.init.InitializerFailedException;
import rs.sol.soloist.server.builtindomains.builtincommands.CmdCreateObjectAndLinkToObject;
import rs.sol.soloist.server.builtindomains.builtindatatypes.Boolean;
import rs.sol.soloist.server.builtindomains.builtindatatypes.Text;
import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIButtonComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIDeckComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIHTMLComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIImageComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUILinkComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUIStatusBarComponent;
import rs.sol.soloist.server.guiconfiguration.components.GUITabComponent;
import rs.sol.soloist.server.guiconfiguration.construction.GUIComponent;
import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding;
import rs.sol.soloist.server.guiconfiguration.construction.GUIFactory;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIElementComponent;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIFieldWidget;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIInputKind;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIListWidget;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUISingleElementComponent;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUISlotEditorKind;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUISlotValueInput;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUISubnodesInput;
import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUITreeWidget;
import rs.sol.soloist.server.guiconfiguration.layout.CellLayoutData;
import rs.sol.soloist.server.guiconfiguration.layout.FlowLayout;
import rs.sol.soloist.server.guiconfiguration.layout.HorizontalAlignment;
import rs.sol.soloist.server.guiconfiguration.layout.LayoutData;
import rs.sol.soloist.server.guiconfiguration.layout.TableLayoutData;
import rs.sol.soloist.server.guiconfiguration.layout.VerticalAlignment;
import rs.sol.soloist.server.guiconfiguration.style.GUIBindingsFeature;
import rs.sol.soloist.server.guiconfiguration.style.GUIContext;
import rs.sol.soloist.server.guiconfiguration.style.GUINavigatorFeature;
import rs.sol.soloist.server.guiconfiguration.style.GUIObjectSetting;
import rs.sol.soloist.server.guiconfiguration.style.GUIPictureFeature;
import rs.sol.soloist.server.guiconfiguration.style.GUITextFeature;
import rs.sol.soloist.server.server.SoloistServiceServlet;
import companyorganization.Department;
import companyorganization.Employee;
import configuration.ObjectSpaceInit;
public class ApplicationInit implements Initializer {
private static final String COPYRIGHT_TEXT = "Copyright © 2011 - Serbian Object Laboratories (SOL) - Licence ";
private static final String TITLE = "SOLoist Demo - Company Organization";
private GUIApplicationComponent application;
private GUIContext context;
private GUIPanelComponent mainPanel;
private GUIPanelComponent titlePanel;
private GUIDeckComponent centralPanel;
private GUIPanelComponent departmentPanel;
private GUIElementComponent departmentTreeView;
private GUIElementComponent membersList;
private GUIPanelComponent departmentButtonPanel;
private GUIPanelComponent employeePanel;
private GUITabComponent employeePanelTab;
public void init() throws InitializerFailedException {
application = new GUIApplicationComponent();
SoloistServiceServlet.registerApplication(application);
application.name.set(Text.fromString("CompanyOrganization"));
application.title.set(Text.fromString("Company Organization"));
context = new GUIContext();
context.supercontext.set(DefaultContextInit.getRoot());
application.context.set(context);
mainPanel = GUIPanelComponent.createVertical(application);
mainPanel.styleName.set(Text.fromString("main_panel"));
// Title panel
initTitlePanel();
// Central panel
centralPanel = GUIDeckComponent.create(GUIPanelComponent.createFlow(mainPanel));
centralPanel.styleName.set(Text.fromString("centralPanel"));
initDepartmentPanel();
initEmployeePanel();
// Bottom panel
initBottomPanel();
// Style settings
initStyle();
}
public void initTitlePanel() {
titlePanel = GUIPanelComponent.createHorizontal(mainPanel);
titlePanel.styleName.set(Text.fromString("titlePanel"));
CellLayoutData.setAlignment(titlePanel, VerticalAlignment.TOP);
CellLayoutData.setCellSize(titlePanel, "100%", "80");
// Logo
GUIImageComponent leftLogoComponent = GUIImageComponent.create(titlePanel);
leftLogoComponent.url.set(Text.fromString("res/img/logo-left.png"));
leftLogoComponent.styleName.set(Text.fromString("logo-image"));
CellLayoutData.setCellSize(leftLogoComponent, "200", null);
GUILabelComponent pageTitle = GUILabelComponent.create(titlePanel, TITLE, null);
pageTitle.styleName.set(Text.fromString("page_title"));
GUILinkComponent poweredBy = GUILinkComponent.create(titlePanel, "Powered by SOLoist", "http://www.soloist4uml.com/");
poweredBy.styleName.set(Text.fromString("poweredBy"));
CellLayoutData.setAlignment(poweredBy, VerticalAlignment.BOTTOM);
}
public void initDepartmentPanel() {
departmentPanel = GUIPanelComponent.createVertical(GUIPanelComponent.createFlow(centralPanel));
departmentPanel.styleName.set(Text.fromString("tablePanels"));
GUILabelComponent labelEmployeeTitle = GUILabelComponent.create(departmentPanel, "Departments details", null);
labelEmployeeTitle.styleName.set(Text.fromString("titleLabel"));
GUIPanelComponent departmentDetailsPanel = GUIPanelComponent.createHorizontal(departmentPanel);
departmentDetailsPanel.styleName.set(Text.fromString("tablePanels"));
// Department panel
GUIPanelComponent treePanel = GUIPanelComponent.createVertical(departmentDetailsPanel);
treePanel.styleName.set(Text.fromString("tablePanels"));
GUILabelComponent.create(treePanel, "Select Department: ", null);
departmentTreeView = GUIElementComponent.create(treePanel, new GUIInputKind(), new GUITreeWidget(), GUISubnodesInput.create(ObjectSpaceInit
.getRootDepartment(), true), null);
departmentTreeView.styleName.set(Text.fromString("departments"));
departmentButtonPanel = GUIPanelComponent.create(treePanel, new FlowLayout());
departmentButtonPanel.styleName.set(Text.fromString("buttonPanel"));
initDepartmentButtons();
GUIPanelComponent detailsPanel = GUIPanelComponent.createTable(departmentDetailsPanel);
detailsPanel.styleName.set(Text.fromString("tablePanels"));
GUILabelComponent.create(detailsPanel, "Name: ", 0, 0);
GUIElementComponent nameSlot = GUIElementComponent.createSlotEditor(detailsPanel, Department.PROPERTIES.name, 0, 1);
LayoutData.setSize(nameSlot, "300px", "25px");
GUILabelComponent lab3 = GUILabelComponent.create(detailsPanel, "Responsibility: ", 1, 0);
CellLayoutData.setAlignment(lab3, VerticalAlignment.TOP);
GUIElementComponent respSlotComponent = GUIElementComponent.createSlotEditor(detailsPanel, Department.PROPERTIES.responsibility,
GUIFieldWidget.createMultilineText(), 1, 1);
LayoutData.setSize(respSlotComponent, "300px", "100px");
GUILabelComponent.create(detailsPanel, "Members: ", 3, 0);
membersList = GUIElementComponent.create(detailsPanel, new GUIInputKind(), new GUIListWidget(), GUISlotValueInput
.create(Department.PROPERTIES.members), new TableLayoutData(4, 0, 1, 2));
membersList.styleName.set(Text.fromString("members"));
// end Department panel
// Bindings for departments
GUIComponentBinding.create(departmentTreeView.value, GUISlotEditorKind.get(nameSlot).element);
GUIComponentBinding.create(departmentTreeView.value, GUISlotEditorKind.get(respSlotComponent).element);
GUIComponentBinding.create(departmentTreeView.value, GUISlotValueInput.get(membersList).element);
}
public void initEmployeePanel() {
employeePanel = GUIPanelComponent.createVertical(centralPanel);
employeePanel.styleName.set(Text.fromString("tablePanels"));
GUIButtonComponent backLink = GUIButtonComponent.createLink(employeePanel, "Home page");
GUIComponentBinding.create(backLink.click, departmentPanel.show);
backLink.styleName.set(Text.fromString("button-link"));
GUIPanelComponent employeeSinglePanel = GUIPanelComponent.createHorizontal(employeePanel);
employeeSinglePanel.styleName.set(Text.fromString("tablePanels"));
GUILabelComponent labelEmployeeTitle = GUILabelComponent.create(employeeSinglePanel, "Employee details ", null);
labelEmployeeTitle.styleName.set(Text.fromString("titleLabel"));
GUISingleElementComponent singleEmployee = new GUISingleElementComponent();
employeeSinglePanel.children.add(singleEmployee);
// Employees tab
employeePanelTab = GUITabComponent.create(employeePanel, new String[] { "General", "Department" });
// General tab
GUIPanelComponent wrapPanelGeneral = GUIPanelComponent.createHorizontal(employeePanelTab);
GUIPanelComponent panelGeneral = GUIPanelComponent.createTable(wrapPanelGeneral);
panelGeneral.styleName.set(Text.fromString("tablePanels"));
GUILabelComponent.create(panelGeneral, "Name: ", 0, 0);
GUIElementComponent employeeNameSlotComponent = GUIElementComponent.createSlotEditor(panelGeneral, Employee.PROPERTIES.name, 0, 1);
GUILabelComponent.create(panelGeneral, "Date of birth: ", 1, 0);
GUIElementComponent dateSlotComponent = GUIElementComponent.createSlotEditor(panelGeneral, Employee.PROPERTIES.dateOfBirth, 1, 1);
LayoutData.setSize(dateSlotComponent, "167px", null);
GUILabelComponent.create(panelGeneral, "Is married: ", 2, 0);
GUIElementComponent isMarriedSlotComponent = GUIElementComponent.createSlotEditor(panelGeneral, Employee.PROPERTIES.isMarried, 2, 1);
GUILabelComponent.create(panelGeneral, "Gender: ", 3, 0);
GUIElementComponent genderSlotComponent = GUIElementComponent.createSlotEditor(panelGeneral, Employee.PROPERTIES.gender, 3, 1);
GUILabelComponent.create(panelGeneral, "Number of children: ", 4, 0);
GUIElementComponent numOfChSlotComponent = GUIElementComponent.createSlotEditor(panelGeneral, Employee.PROPERTIES.numberOfChildren, 4, 1);
GUILabelComponent.create(panelGeneral, "Department: ", 5, 0);
GUIElementComponent departmentGeneralList = GUIElementComponent.create(panelGeneral, new GUIInputKind(), new GUIListWidget(),
GUISlotValueInput.create(Employee.PROPERTIES.dept), new TableLayoutData(5, 1));
GUILabelComponent.create(panelGeneral, "Contract: ", 6, 0);
GUIPanelComponent panelFile = GUIFactory.createFileComponent(Employee.PROPERTIES.contract, true, panelGeneral, new TableLayoutData(6, 1));
GUIFactory.getUploadButton(panelFile).name.set(Text.fromString("Contract Upload Button"));
GUIFactory.getRemoveButton(panelFile).name.set(Text.fromString("Contract Remove Button"));
GUIPanelComponent wrapPicturePanel = GUIPanelComponent.createVertical(wrapPanelGeneral);
wrapPicturePanel.styleName.set(Text.fromString("photo"));
GUILabelComponent.create(wrapPicturePanel, "Photo: ", new TableLayoutData(0, 2));
GUIPanelComponent panelPicture = GUIFactory.createFileComponent(Employee.PROPERTIES.photo, true, wrapPicturePanel, null);
GUIComponent picComp = panelPicture.children.at(0);
LayoutData.setSize(picComp, null, "250px");
GUIFactory.getUploadButton(panelPicture).name.set(Text.fromString("Picture Upload Button"));
GUIFactory.getRemoveButton(panelPicture).name.set(Text.fromString("Picture Remove Button"));
// Department tab
GUIPanelComponent panelDepartment = GUIPanelComponent.createVertical(employeePanelTab);
panelDepartment.styleName.set(Text.fromString("tablePanels"));
GUILabelComponent.create(panelDepartment, "Membership: ");
GUIElementComponent membershipSlotComponent = GUIElementComponent.createSlotEditor(panelDepartment, Employee.PROPERTIES.dept,
new GUITreeWidget(), GUISubnodesInput.create(ObjectSpaceInit.getRootDepartment(), true), null);
membershipSlotComponent.styleName.set(Text.fromString("membership"));
// Bindings for employees
GUIComponentBinding.create(employeePanelTab.input, singleEmployee.element);
// General tab
GUIComponentBinding.create(employeePanelTab.input, GUISlotEditorKind.get(employeeNameSlotComponent).element);
GUIComponentBinding.create(employeePanelTab.input, GUISlotEditorKind.get(dateSlotComponent).element);
GUIComponentBinding.create(employeePanelTab.input, GUISlotEditorKind.get(isMarriedSlotComponent).element);
GUIComponentBinding.create(employeePanelTab.input, GUISlotEditorKind.get(genderSlotComponent).element);
GUIComponentBinding.create(employeePanelTab.input, GUISlotEditorKind.get(numOfChSlotComponent).element);
GUIComponentBinding.create(employeePanelTab.input, panelFile.input);
GUIComponentBinding.create(employeePanelTab.input, GUISlotValueInput.get(departmentGeneralList).element);
GUIComponentBinding.create(employeePanelTab.input, panelPicture.input);
// Department tab
GUIComponentBinding.create(employeePanelTab.input, GUISlotEditorKind.get(membershipSlotComponent).element);
}
public void initDepartmentButtons() {
GUIButtonComponent btnCreateEmpl = GUIButtonComponent.create(departmentButtonPanel, "Create Employee");
btnCreateEmpl.styleName.set(Text.fromString("button"));
CmdCreateObjectAndLinkToObject createEmplCommand = new CmdCreateObjectAndLinkToObject();
createEmplCommand.className.set(Text.fromString(Employee.FQ_TYPE_NAME));
createEmplCommand.assocEndName.set(Text.fromString(Department.FQPropertyNames.members));
createEmplCommand.type.set(Text.fromString(Department.FQ_TYPE_NAME));
btnCreateEmpl.command.add(createEmplCommand);
GUIComponentBinding.create(departmentTreeView.value, btnCreateEmpl, CmdCreateObjectAndLinkToObject.PROPERTIES.target);
GUIButtonComponent btnCreateSubDepr = GUIButtonComponent.create(departmentButtonPanel, "Create Subdepartment");
btnCreateSubDepr.styleName.set(Text.fromString("button"));
CmdCreateObjectAndLinkToObject createSubDeprCommand = new CmdCreateObjectAndLinkToObject();
createSubDeprCommand.className.set(Text.fromString(Department.FQ_TYPE_NAME));
createSubDeprCommand.assocEndName.set(Text.fromString(Department.FQPropertyNames.subDepts));
createSubDeprCommand.type.set(Text.fromString(Department.FQ_TYPE_NAME));
btnCreateSubDepr.command.add(createSubDeprCommand);
GUIComponentBinding.create(departmentTreeView.value, btnCreateSubDepr, CmdCreateObjectAndLinkToObject.PROPERTIES.target);
}
public void initBottomPanel() {
GUIPanelComponent bottomPanel = GUIPanelComponent.createVertical(mainPanel);
bottomPanel.styleName.set(Text.fromString("bottomPanel"));
GUIPanelComponent statusBarPanel = GUIPanelComponent.createHorizontal(bottomPanel);
statusBarPanel.styleName.set(Text.fromString("status_bar_panel"));
CellLayoutData.setCellSize(statusBarPanel, "100%", null);
GUILabelComponent statusBarLabel = GUILabelComponent.create(statusBarPanel, "Status bar: ", null);
CellLayoutData.setCellSize(statusBarLabel, "75px", null);
statusBarLabel.styleName.set(Text.fromString("status_bar_label"));
GUIStatusBarComponent statusBar = GUIStatusBarComponent.create(statusBarPanel);
statusBar.styleName.set(Text.fromString("status_bar"));
GUIHTMLComponent html = new GUIHTMLComponent();
html.parent.set(statusBarPanel);
html.html.set(Text.fromString(COPYRIGHT_TEXT));
html.styleName.set(Text.fromString("footer_panel"));
CellLayoutData.setAlignment(html, HorizontalAlignment.LEFT);
CellLayoutData.setSize(html, "400", null);
}
public void initStyle() {
// Object setting for department
GUIObjectSetting departmentOS = GUIObjectSetting.create(application.getContext(), Department.CLASSIFIER);
GUIPictureFeature.createSmallIcon(departmentOS, "res/img/CompanyOrganizationIcons/3.01_Department1.png");
GUITextFeature.createName(departmentOS, "name");
GUINavigatorFeature.createSubnodes(departmentOS, "subDepts");
// Object setting for employee
GUIObjectSetting employeeOS = GUIObjectSetting.create(application.getContext(), Employee.CLASSIFIER);
GUIPictureFeature.createSmallIcon(employeeOS, "res/img/CompanyOrganizationIcons/3.03_MaleEmployee2.png");
GUITextFeature.createName(employeeOS, "name");
// Tooltip for department
GUITextFeature tooltipDepr = new GUITextFeature();
tooltipDepr.isFixed.set(new Boolean(true));
tooltipDepr.textValue.set(Text.fromString("Double click to see details"));
departmentOS.features.add(tooltipDepr);
// Tooltip for employee
GUITextFeature tooltipEmpl = new GUITextFeature();
tooltipEmpl.isFixed.set(new Boolean(true));
tooltipEmpl.textValue.set(Text.fromString("Double click to see details"));
employeeOS.features.add(tooltipEmpl);
// Bindings feature for department (double click)
GUIBindingsFeature bfDepartment = new GUIBindingsFeature();
bfDepartment.name.set(Text.fromString(GUIFeatureNames.BINDINGS));
GUIComponentBinding.create(bfDepartment.doubleClick, departmentPanel.input);
GUIComponentBinding.create(bfDepartment.doubleClick, departmentPanel.show);
departmentOS.features.add(bfDepartment);
// Bindings feature for employee (double click)
GUIBindingsFeature bfEmployee = new GUIBindingsFeature();
bfEmployee.name.set(Text.fromString(GUIFeatureNames.BINDINGS));
GUIComponentBinding.create(bfEmployee.doubleClick, employeePanelTab.show);
GUIComponentBinding.create(bfEmployee.doubleClick, employeePanelTab.input);
employeeOS.features.add(bfEmployee);
}
}