X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FTreeTruncationDecoratorFactory.java;h=85bef735bf62d68b5a7f27d6d817e8a6c8b191b2;hp=6087e741033ed8049d4e962fa1e4b9d318f71ef6;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TreeTruncationDecoratorFactory.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TreeTruncationDecoratorFactory.java index 6087e7410..85bef735b 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TreeTruncationDecoratorFactory.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TreeTruncationDecoratorFactory.java @@ -1,91 +1,91 @@ -/******************************************************************************* - * Copyright (c) 2007, 2012 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 implementation - *******************************************************************************/ -package org.simantics.browsing.ui.swt; - -import java.util.Collections; -import java.util.Set; - -import org.eclipse.jface.resource.FontDescriptor; -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.NodeQueryManager; -import org.simantics.browsing.ui.common.ColumnKeys; -import org.simantics.browsing.ui.content.LabelDecorator; -import org.simantics.browsing.ui.content.PrunedChildrenResult; - -/** - * A label decorator factory that shows a [children shown/total] suffix for a - * node context when it is expanded. - * - * @author Tuukka Lehtonen - */ -public class TreeTruncationDecoratorFactory { - - protected int withStyle; - protected Set decoratedColumns; - - public TreeTruncationDecoratorFactory(int withStyle) { - this(withStyle, Collections.singleton(ColumnKeys.SINGLE)); - } - - public TreeTruncationDecoratorFactory(int withStyle, Set decoratedColumns) { - this.withStyle = withStyle; - this.decoratedColumns = decoratedColumns; - } - - public LabelDecorator create(NodeQueryManager manager, NodeContext context) { - boolean expanded = manager.query(context, BuiltinKeys.IS_EXPANDED); - if (!expanded) - return null; - - PrunedChildrenResult prunedChildren = manager.query(context, BuiltinKeys.PRUNED_CHILDREN); - NodeContext[] finalChildren = manager.query(context, BuiltinKeys.FINAL_CHILDREN); - final int prunedLength = prunedChildren.getPrunedChildren().length; - final int finalLength = finalChildren.length; - if (prunedLength == finalLength) { - if (finalLength >= 10) { - return new LabelDecorator.Stub() { - @Override - public String decorateLabel(String label, String column, int itemIndex) { - if (decoratedColumns.contains(column)) - return label + " [" + finalLength + "]"; - return null; - } - @Override - public F decorateFont(F font, String column, int itemIndex) { - //if (decoratedColumns.contains(column)) - // return (F) ((FontDescriptor) font).withStyle(withStyle); - return null; - } - }; - } - return null; - } - - return new LabelDecorator.Stub() { - @Override - public String decorateLabel(String label, String column, int itemIndex) { - if (decoratedColumns.contains(column)) - return label + " [showing " + finalLength + "/" + prunedLength + "]"; - return null; - } - @SuppressWarnings("unchecked") - @Override - public F decorateFont(F font, String column, int itemIndex) { - if (decoratedColumns.contains(column)) - return (F) ((FontDescriptor) font).withStyle(withStyle); - return null; - } - }; - } - +/******************************************************************************* + * Copyright (c) 2007, 2012 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 implementation + *******************************************************************************/ +package org.simantics.browsing.ui.swt; + +import java.util.Collections; +import java.util.Set; + +import org.eclipse.jface.resource.FontDescriptor; +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.NodeQueryManager; +import org.simantics.browsing.ui.common.ColumnKeys; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.content.PrunedChildrenResult; + +/** + * A label decorator factory that shows a [children shown/total] suffix for a + * node context when it is expanded. + * + * @author Tuukka Lehtonen + */ +public class TreeTruncationDecoratorFactory { + + protected int withStyle; + protected Set decoratedColumns; + + public TreeTruncationDecoratorFactory(int withStyle) { + this(withStyle, Collections.singleton(ColumnKeys.SINGLE)); + } + + public TreeTruncationDecoratorFactory(int withStyle, Set decoratedColumns) { + this.withStyle = withStyle; + this.decoratedColumns = decoratedColumns; + } + + public LabelDecorator create(NodeQueryManager manager, NodeContext context) { + boolean expanded = manager.query(context, BuiltinKeys.IS_EXPANDED); + if (!expanded) + return null; + + PrunedChildrenResult prunedChildren = manager.query(context, BuiltinKeys.PRUNED_CHILDREN); + NodeContext[] finalChildren = manager.query(context, BuiltinKeys.FINAL_CHILDREN); + final int prunedLength = prunedChildren.getPrunedChildren().length; + final int finalLength = finalChildren.length; + if (prunedLength == finalLength) { + if (finalLength >= 10) { + return new LabelDecorator.Stub() { + @Override + public String decorateLabel(String label, String column, int itemIndex) { + if (decoratedColumns.contains(column)) + return label + " [" + finalLength + "]"; + return null; + } + @Override + public F decorateFont(F font, String column, int itemIndex) { + //if (decoratedColumns.contains(column)) + // return (F) ((FontDescriptor) font).withStyle(withStyle); + return null; + } + }; + } + return null; + } + + return new LabelDecorator.Stub() { + @Override + public String decorateLabel(String label, String column, int itemIndex) { + if (decoratedColumns.contains(column)) + return label + " [showing " + finalLength + "/" + prunedLength + "]"; + return null; + } + @SuppressWarnings("unchecked") + @Override + public F decorateFont(F font, String column, int itemIndex) { + if (decoratedColumns.contains(column)) + return (F) ((FontDescriptor) font).withStyle(withStyle); + return null; + } + }; + } + } \ No newline at end of file