/** * When a layer selection event comes in, the LayerTree must also select the correct node in the * tree, update the selected layer text, and update all buttons icons. * * @since 1.6.0 */ @Api public void onSelectLayer(LayerSelectedEvent event) { for (TreeNode node : tree.getAllNodes()) { if (node.getName().equals(event.getLayer().getLabel())) { selectedLayerTreeNode = (LayerTreeTreeNode) node; treeGrid.selectRecord(selectedLayerTreeNode); htmlSelectedLayer.setContents( I18nProvider.getLayerTree().activeLayer(selectedLayerTreeNode.getLayer().getLabel())); Canvas[] toolStripMembers = toolStrip.getMembers(); updateButtonIconsAndStates(toolStripMembers); } } }
/** * Causes the node to check its status (visible, showing labels,...) and to update its icon to * match its status. */ public void updateIcon() { if (getLayer().isShowing()) { if (getLayer().isLabelsShowing()) { // show icon labeled and showing setIcon(WidgetLayout.iconLayerShowLabeled); } else { // show showing icon setIcon(WidgetLayout.iconLayerShow); } } else { // show not showing setIcon(WidgetLayout.iconLayerHide); } tree.refreshIcons(); }
/** * 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(); } } } } })); } }