X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FTreeTruncationDecoratorFactory.java;fp=bundles%2Forg.simantics.browsing.ui.swt%2Fsrc%2Forg%2Fsimantics%2Fbrowsing%2Fui%2Fswt%2FTreeTruncationDecoratorFactory.java;h=6087e741033ed8049d4e962fa1e4b9d318f71ef6;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 new file mode 100644 index 000000000..6087e7410 --- /dev/null +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/TreeTruncationDecoratorFactory.java @@ -0,0 +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; + } + }; + } + +} \ No newline at end of file