public class GenerateSQLAction extends EMAction {
public void run(IAction action) {
try {
IStructuredSelection selection = getSelection();
if (selection != null) {
EOModel model = null;
boolean modelSelected = false;
List<String> entityNames = new LinkedList<String>();
Iterator selectionIter = selection.iterator();
while (!modelSelected && selectionIter.hasNext()) {
Object obj = selectionIter.next();
EOEntity entity = EOModelUtils.getRelatedEntity(obj);
if (entity != null) {
model = entity.getModel();
entityNames.add(entity.getName());
} else {
model = EOModelUtils.getRelatedModel(obj);
if (model != null) {
modelSelected = true;
}
}
}
if (modelSelected) {
entityNames = null;
}
if (model != null) {
if (model.isDirty()) {
MessageDialog.openWarning(getWindow().getShell(), "Model Not Saved", "Your model has unsaved changes. Unsaved changes will not be reflected in generated SQL.");
}
GenerateSQLDialog dialog = new GenerateSQLDialog(getWindow().getShell(), model, entityNames);
dialog.open();
}