Search in sources :

Example 1 with EJCoreLayoutContainer

use of org.entirej.framework.core.properties.EJCoreLayoutContainer in project rap by entirej.

the class EJRWTRCPApplication method run.

public void run() {
    final Display display = new Display();
    EJRWTImageRetriever.setGraphicsProvider(new EJRWTGraphicsProvider() {

        private final ImageRegistry PLUGIN_REGISTRY = new ImageRegistry();

        public Image getImage(String name, ClassLoader loader) {
            Image image = PLUGIN_REGISTRY.get(name);
            if (image == null || image.isDisposed()) {
                if (name.startsWith("/") || name.startsWith("\\")) {
                    image = new Image(display, loader.getResourceAsStream(name.substring(1)));
                } else
                    image = new Image(display, loader.getResourceAsStream(name));
                PLUGIN_REGISTRY.put(name, image);
            }
            return image;
        }

        @Override
        public void open(String output, String name) {
            try {
                Desktop.getDesktop().open(new File(output));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public float getAvgCharWidth(Font font) {
            GC gc = new GC(display);
            try {
                gc.setFont(font);
                return gc.getFontMetrics().getAverageCharWidth();
            } finally {
                gc.dispose();
            }
        }

        public int getCharHeight(Font font) {
            if (font.getFontData().length > 0) {
                return font.getFontData()[0].getHeight();
            }
            return 13;
        }

        public void rendererSection(Section section) {
        // IGNOTE
        }
    });
    EJRWTApplicationManager applicationManager = null;
    if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
        applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("application.ejprop");
    } else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
        applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
    } else {
        throw new RuntimeException("application.ejprop not found");
    }
    EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
    // Now build the application container
    EJRWTApplicationContainer appContainer = new EJRWTApplicationContainer(layoutContainer);
    // Add the application menu and status bar to the app
    // container
    EJMessenger messenger = applicationManager.getApplicationMessenger();
    if (messenger == null) {
        throw new NullPointerException("The ApplicationComponentProvider must provide an Messenger via method: getApplicationMessenger()");
    }
    Shell shell = new Shell(display);
    shell.setImage(EJRWTImageRetriever.get(getShellIcon()));
    shell.setText(layoutContainer.getTitle());
    preApplicationBuild(applicationManager);
    applicationManager.buildApplication(appContainer, shell);
    postApplicationBuild(applicationManager);
    shell.layout();
    shell.pack();
    shell.setMaximized(true);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}
Also used : EJRWTApplicationContainer(org.entirej.applicationframework.rwt.application.EJRWTApplicationContainer) EJRWTGraphicsProvider(org.entirej.applicationframework.rwt.application.EJRWTGraphicsProvider) IOException(java.io.IOException) EJRWTApplicationManager(org.entirej.applicationframework.rwt.application.EJRWTApplicationManager) Image(org.eclipse.swt.graphics.Image) Section(org.eclipse.ui.forms.widgets.Section) Font(org.eclipse.swt.graphics.Font) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) Shell(org.eclipse.swt.widgets.Shell) EJMessenger(org.entirej.framework.core.interfaces.EJMessenger) GC(org.eclipse.swt.graphics.GC) File(java.io.File) EJCoreLayoutContainer(org.entirej.framework.core.properties.EJCoreLayoutContainer) Display(org.eclipse.swt.widgets.Display)

Example 2 with EJCoreLayoutContainer

use of org.entirej.framework.core.properties.EJCoreLayoutContainer in project rap by entirej.

the class EJRWTMobileApplicationLauncher method createEntryPoint.

public void createEntryPoint(final Application configuration) {
    configuration.setOperationMode(getOperationMode());
    Map<String, String> properties = new HashMap<String, String>();
    if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
        EJFrameworkInitialiser.initialiseFramework("application.ejprop");
    } else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
        EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
    } else {
        throw new RuntimeException("application.ejprop not found");
    }
    EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
    properties.put(WebClient.PAGE_TITLE, layoutContainer.getTitle());
    properties.put(WebClient.FAVICON, getFavicon());
    properties.put(WebClient.BODY_HTML, getBodyHtml());
    properties.put(WebClient.THEME_ID, THEME_DEFAULT);
    addOtherResources(configuration);
    configuration.addResource(getFavicon(), new FileResource());
    configuration.addResource(getLoadingImage(), new FileResource());
    configuration.addStyleSheet(THEME_DEFAULT, "resource/theme/default.css");
    configuration.addStyleSheet(THEME_DEFAULT, getBaseThemeCSSLocation());
    configuration.addResource(getBaseThemeCSSLocation(), new FileResource());
    configuration.addStyleSheet(THEME_DEFAULT, "org/entirej/rwt/mobile/mobile.css");
    configuration.addResource("org/entirej/rwt/mobile/mobile.css", new FileResource());
    if (getThemeCSSLocation() != null) {
        configuration.addStyleSheet(THEME_DEFAULT, getThemeCSSLocation());
        configuration.addResource(getThemeCSSLocation(), new FileResource());
    }
    configuration.addEntryPoint(String.format("/%s", getWebPathContext()), new EntryPointFactory() {

        public EntryPoint create() {
            try {
                RWT.getServiceManager().registerServiceHandler(VACSSServiceHandler.SERVICE_HANDLER, new VACSSServiceHandler());
                RWT.getServiceManager().registerServiceHandler(EJRWTFileDownload.SERVICE_HANDLER, EJRWTFileDownload.newServiceHandler());
                registerServiceHandlers();
            } catch (java.lang.IllegalArgumentException e) {
            // ignore if already registered
            }
            registerWidgetHandlers();
            return new EntryPoint() {

                public int createUI() {
                    EJRWTImageRetriever.setGraphicsProvider(new EJRWTGraphicsProvider() {

                        @Override
                        public void promptFileUpload(final EJFileUpload fileUpload, final Callable<Object> callable) {
                            if (fileUpload.isMultiSelection()) {
                                EJRWTFileUpload.promptMultipleFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {

                                    @Override
                                    public void select(String[] files) {
                                        try {
                                            fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
                                            callable.call();
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                });
                            } else {
                                EJRWTFileUpload.promptFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {

                                    @Override
                                    public void select(String[] files) {
                                        try {
                                            fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
                                            callable.call();
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                });
                            }
                        }

                        public Image getImage(String name, ClassLoader loader) {
                            return RWTUtils.getImage(name, loader);
                        }

                        public float getAvgCharWidth(Font font) {
                            return RWTUtils.getAvgCharWidth(font);
                        }

                        public int getCharHeight(Font font) {
                            return RWTUtils.getCharHeight(font);
                        }

                        public void rendererSection(final Section section) {
                            section.removeListener(SWT.Dispose, section.getListeners(SWT.Dispose)[0]);
                            section.removeListener(SWT.Resize, section.getListeners(SWT.Resize)[0]);
                            section.setFont(section.getParent().getFont());
                            section.setForeground(section.getParent().getForeground());
                            Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
                            IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
                            gfxAdapter.setRoundedBorder(1, section.getTitleBarBackground(), 2, 2, 0, 0);
                            Listener listener = new Listener() {

                                public void handleEvent(Event e) {
                                    Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
                                    IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
                                    Color[] gradientColors = new Color[] { section.getTitleBarBorderColor(), section.getBackground(), section.getTitleBarBackground(), section.getBackground(), section.getBackground() };
                                    int gradientPercent = 0;
                                    Rectangle bounds = section.getClientArea();
                                    if (bounds.height != 0) {
                                        gradientPercent = 30 * 100 / bounds.height;
                                        if (gradientPercent > 100) {
                                            gradientPercent = 100;
                                        }
                                    }
                                    int[] percents = new int[] { 0, 1, 2, gradientPercent, 100 };
                                    gfxAdapter.setBackgroundGradient(gradientColors, percents, true);
                                    gfxAdapter.setRoundedBorder(1, section.getBackground(), 4, 4, 0, 0);
                                }
                            };
                            section.addListener(SWT.Dispose, listener);
                            section.addListener(SWT.Resize, listener);
                        }

                        @Override
                        public void open(final String output, String outputName) {
                            EJRWTFileDownload.download(output, outputName);
                            RWT.getUISession().addUISessionListener(new UISessionListener() {

                                private static final long serialVersionUID = 1L;

                                @Override
                                public void beforeDestroy(UISessionEvent arg0) {
                                    File f = new File(output);
                                    if (f.exists()) {
                                        f.delete();
                                    }
                                }
                            });
                        }
                    });
                    EJRWTApplicationManager applicationManager = null;
                    if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
                        applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("application.ejprop");
                    } else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
                        applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
                    } else {
                        throw new RuntimeException("application.ejprop not found");
                    }
                    EJRWTContext.getPageContext().setManager(applicationManager);
                    EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
                    // Now build the application container
                    EJRWTApplicationContainer appContainer = new EJRWTApplicationContainer(layoutContainer) {

                        @Override
                        protected void buildApplicationContainer() {
                            _mainPane.setLayout(new FillLayout());
                            _mainPane.setData(RWT.CUSTOM_VARIANT, null);
                            _formContainer = createFormContainer(_applicationManager, _mainPane);
                        }
                    };
                    // Add the application menu and status bar to the app
                    // container
                    EJMessenger messenger = applicationManager.getApplicationMessenger();
                    if (messenger == null) {
                        throw new NullPointerException("The ApplicationComponentProvider must provide an Messenger via method: getApplicationMessenger()");
                    }
                    Display display = Display.getDefault();
                    if (display.isDisposed())
                        display = new Display();
                    final Shell shell = new Shell(display, SWT.NO_TRIM);
                    GridLayout gridLayout = new GridLayout(2, false);
                    gridLayout.marginHeight = 0;
                    gridLayout.marginWidth = 0;
                    gridLayout.horizontalSpacing = 1;
                    gridLayout.verticalSpacing = 0;
                    shell.setLayout(gridLayout);
                    final Composite nav = new Composite(shell, SWT.NONE);
                    nav.setLayout(new FillLayout());
                    final GridData navData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
                    navData.widthHint = getSidebarWidth();
                    navData.heightHint = SWT.MAX;
                    // nav.setLayoutData(navData);
                    final GridData navEmptyData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, false);
                    navEmptyData.minimumWidth = 0;
                    navEmptyData.widthHint = 0;
                    nav.setLayoutData(navEmptyData);
                    nav.setVisible(false);
                    Composite page = new Composite(shell, SWT.NONE);
                    GridLayout gridLayoutPage = new GridLayout(1, false);
                    gridLayoutPage.marginHeight = 0;
                    gridLayoutPage.marginWidth = 0;
                    gridLayoutPage.verticalSpacing = 1;
                    page.setLayout(gridLayoutPage);
                    GridData pageData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
                    page.setLayoutData(pageData);
                    Composite pageHeader = new Composite(page, SWT.NONE);
                    GridData pageHData = new GridData(GridData.FILL_HORIZONTAL);
                    pageHData.heightHint = 40;
                    pageHData.minimumHeight = 40;
                    pageHeader.setLayoutData(pageHData);
                    GridLayout gridLayoutHeader = new GridLayout(8, false);
                    pageHeader.setLayout(gridLayoutHeader);
                    gridLayoutHeader.marginHeight = 1;
                    gridLayoutHeader.marginWidth = 1;
                    Button pageB = new Button(pageHeader, SWT.PUSH);
                    pageB.setImage(EJRWTImageRetriever.get("icons/menu-32.png"));
                    pageB.addSelectionListener(new SelectionAdapter() {

                        @Override
                        public void widgetSelected(SelectionEvent e) {
                            nav.setVisible(!nav.isVisible());
                            nav.setLayoutData(nav.isVisible() ? navData : navEmptyData);
                            shell.layout();
                        }
                    });
                    ui = new UI() {

                        @Override
                        public void showMenu(boolean show) {
                            nav.setVisible(show);
                            nav.setLayoutData(show ? navData : navEmptyData);
                            shell.layout();
                        }
                    };
                    final GridData actioBData = new GridData(SWT.BEGINNING, SWT.BEGINNING, false, true);
                    actioBData.widthHint = 40;
                    actioBData.heightHint = 40;
                    pageB.setLayoutData(actioBData);
                    Text headerText = new Text(pageHeader, SWT.SINGLE | SWT.READ_ONLY | SWT.CENTER);
                    final GridData headerTextData = new GridData(SWT.FILL, SWT.FILL, true, true);
                    headerTextData.heightHint = 40;
                    headerTextData.grabExcessHorizontalSpace = true;
                    headerText.setLayoutData(headerTextData);
                    headerText.setText(layoutContainer.getTitle());
                    createToolBar(applicationManager, pageHeader);
                    Composite pageBody = new Composite(page, SWT.NONE);
                    GridData pageBData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
                    pageBody.setLayoutData(pageBData);
                    pageBody.setLayout(new FillLayout());
                    nav.setData(RWT.CUSTOM_VARIANT, "sidebar");
                    pageHeader.setData(RWT.CUSTOM_VARIANT, "drawerHeader");
                    // pageBody.setData(RWT.CUSTOM_VARIANT, "applayout");
                    pageB.setData(RWT.CUSTOM_VARIANT, "drawerAction");
                    headerText.setData(RWT.CUSTOM_VARIANT, "drawerTitle");
                    EJRWTContext.getPageContext().setManager(applicationManager);
                    getContext().getUISession().setAttribute("ej.MobileMode", true);
                    try {
                        preApplicationBuild(applicationManager);
                    } finally {
                        applicationManager.getConnection().close();
                    }
                    createNavigator(applicationManager, nav);
                    createDrawerBody(applicationManager, appContainer, pageBody);
                    try {
                        postApplicationBuild(applicationManager);
                    } finally {
                        applicationManager.getConnection().close();
                    }
                    shell.layout();
                    shell.setMaximized(true);
                    return openShell(display, shell);
                }
            };
        }
    }, properties);
}
Also used : HashMap(java.util.HashMap) Rectangle(org.eclipse.swt.graphics.Rectangle) EntryPoint(org.eclipse.rap.rwt.application.EntryPoint) EJRWTApplicationManager(org.entirej.applicationframework.rwt.application.EJRWTApplicationManager) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EJCoreLayoutContainer(org.entirej.framework.core.properties.EJCoreLayoutContainer) EJRWTApplicationContainer(org.entirej.applicationframework.rwt.application.EJRWTApplicationContainer) EJRWTGraphicsProvider(org.entirej.applicationframework.rwt.application.EJRWTGraphicsProvider) Color(org.eclipse.swt.graphics.Color) FillLayout(org.eclipse.swt.layout.FillLayout) UISessionEvent(org.eclipse.rap.rwt.service.UISessionEvent) IWidgetGraphicsAdapter(org.eclipse.swt.internal.widgets.IWidgetGraphicsAdapter) EntryPointFactory(org.eclipse.rap.rwt.application.EntryPointFactory) File(java.io.File) EJFileUpload(org.entirej.framework.core.data.controllers.EJFileUpload) Listener(org.eclipse.swt.widgets.Listener) UISessionListener(org.eclipse.rap.rwt.service.UISessionListener) FileSelectionCallBack(org.entirej.applicationframework.rwt.file.EJRWTFileUpload.FileSelectionCallBack) UISessionListener(org.eclipse.rap.rwt.service.UISessionListener) Callable(java.util.concurrent.Callable) Font(org.eclipse.swt.graphics.Font) Shell(org.eclipse.swt.widgets.Shell) GridLayout(org.eclipse.swt.layout.GridLayout) EJMessenger(org.entirej.framework.core.interfaces.EJMessenger) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) Section(org.eclipse.ui.forms.widgets.Section) EntryPoint(org.eclipse.rap.rwt.application.EntryPoint) VACSSServiceHandler(org.entirej.applicationframework.rwt.renderers.html.EJRWTHtmlTableBlockRenderer.VACSSServiceHandler) GridData(org.eclipse.swt.layout.GridData) Event(org.eclipse.swt.widgets.Event) UISessionEvent(org.eclipse.rap.rwt.service.UISessionEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Display(org.eclipse.swt.widgets.Display)

Example 3 with EJCoreLayoutContainer

use of org.entirej.framework.core.properties.EJCoreLayoutContainer in project rap by entirej.

the class EJRWTApplicationLauncher method createEntryPoint.

public void createEntryPoint(final Application configuration) {
    configuration.setOperationMode(getOperationMode());
    Map<String, String> properties = new HashMap<String, String>();
    if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
        EJFrameworkInitialiser.initialiseFramework("application.ejprop");
    } else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
        EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
    } else {
        throw new RuntimeException("application.ejprop not found");
    }
    final EJCoreProperties coreProperties = EJCoreProperties.getInstance();
    EJCoreLayoutContainer layoutContainer = coreProperties.getLayoutContainer();
    properties.put(WebClient.PAGE_TITLE, layoutContainer.getTitle());
    String favicon = getFavicon();
    if (favicon == null) {
        favicon = ICONS_FAVICON_ICO;
    }
    properties.put(WebClient.FAVICON, favicon);
    properties.put(WebClient.BODY_HTML, getBodyHtml());
    properties.put(WebClient.THEME_ID, THEME_DEFAULT);
    addOtherResources(configuration);
    configuration.addResource(favicon, new FileResource());
    configuration.addResource(getLoadingImage(), new FileResource());
    configuration.addStyleSheet(THEME_DEFAULT, "resource/theme/default.css");
    String baseThemeCSSLocation = getBaseThemeCSSLocation();
    if (baseThemeCSSLocation == null) {
        baseThemeCSSLocation = THEME_DEFAULT_CSS;
    }
    configuration.addStyleSheet(THEME_DEFAULT, baseThemeCSSLocation);
    properties.put(WebClient.PAGE_OVERFLOW, "scrollY");
    configuration.addResource(baseThemeCSSLocation, new FileResource());
    if (getThemeCSSLocation() != null) {
        configuration.addStyleSheet(THEME_DEFAULT, getThemeCSSLocation());
        configuration.addResource(getThemeCSSLocation(), new FileResource());
    }
    configuration.addEntryPoint(String.format("/%s", getWebPathContext()), new EntryPointFactory() {

        public EntryPoint create() {
            try {
                RWT.getServiceManager().registerServiceHandler(VACSSServiceHandler.SERVICE_HANDLER, new VACSSServiceHandler());
                RWT.getServiceManager().registerServiceHandler(EJRWTFileDownload.SERVICE_HANDLER, EJRWTFileDownload.newServiceHandler());
                registerServiceHandlers();
            } catch (java.lang.IllegalArgumentException e) {
            // ignore if already registered
            }
            registerWidgetHandlers();
            final EntryPoint wrapped = newEntryPoint();
            return new EntryPoint() {

                public int createUI() {
                    BrowserNavigation service = RWT.getClient().getService(BrowserNavigation.class);
                    BrowserNavigationListener listener = new BrowserNavigationListener() {

                        @Override
                        public void navigated(BrowserNavigationEvent event) {
                            EJRWTContext.getPageContext().setState(event.getState());
                        }
                    };
                    service.addBrowserNavigationListener(listener);
                    int createUI = wrapped.createUI();
                    return createUI;
                }
            };
        }

        private EntryPoint newEntryPoint() {
            return new EntryPoint() {

                public int createUI() {
                    {
                        // connect BaseURL
                        StringBuffer url = new StringBuffer();
                        url.append(RWT.getRequest().getContextPath());
                        url.append(RWT.getRequest().getServletPath());
                        String encodeURL = RWT.getResponse().encodeURL(url.toString());
                        if (encodeURL.contains("jsessionid")) {
                            encodeURL = encodeURL.substring(0, encodeURL.indexOf("jsessionid"));
                        }
                        int patchIndex = encodeURL.lastIndexOf(getWebPathContext());
                        if (patchIndex > -1) {
                            encodeURL = encodeURL.substring(0, patchIndex);
                        }
                        _baseURL = encodeURL;
                    }
                    RWTUtils.patchClient(getWebPathContext(), getTimeoutUrl());
                    EJRWTImageRetriever.setGraphicsProvider(new EJRWTGraphicsProvider() {

                        @Override
                        public void promptFileUpload(final EJFileUpload fileUpload, final Callable<Object> callable) {
                            if (fileUpload.isMultiSelection()) {
                                EJRWTFileUpload.promptMultipleFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {

                                    @Override
                                    public void select(String[] files) {
                                        try {
                                            fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
                                            callable.call();
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                });
                            } else {
                                EJRWTFileUpload.promptFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {

                                    @Override
                                    public void select(String[] files) {
                                        try {
                                            fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
                                            callable.call();
                                        } catch (Exception e) {
                                            e.printStackTrace();
                                        }
                                    }
                                });
                            }
                        }

                        public Image getImage(String name, ClassLoader loader) {
                            return RWTUtils.getImage(name, loader);
                        }

                        @Override
                        public void open(final String output, String outputName) {
                            EJRWTFileDownload.download(output, outputName);
                            RWT.getUISession().addUISessionListener(new UISessionListener() {

                                private static final long serialVersionUID = 1L;

                                @Override
                                public void beforeDestroy(UISessionEvent arg0) {
                                    File f = new File(output);
                                    if (f.exists()) {
                                        f.delete();
                                    }
                                }
                            });
                        }

                        public float getAvgCharWidth(Font font) {
                            return RWTUtils.getAvgCharWidth(font);
                        }

                        public int getCharHeight(Font font) {
                            return RWTUtils.getCharHeight(font);
                        }

                        public void rendererSection(final Section section) {
                            section.removeListener(SWT.Dispose, section.getListeners(SWT.Dispose)[0]);
                            section.removeListener(SWT.Resize, section.getListeners(SWT.Resize)[0]);
                            section.setFont(section.getParent().getFont());
                            section.setForeground(section.getParent().getForeground());
                            Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
                            IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
                            gfxAdapter.setRoundedBorder(1, section.getTitleBarBackground(), 2, 2, 0, 0);
                            Listener listener = new Listener() {

                                public void handleEvent(Event e) {
                                    Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
                                    IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
                                    Color[] gradientColors = new Color[] { section.getTitleBarBorderColor(), section.getBackground(), section.getTitleBarBackground(), section.getBackground(), section.getBackground() };
                                    int gradientPercent = 0;
                                    Rectangle bounds = section.getClientArea();
                                    if (bounds.height != 0) {
                                        gradientPercent = 30 * 100 / bounds.height;
                                        if (gradientPercent > 100) {
                                            gradientPercent = 100;
                                        }
                                    }
                                    int[] percents = new int[] { 0, 1, 2, gradientPercent, 100 };
                                    gfxAdapter.setBackgroundGradient(gradientColors, percents, true);
                                    gfxAdapter.setRoundedBorder(1, section.getBackground(), 4, 4, 0, 0);
                                }
                            };
                            section.addListener(SWT.Dispose, listener);
                            section.addListener(SWT.Resize, listener);
                        }
                    });
                    final EJRWTApplicationManager applicationManager;
                    if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
                        applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("application.ejprop");
                    } else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
                        applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
                    } else {
                        throw new RuntimeException("application.ejprop not found");
                    }
                    EJRWTContext.getPageContext().setManager(applicationManager);
                    getContext().getUISession().setAttribute("ej.applicationManager", applicationManager);
                    EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
                    // Now build the application container
                    EJRWTApplicationContainer appContainer = new EJRWTApplicationContainer(layoutContainer);
                    // Add the application menu and status bar to the app
                    // container
                    EJMessenger messenger = applicationManager.getApplicationMessenger();
                    if (messenger == null) {
                        throw new NullPointerException("The ApplicationComponentProvider must provide an Messenger via method: getApplicationMessenger()");
                    }
                    Display display = Display.getDefault();
                    if (display.isDisposed())
                        display = new Display();
                    Shell shell = new Shell(display, SWT.NO_TRIM);
                    // check test mode
                    StartupParameters service = RWT.getClient().getService(StartupParameters.class);
                    if (service != null && Boolean.valueOf(service.getParameter("TEST_MODE"))) {
                        EJ_RWT.setTestMode(true);
                    }
                    try {
                        preApplicationBuild(applicationManager);
                    } finally {
                        applicationManager.getConnection().close();
                    }
                    applicationManager.buildApplication(appContainer, shell);
                    final EJRWTApplicationManager appman = applicationManager;
                    Display.getCurrent().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                postApplicationBuild(appman);
                            } finally {
                                appman.getConnection().close();
                            }
                        }
                    });
                    shell.layout();
                    shell.setMaximized(true);
                    // disable due to RWT bug
                    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=410895
                    // ExitConfirmation confirmation =
                    // RWT.getClient().getService(ExitConfirmation.class);
                    // String message = getDefaultTabCloseMessage();
                    // if ("__DEFAULT__".equals(message))
                    // {
                    // confirmation.setMessage(String.format("Do you want to close %s ?",
                    // EJCoreProperties.getInstance().getLayoutContainer().getTitle()));
                    // }
                    // else if (message != null)
                    // {
                    // confirmation.setMessage(message);
                    // }
                    final ServerPushSession pushSession = new ServerPushSession();
                    RWT.getUISession().addUISessionListener(new UISessionListener() {

                        public void beforeDestroy(UISessionEvent event) {
                            if (applicationManager.getApplicationActionProcessor() != null)
                                try {
                                    applicationManager.getApplicationActionProcessor().whenApplicationEnd(applicationManager);
                                } catch (EJActionProcessorException e) {
                                    e.printStackTrace();
                                }
                            pushSession.stop();
                        }
                    });
                    if (applicationManager.getApplicationActionProcessor() != null)
                        try {
                            applicationManager.getApplicationActionProcessor().whenApplicationStart(applicationManager);
                        } catch (EJActionProcessorException e) {
                            e.printStackTrace();
                        }
                    EJFrameworkExtensionProperties definedProperties = coreProperties.getApplicationDefinedProperties();
                    if (definedProperties != null && definedProperties.getBooleanProperty("LIVE_CONNECTION", false))
                        pushSession.start();
                    return openShell(display, shell);
                }
            };
        }
    }, properties);
    // services
    {
        final String SERVICE = "SERVICE";
        final String SERVICE_LIST = "SERVICE_LIST";
        final String SERVICE_PATH = "SERVICE_PATH";
        final String SERVICE_FORM = "SERVICE_FORM";
        final String SERVICE_NAME = "SERVICE_NAME";
        EJFrameworkExtensionProperties definedProperties = coreProperties.getApplicationDefinedProperties();
        if (canLoadServices() && definedProperties != null) {
            EJFrameworkExtensionProperties group = definedProperties.getPropertyGroup(SERVICE);
            if (group != null && group.getPropertyList(SERVICE_LIST) != null) {
                EJCoreFrameworkExtensionPropertyList list = group.getPropertyList(SERVICE_LIST);
                List<EJFrameworkExtensionPropertyListEntry> allListEntries = list.getAllListEntries();
                for (EJFrameworkExtensionPropertyListEntry entry : allListEntries) {
                    final String formId = entry.getProperty(SERVICE_FORM);
                    HashMap<String, String> srvproperties = new HashMap<String, String>(properties);
                    srvproperties.put(WebClient.PAGE_TITLE, entry.getProperty(SERVICE_NAME));
                    if (entry.getProperty(SERVICE_PATH) != null && formId != null && formId != null) {
                        configuration.addEntryPoint(String.format("/%s", entry.getProperty(SERVICE_PATH)), new EntryPointFactory() {

                            public EntryPoint create() {
                                try {
                                    RWT.getServiceManager().registerServiceHandler(VACSSServiceHandler.SERVICE_HANDLER, new VACSSServiceHandler());
                                    RWT.getServiceManager().registerServiceHandler(EJRWTFileDownload.SERVICE_HANDLER, EJRWTFileDownload.newServiceHandler());
                                    registerServiceHandlers();
                                } catch (java.lang.IllegalArgumentException e) {
                                // ignore if already registered
                                }
                                registerWidgetHandlers();
                                final EntryPoint wrapped = newServiceEntryPoint(formId);
                                return new EntryPoint() {

                                    public int createUI() {
                                        BrowserNavigation service = RWT.getClient().getService(BrowserNavigation.class);
                                        BrowserNavigationListener listener = new BrowserNavigationListener() {

                                            @Override
                                            public void navigated(BrowserNavigationEvent event) {
                                                EJRWTContext.getPageContext().setState(event.getState());
                                            }
                                        };
                                        service.addBrowserNavigationListener(listener);
                                        int createUI = wrapped.createUI();
                                        return createUI;
                                    }
                                };
                            }

                            private EntryPoint newServiceEntryPoint(String serviceFormID) {
                                return new EntryPoint() {

                                    public int createUI() {
                                        RWTUtils.patchClient(getWebPathContext(), null);
                                        EJRWTImageRetriever.setGraphicsProvider(new EJRWTGraphicsProvider() {

                                            @Override
                                            public void promptFileUpload(final EJFileUpload fileUpload, final Callable<Object> callable) {
                                                if (fileUpload.isMultiSelection()) {
                                                    EJRWTFileUpload.promptMultipleFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {

                                                        @Override
                                                        public void select(String[] files) {
                                                            try {
                                                                fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
                                                                callable.call();
                                                            } catch (Exception e) {
                                                                e.printStackTrace();
                                                            }
                                                        }
                                                    });
                                                } else {
                                                    EJRWTFileUpload.promptFileUpload(fileUpload.getTitle(), fileUpload.getUploadSizeLimit(), fileUpload.getUploadTimeLimit(), fileUpload.getFileExtensions().toArray(new String[0]), new FileSelectionCallBack() {

                                                        @Override
                                                        public void select(String[] files) {
                                                            try {
                                                                fileUpload.setFilePaths(files != null ? Arrays.asList(files) : null);
                                                                callable.call();
                                                            } catch (Exception e) {
                                                                e.printStackTrace();
                                                            }
                                                        }
                                                    });
                                                }
                                            }

                                            public Image getImage(String name, ClassLoader loader) {
                                                return RWTUtils.getImage(name, loader);
                                            }

                                            @Override
                                            public void open(final String output, String outputName) {
                                                EJRWTFileDownload.download(output, outputName);
                                                RWT.getUISession().addUISessionListener(new UISessionListener() {

                                                    private static final long serialVersionUID = 1L;

                                                    @Override
                                                    public void beforeDestroy(UISessionEvent arg0) {
                                                        File f = new File(output);
                                                        if (f.exists()) {
                                                            f.delete();
                                                        }
                                                    }
                                                });
                                            }

                                            public float getAvgCharWidth(Font font) {
                                                return RWTUtils.getAvgCharWidth(font);
                                            }

                                            public int getCharHeight(Font font) {
                                                return RWTUtils.getCharHeight(font);
                                            }

                                            public void rendererSection(final Section section) {
                                                section.removeListener(SWT.Dispose, section.getListeners(SWT.Dispose)[0]);
                                                section.removeListener(SWT.Resize, section.getListeners(SWT.Resize)[0]);
                                                section.setFont(section.getParent().getFont());
                                                section.setForeground(section.getParent().getForeground());
                                                Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
                                                IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
                                                gfxAdapter.setRoundedBorder(1, section.getTitleBarBackground(), 2, 2, 0, 0);
                                                Listener listener = new Listener() {

                                                    public void handleEvent(Event e) {
                                                        Object adapter = section.getAdapter(IWidgetGraphicsAdapter.class);
                                                        IWidgetGraphicsAdapter gfxAdapter = (IWidgetGraphicsAdapter) adapter;
                                                        Color[] gradientColors = new Color[] { section.getTitleBarBorderColor(), section.getBackground(), section.getTitleBarBackground(), section.getBackground(), section.getBackground() };
                                                        int gradientPercent = 0;
                                                        Rectangle bounds = section.getClientArea();
                                                        if (bounds.height != 0) {
                                                            gradientPercent = 30 * 100 / bounds.height;
                                                            if (gradientPercent > 100) {
                                                                gradientPercent = 100;
                                                            }
                                                        }
                                                        int[] percents = new int[] { 0, 1, 2, gradientPercent, 100 };
                                                        gfxAdapter.setBackgroundGradient(gradientColors, percents, true);
                                                        gfxAdapter.setRoundedBorder(1, section.getBackground(), 4, 4, 0, 0);
                                                    }
                                                };
                                                section.addListener(SWT.Dispose, listener);
                                                section.addListener(SWT.Resize, listener);
                                            }
                                        });
                                        final EJRWTApplicationManager applicationManager;
                                        if (this.getClass().getClassLoader().getResource("application.ejprop") != null) {
                                            applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("application.ejprop");
                                        } else if (this.getClass().getClassLoader().getResource("EntireJApplication.properties") != null) {
                                            applicationManager = (EJRWTApplicationManager) EJFrameworkInitialiser.initialiseFramework("EntireJApplication.properties");
                                        } else {
                                            throw new RuntimeException("application.ejprop not found");
                                        }
                                        EJRWTContext.getPageContext().setManager(applicationManager);
                                        getContext().getUISession().setAttribute("ej.applicationManager", applicationManager);
                                        EJCoreLayoutContainer layoutContainer = EJCoreProperties.getInstance().getLayoutContainer();
                                        // Now build the application container
                                        EJRWTApplicationContainer appContainer = new EJRWTApplicationContainer(layoutContainer);
                                        // Add the application menu and status bar to the app
                                        // container
                                        EJMessenger messenger = applicationManager.getApplicationMessenger();
                                        if (messenger == null) {
                                            throw new NullPointerException("The ApplicationComponentProvider must provide an Messenger via method: getApplicationMessenger()");
                                        }
                                        Display display = Display.getDefault();
                                        if (display.isDisposed())
                                            display = new Display();
                                        Shell shell = new Shell(display, SWT.NO_TRIM);
                                        applicationManager.buildServiceApplication(appContainer, shell, formId);
                                        final EJRWTApplicationManager appman = applicationManager;
                                        Display.getCurrent().asyncExec(new Runnable() {

                                            @Override
                                            public void run() {
                                                try {
                                                    postApplicationBuild(appman);
                                                } finally {
                                                    appman.getConnection().close();
                                                }
                                            }
                                        });
                                        shell.layout();
                                        shell.setMaximized(true);
                                        final ServerPushSession pushSession = new ServerPushSession();
                                        RWT.getUISession().addUISessionListener(new UISessionListener() {

                                            public void beforeDestroy(UISessionEvent event) {
                                                pushSession.stop();
                                            }
                                        });
                                        pushSession.start();
                                        return openShell(display, shell);
                                    }
                                };
                            }
                        }, srvproperties);
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Rectangle(org.eclipse.swt.graphics.Rectangle) EntryPoint(org.eclipse.rap.rwt.application.EntryPoint) EJActionProcessorException(org.entirej.framework.core.EJActionProcessorException) EJRWTApplicationManager(org.entirej.applicationframework.rwt.application.EJRWTApplicationManager) Image(org.eclipse.swt.graphics.Image) List(java.util.List) EJCoreFrameworkExtensionPropertyList(org.entirej.framework.core.extensions.properties.EJCoreFrameworkExtensionPropertyList) EJCoreLayoutContainer(org.entirej.framework.core.properties.EJCoreLayoutContainer) ServerPushSession(org.eclipse.rap.rwt.service.ServerPushSession) EJRWTApplicationContainer(org.entirej.applicationframework.rwt.application.EJRWTApplicationContainer) BrowserNavigation(org.eclipse.rap.rwt.client.service.BrowserNavigation) EJRWTGraphicsProvider(org.entirej.applicationframework.rwt.application.EJRWTGraphicsProvider) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) Color(org.eclipse.swt.graphics.Color) UISessionEvent(org.eclipse.rap.rwt.service.UISessionEvent) EJFrameworkExtensionPropertyListEntry(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionPropertyListEntry) IWidgetGraphicsAdapter(org.eclipse.swt.internal.widgets.IWidgetGraphicsAdapter) EntryPointFactory(org.eclipse.rap.rwt.application.EntryPointFactory) EJCoreProperties(org.entirej.framework.core.properties.EJCoreProperties) File(java.io.File) EJFileUpload(org.entirej.framework.core.data.controllers.EJFileUpload) BrowserNavigationListener(org.eclipse.rap.rwt.client.service.BrowserNavigationListener) Listener(org.eclipse.swt.widgets.Listener) UISessionListener(org.eclipse.rap.rwt.service.UISessionListener) FileSelectionCallBack(org.entirej.applicationframework.rwt.file.EJRWTFileUpload.FileSelectionCallBack) UISessionListener(org.eclipse.rap.rwt.service.UISessionListener) Callable(java.util.concurrent.Callable) Font(org.eclipse.swt.graphics.Font) Shell(org.eclipse.swt.widgets.Shell) EJCoreFrameworkExtensionPropertyList(org.entirej.framework.core.extensions.properties.EJCoreFrameworkExtensionPropertyList) EJMessenger(org.entirej.framework.core.interfaces.EJMessenger) BrowserNavigationEvent(org.eclipse.rap.rwt.client.service.BrowserNavigationEvent) BrowserNavigationListener(org.eclipse.rap.rwt.client.service.BrowserNavigationListener) Section(org.eclipse.ui.forms.widgets.Section) EntryPoint(org.eclipse.rap.rwt.application.EntryPoint) EJActionProcessorException(org.entirej.framework.core.EJActionProcessorException) IOException(java.io.IOException) VACSSServiceHandler(org.entirej.applicationframework.rwt.renderers.html.EJRWTHtmlTableBlockRenderer.VACSSServiceHandler) BrowserNavigationEvent(org.eclipse.rap.rwt.client.service.BrowserNavigationEvent) Event(org.eclipse.swt.widgets.Event) UISessionEvent(org.eclipse.rap.rwt.service.UISessionEvent) StartupParameters(org.eclipse.rap.rwt.client.service.StartupParameters) Display(org.eclipse.swt.widgets.Display)

Aggregations

File (java.io.File)3 Font (org.eclipse.swt.graphics.Font)3 Display (org.eclipse.swt.widgets.Display)3 Shell (org.eclipse.swt.widgets.Shell)3 Section (org.eclipse.ui.forms.widgets.Section)3 EJRWTApplicationContainer (org.entirej.applicationframework.rwt.application.EJRWTApplicationContainer)3 EJRWTApplicationManager (org.entirej.applicationframework.rwt.application.EJRWTApplicationManager)3 EJRWTGraphicsProvider (org.entirej.applicationframework.rwt.application.EJRWTGraphicsProvider)3 EJMessenger (org.entirej.framework.core.interfaces.EJMessenger)3 EJCoreLayoutContainer (org.entirej.framework.core.properties.EJCoreLayoutContainer)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Callable (java.util.concurrent.Callable)2 EntryPoint (org.eclipse.rap.rwt.application.EntryPoint)2 EntryPointFactory (org.eclipse.rap.rwt.application.EntryPointFactory)2 UISessionEvent (org.eclipse.rap.rwt.service.UISessionEvent)2 UISessionListener (org.eclipse.rap.rwt.service.UISessionListener)2 Color (org.eclipse.swt.graphics.Color)2 Image (org.eclipse.swt.graphics.Image)2 Rectangle (org.eclipse.swt.graphics.Rectangle)2