-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 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.swt.contentassist;\r
-\r
-import org.simantics.browsing.ui.common.modifiers.Enumeration;\r
-import org.simantics.db.Session;\r
-import org.simantics.db.WriteGraph;\r
-import org.simantics.db.common.request.WriteRequest;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.utils.ObjectUtils;\r
-\r
-/**\r
- * @author Tuukka Lehtonen\r
- */\r
-public abstract class GraphContentAssistModifier<T> extends AbstractContentAssistModifier<T> {\r
-\r
- protected final Session session;\r
-\r
- public GraphContentAssistModifier(Session session, Enumeration<T> enumeration, T value) {\r
- super(enumeration, value);\r
- if (session == null)\r
- throw new NullPointerException("null session");\r
- this.session = session;\r
- }\r
-\r
- @Override\r
- protected void modifyWithValue(final T oldEnumObject, final String enumObject) {\r
- if (ObjectUtils.objectEquals(oldEnumObject, enumObject))\r
- return;\r
-\r
- try {\r
- session.getSession().syncRequest(new WriteRequest() {\r
- @Override\r
- public void perform(WriteGraph graph) throws DatabaseException {\r
-// System.out.println("old enum object: " + oldEnumObject);\r
-// System.out.println("enum object: " + enumObject);\r
- modifyWithObject(graph, oldEnumObject, enumObject);\r
- }\r
- });\r
- } catch (DatabaseException e) {\r
- handleException(e);\r
- }\r
- }\r
-\r
- /**\r
- * Implement this modifier to perform database modifications.\r
- * \r
- * @param graph\r
- * @param oldEnumObject\r
- * @param enumObject\r
- */\r
- protected abstract void modifyWithObject(WriteGraph graph, T oldEnumObject, String enumObject) throws DatabaseException;\r
-\r
- /**\r
- * Client overridable handler for possible exceptions that may occur while\r
- * performing the database modifications.\r
- * \r
- * <p>\r
- * This default implementation merely forwards the exception as a runtime\r
- * exception.\r
- * \r
- * @param e\r
- */\r
- protected void handleException(DatabaseException e) {\r
- throw new RuntimeException(e);\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.contentassist;
+
+import org.simantics.browsing.ui.common.modifiers.Enumeration;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.utils.ObjectUtils;
+
+/**
+ * @author Tuukka Lehtonen
+ */
+public abstract class GraphContentAssistModifier<T> extends AbstractContentAssistModifier<T> {
+
+ protected final Session session;
+
+ public GraphContentAssistModifier(Session session, Enumeration<T> enumeration, T value) {
+ super(enumeration, value);
+ if (session == null)
+ throw new NullPointerException("null session");
+ this.session = session;
+ }
+
+ @Override
+ protected void modifyWithValue(final T oldEnumObject, final String enumObject) {
+ if (ObjectUtils.objectEquals(oldEnumObject, enumObject))
+ return;
+
+ try {
+ session.getSession().syncRequest(new WriteRequest() {
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+// System.out.println("old enum object: " + oldEnumObject);
+// System.out.println("enum object: " + enumObject);
+ modifyWithObject(graph, oldEnumObject, enumObject);
+ }
+ });
+ } catch (DatabaseException e) {
+ handleException(e);
+ }
+ }
+
+ /**
+ * Implement this modifier to perform database modifications.
+ *
+ * @param graph
+ * @param oldEnumObject
+ * @param enumObject
+ */
+ protected abstract void modifyWithObject(WriteGraph graph, T oldEnumObject, String enumObject) throws DatabaseException;
+
+ /**
+ * Client overridable handler for possible exceptions that may occur while
+ * performing the database modifications.
+ *
+ * <p>
+ * This default implementation merely forwards the exception as a runtime
+ * exception.
+ *
+ * @param e
+ */
+ protected void handleException(DatabaseException e) {
+ throw new RuntimeException(e);
+ }
+
+}