/** * Builds the toolbar * * @param mapWidget The mapWidget containing the layerTree * @return {@link com.smartgwt.client.widgets.toolbar.ToolStrip} which was built */ private ToolStrip buildToolstrip(MapWidget mapWidget) { toolStrip = new ToolStrip(); toolStrip.setWidth100(); toolStrip.setPadding(3); ClientLayerTreeInfo layerTreeInfo = mapModel.getMapInfo().getLayerTree(); if (layerTreeInfo != null) { for (ClientToolInfo tool : layerTreeInfo.getTools()) { String id = tool.getToolId(); Canvas button = null; ToolbarBaseAction action = LayerTreeRegistry.getToolbarAction(id, mapWidget); if (action instanceof ToolbarWidget) { toolStrip.addMember(((ToolbarWidget) action).getWidget()); } else if (action instanceof ToolbarCanvas) { button = ((ToolbarCanvas) action).getCanvas(); } else if (action instanceof LayerTreeAction) { button = new LayerTreeButton(this, (LayerTreeAction) action); } else if (action instanceof LayerTreeModalAction) { button = new LayerTreeModalButton(this, (LayerTreeModalAction) action); } else { String msg = "LayerTree tool with id " + id + " unknown."; Log.logError(msg); // console log SC.warn(msg); // in your face } if (button != null) { toolStrip.addMember(button); LayoutSpacer spacer = new LayoutSpacer(); spacer.setWidth(WidgetLayout.layerTreePadding); toolStrip.addMember(spacer); } } } final Canvas[] toolStripMembers = toolStrip.getMembers(); // delaying this fixes an image 'undefined' error Timer t = new Timer() { public void run() { updateButtonIconsAndStates(toolStripMembers); } }; t.schedule(10); return toolStrip; }
/** * Builds up the tree showing the layers * * @param mapModel The mapModel containing the layerTree */ private void buildTree(MapModel mapModel) { treeGrid.setWidth100(); treeGrid.setHeight100(); treeGrid.setShowHeader(false); tree = new RefreshableTree(); final TreeNode nodeRoot = new TreeNode("ROOT"); tree.setRoot(nodeRoot); // invisible ROOT node (ROOT node is required) ClientLayerTreeInfo layerTreeInfo = mapModel.getMapInfo().getLayerTree(); if (layerTreeInfo != null) { ClientLayerTreeNodeInfo treeNode = layerTreeInfo.getTreeNode(); processNode(treeNode, nodeRoot, tree, mapModel, false); } treeGrid.setData(tree); treeGrid.addLeafClickHandler(this); treeGrid.addFolderClickHandler(this); // -- add event listeners to layers for (Layer<?> layer : mapModel.getLayers()) { registrations.add( layer.addLayerChangedHandler( new LayerChangedHandler() { public void onLabelChange(LayerLabeledEvent event) {} public void onVisibleChange(LayerShownEvent event) { for (TreeNode node : tree.getAllNodes()) { if (node.getName().equals(event.getLayer().getLabel())) { if (node instanceof LayerTreeTreeNode) { ((LayerTreeTreeNode) node).updateIcon(); } } } } })); } }