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.group = graph.adapt(group, Group.class);
51 public void activate(RequestProcessor processor, final Resource runtimeDiagram, final EvaluationContext observer) {
54 processor.syncRequest(new ReadRequest() {
57 public void run(ReadGraph graph) throws DatabaseException {
59 GroupStyleProfileEntry.this.style.activate(graph, runtimeDiagram, entry, GroupStyleProfileEntry.this.group, observer);
67 } catch (DatabaseException e) {
68 ErrorLogger.defaultLogError(e);
73 public void deactivate(Resource diagram, EvaluationContext observer) {
75 System.out.println("GroupStyleProfileEntry has null style!");
79 style.deactivate(diagram, entry, group, observer);
84 public void apply(EvaluationContext observer) {
86 System.out.println("GroupStyleProfileEntry has null style!");
89 style.apply(entry, group, observer);
93 public int hashCode() {
94 return entry.hashCode();
98 public boolean equals(Object object) {
101 else if (object == null)
103 else if (GroupStyleProfileEntry.class != object.getClass())
105 GroupStyleProfileEntry other = (GroupStyleProfileEntry)object;
106 return entry.equals(other.entry);
110 public String toString() {
111 return "" + style + " applied to " + group;
115 public boolean isActive() {
120 public double getPriority() {