X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FGroupStyleProfileEntry.java;fp=bundles%2Forg.simantics.diagram%2Fsrc%2Forg%2Fsimantics%2Fdiagram%2Fadapter%2FGroupStyleProfileEntry.java;h=32c285721a76b978261a9d69e103184734fcf92d;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 new file mode 100644 index 000000000..32c285721 --- /dev/null +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/adapter/GroupStyleProfileEntry.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * 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; + } + +}