WGADesign wgaDesign = (WGADesign) design;
// create new folder and dirlink in design-root
try {
registerExternalDesign(wgaDesign);
} catch (IOException e) {
throw new CoreException(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "Unable to register external design.", e));
}
}
if (createdb) {
IContainer container = null;
if (design instanceof WGADesign) {
container = ((WGADesign) design).getProject();
} else {
container = (IFolder) design;
}
WGAConfiguration wgaConfig = null;
try {
wgaConfig = retrieveWGAConfig(true);
} catch (IncompatibleWGAConfigVersion e) {
MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Warning",
"Unable to register design in runtime. WGA Version seams to be incompatible. Please ensure you are using the latest version of WGADevelopmentStudio.");
WGADesignerPlugin.getDefault().logError(e.getMessage(), e);
} catch (IOException e) {
throw new CoreException(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "Unable to create default wga configuration.", e));
}
if (wgaConfig != null) {
if (dbkey == null) {
dbkey = container.getName();
}
dbkey = dbkey.toLowerCase();
if (title == null) {
title = container.getName();
}
if (domain == null) {
domain = wgaConfig.getDefaultDomain();
}
// check if db already exists
boolean csExists = wgaConfig.hasContentDatabase(dbkey);
if (csExists) {
throw new CoreException(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "A database with key '" + dbkey + "' already exists."));
} else {
int existingDbs = wgaConfig.getContentDatabases().size();
ContentStore cs = wgaConfig.createContentStoreOnEmbeddedServer(dbkey, container.getName());
cs.setDomain(domain.getUid());
cs.setTitle(title);
if (properties != null) {
cs.setDefaultLanguage(properties.getProperty(DesignTemplate.PROP_DEFAULT_LANGUAGE, Locale.getDefault().getLanguage()));
} else {
cs.setDefaultLanguage(Locale.getDefault().getLanguage());
}
// if this is the first autocreated db - make it the default
// db
if (wgaConfig.getDefaultDatabase() == null && existingDbs == 0) {
wgaConfig.setDefaultDatabase(cs.getKey());
}
}
try {
saveWGAConfig(wgaConfig);
} catch (Exception e) {
throw new CoreException(new Status(Status.ERROR, WGADesignerPlugin.PLUGIN_ID, "Unable to update wga configfile.", e));
}
}
}
}