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