X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.structural.ui%2Fsrc%2Forg%2Fsimantics%2Fstructural%2Fui%2FmenuContributions%2FShowAllChildrenContribution.java;h=4c0c0bc2b543dd18deb127db145db3f7e47a19c0;hb=666ee533a3cfa9f59e79215a269f8342227cdbda;hp=ee6bb9bbb33a9212fd7e17d2adef54b4cd5f5d65;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/menuContributions/ShowAllChildrenContribution.java b/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/menuContributions/ShowAllChildrenContribution.java index ee6bb9bbb..4c0c0bc2b 100644 --- a/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/menuContributions/ShowAllChildrenContribution.java +++ b/bundles/org.simantics.structural.ui/src/org/simantics/structural/ui/menuContributions/ShowAllChildrenContribution.java @@ -1,100 +1,100 @@ -/******************************************************************************* - * 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 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 nodes; - - public ShowAllChildrenAction(ShowMaxChildrenProcessor processor, List 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); - } - } - -} +/******************************************************************************* + * 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 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 nodes; + + public ShowAllChildrenAction(ShowMaxChildrenProcessor processor, List 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); + } + } + +}