abstract public class ApplicationEntryPoint implements EntryPoint { private ApplicationSession mSession; private ApplicationWindow mApplicationWindow; private ApplicationController mController; private String mDeferredUsecaseRun; public ApplicationEntryPoint(UseCaseRegister usecaseRegister) { mSession = new ApplicationSession(); } public ApplicationSession getSession() { return mSession; } protected Shell createMainShell( Display display ) { Shell shell = new Shell(display, SWT.NO_TRIM); shell.setMaximized(true); shell.setData(RWT.CUSTOM_VARIANT, "mainshell"); shell.setLayout(new FillLayout()); return shell; } protected void clearShell(Shell shell) { Control[] controls = shell.getChildren(); for (int i = 0; i < controls.length; i++) { if(controls[i] != null) { controls[i].dispose(); } } } }
public class ApplicationConfig implements ApplicationConfiguration { public ApplicationConfig() {} public void configure( Application application ) { application.setOperationMode(OperationMode.SWT_COMPATIBILITY); application.addResource("/images/16/help2.png", new ResourceLoader() { @Override public InputStream getResourceAsStream(String arg0) throws IOException { return ApplicationConfig.class. GetClassLoader(). getResourceAsStream("/images/16/help2.png"); } }); Map<String, String> properties = new HashMap<String, String>(); properties.put( WebClient.FAVICON, "/images/16/help2.png" ); properties.put( WebClient.PAGE_TITLE, "Public area" ); application.addEntryPoint("/public", new PublicAreaEntryPointFactory(), properties); properties = new HashMap<String, String>(); properties.put( WebClient.PAGE_TITLE, "Main area" ); application.addEntryPoint("/main", new MainApplicationEntryPointFactory(), properties); } }
abstract public class ApplicationEntryPointFactory implements EntryPointFactory { public ApplicationEntryPointFactory() {} public EntryPoint create() { return null; } }
final public class ApplicationSession { private PersistentManager mPersistent; private HttpSession mHttpSession; private String mLogin = ""; private Boolean mLoggedIn = false; private Locale mLocale = null; private User mUser; private Logger mLogger; public ApplicationSession() { mLocale = new Locale("ru", "RU"); mHttpSession = RWT.getUISession().getHttpSession(); mPersistent = new PersistentManager("mo"); /* * . */ if (mHttpSession.getAttribute("login") != null) mLogin = (String) mHttpSession.getAttribute("login"); if (mHttpSession.getAttribute("user") != null) mUser = (User) mHttpSession.getAttribute("user"); mLogger = LoggerFactory.getLogger(ApplicationSession.class); } final public void login(User user, String login) { mLogin = login; mPersistent.setUser(user); mHttpSession.setAttribute("login", mLogin); mHttpSession.setAttribute("user", user); logger().debug(" {}", mLogin); } final public Logger logger() { return mLogger; } final public void setUser(User user) { mUser = user; mHttpSession.setAttribute("user", user); } final public User getUser() { return mUser; } final public PersistentManager persistent() { return mPersistent; } final public String getId() { return mHttpSession.getId(); } final public Locale getLocale() { return mLocale; } final public void setLanguage(String language) { if (language.toUpperCase().equals("RUSSIAN") || language.toUpperCase().equals("RU")) { mLocale = new Locale("ru", "RU"); } else { mLocale = new Locale("en", "EN"); } } }
/** * . * - * . */ public class MainApplicationEntryPointFactory extends ApplicationEntryPointFactory { public MainApplicationEntryPointFactory() { super(); } @Override public EntryPoint create() { MainApplicationEntryPoint mainApp = new MainApplicationEntryPoint(getUsecaseRegister()); return mainApp; } } /** * , . * * URI, . */ public class MainApplicationEntryPoint extends ApplicationEntryPoint { private Shell mShell; private CommonController mLoginController; private ApplicationController mCtrl; public MainApplicationEntryPoint() { super(); } @Override public int createUI() { Display display = new Display(); mShell = createMainShell( display ); // try { if (getSession().getUser() != null) { // // . mCtrl = new MainApplicationController(getSession(), mShell); mCtrl.init(); } else { mCtrl = new PublicAreaController(getSession(), mShell); mCtrl.init(); } catch (Exception ex) { MessageDialog.openError(mShell, "!", ex.getMessage()); } // , , // . mShell.open(); // while( !mShell.isDisposed() ) { if( !display.readAndDispatch() ) { display.sleep(); } } display.dispose(); return 0; } }
public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { /* * */ Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("contextName", "app"); context.registerService(ApplicationConfiguration.class.getName(), new ApplicationConfig(), props); } public void stop(BundleContext context) throws Exception { } }
Source: https://habr.com/ru/post/179411/