Skip to content

Commit 105f8af

Browse files
authored
Merge pull request #3102 from ControlSystemStudio/CSSTUDIO-1704-action-button-widget
Save & restore actions and actions ordering
2 parents b9fcc4c + 3f52a41 commit 105f8af

36 files changed

+1396
-593
lines changed

app/display/actions/src/main/java/org/csstudio/display/actions/OpenFileAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@ public void writeToXML(ModelWriter modelWriter, XMLStreamWriter writer) throws E
7272
writer.writeEndElement();
7373
}
7474

75-
@Override
76-
public boolean matchesAction(String actionId) {
77-
return actionId.equalsIgnoreCase(OPEN_FILE);
78-
}
79-
8075
@Override
8176
public Image getImage() {
8277
return ImageCache.getImage(ActionsDialog.class, "/icons/open_file.png");

app/display/actions/src/main/java/org/csstudio/display/actions/OpenWebPageAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ public void writeToXML(ModelWriter modelWriter, XMLStreamWriter writer) throws E
6060
writer.writeEndElement();
6161
}
6262

63-
@Override
64-
public boolean matchesAction(String actionId) {
65-
return actionId.equalsIgnoreCase(OPEN_WEBPAGE);
66-
}
67-
6863
@Override
6964
public Image getImage() {
7065
return ImageCache.getImage(ActionsDialog.class, "/icons/web_browser.png");

app/display/actions/src/main/java/org/csstudio/display/actions/WritePVAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ public Image getImage() {
8686
return ImageCache.getImage(ActionsDialog.class, "/icons/write_pv.png");
8787
}
8888

89-
@Override
90-
public boolean matchesAction(String actionId) {
91-
return actionId.equalsIgnoreCase(WRITE_PV);
92-
}
93-
9489
public String getPV() {
9590
return pv;
9691
}

app/display/model/src/main/java/org/csstudio/display/builder/model/properties/ActionsWidgetProperty.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void readFromXML(final ModelReader modelReader, final Element propertyXml
8787
// the action type id.
8888
ServiceLoader<ActionInfo> loader = ServiceLoader.load(ActionInfo.class);
8989
Optional<ServiceLoader.Provider<ActionInfo>> optionalActionInfo =
90-
loader.stream().filter(p -> p.get().matchesAction(type)).findFirst();
90+
loader.stream().filter(p -> p.get().getType().equalsIgnoreCase(type) || p.get().matchesAction(type)).findFirst();
9191
if (optionalActionInfo.isPresent()) {
9292
actionInfo = optionalActionInfo.get().get();
9393
} else {

app/display/model/src/main/java/org/csstudio/display/builder/model/spi/ActionInfo.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@
2929
import org.w3c.dom.Element;
3030

3131
import javax.xml.stream.XMLStreamWriter;
32+
import java.util.Comparator;
3233
import java.util.List;
3334

34-
public interface ActionInfo {
35+
public interface ActionInfo extends Comparable<ActionInfo> {
3536

3637
/**
38+
* If action type is not sufficient to determine match, implementations may add additional logic
39+
* to resolve match. For instance: legacy display formats may use a different string to define the action type.
3740
* @param actionId Action id, e.g. open_display.
3841
* @return <code>true</code> if the input string is implemented by the {@link ActionInfo}.
3942
*/
@@ -42,8 +45,7 @@ default boolean matchesAction(String actionId) {
4245
}
4346

4447
/**
45-
* The id/type of action, which is either a fully qualified class name, or a legacy identifier
46-
* string like 'open_display'. Must be unique between all implementations.
48+
* Non-null identifier, must be unique between all implementations.
4749
*
4850
* @return The action 'type'.
4951
*/
@@ -117,4 +119,18 @@ default List<MenuItem> getContextMenuItems(Widget widget) {
117119
* @return The {@link ActionInfo} object with committed values.
118120
*/
119121
ActionInfo commit();
122+
123+
/**
124+
* Comparator for the sake of sorting {@link ActionInfo}s. Uses {@link ActionInfo#getDescription()}.
125+
* @param other the object to be compared.
126+
* @return Any occurrence of <code>null</code> in the {@link ActionInfo#getDescription()}
127+
* fields will return 0. Otherwise, comparison of {@link ActionInfo#getDescription()}.
128+
*/
129+
@Override
130+
default int compareTo(ActionInfo other){
131+
if(getDescription() == null || other.getDescription() == null){
132+
return 0;
133+
}
134+
return getDescription().compareTo(other.getDescription());
135+
}
120136
}

app/display/representation-javafx/src/main/java/org/csstudio/display/builder/representation/javafx/actionsdialog/ActionsDialogController.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import static org.csstudio.display.builder.representation.ToolkitRepresentation.logger;
2222

23+
import java.util.Comparator;
24+
import java.util.List;
2325
import java.util.ServiceLoader;
2426
import java.util.logging.Level;
2527
import java.util.stream.Collectors;
@@ -103,7 +105,7 @@ protected void updateItem(final ActionsDialogActionItem actionsDialogActionItem,
103105
logger.log(Level.WARNING, "Error displaying " + actionsDialogActionItem, ex);
104106
}
105107
}
106-
};
108+
}
107109

108110
/** Initialize */
109111
@FXML
@@ -116,7 +118,10 @@ public void initialize() {
116118

117119
ServiceLoader<ActionInfo> actionInfos = ServiceLoader.load(ActionInfo.class);
118120

119-
for (ActionInfo actionInfo : actionInfos)
121+
// Order actions, see ActionInfo#compareTo
122+
List<ActionInfo> sortedActionInfos = actionInfos.stream().map(p -> p.get()).sorted().toList();
123+
124+
for (ActionInfo actionInfo : sortedActionInfos)
120125
{
121126
final ImageView icon = new ImageView(actionInfo.getImage());
122127
final MenuItem item = new MenuItem(actionInfo.toString(), icon);
36.7 KB
Loading
168 KB
Loading
37.1 KB
Loading

app/save-and-restore/app/doc/index.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,12 @@ The search result table of the Search And Filter view also supports a contect me
384384

385385
.. image:: images/search-result-context-menu.png
386386

387+
Invoke a restore operation from search result
388+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
389+
390+
Snapshot and composite snapshot items in the search result table support an additional context menu item users can
391+
choose in order to perform a restore operation.
392+
387393
Snapshot View Context Menu
388394
--------------------------
389395

@@ -416,4 +422,36 @@ Authorization uses a role-based approach like so:
416422

417423
Roles are defined and managed on the service. Role (group) membership is managed in Active Directory or LDAP.
418424

425+
Integration with the Display Builder application
426+
------------------------------------------------
427+
428+
It is possible to configure Display Builder actions to interact with the Save-And-Restore application. Such actions are available as either items
429+
in the context menu of a Display Builder widget, or actions associated with an Action Button widget, or both.
430+
431+
When Save-And-Restore actions are executed, the application is launched or put in focus. The following action types
432+
are supported:
433+
434+
* | Open a configuration, snapshot or composite snapshot node in the Save-And-Restore application.
435+
| This can be used to quickly access a particular node in order to invoke a restore operation.
436+
* | Open a named filter in the Save-And-Restore application.
437+
| This will open/show the search and filter view and automatically perform the search associated with the named filter.
438+
| This feature can be used to quickly navigate from a Display Builder screen to a view containing a set of commonly used snapshots.
439+
440+
Configuring actions
441+
^^^^^^^^^^^^^^^^^^^
442+
443+
When configuring an action in the Display Builder editor, supported actions are available from a list:
444+
445+
.. image:: images/select_action.png
446+
:width: 70%
447+
448+
For the open node action, user may either paste the unique id of a node into the input field, or launch a
449+
browser to select a node:
450+
451+
.. image:: images/open_node.png
452+
:width: 70%
453+
454+
For the open filter action, user can select from a drop-down list showing existing named filters:
419455

456+
.. image:: images/open_filter.png
457+
:width: 70%

0 commit comments

Comments
 (0)