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%2FDefaultShowMaxChildrenProcessor.java;h=8cb67e4223845b12aea51ba216ffc58657ea8081;hp=3314685f22e97b3d564917bb4612f0103226b26c;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultShowMaxChildrenProcessor.java b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultShowMaxChildrenProcessor.java index 3314685f2..8cb67e422 100644 --- a/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultShowMaxChildrenProcessor.java +++ b/bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/DefaultShowMaxChildrenProcessor.java @@ -1,112 +1,112 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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 gnu.trove.map.hash.THashMap; -import gnu.trove.map.hash.TObjectIntHashMap; - -import org.simantics.browsing.ui.BuiltinKeys; -import org.simantics.browsing.ui.GraphExplorer; -import org.simantics.browsing.ui.NodeContext; -import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey; -import org.simantics.browsing.ui.PrimitiveQueryUpdater; -import org.simantics.browsing.ui.common.processors.AbstractPrimitiveQueryProcessor; -import org.simantics.browsing.ui.common.processors.ProcessorLifecycle; -import org.simantics.browsing.ui.common.processors.ShowMaxChildrenProcessor; - -/** - * @author Tuukka Lehtonen - */ -public class DefaultShowMaxChildrenProcessor extends AbstractPrimitiveQueryProcessor implements - ShowMaxChildrenProcessor, ProcessorLifecycle { - - private final Integer MAX_INT = Integer.MAX_VALUE; - - /** - * The set of currently expanded node contexts. - */ - private final TObjectIntHashMap showMaxChildren = new TObjectIntHashMap(); - private final THashMap showMaxChildrenQueries = new THashMap(); - - public DefaultShowMaxChildrenProcessor() { - } - - @Override - public Object getIdentifier() { - return BuiltinKeys.SHOW_MAX_CHILDREN; - } - - @Override - public String toString() { - return "ShowMaxChildrenProcessor"; - } - - @Override - public Integer query(PrimitiveQueryUpdater updater, NodeContext context, PrimitiveQueryKey key) { - int maxChildren = showMaxChildren.get(context); - //System.out.println("maxChildren(" + updater + ", " + context + "): " + maxChildren); - showMaxChildrenQueries.put(context, updater); - if (maxChildren == 0) - return null; - return Integer.valueOf(maxChildren); - } - - @Override - public boolean setShowMaxChildren(NodeContext context, int maxChildren) { - return _setShowMaxChildren(context, maxChildren); - } - - @Override - public boolean replaceShowMaxChildren(NodeContext context, int maxChildren) { - return nodeStatusChanged(context, maxChildren); - } - - private boolean _setShowMaxChildren(NodeContext context, int maxChildren) { - if (maxChildren > 0) { - return this.showMaxChildren.put(context, maxChildren) != maxChildren; - } else { - return this.showMaxChildren.remove(context) != 0; - } - } - - protected boolean nodeStatusChanged(NodeContext context, int maxChildren) { - boolean result = _setShowMaxChildren(context, maxChildren); - PrimitiveQueryUpdater updater = showMaxChildrenQueries.get(context); - if (updater != null) { - Integer newValue = null; - if (maxChildren > 0) { - if (maxChildren != Integer.MAX_VALUE) - newValue = Integer.valueOf(maxChildren); - else - newValue = MAX_INT; - } - updater.scheduleReplace(context, BuiltinKeys.SHOW_MAX_CHILDREN, newValue); - } - return result; - } - - @Override - public void attached(GraphExplorer explorer) { - } - - @Override - public void detached(GraphExplorer explorer) { - clear(); - } - - @Override - public void clear() { - showMaxChildren.clear(); - showMaxChildrenQueries.clear(); - } - +/******************************************************************************* + * Copyright (c) 2007, 2010 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 gnu.trove.map.hash.THashMap; +import gnu.trove.map.hash.TObjectIntHashMap; + +import org.simantics.browsing.ui.BuiltinKeys; +import org.simantics.browsing.ui.GraphExplorer; +import org.simantics.browsing.ui.NodeContext; +import org.simantics.browsing.ui.NodeContext.PrimitiveQueryKey; +import org.simantics.browsing.ui.PrimitiveQueryUpdater; +import org.simantics.browsing.ui.common.processors.AbstractPrimitiveQueryProcessor; +import org.simantics.browsing.ui.common.processors.ProcessorLifecycle; +import org.simantics.browsing.ui.common.processors.ShowMaxChildrenProcessor; + +/** + * @author Tuukka Lehtonen + */ +public class DefaultShowMaxChildrenProcessor extends AbstractPrimitiveQueryProcessor implements + ShowMaxChildrenProcessor, ProcessorLifecycle { + + private final Integer MAX_INT = Integer.MAX_VALUE; + + /** + * The set of currently expanded node contexts. + */ + private final TObjectIntHashMap showMaxChildren = new TObjectIntHashMap(); + private final THashMap showMaxChildrenQueries = new THashMap(); + + public DefaultShowMaxChildrenProcessor() { + } + + @Override + public Object getIdentifier() { + return BuiltinKeys.SHOW_MAX_CHILDREN; + } + + @Override + public String toString() { + return "ShowMaxChildrenProcessor"; + } + + @Override + public Integer query(PrimitiveQueryUpdater updater, NodeContext context, PrimitiveQueryKey key) { + int maxChildren = showMaxChildren.get(context); + //System.out.println("maxChildren(" + updater + ", " + context + "): " + maxChildren); + showMaxChildrenQueries.put(context, updater); + if (maxChildren == 0) + return null; + return Integer.valueOf(maxChildren); + } + + @Override + public boolean setShowMaxChildren(NodeContext context, int maxChildren) { + return _setShowMaxChildren(context, maxChildren); + } + + @Override + public boolean replaceShowMaxChildren(NodeContext context, int maxChildren) { + return nodeStatusChanged(context, maxChildren); + } + + private boolean _setShowMaxChildren(NodeContext context, int maxChildren) { + if (maxChildren > 0) { + return this.showMaxChildren.put(context, maxChildren) != maxChildren; + } else { + return this.showMaxChildren.remove(context) != 0; + } + } + + protected boolean nodeStatusChanged(NodeContext context, int maxChildren) { + boolean result = _setShowMaxChildren(context, maxChildren); + PrimitiveQueryUpdater updater = showMaxChildrenQueries.get(context); + if (updater != null) { + Integer newValue = null; + if (maxChildren > 0) { + if (maxChildren != Integer.MAX_VALUE) + newValue = Integer.valueOf(maxChildren); + else + newValue = MAX_INT; + } + updater.scheduleReplace(context, BuiltinKeys.SHOW_MAX_CHILDREN, newValue); + } + return result; + } + + @Override + public void attached(GraphExplorer explorer) { + } + + @Override + public void detached(GraphExplorer explorer) { + clear(); + } + + @Override + public void clear() { + showMaxChildren.clear(); + showMaxChildrenQueries.clear(); + } + } \ No newline at end of file