@Override
public void runWithEvent(Event event) {
logger.info("Executing 'create object instance' action: " + event);
ObjectInstance oi = objectInstanceFactory.createObjectInstance(campaign, false);
logger.trace("oi: " + oi);
try {
// if there is no campaign assigned, then ask the user for one
if(campaign == null) {
logger.info("No campaign is set on object template; requesting one from user.");
CampaignChooserDialog ccd = (CampaignChooserDialog)appContext.getBean("campaignChooserDialog",
new Object[] { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell() });
int rc = ccd.open();
logger.trace("rc: " + rc);
if(rc == IDialogConstants.YES_ID) {
oi.setCampaign(ccd.getCampaign());
}
else {
logger.info("Campaign chooser dialog was canceled; aborting object instance build.");
return;
}
}
// create a dialog to get information from the user
IObjectInstanceBuilderDialog dialog = (IObjectInstanceBuilderDialog)appContext.getBean(
"objectInstanceBuilderDialog", new Object[] {
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), oi });
objectInstanceBuilder.setObjectInstanceBuilderDialog(dialog);
if(!objectInstanceBuilder.buildObjectInstance(oi)) {
logger.warn("Object instance build was incomplete; see previous log entries for details.");
alertService.addAlert(new Alert(Alert.Type.INFO, this.getClass().getSimpleName(), Messages
.getString("campaign.manager.actions.object_instance.create.error.build_incomplete.text")));
return;
}
}
catch(ObjectBuilderException e) {
logger.error("Exception while trying to build object instance: " + e.getLocalizedMessage(), e);
alertService
.addAlert(new Alert(Alert.Type.ERROR, this.getClass().getSimpleName(), e.getLocalizedMessage()));
return;
}
campaign.addObjectInstance(oi);
// save the object instance and the campaign
try {
oi.save();
campaign.save();
}
catch(Exception e) {
logger.error("Exception while trying to save object instance: " + e.getLocalizedMessage(), e);