Skip to content

Commit

Permalink
Add data(key, value) method to widget factories. (eclipse-platform#1403)
Browse files Browse the repository at this point in the history
* Add data(key, value) method to widget factories.

Issues: eclipse-platform#1399

* Update bundles/org.eclipse.jface/src/org/eclipse/jface/widgets/AbstractWidgetFactory.java

Co-authored-by: Matthias Becker <[email protected]>

---------

Co-authored-by: Matthias Becker <[email protected]>
  • Loading branch information
marcushoepfner and BeckerWdf authored Dec 13, 2023
1 parent ec32609 commit a7df241
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,21 @@ public F data(Object data) {
addProperty(b -> b.setData(data));
return cast(this);
}

/**
* Sets the application defined property of the receiver with the specified name
* to the given value.
*
* @param key the name of the property
* @param value the new value for the property
* @return this
*
* @see Widget#setData(String, Object)
*
* @since 3.33
*/
public F data(String key, Object value) {
addProperty(b -> b.setData(key, value));
return cast(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,14 @@ public void setsData() {

assertEquals(data, testLabel.getData());
}

@Test
public void setsDataWithKey() {
String data1 = "data1";
String data2 = "data2";
Label testLabel = LabelFactory.newLabel(SWT.NONE).data("id1", data1).data("id2", data2).create(shell);

assertEquals(data1, testLabel.getData("id1"));
assertEquals(data2, testLabel.getData("id2"));
}
}

0 comments on commit a7df241

Please sign in to comment.