Skip to content

Commit 0291117

Browse files
committed
add automatic snapshot name functionnality
1 parent 5a03004 commit 0291117

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/Preferences.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ public class Preferences {
3232
public static int search_result_page_size;
3333
@Preference
3434
public static String default_search_query;
35+
@Preference
36+
public static String default_title_snapshot_configuration;
37+
@Preference
38+
public static String default_title_snapshot_format;
39+
@Preference
40+
public static String default_title_snapshot_date_format;
41+
@Preference
42+
public static String default_title_snapshot_pv1;
43+
@Preference
44+
public static String default_title_snapshot_pv2;
3545

3646
static
3747
{

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/snapshot/SnapshotController.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
import org.phoebus.ui.dialog.DialogHelper;
6868
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
6969

70+
import java.text.SimpleDateFormat;
7071
import java.util.ArrayList;
7172
import java.util.Arrays;
73+
import java.util.Date;
7274
import java.util.HashMap;
7375
import java.util.LinkedHashMap;
7476
import java.util.List;
@@ -265,6 +267,40 @@ public void newSnapshot(Node configurationNode) {
265267
});
266268
});
267269
}
270+
271+
public String getValueVType(String pvEntry, List<SnapshotItem> entries){
272+
String valueOutput ="";
273+
274+
System.out.println("length "+entries.size());
275+
for (SnapshotItem e : entries) {
276+
System.out.println("name "+e.getConfigPv().getPvName());
277+
if (e.getConfigPv().getPvName().equals(pvEntry)){
278+
VType newValue=e.getValue();
279+
if (newValue instanceof VNumber) {
280+
Number newVType = ((VNumber) newValue).getValue();
281+
valueOutput=newVType.toString();
282+
System.out.println("VNumber "+valueOutput);
283+
return valueOutput;
284+
} else if (newValue instanceof VString) {
285+
String newVType = ((VString) newValue).getValue();
286+
valueOutput=newVType.toString();
287+
System.out.println("VString "+valueOutput);
288+
return valueOutput;
289+
} else if (newValue instanceof VStringArray) {
290+
List<String> newVType =((VStringArray) newValue).getData();
291+
valueOutput=newVType.toString();
292+
System.out.println("VStringArray "+valueOutput);
293+
return valueOutput;
294+
} else if (newValue instanceof VEnum) {
295+
VEnum newVType = (VEnum) newValue;
296+
valueOutput=newVType.getValue().toString();
297+
System.out.println("VEnum "+valueOutput);
298+
return valueOutput;
299+
}
300+
}
301+
}
302+
return valueOutput;
303+
}
268304

269305
@FXML
270306
@SuppressWarnings("unused")
@@ -286,6 +322,37 @@ private void takeSnapshot() {
286322
snapshots.set(0, snapshot);
287323
List<TableEntry> tableEntries = createTableEntries(snapshots.get(0));
288324
snapshotTable.updateTable(tableEntries, snapshots, showLiveReadbackProperty.get(), false, showDeltaPercentage);
325+
326+
SimpleDateFormat formater = null;
327+
Date now = new Date();
328+
formater = new SimpleDateFormat("yy-MM-dd");
329+
String defaultTitle="";
330+
if (!Preferences.default_title_snapshot_format.equals("")) {
331+
String[] formatTitle=Preferences.default_title_snapshot_format.split("_");
332+
for (int index = 0; index < formatTitle.length; index++) {
333+
switch (formatTitle[index]) {
334+
case "<date>":
335+
if (!Preferences.default_title_snapshot_date_format.equals("")){
336+
formater = new SimpleDateFormat(Preferences.default_title_snapshot_date_format);
337+
defaultTitle+=defaultTitle+formater.format(now);
338+
}
339+
break;
340+
case "<pv1>":
341+
defaultTitle+=getValueVType(Preferences.default_title_snapshot_pv1,entries);
342+
break;
343+
case "<pv2>":
344+
defaultTitle+=getValueVType(Preferences.default_title_snapshot_pv2,entries);
345+
break;
346+
default:
347+
System.out.println("nothing");
348+
break;
349+
}
350+
if (index<formatTitle.length-1)
351+
defaultTitle+="_";
352+
}
353+
}
354+
snapshotNameProperty.set(defaultTitle);
355+
289356
})
290357
);
291358
}

0 commit comments

Comments
 (0)