1 25 package org.ofbiz.guiapp.xui; 26 27 import java.util.Locale ; 28 29 import javax.swing.JFrame ; 30 import javax.swing.UIManager ; 31 32 import net.xoetrope.swing.XApplet; 33 34 import org.ofbiz.base.container.Container; 35 import org.ofbiz.base.container.ContainerConfig; 36 import org.ofbiz.base.container.ContainerException; 37 import org.ofbiz.base.util.UtilValidate; 38 import org.ofbiz.entity.GenericDelegator; 39 import org.ofbiz.service.GenericDispatcher; 40 import org.ofbiz.service.GenericServiceException; 41 import org.ofbiz.service.LocalDispatcher; 42 import org.ofbiz.base.util.UtilProperties; 43 44 50 public abstract class XuiContainer implements Container { 51 52 public static final String module = XuiContainer.class.getName(); 53 protected static XuiSession session = null; 54 55 protected XuiScreen initialScreen = null; 56 57 protected String startupFile = null; 58 protected String configFile = null; 59 60 public void init(String [] args, String configFile) throws ContainerException { 61 this.configFile = configFile; 62 } 63 64 public boolean start() throws ContainerException { 65 if (this.getContainerConfigName() == null) { 67 throw new ContainerException("Unknown container config name"); 68 } 69 ContainerConfig.Container cc = ContainerConfig.getContainer(this.getContainerConfigName(), configFile); 71 if (cc == null) { 72 throw new ContainerException("No " + this.getContainerConfigName() + " configuration found in container config!"); 73 } 74 75 String delegatorName = ContainerConfig.getPropertyValue(cc, "delegator-name", "default"); 77 GenericDelegator delegator = GenericDelegator.getGenericDelegator(delegatorName); 78 79 String dispatcherName = ContainerConfig.getPropertyValue(cc, "dispatcher-name", "xui-dispatcher"); 81 LocalDispatcher dispatcher = null; 82 try { 83 dispatcher = GenericDispatcher.getLocalDispatcher(dispatcherName, delegator); 84 } catch (GenericServiceException e) { 85 throw new ContainerException(e); 86 } 87 88 String xuiSessionId = ContainerConfig.getPropertyValue(cc, "xui-session-id", null); 90 if (UtilValidate.isEmpty(xuiSessionId)) { 91 throw new ContainerException("No xui-session-id value set in " + this.getContainerConfigName() + "!"); 92 } 93 94 String laf = ContainerConfig.getPropertyValue(cc, "look-and-feel", null); 95 if (UtilValidate.isNotEmpty(laf)) { 96 try { 97 UIManager.setLookAndFeel(laf); 98 } catch (Exception e) { 99 throw new ContainerException(e); 100 } 101 } 102 103 session = new XuiSession(xuiSessionId, delegator, dispatcher, this); 105 106 this.configure(cc); 108 109 if (this.startupFile == null) { 111 this.startupFile = ContainerConfig.getPropertyValue(cc, "startup-file", "xui.properties"); 112 } 113 this.initialScreen = new XuiScreen(); 114 this.initialScreen.setup(this.startupFile); 115 116 return true; 117 } 118 119 public void stop() throws ContainerException { 120 } 121 122 public String getXuiPropertiesName() { 123 return this.startupFile; 124 } 125 126 129 public abstract String getContainerConfigName(); 130 131 139 public abstract void configure(ContainerConfig.Container cc) throws ContainerException; 140 141 public static XuiSession getSession() { 142 return session; 143 } 144 145 class XuiScreen extends XApplet { 146 147 public void setup(String startupFile) { 148 String xuiProps = System.getProperty("ofbiz.home") + "/applications/pos/config/" + startupFile; 149 String suffix = Locale.getDefault().getLanguage(); 150 if ("en" == suffix ) 151 suffix = ""; 152 else 153 suffix = "_" + suffix; 154 UtilProperties.setPropertyValue(xuiProps, "Language", "XuiLabels" + suffix); 155 JFrame frame = new JFrame (); 156 frame.setUndecorated(true); 157 frame.setVisible(false); 158 frame.getContentPane().add(this); 159 super.setup(frame, new String [] { startupFile }); 160 } 161 } 162 } 163 | Popular Tags |