-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management in\r
- * 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.swt;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-\r
-import org.eclipse.jface.viewers.ISelection;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.common.ResourceArray;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.ui.utils.ResourceAdaptionUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public final class PropertyPageUtil {\r
-\r
- public static final int MAX_SELECTION_LENGTH_TO_SHOW = 5;\r
-\r
- public static String computeTitle(ReadGraph graph, ISelection selection) throws DatabaseException {\r
- boolean sameTypes = true;\r
-\r
- try {\r
-\r
- final ResourceArray[] ras = ResourceAdaptionUtils.toResourceArrays(selection);\r
- if (ras.length == 0)\r
- return null;\r
-\r
- // Check if all the input resource are of the same type.\r
- Collection<Resource> types = null;\r
- for (ResourceArray ra : ras) {\r
- if (ra.isEmpty()) {\r
- return null;\r
- }\r
- if (types == null) {\r
- types = graph.getPrincipalTypes(ra.resources[0]);\r
- } else {\r
- Collection<Resource> ts = graph.getPrincipalTypes(ra.resources[0]);\r
- ts.removeAll(types);\r
- if (!ts.isEmpty()) {\r
- sameTypes = false;\r
- break;\r
- }\r
- }\r
- }\r
- if (sameTypes) {\r
- // If the resource no longer exists, provide default name only.\r
- if (!graph.hasStatement(ras[0].resources[0])) {\r
- return null;\r
- }\r
-\r
- String name = safeGetName(graph, ras[0].resources[0]);\r
- if (ras.length > 1)\r
- name += " [" + ras.length +"]";\r
- return name;\r
- } else {\r
- Collection<String> names = new ArrayList<String>(ras.length);\r
- boolean truncate = ras.length > MAX_SELECTION_LENGTH_TO_SHOW;\r
- int end = Math.min(ras.length, MAX_SELECTION_LENGTH_TO_SHOW);\r
- int missing = ras.length - end;\r
- for (int i = 0; i < end; ++i) {\r
- // If the resource no longer exists, provide default name only.\r
- if (!graph.hasStatement(ras[i].resources[0]))\r
- continue;\r
-\r
- names.add(safeGetName(graph, ras[i].resources[0]));\r
- }\r
- if (names.isEmpty()) {\r
- return null;\r
- }\r
-\r
- if (truncate)\r
- names.add("+ " + missing + " more...");\r
-\r
- String name = names.toString();\r
- return name;\r
- }\r
-\r
- } catch (Throwable t) {\r
- t.printStackTrace();\r
- return null;\r
- }\r
- }\r
-\r
- private static String safeGetName(ReadGraph g, Resource r) throws DatabaseException {\r
- return NameUtils.getSafeName(g, r);\r
-// try {\r
-// //System.out.println("safeGetName " + r);\r
-// return g.adapt(r, String.class);\r
-// } catch (AdaptionException e) {\r
-// return NameUtils.getSafeName(g, r);\r
-// }\r
- }\r
-\r
+/*******************************************************************************
+ * 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.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.jface.viewers.ISelection;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.common.ResourceArray;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.ui.utils.ResourceAdaptionUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public final class PropertyPageUtil {
+
+ public static final int MAX_SELECTION_LENGTH_TO_SHOW = 5;
+
+ public static String computeTitle(ReadGraph graph, ISelection selection) throws DatabaseException {
+ boolean sameTypes = true;
+
+ try {
+
+ final ResourceArray[] ras = ResourceAdaptionUtils.toResourceArrays(selection);
+ if (ras.length == 0)
+ return null;
+
+ // Check if all the input resource are of the same type.
+ Collection<Resource> types = null;
+ for (ResourceArray ra : ras) {
+ if (ra.isEmpty()) {
+ return null;
+ }
+ if (types == null) {
+ types = graph.getPrincipalTypes(ra.resources[0]);
+ } else {
+ Collection<Resource> ts = graph.getPrincipalTypes(ra.resources[0]);
+ ts.removeAll(types);
+ if (!ts.isEmpty()) {
+ sameTypes = false;
+ break;
+ }
+ }
+ }
+ if (sameTypes) {
+ // If the resource no longer exists, provide default name only.
+ if (!graph.hasStatement(ras[0].resources[0])) {
+ return null;
+ }
+
+ String name = safeGetName(graph, ras[0].resources[0]);
+ if (ras.length > 1)
+ name += " [" + ras.length +"]";
+ return name;
+ } else {
+ Collection<String> names = new ArrayList<String>(ras.length);
+ boolean truncate = ras.length > MAX_SELECTION_LENGTH_TO_SHOW;
+ int end = Math.min(ras.length, MAX_SELECTION_LENGTH_TO_SHOW);
+ int missing = ras.length - end;
+ for (int i = 0; i < end; ++i) {
+ // If the resource no longer exists, provide default name only.
+ if (!graph.hasStatement(ras[i].resources[0]))
+ continue;
+
+ names.add(safeGetName(graph, ras[i].resources[0]));
+ }
+ if (names.isEmpty()) {
+ return null;
+ }
+
+ if (truncate)
+ names.add("+ " + missing + " more...");
+
+ String name = names.toString();
+ return name;
+ }
+
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return null;
+ }
+ }
+
+ private static String safeGetName(ReadGraph g, Resource r) throws DatabaseException {
+ return NameUtils.getSafeName(g, r);
+// try {
+// //System.out.println("safeGetName " + r);
+// return g.adapt(r, String.class);
+// } catch (AdaptionException e) {
+// return NameUtils.getSafeName(g, r);
+// }
+ }
+
}
\ No newline at end of file