Source:
private void updatePaletteForDiagramWithLayer(DiagramDescription description, Session session, DDiagram dDiagram) { List<Layer> layersInActivatedViewpoints = Lists.newArrayList(new DiagramComponentizationManager().getAllLayers(session.getSelectedViewpoints(false), description)); HashSet<Layer> layersInActivatedViewpointsSet = new HashSet<Layer>(layersInActivatedViewpoints); HashSet<Layer> activatedLayersSet = new HashSet<Layer>(dDiagram.getActivatedLayers()); final List<Layer> activatedLayers = PaletteManagerImpl.getActivatedLayers(layersInActivatedViewpointsSet, activatedLayersSet); final List<Layer> deactivatedLayers = PaletteManagerImpl.getDeactivatedLayers(layersInActivatedViewpointsSet, activatedLayersSet); for (final ToolSection section : new DiagramComponentizationManager().getRootPaletteSections(session.getSelectedViewpoints(false), description)) { updateFilters(session, new DiagramComponentizationManager().getAllToolEntries(session.getSelectedViewpoints(false), section)); } for (final ToolSection section : new DiagramComponentizationManager().getRootPaletteSections(session.getSelectedViewpoints(false), description)) { Option<SectionPaletteDrawer> paletteEntry = getPaletteEntry(paletteRoot, new IdentifiedElementQuery(section).getLabel(), SectionPaletteDrawer.class); if (!paletteEntry.some()) { final PaletteContainer container = PaletteManagerImpl.createPaletteDrawner(section); updateContainer(session, dDiagram, container, new DiagramComponentizationManager().getAllToolEntries(session.getSelectedViewpoints(false), section)); paletteRoot.add(container); } else { updateContainer(session, dDiagram, paletteEntry.get(), new DiagramComponentizationManager().getAllToolEntries(session.getSelectedViewpoints(false), section)); } } for (final Layer layer : Lists.newArrayList(deactivatedLayers)) { setLayerVisibility(layer, false); } for (final Layer layer : Lists.newArrayList(activatedLayers)) { setLayerVisibility(layer, true); } }

Target:
private void updatePaletteForDiagramWithLayer(DiagramDescription description, Session session, DDiagram dDiagram) { HashSet<Layer> layersInActivatedViewpoints = new HashSet<Layer>(new DiagramComponentizationManager().getAllLayers(session.getSelectedViewpoints(false), description)); HashSet<Layer> activatedLayers = new HashSet<Layer>(dDiagram.getActivatedLayers()); final List<Layer> activatedLayersOfSelectedViewpoints = Lists.newArrayList(Sets.intersection(layersInActivatedViewpoints, activatedLayers)); final List<Layer> deactivatedLayers = Lists.newArrayList(Sets.difference(layersInActivatedViewpoints, activatedLayers)); for (final ToolSection section : new DiagramComponentizationManager().getRootPaletteSections(session.getSelectedViewpoints(false), description)) { updateFilters(session, new DiagramComponentizationManager().getAllToolEntries(session.getSelectedViewpoints(false), section)); } for (final ToolSection section : new DiagramComponentizationManager().getRootPaletteSections(session.getSelectedViewpoints(false), description)) { Option<SectionPaletteDrawer> paletteEntry = getPaletteEntry(paletteRoot, new IdentifiedElementQuery(section).getLabel(), SectionPaletteDrawer.class); if (!paletteEntry.some()) { final PaletteContainer container = PaletteManagerImpl.createPaletteDrawner(section); updateContainer(session, dDiagram, container, new DiagramComponentizationManager().getAllToolEntries(session.getSelectedViewpoints(false), section)); paletteRoot.add(container); } else { updateContainer(session, dDiagram, paletteEntry.get(), new DiagramComponentizationManager().getAllToolEntries(session.getSelectedViewpoints(false), section)); } } for (final Layer layer : Lists.newArrayList(deactivatedLayers)) { setLayerVisibility(layer, false); } for (final Layer layer : Lists.newArrayList(activatedLayersOfSelectedViewpoints)) { setLayerVisibility(layer, true); } }