-/*******************************************************************************\r
- * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementatio\r
- *******************************************************************************/\r
-package org.simantics.structural.ui.menuContributions;\r
-\r
-import java.util.List;\r
-\r
-import org.eclipse.jface.action.Action;\r
-import org.eclipse.jface.action.ActionContributionItem;\r
-import org.eclipse.jface.action.IContributionItem;\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.eclipse.jface.viewers.ISelectionProvider;\r
-import org.eclipse.ui.IWorkbenchPart;\r
-import org.eclipse.ui.actions.CompoundContributionItem;\r
-import org.simantics.browsing.ui.BuiltinKeys;\r
-import org.simantics.browsing.ui.GraphExplorer;\r
-import org.simantics.browsing.ui.NodeContext;\r
-import org.simantics.browsing.ui.common.processors.ShowMaxChildrenProcessor;\r
-import org.simantics.browsing.ui.content.PrunedChildrenResult;\r
-import org.simantics.db.layer0.SelectionHints;\r
-import org.simantics.structural.ui.Activator;\r
-import org.simantics.utils.ui.ISelectionUtils;\r
-import org.simantics.utils.ui.workbench.WorkbenchUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public class ShowAllChildrenContribution extends CompoundContributionItem {\r
-\r
- static IContributionItem[] NONE = {};\r
-\r
- @Override\r
- protected IContributionItem[] getContributionItems() {\r
- IWorkbenchPart part = WorkbenchUtils.getActiveWorkbenchPart();\r
- if (part == null)\r
- return NONE;\r
-\r
- GraphExplorer explorer = (GraphExplorer) part.getAdapter(GraphExplorer.class);\r
- if (explorer == null)\r
- return NONE;\r
-\r
- ISelectionProvider sp = (ISelectionProvider) explorer.getAdapter(ISelectionProvider.class);\r
- if (sp == null)\r
- return NONE;\r
-\r
- ISelection s = sp.getSelection();\r
- List<NodeContext> nodes = ISelectionUtils.getPossibleKeys(s, SelectionHints.KEY_MAIN, NodeContext.class);\r
- if (nodes.isEmpty())\r
- return NONE;\r
-\r
- boolean allTruncated = true;\r
- for (NodeContext node : nodes) {\r
- PrunedChildrenResult prunedChildren = explorer.query(node, BuiltinKeys.PRUNED_CHILDREN);\r
- NodeContext[] finalChildren = explorer.query(node, BuiltinKeys.FINAL_CHILDREN);\r
- if (prunedChildren == null || finalChildren == null\r
- || prunedChildren.getPrunedChildren().length == finalChildren.length) {\r
- allTruncated = false;\r
- break;\r
- }\r
- }\r
- if (!allTruncated)\r
- return NONE;\r
-\r
- ShowMaxChildrenProcessor processor = (ShowMaxChildrenProcessor) explorer.getPrimitiveProcessor(BuiltinKeys.SHOW_MAX_CHILDREN);\r
- if (processor == null)\r
- return NONE;\r
-\r
- // Show all children\r
- return new IContributionItem[] {\r
- new ActionContributionItem(new ShowAllChildrenAction(processor, nodes))\r
- };\r
- }\r
-\r
- static class ShowAllChildrenAction extends Action {\r
- private ShowMaxChildrenProcessor processor;\r
- private List<NodeContext> nodes;\r
-\r
- public ShowAllChildrenAction(ShowMaxChildrenProcessor processor, List<NodeContext> nodes) {\r
- super("Show All Children");\r
- setImageDescriptor(Activator.SHOW_ALL_CHILDREN_ICON);\r
- this.processor = processor;\r
- this.nodes = nodes;\r
- }\r
-\r
- @Override\r
- public void run() {\r
- for (NodeContext node : nodes)\r
- processor.replaceShowMaxChildren(node, Integer.MAX_VALUE);\r
- }\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementatio
+ *******************************************************************************/
+package org.simantics.structural.ui.menuContributions;
+
+import java.util.List;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.ActionContributionItem;
+import org.eclipse.jface.action.IContributionItem;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.actions.CompoundContributionItem;
+import org.simantics.browsing.ui.BuiltinKeys;
+import org.simantics.browsing.ui.GraphExplorer;
+import org.simantics.browsing.ui.NodeContext;
+import org.simantics.browsing.ui.common.processors.ShowMaxChildrenProcessor;
+import org.simantics.browsing.ui.content.PrunedChildrenResult;
+import org.simantics.db.layer0.SelectionHints;
+import org.simantics.structural.ui.Activator;
+import org.simantics.utils.ui.ISelectionUtils;
+import org.simantics.utils.ui.workbench.WorkbenchUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public class ShowAllChildrenContribution extends CompoundContributionItem {
+
+ static IContributionItem[] NONE = {};
+
+ @Override
+ protected IContributionItem[] getContributionItems() {
+ IWorkbenchPart part = WorkbenchUtils.getActiveWorkbenchPart();
+ if (part == null)
+ return NONE;
+
+ GraphExplorer explorer = (GraphExplorer) part.getAdapter(GraphExplorer.class);
+ if (explorer == null)
+ return NONE;
+
+ ISelectionProvider sp = (ISelectionProvider) explorer.getAdapter(ISelectionProvider.class);
+ if (sp == null)
+ return NONE;
+
+ ISelection s = sp.getSelection();
+ List<NodeContext> nodes = ISelectionUtils.getPossibleKeys(s, SelectionHints.KEY_MAIN, NodeContext.class);
+ if (nodes.isEmpty())
+ return NONE;
+
+ boolean allTruncated = true;
+ for (NodeContext node : nodes) {
+ PrunedChildrenResult prunedChildren = explorer.query(node, BuiltinKeys.PRUNED_CHILDREN);
+ NodeContext[] finalChildren = explorer.query(node, BuiltinKeys.FINAL_CHILDREN);
+ if (prunedChildren == null || finalChildren == null
+ || prunedChildren.getPrunedChildren().length == finalChildren.length) {
+ allTruncated = false;
+ break;
+ }
+ }
+ if (!allTruncated)
+ return NONE;
+
+ ShowMaxChildrenProcessor processor = (ShowMaxChildrenProcessor) explorer.getPrimitiveProcessor(BuiltinKeys.SHOW_MAX_CHILDREN);
+ if (processor == null)
+ return NONE;
+
+ // Show all children
+ return new IContributionItem[] {
+ new ActionContributionItem(new ShowAllChildrenAction(processor, nodes))
+ };
+ }
+
+ static class ShowAllChildrenAction extends Action {
+ private ShowMaxChildrenProcessor processor;
+ private List<NodeContext> nodes;
+
+ public ShowAllChildrenAction(ShowMaxChildrenProcessor processor, List<NodeContext> nodes) {
+ super("Show All Children");
+ setImageDescriptor(Activator.SHOW_ALL_CHILDREN_ICON);
+ this.processor = processor;
+ this.nodes = nodes;
+ }
+
+ @Override
+ public void run() {
+ for (NodeContext node : nodes)
+ processor.replaceShowMaxChildren(node, Integer.MAX_VALUE);
+ }
+ }
+
+}