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.EnumeratedValue;
15 import org.simantics.browsing.ui.common.modifiers.Enumeration;
16 import org.simantics.db.Session;
17 import org.simantics.db.WriteGraph;
18 import org.simantics.db.common.request.WriteRequest;
19 import org.simantics.db.exception.DatabaseException;
20 import org.simantics.utils.ObjectUtils;
23 * @author Tuukka Lehtonen
25 public abstract class GraphContentAssistEnumerationModifier<T> extends AbstractContentAssistEnumerationModifier<T> {
27 protected final Session session;
29 public GraphContentAssistEnumerationModifier(Session session, Enumeration<T> enumeration, T value) {
30 this(session, enumeration, enumeration.find(value));
33 public GraphContentAssistEnumerationModifier(Session session, Enumeration<T> enumeration, EnumeratedValue<T> value) {
34 super(enumeration, value);
36 throw new NullPointerException("null session");
37 this.session = session;
41 protected void modifyWithObject(final T oldEnumObject, final T enumObject, boolean force) {
42 if (!force && ObjectUtils.objectEquals(oldEnumObject, enumObject))
46 session.getSession().syncRequest(new WriteRequest() {
48 public void perform(WriteGraph graph) throws DatabaseException {
49 // System.out.println("old enum object: " + oldEnumObject);
50 // System.out.println("enum object: " + enumObject);
51 modifyWithObject(graph, oldEnumObject, enumObject);
54 } catch (DatabaseException e) {
60 * Implement this modifier to perform database modifications.
63 * @param oldEnumObject
66 protected abstract void modifyWithObject(WriteGraph graph, T oldEnumObject, T enumObject) throws DatabaseException;
69 * Client overridable handler for possible exceptions that may occur while
70 * performing the database modifications.
73 * This default implementation merely forwards the exception as a runtime
78 protected void handleException(DatabaseException e) {
79 throw new RuntimeException(e);