return new AttributeSecuritySample();
}
};
public Canvas getViewPanel() {
final VLayout layout = new VLayout();
layout.setMembersMargin(10);
layout.setWidth100();
layout.setHeight100();
// Create horizontal layout for login buttons:
HLayout buttonLayout = new HLayout();
buttonLayout.setMembersMargin(10);
buttonLayout.setHeight(20);
// Map with ID duisburgMap is defined in the XML configuration. (mapDuisburg.xml)
map = new MapWidget("mapBeans", "gwt-samples");
map.setVisible(false);
layout.addMember(map);
map.init();
// Create login handler that re-initializes the map on a successful login:
final BooleanCallback initMapCallback = new BooleanCallback() {
public void execute(Boolean value) {
if (value) {
map.destroy();
map = new MapWidget("mapBeans", "gwt-samples");
map.setVisible(false);
layout.addMember(map);
map.init();
}
}
};
// Create a button that logs in user "elvis":
IButton loginButtonMarino = new IButton(I18nProvider.getSampleMessages().securityLogInWith("elvis"));
loginButtonMarino.setWidth(150);
loginButtonMarino.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Authentication.getInstance().login("elvis", "elvis", initMapCallback);
if (null != featureAttributeWindow) {
featureAttributeWindow.destroy();
featureAttributeWindow = null;
}
}
});
buttonLayout.addMember(loginButtonMarino);
// Create a button that logs in user "luc":
IButton loginButtonLuc = new IButton(I18nProvider.getSampleMessages().securityLogInWith("luc"));
loginButtonLuc.setWidth(150);
loginButtonLuc.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Authentication.getInstance().login("luc", "luc", initMapCallback);
if (null != featureAttributeWindow) {
featureAttributeWindow.destroy();
featureAttributeWindow = null;
}
}
});
buttonLayout.addMember(loginButtonLuc);
// Set up the search command, that will fetch a feature:
// Searches for ID=1, but we might as well have created a filter on one of the attributes...
SearchFeatureRequest request = new SearchFeatureRequest();
request.setBooleanOperator("AND");
request.setCrs("EPSG:900913"); // Can normally be acquired from the MapModel.
request.setLayerId("layerBeans");
request.setMax(1);
request.setCriteria(new SearchCriterion[] { new SearchCriterion("id", "=", "1") });
final GwtCommand command = new GwtCommand(SearchFeatureRequest.COMMAND);
command.setCommandRequest(request);
// Create a button that executes the search command:
IButton editFeatureButton = new IButton(I18nProvider.getSampleMessages().attributeSecurityButtonTitle());
editFeatureButton.setWidth(200);
editFeatureButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
layer = (VectorLayer) map.getMapModel().getLayer("clientLayerBeans");
GwtCommandDispatcher.getInstance().execute(command, new CommandCallback() {
public void execute(CommandResponse response) {
if (response instanceof SearchFeatureResponse) {
SearchFeatureResponse resp = (SearchFeatureResponse) response;
for (org.geomajas.layer.feature.Feature dtoFeature : resp.getFeatures()) {
Feature feature = new Feature(dtoFeature, layer);
if (null != featureAttributeWindow) {
featureAttributeWindow.destroy();
featureAttributeWindow = null;
}
featureAttributeWindow = new FeatureAttributeWindow(feature, true);
featureAttributeWindow.setWidth(400);
layout.addMember(featureAttributeWindow);
}
}
}
});
}
});
layout.addMember(buttonLayout);
layout.addMember(editFeatureButton);
return layout;
}