MessageHandler.error("State container has no container!");
return;
}
// Open a dialog to get the refinement name and class.
Query query = new Query();
String defaultName = container.uniqueName(state.getName());
query.addLine("Name", "Name", defaultName);
// See whether the configuration offers state refinements.
Configuration configuration = ((FSMGraphController) getController())
.getConfiguration();
Entity refinements = configuration.getEntity("_stateRefinements");
// Default choices.
String[] choiceClasses = { "ptolemy.domains.fsm.modal.Refinement",
"ptolemy.domains.fsm.modal.ModalController" };
String[] choiceNames = { "Default Refinement",
"State Machine Refinement" };
// Check the configuration to see whether the default is overridden.
if (refinements instanceof CompositeEntity) {
// There is a specification.
List refinementList = ((CompositeEntity) refinements)
.entityList();
choiceNames = new String[refinementList.size()];
choiceClasses = new String[refinementList.size()];
Iterator iterator = refinementList.iterator();
int count = 0;
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
choiceNames[count] = entity.getName();
choiceClasses[count++] = entity.getClass().getName();
}
}
query
.addChoice("Class", "Class", choiceNames, choiceNames[0],
true);
// FIXME: Need a frame owner for first arg.
// Perhaps calling getController(), which returns a GraphController
// will be a good start.
ComponentDialog dialog = new ComponentDialog(null,
"Specify Refinement", query);
if (!dialog.buttonPressed().equals("OK")) {
return;
}
final String newName = query.getStringValue("Name");
if (container.getEntity(newName) != null) {
MessageHandler.error("There is already a refinement with name "
+ newName + ".");
return;
}
int choiceIndex = query.getIntValue("Class");
String newClass = choiceClasses[choiceIndex];
String currentRefinements = state.refinementName.getExpression();
if ((currentRefinements == null) || currentRefinements.equals("")) {