1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 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.diagram.adapter;
\r
14 import org.simantics.db.ReadGraph;
\r
15 import org.simantics.db.RequestProcessor;
\r
16 import org.simantics.db.Resource;
\r
17 import org.simantics.db.common.request.ReadRequest;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
19 import org.simantics.diagram.stubs.DiagramResource;
\r
20 import org.simantics.scenegraph.profile.EvaluationContext;
\r
21 import org.simantics.scenegraph.profile.Group;
\r
22 import org.simantics.scenegraph.profile.ProfileEntry;
\r
23 import org.simantics.scenegraph.profile.Style;
\r
24 import org.simantics.utils.ui.ErrorLogger;
\r
26 public class GroupStyleProfileEntry implements ProfileEntry {
\r
28 private final Resource entry;
\r
29 private boolean active = false;
\r
31 private Style style;
\r
32 private Group group;
\r
33 private double priority;
\r
35 public GroupStyleProfileEntry(ReadGraph graph, Resource entry) throws DatabaseException {
\r
38 DiagramResource dr = DiagramResource.getInstance(graph);
\r
39 Resource style = graph.getPossibleObject(entry, dr.ProfileEntry_HasStyle);
\r
40 Resource group = graph.getPossibleObject(entry, dr.ProfileEntry_HasGroup);
\r
42 Double priority = graph.getPossibleRelatedValue(entry, dr.ProfileEntry_HasPriority);
\r
43 if(priority != null) this.priority = priority;
\r
44 else this.priority = 0;
\r
46 GroupStyleProfileEntry.this.style = graph.adapt(style, Style.class);
\r
47 GroupStyleProfileEntry.this.group = graph.adapt(group, Group.class);
\r
51 public void activate(RequestProcessor processor, final Resource runtimeDiagram, final EvaluationContext observer) {
\r
54 processor.syncRequest(new ReadRequest() {
\r
57 public void run(ReadGraph graph) throws DatabaseException {
\r
59 GroupStyleProfileEntry.this.style.activate(graph, runtimeDiagram, entry, GroupStyleProfileEntry.this.group, observer);
\r
67 } catch (DatabaseException e) {
\r
68 ErrorLogger.defaultLogError(e);
\r
73 public void deactivate(Resource diagram, EvaluationContext observer) {
\r
74 if (style == null) {
\r
75 System.out.println("GroupStyleProfileEntry has null style!");
\r
79 style.deactivate(diagram, entry, group, observer);
\r
84 public void apply(EvaluationContext observer) {
\r
85 if (style == null) {
\r
86 System.out.println("GroupStyleProfileEntry has null style!");
\r
89 style.apply(entry, group, observer);
\r
93 public int hashCode() {
\r
94 return entry.hashCode();
\r
98 public boolean equals(Object object) {
\r
101 else if (object == null)
\r
103 else if (GroupStyleProfileEntry.class != object.getClass())
\r
105 GroupStyleProfileEntry other = (GroupStyleProfileEntry)object;
\r
106 return entry.equals(other.entry);
\r
110 public String toString() {
\r
111 return "" + style + " applied to " + group;
\r
115 public boolean isActive() {
\r
120 public double getPriority() {
\r