]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/labelers/ConstantLabelerFactory.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.browsing.ui.common / src / org / simantics / browsing / ui / common / labelers / ConstantLabelerFactory.java
diff --git a/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/labelers/ConstantLabelerFactory.java b/bundles/org.simantics.browsing.ui.common/src/org/simantics/browsing/ui/common/labelers/ConstantLabelerFactory.java
new file mode 100644 (file)
index 0000000..fdcbe82
--- /dev/null
@@ -0,0 +1,52 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in 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 implementation\r
+ *******************************************************************************/\r
+package org.simantics.browsing.ui.common.labelers;\r
+\r
+import java.util.Map;\r
+\r
+import org.simantics.browsing.ui.NodeContext;\r
+import org.simantics.browsing.ui.PrimitiveQueryUpdater;\r
+import org.simantics.browsing.ui.BuiltinKeys.LabelerKey;\r
+import org.simantics.browsing.ui.content.Labeler;\r
+import org.simantics.browsing.ui.content.LabelerFactory;\r
+import org.simantics.utils.datastructures.ArrayMap;\r
+\r
+/**\r
+ * @author Tuukka Lehtonen\r
+ */\r
+public class ConstantLabelerFactory implements LabelerFactory {\r
+\r
+    private final LabelerStub stub;\r
+\r
+    public ConstantLabelerFactory(int category, Map<String, String> labels) {\r
+        stub = new LabelerStub();\r
+        stub.setContent(new LabelerContent(category, labels));\r
+    }\r
+\r
+    public ConstantLabelerFactory(int category, String ... keyValuePairs) {\r
+        assert((keyValuePairs.length & 1) == 0);\r
+        stub = new LabelerStub();\r
+        String[] keys = new String[keyValuePairs.length / 2];\r
+        String[] values = new String[keyValuePairs.length / 2];\r
+        for(int i=0;i<keyValuePairs.length/2;i++) {\r
+            keys[i] = keyValuePairs[2*i];\r
+            values[i] = keyValuePairs[2*i+1];\r
+        }\r
+        stub.setContent(new LabelerContent(category, new ArrayMap<String, String>(keys, values)));\r
+    }\r
+\r
+    @Override\r
+    public Labeler create(PrimitiveQueryUpdater manager, NodeContext context, LabelerKey key) {\r
+        return stub;\r
+    }\r
+\r
+}\r