Search in sources :

Example 1 with EJQueryCriteria

use of org.entirej.framework.core.service.EJQueryCriteria in project rap by entirej.

the class EJRWTQueryScreenRenderer method setupQueryScreen.

private void setupQueryScreen() {
    // Setup pane for query window
    EJFrameworkExtensionProperties rendererProperties = _block.getProperties().getQueryScreenRendererProperties();
    String title = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.TITLE);
    final int width = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.WIDTH, 300);
    final int height = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.HEIGHT, 500);
    _maximize = rendererProperties.getBooleanProperty(EJRWTScreenRendererDefinitionProperties.MAXIMIZE, false);
    final int numCols = rendererProperties.getIntProperty(EJRWTScreenRendererDefinitionProperties.NUM_COLS, 1);
    final String queryButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.EXECUTE_BUTTON_TEXT);
    final String cancelButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.CANCEL_BUTTON_TEXT);
    final String clearButtonLabel = rendererProperties.getStringProperty(EJRWTScreenRendererDefinitionProperties.CLEAR_BUTTON_TEXT);
    _queryDialog = new EJRWTAbstractDialog(getRWTManager().getShell()) {

        private static final long serialVersionUID = -4685316941898120169L;

        @Override
        public void createBody(Composite parent) {
            EJ_RWT.setTestId(parent, _block.getProperties().getName() + ".query-screen");
            parent.setLayout(new FillLayout());
            final ScrolledComposite scrollComposite = new EJRWTScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL);
            EJRWTEntireJGridPane _mainPane = new EJRWTEntireJGridPane(scrollComposite, numCols);
            _mainPane.cleanLayout();
            EJBlockProperties blockProperties = _block.getProperties();
            addAllItemGroups(blockProperties.getScreenItemGroupContainer(EJScreenType.QUERY), _mainPane, EJScreenType.QUERY);
            scrollComposite.setContent(_mainPane);
            scrollComposite.setExpandHorizontal(true);
            scrollComposite.setExpandVertical(true);
            // remove the oddset
            scrollComposite.setMinSize(width, height - 10);
            _block.addItemValueChangedListener(EJRWTQueryScreenRenderer.this);
            EJRWTItemTextChangeNotifier.ChangeListener changeListener = new ChangeListener() {

                @Override
                public void changed() {
                    validate();
                }
            };
            Collection<EJManagedItemRendererWrapper> registeredRenderers = _itemRegister.getRegisteredRenderers();
            for (EJManagedItemRendererWrapper ejManagedItemRendererWrapper : registeredRenderers) {
                if (ejManagedItemRendererWrapper.getUnmanagedRenderer() instanceof EJRWTItemTextChangeNotifier) {
                    ((EJRWTItemTextChangeNotifier) ejManagedItemRendererWrapper.getUnmanagedRenderer()).addListener(changeListener);
                }
            }
        }

        @Override
        public void validate() {
            Button button = getButton(QUERY_OK_ACTION_COMMAND);
            if (button == null) {
                return;
            }
            Collection<EJScreenItemController> allScreenItems = _block.getAllScreenItems(EJScreenType.QUERY);
            for (EJScreenItemController ejScreenItemController : allScreenItems) {
                if (!ejScreenItemController.getManagedItemRenderer().isValid()) {
                    button.setEnabled(false);
                    return;
                }
            }
            button.setEnabled(true);
        }

        @Override
        public int open() {
            validate();
            setFoucsItemRenderer();
            return super.open();
        }

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            EJ_RWT.setTestId(createButton(parent, QUERY_OK_ACTION_COMMAND, queryButtonLabel == null ? "Query" : queryButtonLabel, true), _block.getProperties().getName() + ".ok");
            EJ_RWT.setTestId(createButton(parent, QUERY_CLEAR_ACTION_COMMAND, clearButtonLabel == null ? "Clear" : clearButtonLabel, false), _block.getProperties().getName() + ".clear");
            EJ_RWT.setTestId(createButton(parent, QUERY_CANCEL_ACTION_COMMAND, cancelButtonLabel == null ? "Cancel" : cancelButtonLabel, false), _block.getProperties().getName() + ".cancel");
        }

        @Override
        public void canceled() {
            close();
        }

        @Override
        public boolean close() {
            _block.removeItemValueChangedListener(EJRWTQueryScreenRenderer.this);
            _block.setRendererFocus(true);
            return super.close();
        }

        @Override
        protected void buttonPressed(int buttonId) {
            Display.getDefault().asyncExec(() -> {
                try {
                    switch(buttonId) {
                        case QUERY_OK_ACTION_COMMAND:
                            {
                                EJQueryBlock b = new EJLovBlock(_block.getBlock());
                                EJQueryCriteria queryCriteria = new EJQueryCriteria(b);
                                EJDataRecord record = getQueryRecord();
                                for (EJDataItem item : record.getAllItems()) {
                                    boolean serviceItem = item.isBlockServiceItem();
                                    if (item.getValue() != null) {
                                        if (item.getProperties().getDataTypeClass().isAssignableFrom(String.class)) {
                                            String value = (String) item.getValue();
                                            if (value.contains("%")) {
                                                queryCriteria.add(EJRestrictions.like(item.getName(), serviceItem, item.getValue()));
                                            } else {
                                                queryCriteria.add(EJRestrictions.equals(item.getName(), serviceItem, item.getValue()));
                                            }
                                        } else {
                                            queryCriteria.add(EJRestrictions.equals(item.getName(), serviceItem, item.getValue()));
                                        }
                                    }
                                }
                                try {
                                    _block.executeQuery(queryCriteria);
                                } catch (EJApplicationException e) {
                                    setButtonEnable(buttonId, false);
                                    throw e;
                                }
                                close();
                                break;
                            }
                        case QUERY_CLEAR_ACTION_COMMAND:
                            {
                                _itemRegister.clearRegisteredValues();
                                _itemRegister.register(_block.createRecord(EJRecordType.QUERY));
                                break;
                            }
                        case QUERY_CANCEL_ACTION_COMMAND:
                            {
                                close();
                                break;
                            }
                    }
                } catch (EJApplicationException e) {
                    _logger.trace(e.getMessage());
                    _frameworkManager.handleException(e);
                    return;
                }
            });
        }
    };
    _queryDialog.create();
    _queryDialog.getShell().setData("QUERY - " + _block.getProperties().getName());
    _queryDialog.getShell().setText(title != null ? title : "");
    // add dialog border offsets
    _queryDialog.getShell().setSize(width + 80, height + 100);
}
Also used : EJQueryCriteria(org.entirej.framework.core.service.EJQueryCriteria) EJQueryBlock(org.entirej.framework.core.EJQueryBlock) EJLovBlock(org.entirej.framework.core.EJLovBlock) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) EJRWTAbstractDialog(org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog) Button(org.eclipse.swt.widgets.Button) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ChangeListener(org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener) EJFrameworkExtensionProperties(org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties) EJRWTScrolledComposite(org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) EJDataItem(org.entirej.framework.core.data.EJDataItem) EJApplicationException(org.entirej.framework.core.EJApplicationException) FillLayout(org.eclipse.swt.layout.FillLayout) EJScreenItemController(org.entirej.framework.core.interfaces.EJScreenItemController) EJManagedItemRendererWrapper(org.entirej.framework.core.renderers.EJManagedItemRendererWrapper) EJBlockProperties(org.entirej.framework.core.properties.interfaces.EJBlockProperties) EJRWTItemTextChangeNotifier(org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier) Collection(java.util.Collection) EJDataRecord(org.entirej.framework.core.data.EJDataRecord) EJRWTEntireJGridPane(org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)

Aggregations

Collection (java.util.Collection)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 FillLayout (org.eclipse.swt.layout.FillLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 EJRWTAbstractDialog (org.entirej.applicationframework.rwt.application.form.containers.EJRWTAbstractDialog)1 EJRWTEntireJGridPane (org.entirej.applicationframework.rwt.layout.EJRWTEntireJGridPane)1 EJRWTScrolledComposite (org.entirej.applicationframework.rwt.layout.EJRWTScrolledComposite)1 EJRWTItemTextChangeNotifier (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier)1 ChangeListener (org.entirej.applicationframework.rwt.renderers.item.EJRWTItemTextChangeNotifier.ChangeListener)1 EJApplicationException (org.entirej.framework.core.EJApplicationException)1 EJLovBlock (org.entirej.framework.core.EJLovBlock)1 EJQueryBlock (org.entirej.framework.core.EJQueryBlock)1 EJDataItem (org.entirej.framework.core.data.EJDataItem)1 EJDataRecord (org.entirej.framework.core.data.EJDataRecord)1 EJScreenItemController (org.entirej.framework.core.interfaces.EJScreenItemController)1 EJFrameworkExtensionProperties (org.entirej.framework.core.properties.definitions.interfaces.EJFrameworkExtensionProperties)1 EJBlockProperties (org.entirej.framework.core.properties.interfaces.EJBlockProperties)1 EJManagedItemRendererWrapper (org.entirej.framework.core.renderers.EJManagedItemRendererWrapper)1 EJQueryCriteria (org.entirej.framework.core.service.EJQueryCriteria)1