1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 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.graph.impl;
14 import org.simantics.browsing.ui.common.modifiers.AbstractEnumerationModifier;
15 import org.simantics.browsing.ui.common.modifiers.EnumeratedValue;
16 import org.simantics.browsing.ui.common.modifiers.Enumeration;
17 import org.simantics.db.Session;
18 import org.simantics.db.WriteGraph;
19 import org.simantics.db.common.request.WriteRequest;
20 import org.simantics.db.exception.DatabaseException;
21 import org.simantics.utils.ObjectUtils;
24 * A graph resource based EnumerationModifier utility implementation.
26 * @author Tuukka Lehtonen
28 public abstract class GraphEnumerationModifierBase<T> extends AbstractEnumerationModifier<T> {
30 protected final Session session;
32 public GraphEnumerationModifierBase(Session session, Enumeration<T> enumeration, T value) {
33 this(session, enumeration, enumeration.find(value));
36 public GraphEnumerationModifierBase(Session session, Enumeration<T> enumeration, EnumeratedValue<T> value) {
37 super(enumeration, value);
39 throw new NullPointerException("null session");
40 this.session = session;
44 protected void modifyWithObject(final T oldEnumObject, final T enumObject) {
45 if (ObjectUtils.objectEquals(oldEnumObject, enumObject))
49 session.getSession().syncRequest(new WriteRequest() {
51 public void perform(WriteGraph graph) throws DatabaseException {
52 // System.out.println("old enum object: " + oldEnumObject);
53 // System.out.println("enum object: " + enumObject);
54 modifyWithObject(graph, oldEnumObject, enumObject);
57 } catch (DatabaseException e) {
63 * Implement this modifier to perform database modifications.
66 * @param oldEnumObject
69 protected abstract void modifyWithObject(WriteGraph graph, T oldEnumObject, T enumObject) throws DatabaseException;
72 * Client overridable handler for possible exceptions that may occur while
73 * performing the database modifications.
76 * This default implementation merely forwards the exception as a runtime
81 protected void handleException(DatabaseException e) {
82 throw new RuntimeException(e);