Search in sources :

Example 1 with DualListField

use of com.extjs.gxt.ui.client.widget.form.DualListField in project jahia by Jahia.

the class AbstractContentEngine method refillDependantListWidgetOn.

protected void refillDependantListWidgetOn(final String propertyId, final List<String> dependentProperties) {
    final String nodeTypeName = propertyId.substring(0, propertyId.indexOf('.'));
    final String propertyName = propertyId.substring(propertyId.indexOf('.') + 1);
    Map<String, List<GWTJahiaNodePropertyValue>> dependentValues = new HashMap<String, List<GWTJahiaNodePropertyValue>>();
    for (TabItem tab : tabs.getItems()) {
        EditEngineTabItem item = tab.getData("item");
        if (item instanceof PropertiesTabItem) {
            for (PropertiesEditor pe : ((PropertiesTabItem) item).getLangPropertiesEditorMap().values()) {
                if (pe != null) {
                    for (Field<?> field : pe.getFields()) {
                        if (field instanceof PropertiesEditor.PropertyAdapterField) {
                            String name = ((PropertiesEditor.PropertyAdapterField) field).getDefinition().getName();
                            if (dependentProperties.contains(name)) {
                                dependentValues.put(name, PropertiesEditor.getPropertyValues(field, pe.getGWTJahiaItemDefinition(name)));
                            }
                        }
                    }
                }
            }
        }
    }
    JahiaContentManagementService.App.getInstance().getFieldInitializerValues(nodeTypeName, propertyName, parentPath, dependentValues, new BaseAsyncCallback<GWTChoiceListInitializer>() {

        @Override
        public void onSuccess(GWTChoiceListInitializer result) {
            choiceListInitializersValues.put(propertyId, result);
            if (result.getDisplayValues() != null) {
                String nameForDualFields = "from-" + propertyName;
                for (TabItem tab : tabs.getItems()) {
                    EditEngineTabItem item = tab.getData("item");
                    if (item instanceof PropertiesTabItem) {
                        PropertiesEditor pe = ((PropertiesTabItem) item).getPropertiesEditor();
                        if (pe != null) {
                            for (Field<?> field : pe.getFields()) {
                                if (field instanceof PropertiesEditor.PropertyAdapterField) {
                                    field = ((PropertiesEditor.PropertyAdapterField) field).getField();
                                }
                                if (propertyName.equals(field.getName()) || (field instanceof DualListField<?> && nameForDualFields.equals(field.getName()))) {
                                    if (field instanceof DualListField<?>) {
                                        @SuppressWarnings("unchecked") DualListField<GWTJahiaValueDisplayBean> dualListField = (DualListField<GWTJahiaValueDisplayBean>) field;
                                        ListStore<GWTJahiaValueDisplayBean> store = dualListField.getToField().getStore();
                                        for (GWTJahiaValueDisplayBean toValue : store.getModels()) {
                                            if (!result.getDisplayValues().contains(toValue)) {
                                                store.remove(toValue);
                                            }
                                        }
                                        dualListField.getToField().getListView().refresh();
                                        store = dualListField.getFromField().getStore();
                                        store.removeAll();
                                        store.add(result.getDisplayValues());
                                        dualListField.getFromField().getListView().refresh();
                                    } else if (field instanceof ComboBox<?>) {
                                        @SuppressWarnings("unchecked") ComboBox<GWTJahiaValueDisplayBean> comboBox = (ComboBox<GWTJahiaValueDisplayBean>) field;
                                        if (comboBox.getValue() != null && !result.getDisplayValues().contains(comboBox.getValue())) {
                                            try {
                                                comboBox.clear();
                                            } catch (Exception ex) {
                                            /*
                                                             * it could happen that the combobox is empty and so exception is thrown
                                                             * and combobox isn't reinitialized
                                                             */
                                            }
                                        }
                                        ListStore<GWTJahiaValueDisplayBean> store = new ListStore<GWTJahiaValueDisplayBean>();
                                        store.add(result.getDisplayValues());
                                        comboBox.setStore(store);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        @Override
        public void onApplicationFailure(Throwable caught) {
            Log.error("Unable to load avalibale mixin", caught);
        }
    });
}
Also used : ListStore(com.extjs.gxt.ui.client.store.ListStore) GWTJahiaNodePropertyValue(org.jahia.ajax.gwt.client.data.definition.GWTJahiaNodePropertyValue) DualListField(com.extjs.gxt.ui.client.widget.form.DualListField) Field(com.extjs.gxt.ui.client.widget.form.Field) PropertiesEditor(org.jahia.ajax.gwt.client.widget.definition.PropertiesEditor) ComboBox(com.extjs.gxt.ui.client.widget.form.ComboBox) GWTChoiceListInitializer(org.jahia.ajax.gwt.client.data.GWTChoiceListInitializer) TabItem(com.extjs.gxt.ui.client.widget.TabItem) AsyncTabItem(org.jahia.ajax.gwt.client.widget.AsyncTabItem) DualListField(com.extjs.gxt.ui.client.widget.form.DualListField) GWTJahiaValueDisplayBean(org.jahia.ajax.gwt.client.data.GWTJahiaValueDisplayBean)

Example 2 with DualListField

use of com.extjs.gxt.ui.client.widget.form.DualListField in project jahia by Jahia.

the class ChildItemsTabItem method displayProperties.

private void displayProperties(final GWTJahiaNode item, List<GWTJahiaNodeType> nodeTypes, Map<String, GWTJahiaNodeProperty> properties) {
    // change property
    for (GWTJahiaNodeType nt : nodeTypes) {
        if (nt.getName().equals("jnt:unstructuredChildNodeDefinition") || nt.getSuperTypes().contains("jnt:unstructuredChildNodeDefinition") || nt.getName().equals("jnt:unstructuredPropertyDefinition") || nt.getSuperTypes().contains("jnt:unstructuredPropertyDefinition")) {
            for (GWTJahiaItemDefinition def : nt.getInheritedItems()) {
                if (def.isHidden()) {
                    def.setHidden(false);
                    def.setProtected(true);
                }
            }
        }
    }
    propertiesEditor = new PropertiesEditor(nodeTypes, properties, null);
    propertiesEditor.setChoiceListInitializersValues(initializerMap);
    if (!propertiesEditorsByLang.containsKey(item)) {
        propertiesEditorsByLang.put(item, new HashMap<String, PropertiesEditor>());
    }
    propertiesEditorsByLang.get(item).put(currentLanguage, propertiesEditor);
    PropertiesEditor previous = propertiesEditors.get(item);
    propertiesEditors.put(item, propertiesEditor);
    propertiesEditor.renderNewFormPanel();
    syncWithPrevious(previous, propertiesEditor);
    for (final String key : columnsKeys) {
        if (propertiesEditor.getFieldsMap().containsKey(key)) {
            final PropertiesEditor.PropertyAdapterField field = propertiesEditor.getFieldsMap().get(key);
            if (field.getField() instanceof DualListField) {
                ((DualListField<GWTJahiaValueDisplayBean>) field.getField()).getToList().getStore().addStoreListener(new StoreListener<GWTJahiaValueDisplayBean>() {

                    @Override
                    public void handleEvent(StoreEvent<GWTJahiaValueDisplayBean> e) {
                        List<String> strings = new ArrayList<String>();
                        List<GWTJahiaValueDisplayBean> beans = ((ListStore<GWTJahiaValueDisplayBean>) e.getSource()).getModels();
                        for (GWTJahiaValueDisplayBean bean : beans) {
                            strings.add(bean.getValue());
                        }
                        item.set(key, strings);
                        store.update(item);
                        super.handleEvent(e);
                    }
                });
            } else {
                field.addListener(Events.Change, new Listener<BaseEvent>() {

                    public void handleEvent(BaseEvent be) {
                        Object value = field.getValue();
                        if (value instanceof GWTJahiaValueDisplayBean) {
                            value = ((GWTJahiaValueDisplayBean) value).getValue();
                        }
                        item.set(key, value);
                        store.update(item);
                    }
                });
            }
        }
    }
}
Also used : PropertiesEditor(org.jahia.ajax.gwt.client.widget.definition.PropertiesEditor) DualListField(com.extjs.gxt.ui.client.widget.form.DualListField) GWTJahiaValueDisplayBean(org.jahia.ajax.gwt.client.data.GWTJahiaValueDisplayBean)

Example 3 with DualListField

use of com.extjs.gxt.ui.client.widget.form.DualListField in project geo-platform by geosdi.

the class ShareProjectPanel method addComponent.

@Override
public void addComponent() {
    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.setSpacing(10);
    FieldSet fieldSet = new FieldSet();
    fieldSet.setHeadingHtml(LayerModuleConstants.INSTANCE.ShareProjectPanel_fieldSetHeadingText());
    fieldSet.setWidth(GPProjectManagementWidget.COMPONENT_WIDTH - 25);
    this.projectNameLabel = new Label();
    this.projectNameLabel.setStyleAttribute("font-size", "13");
    this.ownerLabel = new Label();
    this.ownerLabel.setStyleAttribute("font-size", "13");
    this.organizationLabel = new Label();
    this.organizationLabel.setStyleAttribute("font-size", "13");
    fieldSet.add(this.projectNameLabel, new MarginData(10));
    fieldSet.add(ownerLabel, new MarginData(10));
    fieldSet.add(organizationLabel, new MarginData(10));
    verticalPanel.add(fieldSet);
    // 
    LayoutContainer labelListContainer = new LayoutContainer(new BorderLayout());
    labelListContainer.setHeight(20);
    labelListContainer.setStyleAttribute("background-color", "white");
    labelListContainer.setWidth(GPProjectManagementWidget.COMPONENT_WIDTH - 25);
    Label organizationUserLabel = new Label(LayerModuleConstants.INSTANCE.ShareProjectPanel_organizationUserLabelText() + ":");
    organizationUserLabel.setStyleAttribute("font-size", "13");
    organizationUserLabel.setStyleAttribute("font-weight", "bold");
    labelListContainer.add(organizationUserLabel, new BorderLayoutData(Style.LayoutRegion.WEST));
    Label projectSharedUserLabel = new Label(LayerModuleConstants.INSTANCE.ShareProjectPanel_projectSharedUserLabelText() + ":");
    projectSharedUserLabel.setStyleAttribute("font-size", "13");
    projectSharedUserLabel.setStyleAttribute("font-weight", "bold");
    labelListContainer.add(projectSharedUserLabel, new BorderLayoutData(Style.LayoutRegion.EAST));
    verticalPanel.add(labelListContainer);
    // 
    final DualListField<GPSimpleUser> lists = new DualListField<GPSimpleUser>();
    lists.setMode(Mode.INSERT);
    lists.setHeight("" + GPProjectManagementWidget.COMPONENT_HEIGHT / 1.75);
    lists.setStyleAttribute("margin-left", "11px");
    lists.setHideLabel(Boolean.TRUE);
    ListField<GPSimpleUser> from = lists.getFromList();
    from.setDisplayField(GPSimpleUserKeyValue.NAME.toString());
    this.fromStore = new ListStore<GPSimpleUser>();
    from.setStore(this.fromStore);
    ListField<GPSimpleUser> to = lists.getToList();
    to.setDisplayField(GPSimpleUserKeyValue.NAME.toString());
    this.toStore = new ListStore<GPSimpleUser>();
    to.setStore(this.toStore);
    Button cancelButton = new Button(LayerModuleConstants.INSTANCE.ShareProjectPanel_cancelButtonText(), AbstractImagePrototype.create(BasicWidgetResources.ICONS.gear()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            ShareProjectPanel.this.reset();
            projectManagementWidget.showSearchProjectPanel();
        }
    });
    super.addButton(cancelButton);
    saveButton = new Button(ButtonsConstants.INSTANCE.saveText(), AbstractImagePrototype.create(BasicWidgetResources.ICONS.save()), new SelectionListener<ButtonEvent>() {

        @Override
        public void componentSelected(ButtonEvent ce) {
            if (project.isDefaultProject() && !MementoModuleInjector.MainInjector.getInstance().getMementoSave().isEmpty()) {
                GeoPlatformMessage.confirmMessage(MementoPersistenceConstants.INSTANCE.MementoSaveCacheManager_unsavedOperationsText(), MementoPersistenceConstants.INSTANCE.MementoSaveCacheManager_unsavedOperationMessageText(), new Listener<MessageBoxEvent>() {

                    @Override
                    public void handleEvent(MessageBoxEvent be) {
                        if (Dialog.YES.equals(be.getButtonClicked().getItemId())) {
                            PeekCacheEvent peekCacheEvent = new PeekCacheEvent();
                            LayerHandlerManager.fireEvent(peekCacheEvent);
                        } else {
                            GeoPlatformMessage.errorMessage(LayerModuleConstants.INSTANCE.ShareProjectPanel_shareVerifySaveOperationsTitleText(), LayerModuleConstants.INSTANCE.ShareProjectPanel_shareVerifySaveOperationsMessageText());
                        }
                    }
                });
            } else {
                toStore.commitChanges();
                List<Long> accountIDsProject = Lists.<Long>newArrayListWithCapacity(toStore.getModels().size());
                IGPAccountDetail accountDetail = Registry.get(UserSessionEnum.ACCOUNT_DETAIL_IN_SESSION.name());
                boolean test = false;
                for (GPSimpleUser user : toStore.getModels()) {
                    if (user.getId().equals(accountDetail.getId())) {
                        test = true;
                    }
                    accountIDsProject.add(user.getId());
                }
                final boolean isShared = test && accountIDsProject.size() > 1;
                ShareProjectPanel.this.reset();
                shareProjectReq.setIdSharedProject(project.getId());
                shareProjectReq.setAccountIDsProject(accountIDsProject);
                GPClientCommandExecutor.executeCommand(new GPClientCommand<ShareProjectResponse>() {

                    private static final long serialVersionUID = 1596346272632793993L;

                    {
                        super.setCommandRequest(shareProjectReq);
                    }

                    @Override
                    public void onCommandSuccess(ShareProjectResponse response) {
                        if (project.isDefaultProject()) {
                            GPClientProject projInSession = Registry.get(UserSessionEnum.CURRENT_PROJECT_ON_TREE.name());
                            projInSession.setProjectShared(isShared);
                        }
                        project.setProjectShared(isShared);
                        loadData(project);
                    }

                    @Override
                    public void onCommandFailure(Throwable exception) {
                        logger.warning("Error on saving user to share project");
                    }
                });
            }
        }
    });
    super.addButton(saveButton);
    super.add(verticalPanel);
    super.add(lists, new FormData("98%"));
    LayoutContainer filterContainer = new LayoutContainer(new BorderLayout());
    this.fromFilter = this.createServerFilter(this.fromFilter, fromStore, LayerModuleConstants.INSTANCE.ShareProjectPanel_fromFilterLabelText());
    filterContainer.add(this.fromFilter, new BorderLayoutData(Style.LayoutRegion.WEST));
    this.toFilter = this.createServerFilter(this.toFilter, toStore, LayerModuleConstants.INSTANCE.ShareProjectPanel_toFilterLabelText());
    filterContainer.add(this.toFilter, new BorderLayoutData(Style.LayoutRegion.EAST));
    filterContainer.setStyleAttribute("margin", "11px");
    super.add(filterContainer);
}
Also used : GPClientProject(org.geosdi.geoplatform.gui.client.model.projects.GPClientProject) Label(com.extjs.gxt.ui.client.widget.Label) MarginData(com.extjs.gxt.ui.client.widget.layout.MarginData) MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) FieldSet(com.extjs.gxt.ui.client.widget.form.FieldSet) BorderLayout(com.extjs.gxt.ui.client.widget.layout.BorderLayout) Button(com.extjs.gxt.ui.client.widget.button.Button) GPSimpleUser(org.geosdi.geoplatform.gui.model.user.GPSimpleUser) PeekCacheEvent(org.geosdi.geoplatform.gui.client.model.memento.puregwt.event.PeekCacheEvent) IGPAccountDetail(org.geosdi.geoplatform.gui.global.security.IGPAccountDetail) FormData(com.extjs.gxt.ui.client.widget.layout.FormData) BorderLayoutData(com.extjs.gxt.ui.client.widget.layout.BorderLayoutData) GetUsersToShareProjectResponse(org.geosdi.geoplatform.gui.client.command.share.GetUsersToShareProjectResponse) ShareProjectResponse(org.geosdi.geoplatform.gui.client.command.share.ShareProjectResponse) VerticalPanel(com.extjs.gxt.ui.client.widget.VerticalPanel) LayoutContainer(com.extjs.gxt.ui.client.widget.LayoutContainer) ButtonEvent(com.extjs.gxt.ui.client.event.ButtonEvent) DualListField(com.extjs.gxt.ui.client.widget.form.DualListField) SelectionListener(com.extjs.gxt.ui.client.event.SelectionListener)

Aggregations

DualListField (com.extjs.gxt.ui.client.widget.form.DualListField)3 GWTJahiaValueDisplayBean (org.jahia.ajax.gwt.client.data.GWTJahiaValueDisplayBean)2 PropertiesEditor (org.jahia.ajax.gwt.client.widget.definition.PropertiesEditor)2 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)1 MessageBoxEvent (com.extjs.gxt.ui.client.event.MessageBoxEvent)1 SelectionListener (com.extjs.gxt.ui.client.event.SelectionListener)1 ListStore (com.extjs.gxt.ui.client.store.ListStore)1 Label (com.extjs.gxt.ui.client.widget.Label)1 LayoutContainer (com.extjs.gxt.ui.client.widget.LayoutContainer)1 TabItem (com.extjs.gxt.ui.client.widget.TabItem)1 VerticalPanel (com.extjs.gxt.ui.client.widget.VerticalPanel)1 Button (com.extjs.gxt.ui.client.widget.button.Button)1 ComboBox (com.extjs.gxt.ui.client.widget.form.ComboBox)1 Field (com.extjs.gxt.ui.client.widget.form.Field)1 FieldSet (com.extjs.gxt.ui.client.widget.form.FieldSet)1 BorderLayout (com.extjs.gxt.ui.client.widget.layout.BorderLayout)1 BorderLayoutData (com.extjs.gxt.ui.client.widget.layout.BorderLayoutData)1 FormData (com.extjs.gxt.ui.client.widget.layout.FormData)1 MarginData (com.extjs.gxt.ui.client.widget.layout.MarginData)1 GetUsersToShareProjectResponse (org.geosdi.geoplatform.gui.client.command.share.GetUsersToShareProjectResponse)1