This is an old revision of the document!
Table of Contents
Google Maps Sample
This sample application fully embeds Google Maps. This is example of how complex external components can be integrated with SOLoist code. You can browse map just as you would on original application. By choosing House from suggest-box map view will be centered on location based on the saved coordinates. You can unlock marker and choose different location, all data will be automatically saved. You could also type in address manually and perform geocoding, exact coordinates will be provided by google maps.
Live example
UML Model
Business Logic Code
//...
GUI Code
package rs.sol.sampleapps.gmaps; import rs.sol.sampleapps.House; import rs.sol.soloist.server.builtindomains.builtindatatypes.Text; import rs.sol.soloist.server.guiconfiguration.components.GUIHTMLComponent; import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent; import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent; import rs.sol.soloist.server.guiconfiguration.construction.GUIComponentBinding; import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUICollectionInput; import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUIElementComponent; import rs.sol.soloist.server.guiconfiguration.elementcomponents.GUISuggestWidget; import rs.sol.soloist.server.guiconfiguration.layout.TableLayoutData; import rs.sol.soloist.server.guiconfiguration.nonvisualcompoments.GUIFindAllInstancesSAPComponent; import rs.sol.soloist.server.uml.concepts.runtime.ISlot; public class GoogleMapsFragment { private ISlot<Text> house; private GUIPanelComponent rootPanel; public GoogleMapsFragment(GUIPanelComponent rootPanel) { this.rootPanel = rootPanel; this.house = rootPanel.input; init(); } private void init() { houseLocationDetails(); GUIElementComponent coordinates = GUIElementComponent.createSlotEditor(rootPanel, House.PROPERTIES.coordinates, house); coordinates.styleName.set(Text.fromString("#coordinatesH")); GUIHTMLComponent.create(rootPanel, "<div id=\"map_canvasH\"></div>"); GUIHTMLComponent html1 = GUIHTMLComponent.create(rootPanel, ""); html1.styleName.set(Text.fromString("#tab1886H")); GUIComponentBinding.create(house, html1.html); } private void houseLocationDetails() { GUIPanelComponent table = GUIPanelComponent.createTable(rootPanel); table.styleName.set(Text.fromString("form")); int row = 0, col = 0; GUILabelComponent.create(table, "House", row, col++).styleName.set(Text.fromString("formLabel")); GUILabelComponent.create(table, "Address", row, col++).styleName.set(Text.fromString("formLabel")); GUILabelComponent.create(table, "City", row, col++).styleName.set(Text.fromString("formLabel")); GUILabelComponent.create(table, "Country", row, col++).styleName.set(Text.fromString("formLabel")); GUIFindAllInstancesSAPComponent allHouses = GUIFindAllInstancesSAPComponent.create(rootPanel, House.FQ_TYPE_NAME); GUIElementComponent suggestBox = GUIElementComponent.createInput(table, new GUISuggestWidget(), new GUICollectionInput()); GUIComponentBinding.create(allHouses.value, GUICollectionInput.get(suggestBox).collection); GUIElementComponent seAddress = GUIElementComponent.createSlotEditor(table, House.PROPERTIES.address, house); seAddress.styleName.set(Text.fromString("#addressH")); GUIElementComponent seCity = GUIElementComponent.createSlotEditor(table, House.PROPERTIES.city, house); seCity.styleName.set(Text.fromString("#cityH")); GUIElementComponent seCountry = GUIElementComponent.createSlotEditor(table, House.PROPERTIES.country, house); seCountry.styleName.set(Text.fromString("#countryH")); row++; col = 0; TableLayoutData.setRowColumn(suggestBox, row, col++); TableLayoutData.setRowColumn(seAddress, row, col++); TableLayoutData.setRowColumn(seCity, row, col++); TableLayoutData.setRowColumn(seCountry, row, col++); GUIComponentBinding.create(suggestBox.value, rootPanel.input); } }
package rs.sol.sampleapps.gmaps; import rs.sol.sampleapps.House; import rs.sol.soloist.helpers.init.DefaultContextInit; import rs.sol.soloist.helpers.init.Initializer; import rs.sol.soloist.helpers.init.InitializerFailedException; import rs.sol.soloist.server.builtindomains.builtindatatypes.Text; import rs.sol.soloist.server.guiconfiguration.components.GUIApplicationComponent; import rs.sol.soloist.server.guiconfiguration.components.GUILabelComponent; import rs.sol.soloist.server.guiconfiguration.components.GUIPanelComponent; import rs.sol.soloist.server.guiconfiguration.style.GUIContext; import rs.sol.soloist.server.guiconfiguration.style.GUIObjectSetting; import rs.sol.soloist.server.guiconfiguration.style.GUITextFeature; import rs.sol.soloist.server.server.SoloistServiceServlet; public enum GMaps implements Initializer { INSTANCE; @Override public void init() throws InitializerFailedException { GUIApplicationComponent application = new GUIApplicationComponent(); application.name.set(Text.fromString("GMapsSample")); SoloistServiceServlet.registerApplication(application); application.context.set(createContextAndStyles()); GUIPanelComponent root = GUIPanelComponent.createFlow(application); GUILabelComponent title = GUILabelComponent.create(root, "Google Maps"); title.styleName.set(Text.fromString("titleStyle")); GUIPanelComponent topPanel = GUIPanelComponent.createFlow(root); topPanel.styleName.set(Text.fromString("topPanel")); new GoogleMapsFragment(topPanel); } private GUIContext createContextAndStyles() { GUIContext context = new GUIContext(); context.supercontext.set(DefaultContextInit.getRoot()); GUIObjectSetting person = GUIObjectSetting.create(context, House.CLASSIFIER); GUITextFeature.createName(person, House.PROPERTIES.code); return context; } }