1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementatio
11 *******************************************************************************/
12 package org.simantics.structural.ui.menuContributions;
14 import java.util.List;
16 import org.eclipse.jface.action.Action;
17 import org.eclipse.jface.action.ActionContributionItem;
18 import org.eclipse.jface.action.IContributionItem;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.ISelectionProvider;
21 import org.eclipse.ui.IWorkbenchPart;
22 import org.eclipse.ui.actions.CompoundContributionItem;
23 import org.simantics.browsing.ui.BuiltinKeys;
24 import org.simantics.browsing.ui.GraphExplorer;
25 import org.simantics.browsing.ui.NodeContext;
26 import org.simantics.browsing.ui.common.processors.ShowMaxChildrenProcessor;
27 import org.simantics.browsing.ui.content.PrunedChildrenResult;
28 import org.simantics.db.layer0.SelectionHints;
29 import org.simantics.structural.ui.Activator;
30 import org.simantics.utils.ui.ISelectionUtils;
31 import org.simantics.utils.ui.workbench.WorkbenchUtils;
34 * @author Tuukka Lehtonen
36 public class ShowAllChildrenContribution extends CompoundContributionItem {
38 static IContributionItem[] NONE = {};
41 protected IContributionItem[] getContributionItems() {
42 IWorkbenchPart part = WorkbenchUtils.getActiveWorkbenchPart();
46 GraphExplorer explorer = (GraphExplorer) part.getAdapter(GraphExplorer.class);
50 ISelectionProvider sp = (ISelectionProvider) explorer.getAdapter(ISelectionProvider.class);
54 ISelection s = sp.getSelection();
55 List<NodeContext> nodes = ISelectionUtils.getPossibleKeys(s, SelectionHints.KEY_MAIN, NodeContext.class);
59 boolean allTruncated = true;
60 for (NodeContext node : nodes) {
61 PrunedChildrenResult prunedChildren = explorer.query(node, BuiltinKeys.PRUNED_CHILDREN);
62 NodeContext[] finalChildren = explorer.query(node, BuiltinKeys.FINAL_CHILDREN);
63 if (prunedChildren == null || finalChildren == null
64 || prunedChildren.getPrunedChildren().length == finalChildren.length) {
72 ShowMaxChildrenProcessor processor = (ShowMaxChildrenProcessor) explorer.getPrimitiveProcessor(BuiltinKeys.SHOW_MAX_CHILDREN);
73 if (processor == null)
77 return new IContributionItem[] {
78 new ActionContributionItem(new ShowAllChildrenAction(processor, nodes))
82 static class ShowAllChildrenAction extends Action {
83 private ShowMaxChildrenProcessor processor;
84 private List<NodeContext> nodes;
86 public ShowAllChildrenAction(ShowMaxChildrenProcessor processor, List<NodeContext> nodes) {
87 super("Show All Children");
88 setImageDescriptor(Activator.SHOW_ALL_CHILDREN_ICON);
89 this.processor = processor;
95 for (NodeContext node : nodes)
96 processor.replaceShowMaxChildren(node, Integer.MAX_VALUE);