Search in sources :

Example 1 with AccountView

use of org.eclipse.kapua.app.console.client.account.AccountView in project kapua by eclipse.

the class WestNavigationView method onRender.

protected void onRender(final Element parent, int index) {
    super.onRender(parent, index);
    setLayout(new FitLayout());
    setBorders(false);
    // 
    // accordion
    m_accordionLayout = new AccordionLayout();
    m_accordionLayout.setFill(true);
    m_accordionPanel = new ContentPanel();
    m_accordionPanel.setBorders(false);
    m_accordionPanel.setBodyBorder(false);
    m_accordionPanel.setLayout(m_accordionLayout);
    m_accordionPanel.setHeaderVisible(false);
    m_accordionPanel.setId("accordion-panel");
    add(m_accordionPanel);
    // 
    // Top managing panel
    m_accountPanel = new ContentPanel();
    m_accountPanel.setBorders(false);
    m_accountPanel.setBodyBorder(true);
    m_accountPanel.setAnimCollapse(true);
    m_accountPanel.setHeaderVisible(false);
    m_accountPanel.setScrollMode(Scroll.AUTOY);
    // 
    // Bottom manage panel
    m_managePanel = new ContentPanel();
    m_managePanel.setBorders(false);
    m_managePanel.setBodyBorder(false);
    m_managePanel.setHeading(MSGS.manageHeading());
    m_managePanel.setHeaderVisible(true);
    m_accountStore = new TreeStore<ModelData>();
    m_manageStore = new TreeStore<ModelData>();
    // 
    // Adding item to stores
    // 
    addMenuItems();
    ColumnConfig name = new ColumnConfig("name", "Name", 100);
    name.setRenderer(new WidgetTreeGridCellRenderer<ModelData>() {

        @Override
        public Widget getWidget(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
            Label label = new Label((String) model.get(property));
            label.setStyleAttribute("padding-left", "5px");
            if (((String) model.get(property)).equals("Dashboard")) {
                // Adding refresh button
                label.setStyleAttribute("padding-right", "50px");
                label.setStyleAttribute("background-color", "transparent");
                ContentPanel dashboardLabelPanel = new ContentPanel();
                dashboardLabelPanel.setHeaderVisible(false);
                dashboardLabelPanel.setBorders(false);
                dashboardLabelPanel.setBodyBorder(false);
                dashboardLabelPanel.setLayout(new FitLayout());
                dashboardLabelPanel.setStyleAttribute("background-color", "transparent");
                dashboardLabelPanel.add(label);
                imgRefreshLabel = new Label("<image src=\"eclipse/org/eclipse/kapua/app/console/icon/refresh.png\" " + "width=\"15\" height=\"15\" " + "style=\"vertical-align: middle\" title=\"" + MSGS.refreshButton() + "\"/>");
                dashboardLabelPanel.add(imgRefreshLabel);
                dashboardLabelPanel.setBodyStyle("background-color:transparent");
                imgRefreshLabel.addListener(Events.OnClick, new Listener<BaseEvent>() {

                    @Override
                    public void handleEvent(BaseEvent be) {
                        if (dashboardSelected) {
                            m_dashboardView.refresh();
                        }
                    }
                });
                return dashboardLabelPanel;
            }
            return label;
        }
    });
    ColumnModel cm = new ColumnModel(Arrays.asList(name));
    m_accountTree = new TreeGrid<ModelData>(m_accountStore, cm);
    m_accountTree.setBorders(false);
    m_accountTree.setHideHeaders(true);
    m_accountTree.setAutoExpandColumn("name");
    m_accountTree.getTreeView().setRowHeight(36);
    m_accountTree.getTreeView().setForceFit(true);
    m_accountTree.setIconProvider(new ModelIconProvider<ModelData>() {

        public AbstractImagePrototype getIcon(ModelData model) {
            if (model.get("icon") != null) {
                ImageResource ir = (ImageResource) model.get("icon");
                return AbstractImagePrototype.create(ir);
            } else {
                return null;
            }
        }
    });
    m_accountTree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    m_accountTree.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ModelData>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<ModelData> se) {
            ModelData selected = se.getSelectedItem();
            if (selected == null)
                return;
            if (dashboardSelected && ((String) selected.get("id")).equals("dashboard")) {
                return;
            }
            m_manageTree.getSelectionModel().deselectAll();
            m_centerPanel.removeAll();
            ContentPanel panel = new ContentPanel(new FitLayout());
            panel.setBorders(false);
            panel.setBodyBorder(false);
            String selectedId = (String) selected.get("id");
            if ("dashboard".equals(selectedId)) {
                panel.setHeaderVisible(false);
                m_dashboardView = new DashboardView(m_currentSession);
                panel.add(m_dashboardView);
                m_centerPanel.add(panel);
                m_centerPanel.layout();
                dashboardSelected = true;
            } else if ("devices".equals(selectedId)) {
                panel.setHeaderVisible(false);
                panel.add(new DevicesView(m_currentSession));
                m_centerPanel.add(panel);
                m_centerPanel.layout();
                dashboardSelected = false;
            } else if ("user".equals(selectedId)) {
                panel.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.users16()));
                panel.setHeading(MSGS.users());
                UserView userView = new UserView(m_currentSession);
                userView.setAccount(m_currentSession.getSelectedAccount());
                panel.add(userView);
                m_centerPanel.add(panel);
                m_centerPanel.layout();
                userView.refresh();
                dashboardSelected = false;
            } else if ("mysettings".equals(selectedId)) {
                panel.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.settings()));
                panel.setHeading(MSGS.settings());
                AccountDetailsView settingView = new AccountDetailsView(null, m_currentSession);
                settingView.setAccount(m_currentSession.getSelectedAccount());
                panel.add(settingView);
                m_centerPanel.add(panel);
                m_centerPanel.layout();
                settingView.refresh();
            }
            imgRefreshLabel.setVisible(dashboardSelected);
        }
    });
    ColumnConfig name1 = new ColumnConfig("name", "Name", 100);
    name1.setRenderer(new WidgetTreeGridCellRenderer<ModelData>() {

        @Override
        public Widget getWidget(ModelData model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
            Label label = new Label((String) model.get(property));
            label.setStyleAttribute("padding-left", "5px");
            return label;
        }
    });
    ColumnModel cm1 = new ColumnModel(Arrays.asList(name1));
    m_manageTree = new TreeGrid<ModelData>(m_manageStore, cm1);
    m_manageTree.setBorders(false);
    m_manageTree.setHideHeaders(true);
    m_manageTree.setAutoExpandColumn("name");
    m_manageTree.getTreeView().setRowHeight(36);
    m_manageTree.getTreeView().setForceFit(true);
    m_manageTree.setIconProvider(new ModelIconProvider<ModelData>() {

        public AbstractImagePrototype getIcon(ModelData model) {
            if (model.get("icon") != null) {
                ImageResource ir = (ImageResource) model.get("icon");
                return AbstractImagePrototype.create(ir);
            } else {
                return null;
            }
        }
    });
    m_manageTree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    m_manageTree.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<ModelData>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<ModelData> se) {
            ModelData selected = se.getSelectedItem();
            if (selected == null)
                return;
            m_accountTree.getSelectionModel().deselectAll();
            m_centerPanel.removeAll();
            ContentPanel panel = new ContentPanel(new FitLayout());
            panel.setBorders(false);
            panel.setBodyBorder(false);
            String selectedId = (String) selected.get("id");
            if ("childaccounts".equals(selectedId)) {
                panel.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.childAccounts16()));
                panel.setHeading(MSGS.childaccounts());
                AccountView accountView = new AccountView(m_currentSession);
                panel.add(accountView);
                dashboardSelected = false;
            }
            imgRefreshLabel.setVisible(dashboardSelected);
            m_centerPanel.add(panel);
            m_centerPanel.layout();
        }
    });
    m_accountPanel.add(m_accountTree);
    m_accountPanel.add(m_managePanel);
    m_accountPanel.add(m_manageTree);
    m_accountTree.getSelectionModel().select(0, false);
    m_accordionPanel.add(m_accountPanel);
}
Also used : AbstractImagePrototype(com.google.gwt.user.client.ui.AbstractImagePrototype) ModelData(com.extjs.gxt.ui.client.data.ModelData) BaseModelData(com.extjs.gxt.ui.client.data.BaseModelData) Listener(com.extjs.gxt.ui.client.event.Listener) SelectionChangedListener(com.extjs.gxt.ui.client.event.SelectionChangedListener) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) Widget(com.google.gwt.user.client.ui.Widget) Label(com.extjs.gxt.ui.client.widget.Label) UserView(org.eclipse.kapua.app.console.client.user.UserView) DashboardView(org.eclipse.kapua.app.console.client.overview.DashboardView) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) AccountDetailsView(org.eclipse.kapua.app.console.client.account.AccountDetailsView) ImageResource(com.google.gwt.resources.client.ImageResource) AccountView(org.eclipse.kapua.app.console.client.account.AccountView) FitLayout(com.extjs.gxt.ui.client.widget.layout.FitLayout) AccordionLayout(com.extjs.gxt.ui.client.widget.layout.AccordionLayout) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) ContentPanel(com.extjs.gxt.ui.client.widget.ContentPanel) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) DevicesView(org.eclipse.kapua.app.console.client.device.DevicesView)

Aggregations

BaseModelData (com.extjs.gxt.ui.client.data.BaseModelData)1 ModelData (com.extjs.gxt.ui.client.data.ModelData)1 BaseEvent (com.extjs.gxt.ui.client.event.BaseEvent)1 Listener (com.extjs.gxt.ui.client.event.Listener)1 SelectionChangedListener (com.extjs.gxt.ui.client.event.SelectionChangedListener)1 ContentPanel (com.extjs.gxt.ui.client.widget.ContentPanel)1 Label (com.extjs.gxt.ui.client.widget.Label)1 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)1 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)1 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)1 AccordionLayout (com.extjs.gxt.ui.client.widget.layout.AccordionLayout)1 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)1 ImageResource (com.google.gwt.resources.client.ImageResource)1 AbstractImagePrototype (com.google.gwt.user.client.ui.AbstractImagePrototype)1 Widget (com.google.gwt.user.client.ui.Widget)1 AccountDetailsView (org.eclipse.kapua.app.console.client.account.AccountDetailsView)1 AccountView (org.eclipse.kapua.app.console.client.account.AccountView)1 DevicesView (org.eclipse.kapua.app.console.client.device.DevicesView)1 DashboardView (org.eclipse.kapua.app.console.client.overview.DashboardView)1 UserView (org.eclipse.kapua.app.console.client.user.UserView)1