]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/widgets/Label.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / widgets / Label.java
index c9651a1fa2b564abf71fd1928fcfa7472c694174..7624e0e42bfbdec11814f826173a46fe5ea8837b 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2012 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.browsing.ui.swt.widgets;\r
-\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.simantics.Simantics;\r
-import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory;\r
-import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.common.request.ParametrizedRead;\r
-import org.simantics.db.common.request.UniqueRead;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.management.ISessionContext;\r
-import org.simantics.db.procedure.Listener;\r
-import org.simantics.utils.ui.SWTUtils;\r
-\r
-public class Label extends WidgetImpl {\r
-\r
-       private ReadFactory<?, String> textFactory;\r
-       private ReadFactory<?, Color> colorFactory;\r
-       \r
-       final private org.eclipse.swt.widgets.Label label;\r
-       \r
-       public Label(Composite parent, WidgetSupport support, int style) {\r
-               super(support);\r
-               label = new org.eclipse.swt.widgets.Label(parent, style);\r
-               support.register(this);\r
-       }\r
-       \r
-       public void setTextFactory(ReadFactory<?, String> textFactory) {\r
-               this.textFactory = textFactory;\r
-       }\r
-       \r
-       public void setForegroundFactory(ReadFactory<?, Color> colorFactory) {\r
-               this.colorFactory = colorFactory;\r
-       }\r
-\r
-       public org.eclipse.swt.widgets.Label getWidget() {\r
-               return label;\r
-       }\r
-       \r
-       @Override\r
-       public Control getControl() {\r
-               return label;\r
-       }\r
-\r
-       @Override\r
-       public void setInput(ISessionContext context, Object input) {\r
-\r
-               if(textFactory != null) {\r
-                       textFactory.listen(context, input, new Listener<String>() {\r
-\r
-                               public void exception(final Throwable t) {\r
-                                       SWTUtils.asyncExec(label, new Runnable() {\r
-\r
-                                               @Override\r
-                                               public void run() {\r
-                                                       if(isDisposed()) return;\r
-//                                                     System.out.println("Button received new text: " + text);\r
-                                                       label.setText(t.toString());\r
-                                               }\r
-\r
-                                       });\r
-                               }\r
-\r
-                               @Override\r
-                               public void execute(final String text) {\r
-                                       SWTUtils.asyncExec(label, new Runnable() {\r
-\r
-                                               @Override\r
-                                               public void run() {\r
-                                                       if(isDisposed()) return;\r
-                                                       label.setText(text);\r
-                                                       // TODO: how can we resize without this knife??\r
-                                                       label.getParent().layout();\r
-                                                       label.getParent().getParent().layout();\r
-                                               }\r
-\r
-                                       });\r
-                               }\r
-\r
-                               @Override\r
-                               public boolean isDisposed() {\r
-                                       return label.isDisposed();\r
-                               }\r
-\r
-                       });\r
-               }\r
-               \r
-               if(colorFactory != null) {\r
-                       colorFactory.listen(context, input, new Listener<Color>() {\r
-\r
-                               @Override\r
-                               public void exception(Throwable t) {\r
-                                       t.printStackTrace();\r
-                               }\r
-\r
-                               @Override\r
-                               public void execute(final Color color) {\r
-                                       label.getDisplay().asyncExec(new Runnable() {\r
-\r
-                                               @Override\r
-                                               public void run() {\r
-                                                       if(isDisposed()) return;\r
-                                                       label.setForeground(color);\r
-                                               }\r
-\r
-                                       });\r
-                               }\r
-\r
-                               @Override\r
-                               public boolean isDisposed() {\r
-                                       return label.isDisposed();\r
-                               }\r
-\r
-                       });\r
-               }\r
-               \r
-       }\r
-       \r
-    public <T> void setText(final ParametrizedRead<T, String> read) {\r
-       \r
-       Simantics.getSession().async(new UniqueRead<String>() {\r
-\r
-               @Override\r
-               public String perform(ReadGraph graph) throws DatabaseException {\r
-                       T input = support.getInput(graph);\r
-                       return graph.syncRequest(read.get(input));\r
-               }\r
-\r
-       }, new Listener<String>() {\r
-\r
-               @Override\r
-               public void exception(Throwable t) {\r
-                       t.printStackTrace();\r
-               }\r
-\r
-               @Override\r
-               public void execute(final String text) {\r
-\r
-                       if(isDisposed()) return;\r
-\r
-                       label.getDisplay().asyncExec(new Runnable() {\r
-\r
-                               @Override\r
-                               public void run() {\r
-                                       label.setText(text);\r
-                               }\r
-\r
-                       });\r
-               }\r
-\r
-               @Override\r
-               public boolean isDisposed() {\r
-                       return label.isDisposed();\r
-               }\r
-\r
-       });\r
-\r
-    }\r
-       \r
-       public void setText(String text) {\r
-               label.setText(text);\r
-       }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2012 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.browsing.ui.swt.widgets;
+
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.simantics.Simantics;
+import org.simantics.browsing.ui.swt.widgets.impl.ReadFactory;
+import org.simantics.browsing.ui.swt.widgets.impl.WidgetSupport;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.common.request.ParametrizedRead;
+import org.simantics.db.common.request.UniqueRead;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.management.ISessionContext;
+import org.simantics.db.procedure.Listener;
+import org.simantics.utils.ui.SWTUtils;
+
+public class Label extends WidgetImpl {
+
+       private ReadFactory<?, String> textFactory;
+       private ReadFactory<?, Color> colorFactory;
+       
+       final private org.eclipse.swt.widgets.Label label;
+       
+       public Label(Composite parent, WidgetSupport support, int style) {
+               super(support);
+               label = new org.eclipse.swt.widgets.Label(parent, style);
+               support.register(this);
+       }
+       
+       public void setTextFactory(ReadFactory<?, String> textFactory) {
+               this.textFactory = textFactory;
+       }
+       
+       public void setForegroundFactory(ReadFactory<?, Color> colorFactory) {
+               this.colorFactory = colorFactory;
+       }
+
+       public org.eclipse.swt.widgets.Label getWidget() {
+               return label;
+       }
+       
+       @Override
+       public Control getControl() {
+               return label;
+       }
+
+       @Override
+       public void setInput(ISessionContext context, Object input) {
+
+               if(textFactory != null) {
+                       textFactory.listen(context, input, new Listener<String>() {
+
+                               public void exception(final Throwable t) {
+                                       SWTUtils.asyncExec(label, new Runnable() {
+
+                                               @Override
+                                               public void run() {
+                                                       if(isDisposed()) return;
+//                                                     System.out.println("Button received new text: " + text);
+                                                       label.setText(t.toString());
+                                               }
+
+                                       });
+                               }
+
+                               @Override
+                               public void execute(final String text) {
+                                       SWTUtils.asyncExec(label, new Runnable() {
+
+                                               @Override
+                                               public void run() {
+                                                       if(isDisposed()) return;
+                                                       label.setText(text);
+                                                       // TODO: how can we resize without this knife??
+                                                       label.getParent().layout();
+                                                       label.getParent().getParent().layout();
+                                               }
+
+                                       });
+                               }
+
+                               @Override
+                               public boolean isDisposed() {
+                                       return label.isDisposed();
+                               }
+
+                       });
+               }
+               
+               if(colorFactory != null) {
+                       colorFactory.listen(context, input, new Listener<Color>() {
+
+                               @Override
+                               public void exception(Throwable t) {
+                                       t.printStackTrace();
+                               }
+
+                               @Override
+                               public void execute(final Color color) {
+                                       label.getDisplay().asyncExec(new Runnable() {
+
+                                               @Override
+                                               public void run() {
+                                                       if(isDisposed()) return;
+                                                       label.setForeground(color);
+                                               }
+
+                                       });
+                               }
+
+                               @Override
+                               public boolean isDisposed() {
+                                       return label.isDisposed();
+                               }
+
+                       });
+               }
+               
+       }
+       
+    public <T> void setText(final ParametrizedRead<T, String> read) {
+       
+       Simantics.getSession().async(new UniqueRead<String>() {
+
+               @Override
+               public String perform(ReadGraph graph) throws DatabaseException {
+                       T input = support.getInput(graph);
+                       return graph.syncRequest(read.get(input));
+               }
+
+       }, new Listener<String>() {
+
+               @Override
+               public void exception(Throwable t) {
+                       t.printStackTrace();
+               }
+
+               @Override
+               public void execute(final String text) {
+
+                       if(isDisposed()) return;
+
+                       label.getDisplay().asyncExec(new Runnable() {
+
+                               @Override
+                               public void run() {
+                                       label.setText(text);
+                               }
+
+                       });
+               }
+
+               @Override
+               public boolean isDisposed() {
+                       return label.isDisposed();
+               }
+
+       });
+
+    }
+       
+       public void setText(String text) {
+               label.setText(text);
+       }
+
+}