Search in sources :

Example 1 with RpcProxy

use of com.extjs.gxt.ui.client.data.RpcProxy in project kapua by eclipse.

the class AccountDetailsView method createGrid.

private void createGrid(Element parent) {
    RpcProxy<ListLoadResult<GwtGroupedNVPair>> proxy = new RpcProxy<ListLoadResult<GwtGroupedNVPair>>() {

        @Override
        protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtGroupedNVPair>> callback) {
            gwtAccountService.getAccountInfo(selectedAccount.getId(), callback);
        }
    };
    m_loader = new BaseListLoader<ListLoadResult<GwtGroupedNVPair>>(proxy);
    m_loader.addLoadListener(new DataLoadListener());
    m_store = new GroupingStore<GwtGroupedNVPair>(m_loader);
    m_store.groupBy("groupLoc");
    ColumnConfig name = new ColumnConfig("nameLoc", MSGS.devicePropName(), 50);
    ColumnConfig value = new ColumnConfig("value", MSGS.devicePropValue(), 50);
    List<ColumnConfig> config = new ArrayList<ColumnConfig>();
    config.add(name);
    config.add(value);
    ColumnModel cm = new ColumnModel(config);
    GroupingView view = new GroupingView();
    view.setShowGroupedColumn(false);
    view.setForceFit(true);
    view.setEmptyText(MSGS.accountNoSelectedAccount());
    m_grid = new Grid<GwtGroupedNVPair>(m_store, cm);
    m_grid.setView(view);
    m_grid.setBorders(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    m_grid.disableTextSelection(false);
    add(m_grid);
}
Also used : ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) GwtGroupedNVPair(org.eclipse.kapua.app.console.shared.model.GwtGroupedNVPair) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) GroupingView(com.extjs.gxt.ui.client.widget.grid.GroupingView)

Example 2 with RpcProxy

use of com.extjs.gxt.ui.client.data.RpcProxy in project kapua by eclipse.

the class DeviceConfigSnapshots method initGrid.

private void initGrid() {
    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    ColumnConfig column = new ColumnConfig("snapshotId", MSGS.deviceSnapshotId(), 25);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.CENTER);
    columns.add(column);
    column = new ColumnConfig("createdOnFormatted", MSGS.deviceSnapshotCreatedOn(), 75);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.LEFT);
    columns.add(column);
    // loader and store
    RpcProxy<ListLoadResult<GwtSnapshot>> proxy = new RpcProxy<ListLoadResult<GwtSnapshot>>() {

        @Override
        public void load(Object loadConfig, AsyncCallback<ListLoadResult<GwtSnapshot>> callback) {
            if (m_selectedDevice != null && m_dirty && m_initialized) {
                if (m_selectedDevice.isOnline()) {
                    gwtDeviceManagementService.findDeviceSnapshots(m_selectedDevice, callback);
                } else {
                    ListLoadResult<GwtSnapshot> snapshotResults = new ListLoadResult<GwtSnapshot>() {

                        @Override
                        public List<GwtSnapshot> getData() {
                            List<GwtSnapshot> snapshots = new ArrayList<GwtSnapshot>();
                            return snapshots;
                        }
                    };
                    callback.onSuccess(snapshotResults);
                }
            } else {
                ListLoadResult<GwtSnapshot> snapshotResults = new ListLoadResult<GwtSnapshot>() {

                    @Override
                    public List<GwtSnapshot> getData() {
                        List<GwtSnapshot> snapshots = new ArrayList<GwtSnapshot>();
                        return snapshots;
                    }
                };
                callback.onSuccess(snapshotResults);
            }
            m_dirty = false;
        }
    };
    m_loader = new BaseListLoader<ListLoadResult<GwtSnapshot>>(proxy);
    m_loader.setSortDir(SortDir.DESC);
    m_loader.setSortField("createdOnFormatted");
    m_loader.addLoadListener(new DataLoadListener());
    m_store = new ListStore<GwtSnapshot>(m_loader);
    m_grid = new Grid<GwtSnapshot>(m_store, new ColumnModel(columns));
    m_grid.setBorders(false);
    m_grid.setStateful(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    m_grid.setTrackMouseOver(false);
    m_grid.getView().setAutoFill(true);
    m_grid.getView().setEmptyText(MSGS.deviceSnapshotsNone());
    GridSelectionModel<GwtSnapshot> selectionModel = new GridSelectionModel<GwtSnapshot>();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    m_grid.setSelectionModel(selectionModel);
    m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtSnapshot>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtSnapshot> se) {
            if (se.getSelectedItem() != null) {
                m_downloadButton.setEnabled(true);
                m_rollbackButton.setEnabled(true);
            } else {
                m_downloadButton.setEnabled(false);
                m_rollbackButton.setEnabled(false);
            }
        }
    });
}
Also used : GwtSnapshot(org.eclipse.kapua.app.console.shared.model.GwtSnapshot) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Example 3 with RpcProxy

use of com.extjs.gxt.ui.client.data.RpcProxy in project kapua by eclipse.

the class DeviceTabHistory method initGrid.

private void initGrid() {
    List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
    ColumnConfig column = new ColumnConfig("receivedOnFormatted", MSGS.deviceEventTime(), 75);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.CENTER);
    columns.add(column);
    column = new ColumnConfig("eventType", MSGS.deviceEventType(), 50);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.CENTER);
    columns.add(column);
    TreeGridCellRenderer<GwtDeviceEvent> eventMessageRenderer = new TreeGridCellRenderer<GwtDeviceEvent>() {

        @Override
        public Object render(GwtDeviceEvent model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GwtDeviceEvent> store, Grid<GwtDeviceEvent> grid) {
            StringBuilder message = new StringBuilder("");
            if (model.getEventMessage() != null) {
                message.append("<label title='").append(model.getUnescapedEventMessage()).append("'>").append(model.getUnescapedEventMessage()).append("</label>");
            }
            return message.toString();
        }
    };
    column = new ColumnConfig("eventMessage", MSGS.deviceEventMessage(), 200);
    column.setSortable(false);
    column.setAlignment(HorizontalAlignment.LEFT);
    column.setRenderer(eventMessageRenderer);
    columns.add(column);
    // loader and store
    RpcProxy<PagingLoadResult<GwtDeviceEvent>> proxy = new RpcProxy<PagingLoadResult<GwtDeviceEvent>>() {

        @Override
        public void load(Object loadConfig, AsyncCallback<PagingLoadResult<GwtDeviceEvent>> callback) {
            if (m_selectedDevice != null) {
                PagingLoadConfig pagingConfig = (BasePagingLoadConfig) loadConfig;
                ((BasePagingLoadConfig) pagingConfig).setLimit(DEVICE_PAGE_SIZE);
                gwtDeviceService.findDeviceEvents(pagingConfig, m_selectedDevice, m_dateRangeSelector.getStartDate(), m_dateRangeSelector.getEndDate(), callback);
            }
        }
    };
    m_loader = new BasePagingLoader<PagingLoadResult<GwtDeviceEvent>>(proxy);
    m_loader.setSortDir(SortDir.DESC);
    m_loader.setSortField("receivedOnFormatted");
    m_loader.setRemoteSort(true);
    m_loader.addLoadListener(new DataLoadListener());
    ListStore<GwtDeviceEvent> store = new ListStore<GwtDeviceEvent>(m_loader);
    m_grid = new Grid<GwtDeviceEvent>(store, new ColumnModel(columns));
    m_grid.setBorders(false);
    m_grid.setStateful(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    m_grid.setTrackMouseOver(false);
    m_grid.setAutoExpandColumn("eventMessage");
    m_grid.disableTextSelection(false);
    m_grid.getView().setAutoFill(true);
    m_grid.getView().setEmptyText(MSGS.deviceHistoryTableNoHistory());
    m_pagingToolBar = new PagingToolBar(DEVICE_PAGE_SIZE);
    m_pagingToolBar.bind(m_loader);
    GridSelectionModel<GwtDeviceEvent> selectionModel = new GridSelectionModel<GwtDeviceEvent>();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    m_grid.setSelectionModel(selectionModel);
}
Also used : TreeGridCellRenderer(com.extjs.gxt.ui.client.widget.treegrid.TreeGridCellRenderer) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig) Grid(com.extjs.gxt.ui.client.widget.grid.Grid) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) GwtDeviceEvent(org.eclipse.kapua.app.console.shared.model.GwtDeviceEvent) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) ListStore(com.extjs.gxt.ui.client.store.ListStore) PagingLoadResult(com.extjs.gxt.ui.client.data.PagingLoadResult) PagingToolBar(com.extjs.gxt.ui.client.widget.toolbar.PagingToolBar) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel) PagingLoadConfig(com.extjs.gxt.ui.client.data.PagingLoadConfig) BasePagingLoadConfig(com.extjs.gxt.ui.client.data.BasePagingLoadConfig)

Example 4 with RpcProxy

use of com.extjs.gxt.ui.client.data.RpcProxy in project kura by eclipse.

the class WirelessConfigTab method createWifiNetworksWindow.

private Window createWifiNetworksWindow() {
    final Window window = new Window();
    window.setSize(700, 400);
    window.setPlain(true);
    window.setModal(true);
    window.setBlinkModal(true);
    window.setHeading("Wireless Networks");
    // Create a table to layout the content
    VerticalPanel dialogContents = new VerticalPanel();
    dialogContents.setSpacing(4);
    window.add(dialogContents);
    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
    ColumnConfig column = null;
    column = new ColumnConfig("ssid", "SSID", 100);
    column.setAlignment(HorizontalAlignment.LEFT);
    configs.add(column);
    column = new ColumnConfig("macAddress", "MAC Address", 100);
    column.setAlignment(HorizontalAlignment.CENTER);
    configs.add(column);
    column = new ColumnConfig("signalStrength", "Signal (dBm)", 100);
    column.setAlignment(HorizontalAlignment.CENTER);
    configs.add(column);
    column = new ColumnConfig("channel", "Channel", 100);
    column.setAlignment(HorizontalAlignment.CENTER);
    configs.add(column);
    column = new ColumnConfig("frequency", "Frequency", 100);
    column.setAlignment(HorizontalAlignment.CENTER);
    configs.add(column);
    column = new ColumnConfig("security", "Security", 100);
    column.setAlignment(HorizontalAlignment.LEFT);
    configs.add(column);
    /*
        CheckColumnConfig checkColumn = new CheckColumnConfig("selectAP", "Select", 55);
        CellEditor checkBoxEditor = new CellEditor(new CheckBox());  
        checkColumn.setEditor(checkBoxEditor);
        configs.add(checkColumn); 
		 */
    // rpc data proxy
    RpcProxy<ListLoadResult<GwtWifiHotspotEntry>> proxy = new RpcProxy<ListLoadResult<GwtWifiHotspotEntry>>() {

        @Override
        protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtWifiHotspotEntry>> callback) {
            gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                @Override
                public void onFailure(Throwable ex) {
                    FailureHandler.handle(ex);
                }

                @Override
                public void onSuccess(GwtXSRFToken token) {
                    gwtNetworkService.findWifiHotspots(token, m_selectNetIfConfig.getName(), callback);
                }
            });
        }
    };
    m_wifiHotspotLoader = new BaseListLoader<ListLoadResult<GwtWifiHotspotEntry>>(proxy);
    m_wifiHotspotLoader.setSortDir(SortDir.ASC);
    m_wifiHotspotLoader.setSortField("signalStrength");
    // m_wifiHotspotLoader.setRemoteSort(true);
    SwappableListStore<GwtWifiHotspotEntry> store = new SwappableListStore<GwtWifiHotspotEntry>(m_wifiHotspotLoader);
    store.setKeyProvider(new ModelKeyProvider<GwtWifiHotspotEntry>() {

        public String getKey(GwtWifiHotspotEntry wifiHotspotEntry) {
            return wifiHotspotEntry.getSignalStrength().toString();
        }
    });
    m_grid = new Grid<GwtWifiHotspotEntry>(store, new ColumnModel(configs));
    m_grid.setBorders(false);
    m_grid.setStateful(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    m_grid.setColumnLines(true);
    m_grid.setColumnReordering(true);
    m_grid.setAutoExpandColumn("ssid");
    m_grid.getView().setAutoFill(true);
    // m_grid.addPlugin(checkColumn);
    m_wifiHotspotLoader.addLoadListener(new DataLoadListener(m_grid));
    GridSelectionModel<GwtWifiHotspotEntry> selectionModel = new GridSelectionModel<GwtWifiHotspotEntry>();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    m_grid.setSelectionModel(selectionModel);
    // m_grid.addPlugin(selectionModel);
    m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtWifiHotspotEntry>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtWifiHotspotEntry> se) {
            if (se != null) {
                List<GwtWifiHotspotEntry> list = se.getSelection();
                if ((list != null) && (list.size() > 0)) {
                    GwtWifiHotspotEntry wifiHotspotEntry = list.get(0);
                    if (wifiHotspotEntry != null) {
                        m_ssidField.setValue(GwtSafeHtmlUtils.htmlUnescape(wifiHotspotEntry.getSSID()));
                        String security = wifiHotspotEntry.getSecurity();
                        if (security.equals("None")) {
                            m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityNONE.name()));
                        } else if (security.equals("WEP")) {
                            m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWEP.name()));
                        } else if (security.equals("WPA")) {
                            m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWPA.name()));
                        } else if (security.equals("WPA2") || security.equals("WPA/WPA2")) {
                            m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityWPA2.name()));
                        } else {
                            m_securityCombo.setSimpleValue(MessageUtils.get(GwtWifiSecurity.netWifiSecurityNONE.name()));
                        }
                        if (security.equals("WPA") || security.equals("WPA2") || security.equals("WPA/WPA2")) {
                            GwtWifiCiphers pairwiseCiphers = wifiHotspotEntry.getPairwiseCiphersEnum();
                            if (pairwiseCiphers == GwtWifiCiphers.netWifiCiphers_TKIP) {
                                m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_TKIP.name()));
                            } else if (pairwiseCiphers == GwtWifiCiphers.netWifiCiphers_CCMP) {
                                m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP.name()));
                            } else if (pairwiseCiphers == GwtWifiCiphers.netWifiCiphers_CCMP_TKIP) {
                                m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
                            } else {
                                // let's set it for CCMP TKIP
                                m_pairwiseCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
                            }
                            GwtWifiCiphers groupCiphers = wifiHotspotEntry.getGroupCiphersEnum();
                            if (groupCiphers == GwtWifiCiphers.netWifiCiphers_TKIP) {
                                m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_TKIP.name()));
                            } else if (groupCiphers == GwtWifiCiphers.netWifiCiphers_CCMP) {
                                m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP.name()));
                            } else if (groupCiphers == GwtWifiCiphers.netWifiCiphers_CCMP_TKIP) {
                                m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
                            } else {
                                // let's set it for CCMP TKIP
                                m_groupCiphersCombo.setSimpleValue(MessageUtils.get(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name()));
                            }
                        }
                        // deselect all channels
                        for (int channel = 1; channel <= MAX_WIFI_CHANNEL; channel++) {
                            m_checkboxChannelSelectionModel.deselect(channel - 1);
                        }
                        // select proper channels
                        m_checkboxChannelSelectionModel.select(wifiHotspotEntry.getChannel() - 1, true);
                        window.hide();
                    }
                }
            }
        }
    });
    ContentPanel cp = new ContentPanel();
    cp.setHeading("Wireless Networks in Range");
    cp.setFrame(true);
    cp.setSize(680, 365);
    FillLayout layout = new FillLayout();
    layout.setAdjustForScroll(true);
    cp.setLayout(layout);
    cp.add(m_grid);
    dialogContents.add(cp);
    window.add(dialogContents);
    return window;
}
Also used : ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) GwtWifiCiphers(org.eclipse.kura.web.shared.model.GwtWifiCiphers) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) SwappableListStore(org.eclipse.kura.web.client.util.SwappableListStore) NodeList(com.google.gwt.dom.client.NodeList) List(java.util.List) ArrayList(java.util.ArrayList) Window(com.extjs.gxt.ui.client.widget.Window) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) FillLayout(com.extjs.gxt.ui.client.widget.layout.FillLayout) ContentPanel(com.extjs.gxt.ui.client.widget.ContentPanel) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) VerticalPanel(com.extjs.gxt.ui.client.widget.VerticalPanel) GwtWifiHotspotEntry(org.eclipse.kura.web.shared.model.GwtWifiHotspotEntry) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Example 5 with RpcProxy

use of com.extjs.gxt.ui.client.data.RpcProxy in project kura by eclipse.

the class ServiceTree method initServiceTree.

@SuppressWarnings("unchecked")
private void initServiceTree() {
    // 
    // Service Tree
    // loader and store
    RpcProxy<List<GwtConfigComponent>> proxy = new RpcProxy<List<GwtConfigComponent>>() {

        @Override
        protected void load(Object loadConfig, final AsyncCallback<List<GwtConfigComponent>> callback) {
            gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                @Override
                public void onFailure(Throwable ex) {
                    FailureHandler.handle(ex);
                }

                @Override
                public void onSuccess(GwtXSRFToken token) {
                    gwtComponentService.findComponentConfigurations(token, new AsyncCallback<List<GwtConfigComponent>>() {

                        public void onFailure(Throwable caught) {
                            FailureHandler.handle(caught);
                        }

                        public void onSuccess(List<GwtConfigComponent> results) {
                            callback.onSuccess(results);
                        }
                    });
                }
            });
        }
    };
    m_loader = new BaseTreeLoader<GwtConfigComponent>(proxy);
    m_servicesStore = new TreeStore<ModelData>(m_loader);
    m_servicesStore.setKeyProvider(new ModelKeyProvider<ModelData>() {

        public String getKey(ModelData component) {
            if (component instanceof GwtConfigComponent) {
                return ((GwtConfigComponent) component).getComponentId();
            }
            return component.toString();
        }
    });
    ColumnConfig name1 = new ColumnConfig("componentName", "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_servicesTree = new TreeGrid<ModelData>(m_servicesStore, cm1);
    m_servicesTree.setId("nav-services");
    m_servicesTree.setBorders(false);
    m_servicesTree.setHideHeaders(true);
    m_servicesTree.setAutoExpandColumn("componentName");
    m_servicesTree.getTreeView().setRowHeight(36);
    m_servicesTree.setIconProvider(new ModelIconProvider<ModelData>() {

        public AbstractImagePrototype getIcon(ModelData model) {
            if (model.get("componentIcon") != null) {
                String icon = (String) model.get("componentIcon");
                if ("BluetoothService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.bluetooth32());
                }
                if ("CloudService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.cloud32());
                }
                if ("DiagnosticsService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.diagnostics32());
                } else if ("ClockService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.clock32());
                } else if ("DataService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.databaseConnect32());
                } else if ("MqttDataTransport".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.mqtt32());
                } else if ("PositionService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.gps32());
                } else if ("WatchdogService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.dog32());
                } else if ("SslManagerService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.lock32());
                } else if ("VpnService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.vpn32());
                } else if ("ProvisioningService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.provisioning32());
                } else if ("CommandPasswordService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.command32());
                } else if ("DenaliService".equals(icon)) {
                    return AbstractImagePrototype.create(Resources.INSTANCE.systemLock32());
                } else if (icon != null && (icon.toLowerCase().startsWith("http://") || icon.toLowerCase().startsWith("https://")) && Util.isImagePath(icon)) {
                    return new ScaledAbstractImagePrototype(IconHelper.createPath(icon, 32, 32));
                } else if (icon != null && Util.isImagePath(icon)) {
                    return new ScaledAbstractImagePrototype(IconHelper.createPath(SERVLET_URL + model.get("componentId"), 32, 32));
                } else {
                    return AbstractImagePrototype.create(Resources.INSTANCE.plugin32());
                }
            } else {
                return AbstractImagePrototype.create(Resources.INSTANCE.plugin32());
            }
        }
    });
    // 
    // Selection Listener for the component
    // make sure the form is not dirty before switching.
    final ServiceTree theServiceTree = this;
    m_servicesTree.getSelectionModel().addListener(Events.BeforeSelect, new Listener<BaseEvent>() {

        public void handleEvent(BaseEvent be) {
            final BaseEvent theEvent = be;
            SelectionEvent<ModelData> se = (SelectionEvent<ModelData>) be;
            final GwtConfigComponent componentToSwitchTo = (GwtConfigComponent) se.getModel();
            if (m_serviceConfiguration != null && m_serviceConfiguration.isDirty()) {
                // cancel the event first
                theEvent.setCancelled(true);
                // need to reselect the current entry
                // as the BeforeSelect event cleared it
                // we need to do this without raising events
                m_servicesTree.getSelectionModel().setFiresEvents(false);
                m_servicesTree.getSelectionModel().select(false, m_serviceConfiguration.getGwtConfigComponent());
                m_servicesTree.getSelectionModel().setFiresEvents(true);
                // ask for confirmation before switching
                MessageBox.confirm(MSGS.confirm(), MSGS.deviceConfigDirty(), new Listener<MessageBoxEvent>() {

                    public void handleEvent(MessageBoxEvent ce) {
                        // if confirmed, switch
                        Dialog dialog = ce.getDialog();
                        if (dialog.yesText.equals(ce.getButtonClicked().getText())) {
                            List<Component> comps = m_centerPanel.getItems();
                            if (comps != null && comps.size() > 0) {
                                m_centerPanel.removeAll();
                            }
                            m_centerPanel.setHeading(componentToSwitchTo.getComponentName());
                            m_serviceConfiguration = new ServiceConfiguration(m_currentSession, componentToSwitchTo, theServiceTree);
                            m_centerPanel.add(m_serviceConfiguration);
                            m_centerPanel.layout();
                            m_servicesTree.getSelectionModel().select(false, componentToSwitchTo);
                            theServiceTree.fireEvent(Events.Select);
                        }
                    }
                });
            } else {
                m_servicesTree.getSelectionModel().setFiresEvents(false);
                List<Component> comps = m_centerPanel.getItems();
                if (comps != null && comps.size() > 0) {
                    m_centerPanel.removeAll();
                }
                m_centerPanel.setHeading(componentToSwitchTo.getComponentName());
                m_serviceConfiguration = new ServiceConfiguration(m_currentSession, componentToSwitchTo, theServiceTree);
                m_centerPanel.add(m_serviceConfiguration);
                m_centerPanel.layout();
                m_servicesTree.getSelectionModel().select(false, componentToSwitchTo);
                m_servicesTree.getSelectionModel().setFiresEvents(true);
                theServiceTree.fireEvent(Events.Select);
            }
        }
    });
    // 
    // on selection, complete the switch
    // final ServiceTree theServiceTree = this;
    // m_servicesTree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
    // m_servicesTree.getSelectionModel().addSelectionChangedListener( new SelectionChangedListener<ModelData>() {
    // @Override
    // public void selectionChanged(SelectionChangedEvent<ModelData> se) {
    // 
    // GwtConfigComponent configComponent = (GwtConfigComponent) se.getSelectedItem();
    // if (configComponent != null) {
    // 
    // m_centerPanel.removeAll();
    // 
    // m_centerPanel.setHeading(configComponent.getComponentName());
    // m_serviceConfiguration = new ServiceConfiguration(m_currentSession, configComponent, theServiceTree);
    // m_centerPanel.add(m_serviceConfiguration);
    // m_centerPanel.layout();
    // 
    // theServiceTree.fireEvent(Events.Select);
    // }
    // }
    // });
    m_loader.addLoadListener(new DataLoadListener(m_servicesTree, m_centerPanel));
}
Also used : ScaledAbstractImagePrototype(org.eclipse.kura.web.client.util.ScaledAbstractImagePrototype) AbstractImagePrototype(com.google.gwt.user.client.ui.AbstractImagePrototype) ModelData(com.extjs.gxt.ui.client.data.ModelData) Listener(com.extjs.gxt.ui.client.event.Listener) LoadListener(com.extjs.gxt.ui.client.event.LoadListener) ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) Widget(com.google.gwt.user.client.ui.Widget) Label(com.extjs.gxt.ui.client.widget.Label) ColumnData(com.extjs.gxt.ui.client.widget.grid.ColumnData) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) MessageBoxEvent(com.extjs.gxt.ui.client.event.MessageBoxEvent) Dialog(com.extjs.gxt.ui.client.widget.Dialog) SelectionEvent(com.extjs.gxt.ui.client.event.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) GwtConfigComponent(org.eclipse.kura.web.shared.model.GwtConfigComponent) Component(com.extjs.gxt.ui.client.widget.Component) GwtConfigComponent(org.eclipse.kura.web.shared.model.GwtConfigComponent) ScaledAbstractImagePrototype(org.eclipse.kura.web.client.util.ScaledAbstractImagePrototype) BaseEvent(com.extjs.gxt.ui.client.event.BaseEvent) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Aggregations

RpcProxy (com.extjs.gxt.ui.client.data.RpcProxy)28 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)28 ArrayList (java.util.ArrayList)26 ColumnModel (com.extjs.gxt.ui.client.widget.grid.ColumnModel)24 ColumnConfig (com.extjs.gxt.ui.client.widget.grid.ColumnConfig)22 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)19 GridSelectionModel (com.extjs.gxt.ui.client.widget.grid.GridSelectionModel)13 GwtXSRFToken (org.eclipse.kura.web.shared.model.GwtXSRFToken)11 ListStore (com.extjs.gxt.ui.client.store.ListStore)9 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)8 ContentPanel (com.extjs.gxt.ui.client.widget.ContentPanel)7 ColumnData (com.extjs.gxt.ui.client.widget.grid.ColumnData)7 List (java.util.List)7 Grid (com.extjs.gxt.ui.client.widget.grid.Grid)6 GroupingView (com.extjs.gxt.ui.client.widget.grid.GroupingView)6 ModelData (com.extjs.gxt.ui.client.data.ModelData)5 GridCellRenderer (com.extjs.gxt.ui.client.widget.grid.GridCellRenderer)5 GWTJahiaNode (org.jahia.ajax.gwt.client.data.node.GWTJahiaNode)5 PagingLoadResult (com.extjs.gxt.ui.client.data.PagingLoadResult)4 Window (com.extjs.gxt.ui.client.widget.Window)4