]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.modeling.ui/src/org/simantics/modeling/ui/symbolEditor/GridVisibleFunction.java
Red background color & tooltip for invalid derived property expression
[simantics/platform.git] / bundles / org.simantics.modeling.ui / src / org / simantics / modeling / ui / symbolEditor / GridVisibleFunction.java
1 /*******************************************************************************
2  * Copyright (c) 2013 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.modeling.ui.symbolEditor;
13
14 import org.simantics.g2d.canvas.ICanvasContext;
15 import org.simantics.g2d.participant.GridPainter;
16 import org.simantics.scl.runtime.function.Function1;
17 import org.simantics.utils.datastructures.hints.HintListenerAdapter;
18 import org.simantics.utils.datastructures.hints.IHintContext;
19 import org.simantics.utils.datastructures.hints.IHintObservable;
20 import org.simantics.utils.datastructures.hints.IHintContext.Key;
21
22 /**
23  * A function and a listener for diagram grid visibility. The function
24  * returns the current grid visibility as a Boolean.
25  * 
26  * @author Tuukka Lehtonen
27  */
28 public class GridVisibleFunction extends HintListenerAdapter implements Function1<Object, Boolean> {
29
30         Boolean enabled;
31
32         public GridVisibleFunction(ICanvasContext ctx) {
33                 IHintContext hctx = ctx.getDefaultHintContext();
34                 // Initialize state
35                 hintChanged(hctx, GridPainter.KEY_GRID_ENABLED, null, hctx.getHint(GridPainter.KEY_GRID_ENABLED));
36                 // Start listening
37                 hctx.addKeyHintListener(GridPainter.KEY_GRID_ENABLED, this);
38         }
39
40         @Override
41         public void hintChanged(IHintObservable sender, Key key, Object oldValue, Object newValue) {
42                 enabled = Boolean.valueOf(Boolean.TRUE.equals(newValue));
43         }
44
45         @Override
46         public Boolean apply(Object p0) {
47                 return enabled;
48         }
49
50 }