use of com.extjs.gxt.ui.client.event.SelectionEvent 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));
}
use of com.extjs.gxt.ui.client.event.SelectionEvent in project kura by eclipse.
the class WestNavigationView method initSystemPanel.
private void initSystemPanel() {
//
// System Panel
m_systemPanel = new ContentPanel();
m_systemPanel.setBorders(false);
m_systemPanel.setBodyBorder(true);
m_systemPanel.setAnimCollapse(true);
m_systemPanel.setHeading(MSGS.system());
m_systemPanel.setLayout(new FitLayout());
m_systemStore = new TreeStore<ModelData>();
m_systemStore.add(newItem("status", "Status", Resources.INSTANCE.information32()), false);
m_systemStore.add(newItem("device", MSGS.device(), Resources.INSTANCE.router32()), false);
if (m_gwtSession.isNetAdminAvailable()) {
m_systemStore.add(newItem("network", MSGS.network(), Resources.INSTANCE.network32()), false);
m_systemStore.add(newItem("firewall", MSGS.firewall(), Resources.INSTANCE.firewall32()), false);
}
m_systemStore.add(newItem("packages", MSGS.packages(), Resources.INSTANCE.packages32()), false);
m_systemStore.add(newItem("settings", MSGS.settings(), Resources.INSTANCE.settings32()), false);
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("Status")) {
// Adding refresh button
label.setStyleAttribute("padding-right", "40px");
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);
Image img;
String status;
if (m_connected) {
img = new Image(Resources.INSTANCE.greenPlug32().getSafeUri());
status = MSGS.connectionStatusConnected();
} else {
img = new Image(Resources.INSTANCE.redPlug32().getSafeUri());
status = MSGS.connectionStatusDisconnected();
}
imgRefreshLabel = new Label("<image src=\"" + img.getUrl() + "\" " + "width=\"23\" height=\"23\" " + "style=\"vertical-align: middle\" title=\"" + status + "\"/>");
dashboardLabelPanel.add(imgRefreshLabel);
dashboardLabelPanel.setBodyStyle("background-color:transparent");
return dashboardLabelPanel;
}
return label;
}
});
ColumnModel cm = new ColumnModel(Arrays.asList(name));
m_systemTree = new TreeGrid<ModelData>(m_systemStore, cm);
m_systemTree.setId("nav-system");
m_systemTree.setBorders(false);
m_systemTree.setHideHeaders(true);
m_systemTree.setAutoExpandColumn("name");
m_systemTree.getTreeView().setRowHeight(36);
m_systemTree.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_systemTree.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
m_systemTree.getSelectionModel().addListener(Events.BeforeSelect, new Listener<BaseEvent>() {
@SuppressWarnings("unchecked")
public void handleEvent(BaseEvent be) {
final BaseEvent theEvent = be;
SelectionEvent<ModelData> se = (SelectionEvent<ModelData>) be;
final ModelData selectedModel = se.getModel();
if (selectedModel == null)
return;
// if (m_servicesTree != null && m_servicesTree.isDirty()) {
if (isDirty(m_centerPanel)) {
// cancel the event first
theEvent.setCancelled(true);
// we need to do this without raising events
if (m_systemTree.getSelectionModel().getSelectedItem() != null) {
m_systemTree.getSelectionModel().setFiresEvents(false);
m_systemTree.getSelectionModel().select(false, m_systemTree.getSelectionModel().getSelectedItem());
m_systemTree.getSelectionModel().setFiresEvents(true);
}
MessageBox.confirm(MSGS.confirm(), MSGS.deviceConfigDirty(), new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) {
// if confirmed, delete
Dialog dialog = ce.getDialog();
if (dialog.yesText.equals(ce.getButtonClicked().getText())) {
selectModelId(selectedModel);
}
}
});
} else {
selectModelId(selectedModel);
}
}
});
m_systemPanel.add(m_systemTree);
}
use of com.extjs.gxt.ui.client.event.SelectionEvent in project kapua by eclipse.
the class DeviceConfigComponents method initConfigPanel.
@SuppressWarnings("unchecked")
private void initConfigPanel() {
m_configPanel = new ContentPanel();
m_configPanel.setBorders(false);
m_configPanel.setBodyBorder(false);
m_configPanel.setHeaderVisible(false);
m_configPanel.setStyleAttribute("background-color", "white");
m_configPanel.setScrollMode(Scroll.AUTO);
BorderLayout borderLayout = new BorderLayout();
m_configPanel.setLayout(borderLayout);
// center
m_centerData = new BorderLayoutData(LayoutRegion.CENTER);
m_centerData.setMargins(new Margins(0));
// west
BorderLayoutData westData = new BorderLayoutData(LayoutRegion.WEST, 200);
westData.setSplit(true);
westData.setCollapsible(true);
westData.setMargins(new Margins(0, 5, 0, 0));
// loader and store
RpcProxy<List<GwtConfigComponent>> proxy = new RpcProxy<List<GwtConfigComponent>>() {
@Override
protected void load(Object loadConfig, AsyncCallback<List<GwtConfigComponent>> callback) {
if (m_selectedDevice != null && m_dirty && m_initialized) {
if (m_selectedDevice.isOnline()) {
m_tree.mask(MSGS.loading());
gwtDeviceManagementService.findDeviceConfigurations(m_selectedDevice, callback);
} else {
List<GwtConfigComponent> comps = new ArrayList<GwtConfigComponent>();
GwtConfigComponent comp = new GwtConfigComponent();
comp.setId(MSGS.deviceNoDeviceSelected());
comp.setName(MSGS.deviceNoComponents());
comp.setDescription(MSGS.deviceNoConfigSupported());
comps.add(comp);
callback.onSuccess(comps);
}
} else {
List<GwtConfigComponent> comps = new ArrayList<GwtConfigComponent>();
GwtConfigComponent comp = new GwtConfigComponent();
comp.setId(MSGS.deviceNoDeviceSelected());
comp.setName(MSGS.deviceNoDeviceSelected());
comp.setDescription(MSGS.deviceNoDeviceSelected());
comps.add(comp);
callback.onSuccess(comps);
}
m_dirty = false;
}
};
m_loader = new BaseTreeLoader<GwtConfigComponent>(proxy);
m_loader.addLoadListener(new DataLoadListener());
m_treeStore = new TreeStore<ModelData>(m_loader);
m_tree = new TreePanel<ModelData>(m_treeStore);
m_tree.setWidth(200);
m_tree.setDisplayProperty("componentName");
m_tree.setBorders(true);
m_tree.setAutoSelect(true);
m_tree.setStyleAttribute("background-color", "white");
m_configPanel.add(m_tree, westData);
//
// Selection Listener for the component
// make sure the form is not dirty before switching.
m_tree.getSelectionModel().addListener(Events.BeforeSelect, new Listener<BaseEvent>() {
@SuppressWarnings("rawtypes")
@Override
public void handleEvent(BaseEvent be) {
final BaseEvent theEvent = be;
SelectionEvent<ModelData> se = (SelectionEvent<ModelData>) be;
final GwtConfigComponent componentToSwitchTo = (GwtConfigComponent) se.getModel();
if (m_devConfPanel != null && m_devConfPanel.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
TreePanelSelectionModel selectionModel = (TreePanelSelectionModel) m_tree.getSelectionModel();
selectionModel.setFiresEvents(false);
selectionModel.select(false, m_devConfPanel.getConfiguration());
selectionModel.setFiresEvents(true);
// ask for confirmation before switching
MessageBox.confirm(MSGS.confirm(), MSGS.deviceConfigDirty(), new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent ce) {
// if confirmed, delete
Dialog dialog = ce.getDialog();
if (dialog.yesText.equals(ce.getButtonClicked().getText())) {
m_devConfPanel.removeFromParent();
m_devConfPanel = null;
m_tree.getSelectionModel().select(false, componentToSwitchTo);
}
}
});
} else {
refreshConfigPanel(componentToSwitchTo);
// this is needed to select the item in the Tree
// Temporarly disable the firing of the selection events
// to avoid an infinite loop as BeforeSelect would be invoked again.
TreePanelSelectionModel selectionModel = (TreePanelSelectionModel) m_tree.getSelectionModel();
selectionModel.setFiresEvents(false);
selectionModel.select(false, componentToSwitchTo);
// renable firing of the events
selectionModel.setFiresEvents(true);
}
}
});
m_tree.setIconProvider(new ModelIconProvider<ModelData>() {
public AbstractImagePrototype getIcon(ModelData model) {
if (model instanceof GwtConfigComponent) {
String icon = ((GwtConfigComponent) model).getComponentIcon();
if ("CloudService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.cloud16());
} else if ("ClockService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.clock16());
} else if ("DataService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.databaseConnect());
} else if ("DiagnosticsService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.diagnostics());
} else if ("MqttDataTransport".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.mqtt());
} else if ("PositionService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.gps16());
} else if ("SslManagerService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.lock16());
} else if ("WatchdogService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.dog16());
} else if ("CommandPasswordService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.terminal());
} else if ("VpnService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.vpn());
} else if ("ProvisioningService".equals(icon)) {
return AbstractImagePrototype.create(Resources.INSTANCE.provisioning16());
} else if ("DenaliService".equals(icon)) {
// WebConsole: DenaliService
return AbstractImagePrototype.create(Resources.INSTANCE.monitorDenali());
} else if ("BluetoothService".equals(icon)) {
// Bluetooth: BluetoothService
return AbstractImagePrototype.create(Resources.INSTANCE.bluetooth());
} else if (icon != null && icon.toLowerCase().startsWith("img://")) {
// Replace the base fake protocol with the console base URL
// that was not available on the server side.
icon = icon.replaceFirst("img://", GWT.getHostPageBaseURL());
return new ScaledAbstractImagePrototype(IconHelper.createPath(icon, 16, 16));
} else {
return AbstractImagePrototype.create(Resources.INSTANCE.plugin16());
}
}
return null;
}
});
}
Aggregations