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