1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.browsing.ui.swt.contentassist;
\r
14 import org.simantics.browsing.ui.common.modifiers.Enumeration;
\r
15 import org.simantics.db.Session;
\r
16 import org.simantics.db.WriteGraph;
\r
17 import org.simantics.db.common.request.WriteRequest;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
19 import org.simantics.utils.ObjectUtils;
\r
22 * @author Tuukka Lehtonen
\r
24 public abstract class GraphContentAssistModifier<T> extends AbstractContentAssistModifier<T> {
\r
26 protected final Session session;
\r
28 public GraphContentAssistModifier(Session session, Enumeration<T> enumeration, T value) {
\r
29 super(enumeration, value);
\r
30 if (session == null)
\r
31 throw new NullPointerException("null session");
\r
32 this.session = session;
\r
36 protected void modifyWithValue(final T oldEnumObject, final String enumObject) {
\r
37 if (ObjectUtils.objectEquals(oldEnumObject, enumObject))
\r
41 session.getSession().syncRequest(new WriteRequest() {
\r
43 public void perform(WriteGraph graph) throws DatabaseException {
\r
44 // System.out.println("old enum object: " + oldEnumObject);
\r
45 // System.out.println("enum object: " + enumObject);
\r
46 modifyWithObject(graph, oldEnumObject, enumObject);
\r
49 } catch (DatabaseException e) {
\r
55 * Implement this modifier to perform database modifications.
\r
58 * @param oldEnumObject
\r
61 protected abstract void modifyWithObject(WriteGraph graph, T oldEnumObject, String enumObject) throws DatabaseException;
\r
64 * Client overridable handler for possible exceptions that may occur while
\r
65 * performing the database modifications.
\r
68 * This default implementation merely forwards the exception as a runtime
\r
73 protected void handleException(DatabaseException e) {
\r
74 throw new RuntimeException(e);
\r