Starting application with an initial part displayed [message #1231503] |
Tue, 14 January 2014 20:53 |
Joseph Gagnon Messages: 68 Registered: June 2013 |
Member |
|
|
I'm developing an E4 application which consists of a TrimmedWindow with a menu and part stack. The part stack currently has no content and a part is added to the stack based upon a menu choice. The menu command/handler calls a controller which configures a part and adds it to the part stack. This has been working very well so far.
One thing to note, however, is that app window initially comes up empty (no parts) and the user must select a menu choice to populate the window with a part. I want to set it up so that when the app is opened, a specific part (with a specific configuration) will be opened automatically by default. I'm not sure of the correct way to do that in the context of how I'm currently managing my parts.
Code exmaples follow that show some of what I'm doing.
The handler associated with the command attached to the menu choice to configure a "monitor" part to display inbound and outbound message traffic: (The is the configuration I'd like to have come up automatically when the app opens.)
public class MonitorBothHandler {
@Execute
public void execute(MessageMonitorController controller) {
controller.configureUI(MessageMonitorPart.ConfigType.BOTH);
}
}
The part controller class:
@Creatable
public class MessageMonitorController extends AbstractController {
@Inject
private MApplication application;
@Inject
private EModelService modelService;
@Inject
private EPartService partService;
public void configureUI(ConfigType configType) {
MPartStack container = (MPartStack) modelService.find("edu.mit.ll.s4.mp.partstack.stack", application);
MPart monitorPart = (MPart) modelService.find("edu.mit.ll.s4.mp.app.part.messagemonitor", application);
if (monitorPart != null) {
partService.hidePart(monitorPart);
}
monitorPart = modelService.createModelElement(MPart.class);
monitorPart.setElementId("edu.mit.ll.s4.mp.app.part.messagemonitor");
monitorPart
.setContributionURI("bundleclass://edu.mit.ll.s4.app/edu.mit.ll.s4.mp.ui.MessageMonitorPart");
monitorPart.setCloseable(true);
monitorPart.setLabel("Monitor Messages");
monitorPart.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
monitorPart.getTransientData().put(MessageMonitorPart.CONFIG_TYPE, configType);
container.getChildren().add(monitorPart);
partService.activate(monitorPart);
}
}
The controller code attempts to locate an existing part and if found, I basically am trying to replace the current part with another of the same type, but configured differently. If anyone has suggestions on a better way to do this, please let me know.
The "monitor" part class:
public class MessageMonitorPart {
public enum ConfigType {
INCOMING, OUTGOING, BOTH, SEQUENTIAL
}
public static final String CONFIG_TYPE = "configType";
@Inject
private MPart part;
@Inject
private MessageMonitorModel model;
private ConfigType configType;
private MessagePane[] msgPane;
public MessageMonitorPart() {
}
@PostConstruct
public void init(BorderPane parent) {
configType = (ConfigType) part.getTransientData().get(CONFIG_TYPE);
parent.setPadding(new Insets(5));
parent.setCenter(configMessagePane());
model.configure(configType);
bindControls();
}
private Node configMessagePane() {
BorderPane pane = new BorderPane();
if (configType == ConfigType.BOTH) {
SplitPane sp = new SplitPane();
sp.setOrientation(Orientation.VERTICAL);
msgPane = new MessagePane[2];
BorderPane p1 = new BorderPane();
p1.setTop(createTitlePane("Incoming"));
msgPane[0] = new MessagePane();
p1.setCenter(msgPane[0]);
sp.getItems().add(p1);
BorderPane p2 = new BorderPane();
p2.setTop(createTitlePane("Outgoing"));
msgPane[1] = new MessagePane();
p2.setCenter(msgPane[1]);
sp.getItems().add(p2);
pane.setCenter(sp);
} else {
String title = null;
switch (configType) {
case INCOMING:
title = "Incoming";
break;
case OUTGOING:
title = "Outgoing";
break;
case SEQUENTIAL:
title = "Sequential";
break;
default:
break;
}
BorderPane p1 = new BorderPane();
p1.setTop(createTitlePane(title));
msgPane = new MessagePane[1];
msgPane[0] = new MessagePane();
p1.setCenter(msgPane[0]);
pane.setCenter(p1);
}
return pane;
}
private Node createTitlePane(String title) {
FlowPane pane = new FlowPane();
pane.setPadding(new Insets(5));
Label titleLabel = new Label(title);
titleLabel.getStyleClass().add("message-pane-title");
pane.getChildren().add(titleLabel);
return pane;
}
private void bindControls() {
switch (configType) {
case BOTH:
msgPane[0].bindControls(model.getMessage(0));
msgPane[1].bindControls(model.getMessage(1));
break;
case INCOMING:
case OUTGOING:
case SEQUENTIAL:
msgPane[0].bindControls(model.getMessage(0));
break;
default:
break;
}
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03271 seconds