Skip to content

Commit

Permalink
Adding properties QoS and Retained to Switch
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianromero committed Jul 22, 2019
1 parent 0c741c0 commit ac73445
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/main/java/com/adr/helloiot/topicinfo/TopicInfoSwitch.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class TopicInfoSwitch implements TopicInfo {
private String topicpub = null;
private String icon = "TOGGLE";
private Color color;
protected int qos = 0;
protected boolean retained = true;

public TopicInfoSwitch(TopicInfoFactory factory, TopicInfoSwitchNode editnode) {
this.factory = factory;
Expand All @@ -67,6 +69,8 @@ public void load(SubProperties properties) {
icon = properties.getProperty(".icon", "TOGGLE");
String c = properties.getProperty(".color", null);
color = c == null ? null : Color.valueOf(c);
qos = Integer.parseInt(properties.getProperty(".qos", "0"));
retained = Boolean.parseBoolean(properties.getProperty(".retained", "true"));
}

@Override
Expand All @@ -77,15 +81,17 @@ public void store(SubProperties properties) {
properties.setProperty(".topicpub", topicpub);
properties.setProperty(".icon", icon);
properties.setProperty(".color", color == null ? null : color.toString());
properties.setProperty(".qos", Integer.toString(qos));
properties.setProperty(".retained", Boolean.toString(retained));
}

@Override
public DevicesUnits getDevicesUnits() throws HelloIoTException {
DeviceSwitch l = new DeviceSwitch();
l.setTopic(topic);
l.setTopicPublish(topicpub);
MQTTProperty.setQos(l, 0);
MQTTProperty.setRetained(l, false);
MQTTProperty.setQos(l, qos);
MQTTProperty.setRetained(l, retained);

ButtonSimple s = new ButtonSimple();
s.setText(getLabel().getValue());
Expand Down Expand Up @@ -114,6 +120,8 @@ public void writeToEditNode() {
editnode.edittopicpub.setText(topicpub);
editnode.editicon.setValue(icon);
editnode.editcolor.setValue(color);
editnode.editqos.setValue(qos);
editnode.editretained.setValue(retained);
}

@Override
Expand All @@ -124,6 +132,8 @@ public void readFromEditNode() {
topicpub = editnode.edittopicpub.getText() == null || editnode.edittopicpub.getText().isEmpty() ? null : editnode.edittopicpub.getText();
icon = editnode.editicon.getValue();
color = editnode.editcolor.getValue();
qos = editnode.editqos.getValue();
retained = editnode.editretained.getValue();
}

private String webColor(Color color) {
Expand Down
42 changes: 42 additions & 0 deletions src/main/java/com/adr/helloiot/topicinfo/TopicInfoSwitchNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.adr.fonticon.IconBuilder;
import com.adr.fonticon.IconFontGlyph;
import com.adr.helloiot.util.FXMLNames;
import java.util.ResourceBundle;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
Expand All @@ -33,11 +34,14 @@
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.util.StringConverter;

public class TopicInfoSwitchNode implements TopicInfoNode {

Runnable updatecurrent = null;

@FXML
private ResourceBundle resources;
@FXML
private GridPane container;
@FXML
Expand All @@ -54,6 +58,10 @@ public class TopicInfoSwitchNode implements TopicInfoNode {
public TextField edittopic;
@FXML
public TextField edittopicpub;
@FXML
public ChoiceBox<Integer> editqos;
@FXML
public ChoiceBox<Boolean> editretained;

public TopicInfoSwitchNode() {
FXMLNames.load(this, "com/adr/helloiot/fxml/topicinfoswitchnode");
Expand Down Expand Up @@ -93,6 +101,40 @@ public void initialize() {
editcolor.valueProperty().addListener((ObservableValue<? extends Color> observable, Color oldValue, Color newValue) -> {
updateCurrent();
});

editqos.setConverter(new StringConverter<Integer>() {
@Override
public String toString(Integer object) {
return object.toString();
}

@Override
public Integer fromString(String string) {
return Integer.parseInt(string);
}
});
editqos.setItems(FXCollections.observableArrayList(0, 1, 2));
editqos.getSelectionModel().clearSelection();
editqos.valueProperty().addListener((ObservableValue<? extends Integer> ov, Integer old_val, Integer new_val) -> {
updateCurrent();
});

editretained.setConverter(new StringConverter<Boolean>() {
@Override
public String toString(Boolean object) {
return resources.getString(object ? "label.yes" : "label.no");
}

@Override
public Boolean fromString(String value) {
return Boolean.parseBoolean(value);
}
});
editretained.setItems(FXCollections.observableArrayList(false, true));
editretained.getSelectionModel().clearSelection();
editretained.valueProperty().addListener((ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) -> {
updateCurrent();
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<RowConstraints minHeight="30.0" prefHeight="30.0" />
<RowConstraints minHeight="30.0" prefHeight="30.0" />
<RowConstraints minHeight="30.0" prefHeight="30.0" />
<RowConstraints />
<RowConstraints minHeight="30.0" prefHeight="30.0" />
<RowConstraints minHeight="30.0" prefHeight="30.0" />
</rowConstraints>
<children>
<Label styleClass="unitlabel" text="%label.name" />
Expand All @@ -40,6 +43,11 @@
<Label styleClass="unitlabel" text="%label.color" GridPane.rowIndex="5" />
<ColorPicker fx:id="editcolor" maxWidth="1.7976931348623157E308" styleClass="unitinput" GridPane.columnIndex="1" GridPane.rowIndex="5" />
<Button fx:id="clearcolor" mnemonicParsing="false" onAction="#onClearColor" styleClass="unitbutton" GridPane.columnIndex="2" GridPane.rowIndex="5" />
<Label maxWidth="1.7976931348623157E308" styleClass="unitsection" text="%label.extendedproperties" GridPane.columnSpan="2147483647" GridPane.rowIndex="6" />
<Label styleClass="unitlabel" text="%label.qos" GridPane.rowIndex="7" />
<ChoiceBox fx:id="editqos" maxWidth="1.7976931348623157E308" styleClass="unitinput" GridPane.columnIndex="1" GridPane.rowIndex="7" />
<Label styleClass="unitlabel" text="%label.retained" GridPane.rowIndex="8" />
<ChoiceBox fx:id="editretained" maxWidth="1.7976931348623157E308" styleClass="unitinput" GridPane.columnIndex="1" GridPane.rowIndex="8" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with HelloIot. If not, see <http://www.gnu.org/licenses/>.
#
label.no=No
label.yes=Yes

label.topic = Topic
label.topicpub = Topic (pub)
Expand All @@ -24,3 +26,6 @@ label.page = Page
label.icon = Icon
label.color = Color

label.extendedproperties = Extended properties
label.qos = QoS
label.retained = Retained
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# You should have received a copy of the GNU General Public License
# along with HelloIot. If not, see <http://www.gnu.org/licenses/>.
#
label.no=No
label.yes=S\u00ed

label.topic = Tema
label.topicpub = Tema (pub)
Expand All @@ -24,4 +26,6 @@ label.page = P\u00e1gina
label.icon = Icono
label.color = Color


label.extendedproperties = Otras propiedades
label.qos = QoS
label.retained = Guardar
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<RowConstraints minHeight="30.0" prefHeight="30.0" />
<RowConstraints />
<RowConstraints minHeight="30.0" prefHeight="30.0" />
<RowConstraints />
<RowConstraints />
<RowConstraints minHeight="30.0" prefHeight="30.0" />
<RowConstraints />
<RowConstraints minHeight="30.0" prefHeight="30.0" />
</rowConstraints>
<children>
<Label styleClass="unitlabel" text="%label.name" />
Expand All @@ -48,6 +53,11 @@
<Button fx:id="clearcolor" mnemonicParsing="false" onAction="#onClearColor" styleClass="unitbutton" />
</children>
</HBox>
<Label maxWidth="1.7976931348623157E308" styleClass="unitsection" text="%label.extendedproperties" GridPane.rowIndex="12" />
<Label styleClass="unitlabel" text="%label.qos" GridPane.rowIndex="13" />
<ChoiceBox fx:id="editqos" maxWidth="1.7976931348623157E308" styleClass="unitinput" GridPane.rowIndex="14" />
<Label styleClass="unitlabel" text="%label.retained" GridPane.rowIndex="15" />
<ChoiceBox fx:id="editretained" maxWidth="1.7976931348623157E308" styleClass="unitinput" GridPane.rowIndex="16" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
Expand Down

0 comments on commit ac73445

Please sign in to comment.