Skip to content

Commit

Permalink
Example project improvements to use a template
Browse files Browse the repository at this point in the history
  • Loading branch information
davetcc committed Nov 28, 2024
1 parent c385cda commit 4d62aad
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.thecoderscorner.menu.devicedemo;

import com.thecoderscorner.embedcontrol.core.util.TcApiDefinitions;
import com.thecoderscorner.menu.mgr.MenuInMenu;
import com.thecoderscorner.menu.mgr.MenuManagerServer;
import com.thecoderscorner.menu.persist.MenuStateSerialiser;
Expand Down Expand Up @@ -39,8 +40,9 @@ public void start() {
Runtime.getRuntime().addShutdownHook(new Thread(serializer::saveMenuStates));
// the controller receives updates and things happen on the menu, we register it here.
manager.addMenuManagerListener(context.getBean(EmbeddedJavaDemoController.class));
// See the method for more information.
buildMenuInMenuComponents();
// get the api definitions and start any menu in menu components
var apiDefinitions = context.getBean(TcApiDefinitions.class);
apiDefinitions.configureMenuInMenuComponents(context);

// Give the Local UI access to teh context
JfxLocalAutoUI.setAppContext(context);
Expand All @@ -55,19 +57,4 @@ public void start() {
public static void main(String[] args) {
new EmbeddedJavaDemoApp().start();
}

///
/// here we demonstrate how to include menu in menu components. You can use tcMenu Designer to generate the menu in
/// menu components and add them here, it can build the entire method for you from `Code -> Menu In Menu`
///
public void buildMenuInMenuComponents() {
MenuManagerServer menuManager = context.getBean(MenuManagerServer.class);
MenuCommandProtocol protocol = context.getBean(MenuCommandProtocol.class);
ScheduledExecutorService executor = context.getBean(ScheduledExecutorService.class);
LocalIdentifier localId = new LocalIdentifier(menuManager.getServerUuid(), menuManager.getServerName());
var remMenuAvrBoardConnector = new SocketBasedConnector(localId, executor, Clock.systemUTC(), protocol, "192.168.0.96", 3333, ConnectMode.FULLY_AUTHENTICATED, null);
var remMenuAvrBoard = new MenuInMenu(remMenuAvrBoardConnector, menuManager, menuManager.getManagedMenu().getMenuById(16).orElseThrow(), MenuInMenu.ReplicationMode.REPLICATE_ADD_STATUS_ITEM, 100000, 65000);
remMenuAvrBoard.start();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.thecoderscorner.menu.devicedemo;

import com.thecoderscorner.embedcontrol.core.util.BaseMenuConfig;
import com.thecoderscorner.embedcontrol.core.util.TcApiDefinitions;
import com.thecoderscorner.menu.domain.*;
import com.thecoderscorner.menu.domain.state.MenuTree;
import com.thecoderscorner.menu.persist.JsonMenuItemSerializer;
Expand All @@ -17,7 +19,7 @@
* boolean, text items, etc. Each item in the menu is defined in the APP_MENU_ITEMS string
* in JSON format, which is then deserialized and loaded into a MenuTree object.
*/
public class EmbeddedJavaDemoMenu {
public class EmbeddedJavaDemoMenu implements TcApiDefinitions {
private final static String APP_MENU_ITEMS = """
tcMenuCopy:[
{
Expand Down Expand Up @@ -278,6 +280,11 @@ public MenuTree getMenuTree() {
return menuTree;
}

@Override
public void configureMenuInMenuComponents(BaseMenuConfig config) {

}

public JsonMenuItemSerializer getJsonSerializer() {
return jsonSerializer;
}
Expand Down Expand Up @@ -343,5 +350,5 @@ public RuntimeListMenuItem getStatusMyListItem() {
public SubMenuItem getAVRBoard() {
return (SubMenuItem) menuTree.getMenuById(16).orElseThrow();
}

// end of menu accessors
}

0 comments on commit 4d62aad

Please sign in to comment.