+ @SCLValue(type = "ReadGraph -> Resource -> Variable -> a")
+ public static Object fontModifier(ReadGraph graph, Resource r, final Variable variable) throws DatabaseException {
+ return new DialogModifier() {
+
+ @Override
+ public String getValue() {
+ return null;
+ }
+
+ @Override
+ public String isValid(String label) {
+ return null;
+ }
+
+ @Override
+ public void modify(final String label) {
+ Simantics.getSession().async(new WriteRequest() {
+
+ @Override
+ public void perform(WriteGraph graph) throws DatabaseException {
+ Variable displayValue = variable.getParent(graph);
+ displayValue.setValue(graph, label, Bindings.STRING);
+ }
+
+ });
+ }
+
+ public String query(Object parentControl, Object controlItem, int columnIndex, NodeContext context, Consumer<String> applyCallback) {
+
+ Control ctrl = (Control) parentControl;
+ FontData[] initialValue = null;
+
+ try {
+ String font = Simantics.getSession().syncRequest(new UniqueRead<String>() {
+ @Override
+ public String perform(ReadGraph graph) throws DatabaseException {
+ Variable v = AdaptionUtils.adaptToSingle(context, Variable.class);
+ if(v == null) return null;
+ String displayValue = v.getPossiblePropertyValue(graph, "HasDisplayValue", Bindings.STRING);
+ return displayValue;
+ }
+ });
+ if (font != null) {
+ String[] fields = font.split(",");
+ if (fields.length == 3) {
+ int size = 14;
+ try {
+ size = Integer.parseInt(fields[1]);
+ } catch (NumberFormatException e) {
+ ErrorLogger.defaultLogError(e);
+ }
+ int style = SWT.NORMAL;
+ try {
+ style = Fonts.swtStyle(fields[2]);
+ } catch (RuntimeException e) {
+ ErrorLogger.defaultLogError(e);
+ }
+ initialValue = new FontData[] { new FontData(fields[0], size, style) };
+ }
+ }
+ } catch (DatabaseException e) {
+ ErrorLogger.defaultLogError(e);
+ }
+
+ FontDialog dialog = new FontDialog(ctrl.getShell());
+ if (initialValue != null)
+ dialog.setFontList(initialValue);
+ FontData font = dialog.open();
+ if (font != null)
+ applyCallback.accept(font.getName() + "," + font.getHeight() + "," + Fonts.fromSwtStyle(font.getStyle()));
+ return null;
+ }
+
+ };
+
+ }
+