X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Fview%2Fcontribution%2FEventDecorationRule.java;fp=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Fview%2Fcontribution%2FEventDecorationRule.java;h=1a693501efdc5533ea7d6cb6b6fea123bd49799e;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=5da8829576ddf3e99c204c4a2320a70d38e0cba4;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.event/src/org/simantics/event/view/contribution/EventDecorationRule.java b/bundles/org.simantics.event/src/org/simantics/event/view/contribution/EventDecorationRule.java index 5da882957..1a693501e 100644 --- a/bundles/org.simantics.event/src/org/simantics/event/view/contribution/EventDecorationRule.java +++ b/bundles/org.simantics.event/src/org/simantics/event/view/contribution/EventDecorationRule.java @@ -1,77 +1,77 @@ -/******************************************************************************* - * Copyright (c) 2007, 2011 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.event.view.contribution; - -import org.eclipse.jface.resource.FontDescriptor; -import org.eclipse.swt.SWT; -import org.simantics.browsing.ui.content.LabelDecorator; -import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; -import org.simantics.db.ReadGraph; -import org.simantics.db.Resource; -import org.simantics.db.exception.DatabaseException; -import org.simantics.event.ontology.EventResource; -import org.simantics.event.view.Constants; - -/** - * @author Tuukka Lehtonen - */ -public enum EventDecorationRule implements LabelDecorationRule { - - INSTANCE; - - public static EventDecorationRule get() { - return INSTANCE; - } - - @Override - public boolean isCompatible(Class contentType) { - return contentType.equals(Resource.class); - } - - @Override - public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException { - Resource event = (Resource) content; - - EventResource EVENT = EventResource.getInstance(graph); - - final boolean milestone = graph.hasStatement(event, EVENT.Milestone); - final boolean hidden = graph.hasStatement(event, EVENT.Hidden); - final boolean baseline = graph.hasStatement(event, EVENT.EventLog_HasBaselineEvent_Inverse); - final boolean returnEvent = graph.hasStatement(event, EVENT.ReturnEvent); - final boolean returnedEvent = graph.hasStatement(event, EVENT.ReturnedBy); - if (!milestone && !hidden && !baseline && !returnEvent && !returnedEvent) - return null; - - return new LabelDecorator.Stub() { - @SuppressWarnings("unchecked") - @Override - public F decorateFont(F font, String column, int itemIndex) { - int style = 0; - style |= milestone ? SWT.BOLD : 0; - style |= hidden ? SWT.ITALIC : 0; - return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font; - } - @SuppressWarnings("unchecked") - @Override - public C decorateForeground(C color, String column, int itemIndex) { - if (returnEvent || returnedEvent) - return (C) Constants.RETURN_EVENT_FG; - return color; - } - @Override - public C decorateBackground(C color, String column, int itemIndex) { - return color; - } - }; - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2011 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.event.view.contribution; + +import org.eclipse.jface.resource.FontDescriptor; +import org.eclipse.swt.SWT; +import org.simantics.browsing.ui.content.LabelDecorator; +import org.simantics.browsing.ui.model.labeldecorators.LabelDecorationRule; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.exception.DatabaseException; +import org.simantics.event.ontology.EventResource; +import org.simantics.event.view.Constants; + +/** + * @author Tuukka Lehtonen + */ +public enum EventDecorationRule implements LabelDecorationRule { + + INSTANCE; + + public static EventDecorationRule get() { + return INSTANCE; + } + + @Override + public boolean isCompatible(Class contentType) { + return contentType.equals(Resource.class); + } + + @Override + public LabelDecorator getLabelDecorator(ReadGraph graph, Object content) throws DatabaseException { + Resource event = (Resource) content; + + EventResource EVENT = EventResource.getInstance(graph); + + final boolean milestone = graph.hasStatement(event, EVENT.Milestone); + final boolean hidden = graph.hasStatement(event, EVENT.Hidden); + final boolean baseline = graph.hasStatement(event, EVENT.EventLog_HasBaselineEvent_Inverse); + final boolean returnEvent = graph.hasStatement(event, EVENT.ReturnEvent); + final boolean returnedEvent = graph.hasStatement(event, EVENT.ReturnedBy); + if (!milestone && !hidden && !baseline && !returnEvent && !returnedEvent) + return null; + + return new LabelDecorator.Stub() { + @SuppressWarnings("unchecked") + @Override + public F decorateFont(F font, String column, int itemIndex) { + int style = 0; + style |= milestone ? SWT.BOLD : 0; + style |= hidden ? SWT.ITALIC : 0; + return style != 0 ? (F) ((FontDescriptor) font).setStyle(style) : font; + } + @SuppressWarnings("unchecked") + @Override + public C decorateForeground(C color, String column, int itemIndex) { + if (returnEvent || returnedEvent) + return (C) Constants.RETURN_EVENT_FG; + return color; + } + @Override + public C decorateBackground(C color, String column, int itemIndex) { + return color; + } + }; + } + +}