Search in sources :

Example 1 with ComboEnum

use of com.twinsoft.convertigo.engine.EnginePropertiesManager.ComboEnum in project convertigo by convertigo.

the class List method getServiceResult.

protected void getServiceResult(HttpServletRequest request, Document document) throws Exception {
    Element rootElement = document.getDocumentElement();
    Role[] roles = Engine.authenticatedSessionManager.getRoles(request.getSession());
    for (PropertyCategory propertyCategory : PropertyCategory.getSortedValues()) {
        if (propertyCategory.isVisible() && (AuthenticatedSessionManager.hasRole(roles, Role.WEB_ADMIN) || AuthenticatedSessionManager.hasRole(roles, propertyCategory.viewRoles()))) {
            Element elementCategory = document.createElement("category");
            elementCategory.setAttribute("name", propertyCategory.toString());
            elementCategory.setAttribute("displayName", propertyCategory.getDisplayName());
            rootElement.appendChild(elementCategory);
        }
    }
    NodeList categories = document.getElementsByTagName("category");
    for (PropertyName property : PropertyName.values()) {
        if (property.isVisible()) {
            Element categoryElement = (Element) XMLUtils.findNodeByAttributeValue(categories, "name", property.getCategory().name());
            if (categoryElement != null) {
                String value = EnginePropertiesManager.getProperty(property);
                String originalValue = EnginePropertiesManager.getOriginalProperty(property);
                switch(property.getType()) {
                    case PasswordHash:
                        if ("0".equals(value)) {
                            value = "";
                        }
                    case PasswordPlain:
                        if (value.length() > 0) {
                            originalValue = value = "••••••••••••••••";
                        } else {
                            originalValue = "";
                        }
                        break;
                    default:
                        break;
                }
                Element propertyElement = document.createElement("property");
                propertyElement.setAttribute("name", property.name());
                propertyElement.setAttribute("type", property.getType().name());
                propertyElement.setAttribute("description", property.getDescription());
                propertyElement.setAttribute("value", value);
                propertyElement.setAttribute("originalValue", originalValue);
                propertyElement.setAttribute("isAdvanced", Boolean.toString(property.isAdvance()));
                categoryElement.appendChild(propertyElement);
                if (property.getType() == PropertyType.Combo) {
                    for (ComboEnum ce : property.getCombo()) {
                        String display = ce.getDisplay();
                        if (display != null) {
                            Element comboValueElement = document.createElement("item");
                            comboValueElement.setAttribute("value", ce.getValue());
                            Text comboValueText = document.createTextNode(display);
                            comboValueElement.appendChild(comboValueText);
                            propertyElement.appendChild(comboValueElement);
                        }
                    }
                }
            }
        }
    }
}
Also used : Role(com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role) PropertyCategory(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyCategory) PropertyName(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName) ComboEnum(com.twinsoft.convertigo.engine.EnginePropertiesManager.ComboEnum) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Text(org.w3c.dom.Text)

Example 2 with ComboEnum

use of com.twinsoft.convertigo.engine.EnginePropertiesManager.ComboEnum in project convertigo by convertigo.

the class EnginePreferenceComposite method createContents.

protected void createContents() {
    modifiedProperties = new HashMap<PropertyName, String>();
    boolean all = (filterList == null);
    if (!all) {
        GridLayout mainLayout = new GridLayout(1, true);
        mainLayout.marginTop = 0;
        setLayout(mainLayout);
    }
    bar = new ExpandBar(this, SWT.VERTICAL);
    bar.setData(SwtUtils.CSS_CLASS_KEY, "c8oEnginePreferenceExpandBar");
    GridData gridData = new GridData(GridData.VERTICAL_ALIGN_BEGINNING);
    bar.setLayoutData(gridData);
    for (PropertyCategory propertyCategory : PropertyCategory.getSortedValues()) {
        if (propertyCategory.isVisible()) {
            Composite container = new Composite(bar, SWT.NONE);
            GridLayout layout = new GridLayout(1, true);
            layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 2;
            layout.verticalSpacing = 4;
            container.setLayout(layout);
            if (all || filterList.contains(propertyCategory.getDisplayName())) {
                ExpandItem item = new ExpandItem(bar, SWT.NONE);
                item.setText(propertyCategory.getDisplayName());
                item.setControl(container);
                containersMap.put(propertyCategory, container);
                expandItemsMap.put(propertyCategory, item);
            }
        }
    }
    boolean toggleLineBackground = true;
    for (final PropertyName property : PropertyName.values()) {
        if (property.isVisible() && property.getCategory().isVisible()) {
            toggleLineBackground = !toggleLineBackground;
            Composite container = containersMap.get(property.getCategory());
            if (container != null) {
                Composite line = new Composite(container, SWT.NONE);
                GridLayout layout = new GridLayout(2, false);
                layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 2;
                layout.verticalSpacing = 0;
                line.setLayout(layout);
                GridData data = new GridData(GridData.FILL_HORIZONTAL);
                line.setLayoutData(data);
                if (toggleLineBackground) {
                    line.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
                }
                Label propertyLabel = new Label(line, SWT.WRAP);
                data = new GridData(240, SWT.DEFAULT);
                data.verticalAlignment = SWT.TOP;
                propertyLabel.setText(property.getDescription());
                propertyLabel.setLayoutData(data);
                propertyLabel.setBackground(line.getBackground());
                switch(property.getType()) {
                    case Text:
                        {
                            final Text propertyEditor = new Text(line, SWT.BORDER);
                            data = new GridData(GridData.FILL_HORIZONTAL);
                            data.verticalAlignment = SWT.TOP;
                            propertyEditor.setLayoutData(data);
                            String value = EnginePropertiesManager.getProperty(property);
                            String originalValue = EnginePropertiesManager.getOriginalProperty(property);
                            propertyEditor.setText(originalValue);
                            if (!originalValue.equals(value))
                                propertyEditor.setToolTipText(value);
                            propertyEditor.addModifyListener(new ModifyListener() {

                                public void modifyText(ModifyEvent e) {
                                    modifiedProperties.put(property, propertyEditor.getText());
                                }
                            });
                            break;
                        }
                    case PasswordHash:
                    case PasswordPlain:
                        {
                            final Text propertyEditor = new Text(line, SWT.BORDER);
                            data = new GridData(GridData.FILL_HORIZONTAL);
                            data.verticalAlignment = SWT.TOP;
                            propertyEditor.setLayoutData(data);
                            String value = EnginePropertiesManager.getProperty(property);
                            propertyEditor.setText(value);
                            propertyEditor.setEchoChar('*');
                            propertyEditor.addModifyListener(new ModifyListener() {

                                public void modifyText(ModifyEvent e) {
                                    modifiedProperties.put(property, "" + propertyEditor.getText());
                                }
                            });
                            break;
                        }
                    case Boolean:
                        {
                            final Button propertyEditor = new Button(line, SWT.CHECK);
                            propertyEditor.setBackground(line.getBackground());
                            data = new GridData();
                            data.verticalAlignment = SWT.TOP;
                            propertyEditor.setLayoutData(data);
                            boolean value = Boolean.parseBoolean(EnginePropertiesManager.getProperty(property));
                            propertyEditor.setSelection(value);
                            propertyEditor.addSelectionListener(new SelectionListener() {

                                public void widgetSelected(SelectionEvent e) {
                                    modifiedProperties.put(property, "" + propertyEditor.getSelection());
                                }

                                public void widgetDefaultSelected(SelectionEvent e) {
                                    modifiedProperties.put(property, "" + propertyEditor.getSelection());
                                }
                            });
                            break;
                        }
                    case Combo:
                        {
                            final Combo propertyEditor = new Combo(line, SWT.SIMPLE | SWT.DROP_DOWN | SWT.READ_ONLY);
                            data = new GridData(GridData.FILL_HORIZONTAL);
                            data.verticalAlignment = SWT.TOP;
                            propertyEditor.setLayoutData(data);
                            String value = EnginePropertiesManager.getProperty(property);
                            String comboDisplay, comboValue;
                            int selectedIndex = 0;
                            int i = 0;
                            for (ComboEnum comboItem : property.getCombo()) {
                                comboDisplay = comboItem.getDisplay();
                                if (comboDisplay != null) {
                                    comboValue = comboItem.getValue();
                                    propertyEditor.add(comboDisplay);
                                    propertyEditor.setData(comboDisplay, comboValue);
                                    if (value.equals(comboValue)) {
                                        selectedIndex = i;
                                    }
                                    i++;
                                }
                            }
                            propertyEditor.select(selectedIndex);
                            propertyEditor.addModifyListener(new ModifyListener() {

                                public void modifyText(ModifyEvent e) {
                                    modifiedProperties.put(property, "" + propertyEditor.getData(propertyEditor.getText()));
                                }
                            });
                            break;
                        }
                    case Array:
                        {
                            final Text propertyEditor = new Text(line, SWT.BORDER | SWT.MULTI);
                            data = new GridData(GridData.FILL_HORIZONTAL);
                            data.verticalAlignment = SWT.TOP;
                            propertyEditor.setLayoutData(data);
                            String[] originalValue = EnginePropertiesManager.getOriginalPropertyAsStringArray(property);
                            for (String item : originalValue) {
                                propertyEditor.append(item + "\r\n");
                            }
                            String v1 = EnginePropertiesManager.getProperty(property);
                            String v2 = EnginePropertiesManager.getOriginalProperty(property);
                            if (!v1.equals(v2))
                                propertyEditor.setToolTipText(v1);
                            propertyEditor.addModifyListener(new ModifyListener() {

                                public void modifyText(ModifyEvent e) {
                                    modifiedProperties.put(property, propertyEditor.getText());
                                }
                            });
                            break;
                        }
                }
            }
        }
    }
    for (PropertyCategory propertyCategory : PropertyCategory.getSortedValues()) {
        if (propertyCategory.isVisible()) {
            Composite container = containersMap.get(propertyCategory);
            if (container != null) {
                ExpandItem item = expandItemsMap.get(propertyCategory);
                item.setExpanded(!all);
                item.setHeight(container.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
            }
        }
    }
}
Also used : PropertyName(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName) PropertyCategory(com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyCategory) ExpandBar(org.eclipse.swt.widgets.ExpandBar) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) ComboEnum(com.twinsoft.convertigo.engine.EnginePropertiesManager.ComboEnum) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Combo(org.eclipse.swt.widgets.Combo) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ExpandItem(org.eclipse.swt.widgets.ExpandItem) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ComboEnum (com.twinsoft.convertigo.engine.EnginePropertiesManager.ComboEnum)2 PropertyCategory (com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyCategory)2 PropertyName (com.twinsoft.convertigo.engine.EnginePropertiesManager.PropertyName)2 Role (com.twinsoft.convertigo.engine.AuthenticatedSessionManager.Role)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Combo (org.eclipse.swt.widgets.Combo)1 Composite (org.eclipse.swt.widgets.Composite)1 ExpandBar (org.eclipse.swt.widgets.ExpandBar)1 ExpandItem (org.eclipse.swt.widgets.ExpandItem)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 Element (org.w3c.dom.Element)1 NodeList (org.w3c.dom.NodeList)1 Text (org.w3c.dom.Text)1