X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FGroupStyleProfileEntry.java;h=f38d1971b50a960bb3b80d6b435ffc4d6054e40d;hp=32c285721a76b978261a9d69e103184734fcf92d;hb=12a131c567a24d4aa86fe86e5072f0bfc9b68d5b;hpb=969bd23cab98a79ca9101af33334000879fb60c5 diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GroupStyleProfileEntry.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GroupStyleProfileEntry.java index 32c285721..f38d1971b 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GroupStyleProfileEntry.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GroupStyleProfileEntry.java @@ -1,124 +1,125 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.diagram.adapter; - -import org.simantics.db.ReadGraph; -import org.simantics.db.RequestProcessor; -import org.simantics.db.Resource; -import org.simantics.db.common.request.ReadRequest; -import org.simantics.db.exception.DatabaseException; -import org.simantics.diagram.stubs.DiagramResource; -import org.simantics.scenegraph.profile.EvaluationContext; -import org.simantics.scenegraph.profile.Group; -import org.simantics.scenegraph.profile.ProfileEntry; -import org.simantics.scenegraph.profile.Style; -import org.simantics.utils.ui.ErrorLogger; - -public class GroupStyleProfileEntry implements ProfileEntry { - - private final Resource entry; - private boolean active = false; - - private Style style; - private Group group; - private double priority; - - public GroupStyleProfileEntry(ReadGraph graph, Resource entry) throws DatabaseException { - this.entry = entry; - - DiagramResource dr = DiagramResource.getInstance(graph); - Resource style = graph.getPossibleObject(entry, dr.ProfileEntry_HasStyle); - Resource group = graph.getPossibleObject(entry, dr.ProfileEntry_HasGroup); - - Double priority = graph.getPossibleRelatedValue(entry, dr.ProfileEntry_HasPriority); - if(priority != null) this.priority = priority; - else this.priority = 0; - - GroupStyleProfileEntry.this.style = graph.adapt(style, Style.class); - GroupStyleProfileEntry.this.group = graph.adapt(group, Group.class); - } - - @Override - public void activate(RequestProcessor processor, final Resource runtimeDiagram, final EvaluationContext observer) { - - try { - processor.syncRequest(new ReadRequest() { - - @Override - public void run(ReadGraph graph) throws DatabaseException { - - GroupStyleProfileEntry.this.style.activate(graph, runtimeDiagram, entry, GroupStyleProfileEntry.this.group, observer); - - } - - }); - - active = true; - - } catch (DatabaseException e) { - ErrorLogger.defaultLogError(e); - } - } - - @Override - public void deactivate(Resource diagram, EvaluationContext observer) { - if (style == null) { - System.out.println("GroupStyleProfileEntry has null style!"); - return; - } - - style.deactivate(diagram, entry, group, observer); - active = false; - } - - @Override - public void apply(EvaluationContext observer) { - if (style == null) { - System.out.println("GroupStyleProfileEntry has null style!"); - return; - } - style.apply(entry, group, observer); - } - - @Override - public int hashCode() { - return entry.hashCode(); - } - - @Override - public boolean equals(Object object) { - if (this == object) - return true; - else if (object == null) - return false; - else if (GroupStyleProfileEntry.class != object.getClass()) - return false; - GroupStyleProfileEntry other = (GroupStyleProfileEntry)object; - return entry.equals(other.entry); - } - - @Override - public String toString() { - return "" + style + " applied to " + group; - } - - @Override - public boolean isActive() { - return active; - } - - @Override - public double getPriority() { - return priority; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.diagram.adapter; + +import org.simantics.db.ReadGraph; +import org.simantics.db.RequestProcessor; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.diagram.stubs.DiagramResource; +import org.simantics.scenegraph.profile.EvaluationContext; +import org.simantics.scenegraph.profile.Group; +import org.simantics.scenegraph.profile.ProfileEntry; +import org.simantics.scenegraph.profile.Style; +import org.simantics.utils.ui.ErrorLogger; + +public class GroupStyleProfileEntry implements ProfileEntry { + + private final Resource entry; + private boolean active = false; + + private Style style; + private Group group; + private double priority; + + public GroupStyleProfileEntry(ReadGraph graph, Resource entry) throws DatabaseException { + this.entry = entry; + + DiagramResource dr = DiagramResource.getInstance(graph); + Resource style = graph.getPossibleObject(entry, dr.ProfileEntry_HasStyle); + Resource group = graph.getPossibleObject(entry, dr.ProfileEntry_HasGroup); + + Double priority = graph.getPossibleRelatedValue(entry, dr.ProfileEntry_HasPriority); + if(priority != null) this.priority = priority; + else this.priority = 0; + + GroupStyleProfileEntry.this.style = graph.adapt(style, Style.class); + GroupStyleProfileEntry.this.style.setPriority(this.priority); + GroupStyleProfileEntry.this.group = graph.adapt(group, Group.class); + } + + @Override + public void activate(RequestProcessor processor, final Resource runtimeDiagram, final EvaluationContext observer) { + + try { + processor.syncRequest(new ReadRequest() { + + @Override + public void run(ReadGraph graph) throws DatabaseException { + + GroupStyleProfileEntry.this.style.activate(graph, runtimeDiagram, entry, GroupStyleProfileEntry.this.group, observer); + + } + + }); + + active = true; + + } catch (DatabaseException e) { + ErrorLogger.defaultLogError(e); + } + } + + @Override + public void deactivate(Resource diagram, EvaluationContext observer) { + if (style == null) { + System.out.println("GroupStyleProfileEntry has null style!"); + return; + } + + style.deactivate(diagram, entry, group, observer); + active = false; + } + + @Override + public void apply(EvaluationContext observer) { + if (style == null) { + System.out.println("GroupStyleProfileEntry has null style!"); + return; + } + style.apply(entry, group, observer); + } + + @Override + public int hashCode() { + return entry.hashCode(); + } + + @Override + public boolean equals(Object object) { + if (this == object) + return true; + else if (object == null) + return false; + else if (GroupStyleProfileEntry.class != object.getClass()) + return false; + GroupStyleProfileEntry other = (GroupStyleProfileEntry)object; + return entry.equals(other.entry); + } + + @Override + public String toString() { + return "" + style + " applied to " + group; + } + + @Override + public boolean isActive() { + return active; + } + + @Override + public double getPriority() { + return priority; + } + +}