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.diagram.adapter;
14 import org.simantics.db.ReadGraph;
15 import org.simantics.db.RequestProcessor;
16 import org.simantics.db.Resource;
17 import org.simantics.db.common.request.ReadRequest;
18 import org.simantics.db.exception.DatabaseException;
19 import org.simantics.diagram.stubs.DiagramResource;
20 import org.simantics.scenegraph.profile.EvaluationContext;
21 import org.simantics.scenegraph.profile.Group;
22 import org.simantics.scenegraph.profile.ProfileEntry;
23 import org.simantics.scenegraph.profile.Style;
24 import org.simantics.utils.ui.ErrorLogger;
26 public class GroupStyleProfileEntry implements ProfileEntry {
28 private final Resource entry;
29 private boolean active = false;
33 private double priority;
35 public GroupStyleProfileEntry(ReadGraph graph, Resource entry) throws DatabaseException {
38 DiagramResource dr = DiagramResource.getInstance(graph);
39 Resource style = graph.getPossibleObject(entry, dr.ProfileEntry_HasStyle);
40 Resource group = graph.getPossibleObject(entry, dr.ProfileEntry_HasGroup);
42 Double priority = graph.getPossibleRelatedValue(entry, dr.ProfileEntry_HasPriority);
43 if(priority != null) this.priority = priority;
44 else this.priority = 0;
46 GroupStyleProfileEntry.this.style = graph.adapt(style, Style.class);
47 GroupStyleProfileEntry.this.style.setPriority(this.priority);
48 GroupStyleProfileEntry.this.group = graph.adapt(group, Group.class);
52 public void activate(RequestProcessor processor, final Resource runtimeDiagram, final EvaluationContext observer) {
55 processor.syncRequest(new ReadRequest() {
58 public void run(ReadGraph graph) throws DatabaseException {
60 GroupStyleProfileEntry.this.style.activate(graph, runtimeDiagram, entry, GroupStyleProfileEntry.this.group, observer);
68 } catch (DatabaseException e) {
69 ErrorLogger.defaultLogError(e);
74 public void deactivate(Resource diagram, EvaluationContext observer) {
76 System.out.println("GroupStyleProfileEntry has null style!");
80 style.deactivate(diagram, entry, group, observer);
85 public void apply(EvaluationContext observer) {
87 System.out.println("GroupStyleProfileEntry has null style!");
90 style.apply(entry, group, observer);
94 public int hashCode() {
95 return entry.hashCode();
99 public boolean equals(Object object) {
102 else if (object == null)
104 else if (GroupStyleProfileEntry.class != object.getClass())
106 GroupStyleProfileEntry other = (GroupStyleProfileEntry)object;
107 return entry.equals(other.entry);
111 public String toString() {
112 return "" + style + " applied to " + group;
116 public boolean isActive() {
121 public double getPriority() {