Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Buschtoens2012-01-27 22:12:27 +0000
committerTim Buschtoens2012-01-27 22:12:27 +0000
commit7f83132d2077fe46aff62938fa2ba3f24270677f (patch)
treee3c1fc6bb1aa81a7160f6ce6defe0f32aaca02d0
parentd84b157724903864e9479439fa348f1cedee22cc (diff)
downloadorg.eclipse.rap.incubator.clientscripting-7f83132d2077fe46aff62938fa2ba3f24270677f.tar.gz
org.eclipse.rap.incubator.clientscripting-7f83132d2077fe46aff62938fa2ba3f24270677f.tar.xz
org.eclipse.rap.incubator.clientscripting-7f83132d2077fe46aff62938fa2ba3f24270677f.zip
update demo
-rw-r--r--org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/DateMask.js51
-rw-r--r--org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/Demo.java60
-rw-r--r--org.eclipse.rap.clientscripting/plugin.xml13
-rw-r--r--org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/ClientEventListenerResource.java9
-rw-r--r--org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/EventBindingResource.java9
-rw-r--r--org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/FunctionResource.java9
-rw-r--r--org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/SWTResource.java9
-rw-r--r--org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/WidgetProxyResource.java9
8 files changed, 153 insertions, 16 deletions
diff --git a/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/DateMask.js b/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/DateMask.js
new file mode 100644
index 0000000..b0a97d5
--- /dev/null
+++ b/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/DateMask.js
@@ -0,0 +1,51 @@
+function( ev ) {
+
+ var newCh = ev.character;
+ var keyCode = ev.keyCode;
+ var sel = ev.widget.getSelection()[ 0 ];
+ var text = ev.widget.getText();
+
+ var replaceNextChar = function( value ) {
+ var leftPart = text.slice( 0, sel );
+ var rightPart = text.slice( sel + 1, text.length );
+ text = leftPart + value + rightPart;
+ sel++;
+ };
+
+ var replacePrevChar = function( value ) {
+ var leftPart = text.slice( 0, sel - 1 );
+ var rightPart = text.slice( sel, text.length );
+ text = leftPart + value + rightPart;
+ sel--;
+ };
+
+ var isNumber = function( character ) {
+ var charCode = character.charCodeAt( 0 );
+ return charCode >=48 && charCode <= 57;
+ }
+
+ if( keyCode !== SWT.ARROW_LEFT && keyCode !== SWT.ARROW_RIGHT ) {
+ ev.doit = false;
+ }
+
+ if( text[ sel ] === "_" && isNumber( newCh ) ) {
+ replaceNextChar( newCh );
+ if( text[ sel ] === "." ) {
+ sel++;
+ }
+ } else if( keyCode === SWT.BS && sel > 0 ) {
+ if( text[ sel - 1 ] === "." ) {
+ sel--;
+ }
+ if( isNumber( text[ sel - 1 ] ) ) {
+ replacePrevChar( "_" );
+ } else {
+ sel--;
+ }
+ ev.doit = false;
+ }
+
+ // TODO: Setting text sets selection to last position - compare SWT
+ ev.widget.setText( text );
+ ev.widget.setSelection( [ sel, sel ] );
+};
diff --git a/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/Demo.java b/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/Demo.java
index 5da7936..22cf923 100644
--- a/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/Demo.java
+++ b/org.eclipse.rap.clientscripting.demo/src/org/eclipse/rap/clientscripting/Demo.java
@@ -1,12 +1,19 @@
package org.eclipse.rap.clientscripting;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
import org.eclipse.rwt.internal.widgets.JSExecutor;
import org.eclipse.rwt.lifecycle.IEntryPoint;
+import org.eclipse.rwt.lifecycle.WidgetUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.swt.widgets.Widget;
@SuppressWarnings("restriction")
public class Demo implements IEntryPoint {
@@ -16,8 +23,8 @@ public class Demo implements IEntryPoint {
Shell shell = new Shell( display );
shell.setLayout( new GridLayout( 1, false ) );
- Text text = new Text( shell, SWT.SINGLE | SWT.READ_ONLY );
- text.setText( "__.__.____" );
+ Text text = new Text( shell, SWT.SINGLE );
+ text.setText( "__.__.____ " ); // last empty space prevents horizontal scrolling
addMaskBehavior( text );
shell.pack();
@@ -32,9 +39,52 @@ public class Demo implements IEntryPoint {
}
private void addMaskBehavior( Text text ) {
- String code = "listener = new org.eclipse.rap.clientscripting.ClientEventListener( "
- + "\"function(){}\" );";
+ String code = "var f = new org.eclipse.rap.clientscripting.Function( \"";
+ code += getJSHandler( "DateMask.js" );
+ code += "\" );";
+ code += "new org.eclipse.rap.clientscripting.EventBinding( ";
+ code += getWidgetRef( text );
+ code += ", org.eclipse.rap.clientscripting.SWT.KeyDown, f );";
JSExecutor.executeJS( code );
}
-
+
+ private String getWidgetRef( Widget widget ) {
+ String result = "org.eclipse.rwt.protocol.ObjectManager.getObject( \"";
+ result += WidgetUtil.getId( widget );
+ result += "\" )";
+ return result;
+ }
+
+ private String getJSHandler( String fileName ) {
+ String code = getFileContent( "org/eclipse/rap/clientscripting/" + fileName ).toString();
+ code = code.replace( "\"", "\\\"" );
+ code = code.replace( "\n", "\\n" );
+ return code;
+ }
+
+ private static StringBuffer getFileContent( final String file ) {
+ StringBuffer buffer = new StringBuffer();
+ InputStream stream = Demo.class.getClassLoader().getResourceAsStream( file );
+ if( stream != null ) {
+ InputStreamReader inputStreamReader = new InputStreamReader( stream );
+ BufferedReader bufferedReader = new BufferedReader( inputStreamReader );
+ try {
+ String line = null;
+ try {
+ while( ( line = bufferedReader.readLine() ) != null ) {
+ buffer.append( line );
+ buffer.append( '\n' );
+ }
+ } finally {
+ bufferedReader.close();
+ }
+ } catch( IOException e ) {
+ buffer = null;
+ }
+ } else {
+ buffer = null;
+ }
+ return buffer;
+ }
+
}
diff --git a/org.eclipse.rap.clientscripting/plugin.xml b/org.eclipse.rap.clientscripting/plugin.xml
index ec36f34..394e90c 100644
--- a/org.eclipse.rap.clientscripting/plugin.xml
+++ b/org.eclipse.rap.clientscripting/plugin.xml
@@ -4,14 +4,23 @@
<extension
point="org.eclipse.rap.ui.resources">
<resource
- class="org.eclipse.rap.clientscripting.internal.ClientEventListenerResource">
+ class="org.eclipse.rap.clientscripting.internal.ClientScriptingUtilResource">
</resource>
<resource
- class="org.eclipse.rap.clientscripting.internal.ClientScriptingUtilResource">
+ class="org.eclipse.rap.clientscripting.internal.EventBindingResource">
</resource>
<resource
class="org.eclipse.rap.clientscripting.internal.EventProxyResource">
</resource>
+ <resource
+ class="org.eclipse.rap.clientscripting.internal.FunctionResource">
+ </resource>
+ <resource
+ class="org.eclipse.rap.clientscripting.internal.SWTResource">
+ </resource>
+ <resource
+ class="org.eclipse.rap.clientscripting.internal.WidgetProxyResource">
+ </resource>
</extension>
</plugin>
diff --git a/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/ClientEventListenerResource.java b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/ClientEventListenerResource.java
deleted file mode 100644
index 4d6a984..0000000
--- a/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/ClientEventListenerResource.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package org.eclipse.rap.clientscripting.internal;
-
-public class ClientEventListenerResource extends ClientScriptingResource {
-
- public ClientEventListenerResource() {
- super( "ClientEventListener.js" );
- }
-
-}
diff --git a/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/EventBindingResource.java b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/EventBindingResource.java
new file mode 100644
index 0000000..88de3c2
--- /dev/null
+++ b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/EventBindingResource.java
@@ -0,0 +1,9 @@
+package org.eclipse.rap.clientscripting.internal;
+
+public class EventBindingResource extends ClientScriptingResource {
+
+ public EventBindingResource() {
+ super( "EventBinding.js" );
+ }
+
+}
diff --git a/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/FunctionResource.java b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/FunctionResource.java
new file mode 100644
index 0000000..2abbf0f
--- /dev/null
+++ b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/FunctionResource.java
@@ -0,0 +1,9 @@
+package org.eclipse.rap.clientscripting.internal;
+
+public class FunctionResource extends ClientScriptingResource {
+
+ public FunctionResource() {
+ super( "Function.js" );
+ }
+
+}
diff --git a/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/SWTResource.java b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/SWTResource.java
new file mode 100644
index 0000000..c7c468f
--- /dev/null
+++ b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/SWTResource.java
@@ -0,0 +1,9 @@
+package org.eclipse.rap.clientscripting.internal;
+
+public class SWTResource extends ClientScriptingResource {
+
+ public SWTResource() {
+ super( "SWT.js" );
+ }
+
+}
diff --git a/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/WidgetProxyResource.java b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/WidgetProxyResource.java
new file mode 100644
index 0000000..ed097bb
--- /dev/null
+++ b/org.eclipse.rap.clientscripting/src/org/eclipse/rap/clientscripting/internal/WidgetProxyResource.java
@@ -0,0 +1,9 @@
+package org.eclipse.rap.clientscripting.internal;
+
+public class WidgetProxyResource extends ClientScriptingResource {
+
+ public WidgetProxyResource() {
+ super( "WidgetProxy.js" );
+ }
+
+}

Back to the top