Skip to content

Commit 4507c14

Browse files
author
mytruth
committed
Added check box synchronization.
1 parent dfa69fa commit 4507c14

File tree

6 files changed

+69
-21
lines changed

6 files changed

+69
-21
lines changed

org.rcpml.core/src/org/rcpml/core/datasource/DataSourceElementContentBinding.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,6 @@ public Object getValueType() {
5454
}
5555

5656
private Object getValueFromString(String s) {
57-
if (type == int.class) {
58-
try {
59-
return new Integer(Integer.parseInt(s));
60-
}
61-
catch (Exception e) {
62-
return null;
63-
}
64-
}
65-
if (type == double.class) {
66-
try {
67-
return null;
68-
}
69-
catch (Exception e) {
70-
return new Double(0);
71-
}
72-
}
7357
return s;
7458
}
7559

org.rcpml.emf.example/editors/callgraph.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99

1010
<composite id="topParent">
1111
<group>
12-
<label>Location</label><text path="emfds://@ports.0/location"/>
12+
<!--label>Location</label><text path="emfds://@ports.0/location"/>
1313
<label>Name</label><text path="emfds://@ships.0/name"/>
14-
<label>Quantity</label><spinner path="emfds://@ships.0/@cargo.0/quantity"/>
14+
<label>Quantity</label><spinner path="emfds://@ships.0/@cargo.0/quantity"/-->
15+
16+
<label>Name</label><text path="emfds://name"/>
17+
<label>Int</label><spinner path="emfds://int"/>
18+
<label>Double</label><text path="emfds://double"/>
19+
<label>On</label><checkbox path="emfds://on"/>
1520
</group>
1621
</composite>
1722

org.rcpml.emf.example/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
point="org.eclipse.ui.editors">
66
<editor
77
class="org.rcpml.core.RCPMLExtension:/editors/callgraph.xml"
8-
extensions="callgraph,callgraph_diagram,taipan,taipan_diagram"
8+
extensions="callgraph,callgraph_diagram,taipan,taipan_diagram,model,model_diagram"
99
icon="icons/sample.gif"
1010
id="org.rcpml.emf.editor.callgraph"
1111
name="RCPML Call Graph Editor">

org.rcpml.emf.example/src/org/ecpml/emf/example/EMFDataSourceElementBinding.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,41 @@ public void handleValueChange(IDataSourceElementBinding source) {
6262
}
6363

6464
private void changeValue(Object value) {
65-
obj.eSet(feature, value);
65+
try {
66+
obj.eSet(feature, convertValue(value));
67+
}
68+
catch (Exception e) {
69+
e.printStackTrace();
70+
//if value do not valid - ignore it
71+
}
6672
save();
6773
}
74+
75+
private Object convertValue(Object value) {
76+
if (value == null)
77+
return null;
78+
if (value.getClass() == type) {
79+
return value;
80+
}
81+
if (value instanceof String) {
82+
String s = (String)value;
83+
if (type == int.class) {
84+
return new Integer(Integer.parseInt(s));
85+
}
86+
if (type == double.class) {
87+
return new Double(Double.parseDouble(s));
88+
}
89+
if (type == boolean.class) {
90+
return new Boolean(Boolean.parseBoolean(s));
91+
}
92+
if (type == long.class) {
93+
return new Long(Long.parseLong(s));
94+
}
95+
if (type == short.class) {
96+
return new Short(Short.parseShort(s));
97+
}
98+
}
99+
return value;
100+
}
68101

69102
}

org.rcpml.emf.example/src/org/rcpml/emf/example/synch/EMFSynchronizator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import java.io.File;
44
import java.util.HashMap;
5+
import java.util.Iterator;
56

67
import org.eclipse.core.resources.IFile;
78
import org.eclipse.emf.common.command.BasicCommandStack;
89
import org.eclipse.emf.common.util.URI;
10+
import org.eclipse.emf.ecore.EObject;
911
import org.eclipse.emf.ecore.resource.Resource;
1012
import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
1113
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
@@ -65,6 +67,11 @@ protected Resource getResource() {
6567

6668
public void setInput(IFileEditorInput input) {
6769
updateFile(input);
70+
Iterator it = resource.getContents().iterator();
71+
while (it.hasNext()) {
72+
EObject object = (EObject) it.next();
73+
System.out.println(resource.getURIFragment(object));
74+
}
6875
}
6976

7077
public void fileChanged() {

org.rcpml.swt/src/org/rcpml/swt/AbstractSWTButtonBridge.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.rcpml.swt;
22

3+
import org.eclipse.core.databinding.DataBindingContext;
4+
import org.eclipse.jface.databinding.swt.SWTObservables;
35
import org.eclipse.swt.events.DisposeEvent;
46
import org.eclipse.swt.events.DisposeListener;
57
import org.eclipse.swt.events.SelectionAdapter;
@@ -9,6 +11,9 @@
911
import org.rcpml.core.IController;
1012
import org.rcpml.core.RCPMLTagConstants;
1113
import org.rcpml.core.css.RCPCSSConstants;
14+
import org.rcpml.core.datasource.DataBinding;
15+
import org.rcpml.core.datasource.DataSourceElementContentBinding;
16+
import org.rcpml.swt.databinding.ElementTextObservable;
1217
import org.w3c.dom.Node;
1318

1419
import com.xored.scripting.core.IScriptContextManager;
@@ -20,6 +25,7 @@ public abstract class AbstractSWTButtonBridge extends AbstractSWTBridge {
2025

2126
public static final String TITLE_ATTR = RCPMLTagConstants.TITLE_ATTR;
2227
private static final String ENABLED_ATTR = RCPMLTagConstants.ENABLED_ATTR;
28+
private static final String PATH_ATTR = "path";
2329

2430
protected abstract int getStyle();
2531

@@ -45,7 +51,20 @@ protected void construct( Composite parent ) {
4551

4652
update();
4753

48-
initHandlers();
54+
initHandlers();
55+
56+
DataBindingContext dbc = this.getBindingContext();
57+
58+
dbc.bindValue(SWTObservables.observeSelection(this.fButton), new ElementTextObservable(
59+
getNode()), null, null );
60+
61+
String path = getAttribute(PATH_ATTR);
62+
if (path != null && !path.equals("")) {
63+
getController().bind(new DataBinding(
64+
new DataSourceElementContentBinding(
65+
getNode(), Boolean.class), path));
66+
}
67+
4968
}
5069

5170
protected void initHandlers() {

0 commit comments

Comments
 (0)