Search in sources :

Example 1 with TreeGridView

use of com.extjs.gxt.ui.client.widget.treegrid.TreeGridView in project jahia by Jahia.

the class TemplatesTabItem method create.

/**
 * Performs the creation of the tab item and populates its content. The tab contains two panes: one with the tree of templates,
 * available in the module, and the second pane with the detail structure of the template content.
 *
 * @param config
 *            the tab configuration
 * @return the created tab item
 */
@Override
public TabItem create(GWTSidePanelTab config) {
    super.create(config);
    this.tree.setSelectionModel(new TreeGridSelectionModel<GWTJahiaNode>() {

        @Override
        protected void handleMouseClick(GridEvent<GWTJahiaNode> e) {
            super.handleMouseClick(e);
            if (!getSelectedItem().getPath().equals(editLinker.getMainModule().getPath())) {
                if (!getSelectedItem().getNodeTypes().contains("jnt:virtualsite") && !getSelectedItem().getNodeTypes().contains("jnt:templatesFolder")) {
                    MainModule.staticGoTo(getSelectedItem().getPath(), null);
                }
            }
        }
    });
    this.tree.getSelectionModel().setSelectionMode(Style.SelectionMode.SINGLE);
    this.tree.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GWTJahiaNode>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GWTJahiaNode> se) {
            detailTree.getSelectionModel().deselectAll();
            if (se.getSelectedItem() != null) {
                detailLoader.load(se.getSelectedItem());
            } else {
                detailStore.removeAll();
            }
        }
    });
    tree.setContextMenu(createContextMenu(config.getTreeContextMenu(), tree.getSelectionModel()));
    selectMainNodeTreeLoadListener = new SelectMainNodeTreeLoadListener(tree);
    NodeColumnConfigList columns = new NodeColumnConfigList(config.getTreeColumns());
    columns.init();
    columns.get(0).setRenderer(NodeColumnConfigList.NAME_TREEGRID_RENDERER);
    RpcProxy<List<GWTJahiaNode>> proxy = new RpcProxy<List<GWTJahiaNode>>() {

        @Override
        protected void load(Object currentPage, final AsyncCallback<List<GWTJahiaNode>> callback) {
            if (currentPage != null) {
                GWTJahiaNode gwtJahiaNode = (GWTJahiaNode) currentPage;
                List<String> fields = new ArrayList<String>();
                fields.add(GWTJahiaNode.LOCKS_INFO);
                fields.add(GWTJahiaNode.PERMISSIONS);
                fields.add(GWTJahiaNode.CHILDREN_INFO);
                fields.add(GWTJahiaNode.ICON);
                JahiaContentManagementService.App.getInstance().lsLoad(gwtJahiaNode.getPath(), displayedDetailTypes, null, null, fields, false, 0, 0, false, hiddenDetailTypes, null, false, false, new AsyncCallback<PagingLoadResult<GWTJahiaNode>>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        callback.onFailure(caught);
                    }

                    @Override
                    public void onSuccess(PagingLoadResult<GWTJahiaNode> nodes) {
                        callback.onSuccess(nodes.getData());
                    }
                });
            }
        }
    };
    detailLoader = new BaseTreeLoader<GWTJahiaNode>(proxy) {

        @Override
        public boolean hasChildren(GWTJahiaNode parent) {
            return parent.hasChildren();
        }
    };
    detailStore = new TreeStore<GWTJahiaNode>(detailLoader);
    detailTree = new TreeGrid<GWTJahiaNode>(detailStore, new ColumnModel(columns));
    detailTree.setAutoExpandColumn("displayName");
    detailTree.getTreeView().setRowHeight(25);
    detailTree.getTreeView().setForceFit(true);
    detailTree.setHeight("100%");
    detailTree.setIconProvider(ContentModelIconProvider.getInstance());
    detailTree.setAutoExpand(true);
    detailTree.setContextMenu(createContextMenu(config.getTableContextMenu(), detailTree.getSelectionModel()));
    detailTree.setView(new TreeGridView() {

        @Override
        protected void handleComponentEvent(GridEvent ge) {
            switch(ge.getEventTypeInt()) {
                case Event.ONMOUSEOVER:
                    GWTJahiaNode selection = (GWTJahiaNode) ge.getModel();
                    if (selection != null) {
                        List<Module> modules = ModuleHelper.getModulesByPath().get(selection.getPath());
                        if (modules != null) {
                            for (Module module : modules) {
                                Hover.getInstance().addHover(module, ge);
                            }
                        }
                    }
                    break;
                case Event.ONMOUSEOUT:
                    selection = (GWTJahiaNode) ge.getModel();
                    if (selection != null) {
                        List<Module> modules = ModuleHelper.getModulesByPath().get(selection.getPath());
                        if (modules != null) {
                            for (Module module : modules) {
                                Hover.getInstance().removeHover(module);
                            }
                        }
                    }
                    break;
            }
            editLinker.getMainModule().setCtrlActive(ge);
            super.handleComponentEvent(ge);
        }
    });
    detailTree.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GWTJahiaNode>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GWTJahiaNode> se) {
            if (se.getSelection() != null) {
                for (GWTJahiaNode selection : se.getSelection()) {
                    List<Module> modules = ModuleHelper.getModulesByPath().get(selection.getPath());
                    if (modules != null) {
                        for (Module module : modules) {
                            if (!editLinker.getMainModule().getSelections().containsKey(module)) {
                                editLinker.getMainModule().handleNewModuleSelection(module);
                            }
                        }
                    }
                }
            }
        }
    });
    contentContainer = new LayoutContainer();
    contentContainer.setBorders(false);
    contentContainer.setScrollMode(Style.Scroll.AUTO);
    contentContainer.setLayout(new FitLayout());
    contentContainer.setTitle(Messages.get("label.detail", "detail"));
    contentContainer.add(detailTree);
    VBoxLayoutData contentVBoxData = new VBoxLayoutData();
    contentVBoxData.setFlex(2);
    tab.add(contentContainer, contentVBoxData);
    return tab;
}
Also used : NodeColumnConfigList(org.jahia.ajax.gwt.client.widget.NodeColumnConfigList) TreeGridView(com.extjs.gxt.ui.client.widget.treegrid.TreeGridView) VBoxLayoutData(com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData) GridEvent(com.extjs.gxt.ui.client.event.GridEvent) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) PagingLoadResult(com.extjs.gxt.ui.client.data.PagingLoadResult) NodeColumnConfigList(org.jahia.ajax.gwt.client.widget.NodeColumnConfigList) ArrayList(java.util.ArrayList) List(java.util.List) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) GWTJahiaNode(org.jahia.ajax.gwt.client.data.node.GWTJahiaNode) LayoutContainer(com.extjs.gxt.ui.client.widget.LayoutContainer) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) MainModule(org.jahia.ajax.gwt.client.widget.edit.mainarea.MainModule) Module(org.jahia.ajax.gwt.client.widget.edit.mainarea.Module)

Aggregations

PagingLoadResult (com.extjs.gxt.ui.client.data.PagingLoadResult)1 RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)1 GridEvent (com.extjs.gxt.ui.client.event.GridEvent)1 LayoutContainer (com.extjs.gxt.ui.client.widget.LayoutContainer)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)1 VBoxLayoutData (com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData)1 TreeGridView (com.extjs.gxt.ui.client.widget.treegrid.TreeGridView)1 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 GWTJahiaNode (org.jahia.ajax.gwt.client.data.node.GWTJahiaNode)1 NodeColumnConfigList (org.jahia.ajax.gwt.client.widget.NodeColumnConfigList)1 MainModule (org.jahia.ajax.gwt.client.widget.edit.mainarea.MainModule)1 Module (org.jahia.ajax.gwt.client.widget.edit.mainarea.Module)1