use of com.extjs.gxt.ui.client.widget.treepanel.TreePanelSelectionModel 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