blob: 74453f15989dc50ae3570e30b75bab0100fd0120 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.wizard.ui;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.osbp.preferences.DataSourceConfiguration;
import org.eclipse.osbp.preferences.ProductConfiguration;
import org.eclipse.osbp.preferences.ProductConfigurationPrefs;
import org.eclipse.osbp.wizard.ui.allinonedsl.AllInOneDSLsNewProjectConfigurationPage;
import org.eclipse.osbp.wizard.ui.allinonedsl.AllInOneDSLsNewProjectDataSourcesPage;
import org.eclipse.osbp.wizard.ui.allinonedsl.AllInOneDSLsNewProjectEclipsePage;
import org.eclipse.osbp.wizard.ui.allinonedsl.AllInOneDSLsNewProjectMockDataPage;
import org.eclipse.osbp.wizard.ui.allinonedsl.AllInOneDSLsNewProjectRuntimePage;
import org.eclipse.osbp.wizard.ui.basic.BasicNewProjectWizard;
import org.eclipse.osbp.wizard.ui.basic.BasicProjectInfo;
import org.eclipse.osbp.wizard.ui.basic.CommonProjectWizardTranslator;
import org.eclipse.osbp.wizard.ui.basic.CommonProjectWizardType;
import org.eclipse.osbp.wizard.ui.basic.MockDataGenerateType;
import org.eclipse.osbp.wizard.ui.product.ProductProjectCreator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;
import org.eclipse.xtext.ui.wizard.IProjectInfo;
import com.google.inject.Inject;
/**
* New general OSBP App Wizard.
*/
public class AllInOneDSLsNewProjectWizard extends BasicNewProjectWizard {
@Inject
public AllInOneDSLsNewProjectWizard() {
super(new ProductProjectCreator(), CommonProjectWizardTranslator.instance());
projectInfo = new BasicProjectInfo(CommonProjectWizardType.AllInOneDSLs);
getCreator().setProjectInfo(projectInfo);
setWindowTitle(translator.getDocumentation(this,"titleWindow"));
projectInfo.setDataSourceForAuthentication(ProductConfigurationPrefs.DEFAULT_DERBYLOCALFILE_DATASOURCE);
projectInfo.setDataSourceForBLOB(ProductConfigurationPrefs.DEFAULT_DERBYLOCALFILE_DATASOURCE);
projectInfo.setDataSourceForBPM(ProductConfigurationPrefs.DEFAULT_DERBYLOCALFILE_DATASOURCE);
projectInfo.setDataSourceForBusinessData(ProductConfigurationPrefs.DEFAULT_DERBYLOCALFILE_DATASOURCE);
}
@Override
public void addPages() {
addPage(new AllInOneDSLsNewProjectConfigurationPage(this, "titleConfigurationPage"));
addPage(new AllInOneDSLsNewProjectDataSourcesPage(this, "titleDataSourcesPage", true));
addPage(new AllInOneDSLsNewProjectMockDataPage(this, "titleMockDataPage", true));
addPage(new AllInOneDSLsNewProjectEclipsePage(this, "titleEclipsePage"));
addPage(new AllInOneDSLsNewProjectRuntimePage(this, "titleRuntimePage"));
}
/** select the data source, which should be generally used */
public Combo dataSourceForGeneral;
/** select the specific data source for authentication */
public Combo dataSourceForAuthentication;
/** select the specific data source for blobs */
public Combo dataSourceForBLOB;
/** select the specific data source for the bpm engine */
public Combo dataSourceForBPM;
/** select the specific data source for the business data */
public Combo dataSourceForBusinessData;
/** select the mock generate type, which should be generally used */
public Combo mockGeneralGenerateType;
/** select the mock generate type for business data */
public Combo mockProductDataGenerateType;
/** select the mock generate type for authentication data */
public Combo mockAuthenticationDataGenerateType;
/** select the mock generate type for blob data */
public Combo mockBlobDataGenerateType;
/** select the vaaclipse theme */
public Combo vaaclipseTheme;
/** input the port of the web app generated */
public Text productPortNo;
/** full qualified url for the desktop variant of the application created */
public Text productDesktopUrlPath;
/** full qualified url for the mobile variant of the application created */
public Text productMobileUrlPath;
/** clickable link for the desktop variant of the application created */
public Link productLocalDesktopLink;
/** clickable link for the mobile variant of the application created */
public Link productLocalMobileLink;
/** XMS Size to the used for the application */
public Text xmsSize;
/** XMX Size to the used for the application */
public Text xmxSize;
/** the last selected data source */
private String lastDataSource = "";
@Override
protected IProjectInfo getProjectInfo() {
return projectInfo;
}
/**
* Leave this handler intact, even when it's not used right now!
*/
protected Listener companyDomainChanges = new Listener() {
public void handleEvent(Event e) {
//databaseSchema.setText(StringUtils.stripAccents(companyDomain.getText().trim().toUpperCase().replace(" ", BasicProjectInfo.REPLACING).replace("-", BasicProjectInfo.REPLACING)));
}
};
/**
* Leave this handler intact, even when it's not used right now!
*/
protected Listener businessBundleChanges = new Listener() {
public void handleEvent(Event e) {
//persistenceUnit.setText(StringUtils.stripAccents(businessBundle.getText().trim().toLowerCase().replace(" ", BasicProjectInfo.REPLACING).replace("-", BasicProjectInfo.REPLACING)));
}
};
/**
* Listens on selection change of authentication data source.
* <br>
* Modifies the mock data generator type if necessary.
*/
protected Listener dataSourceForAuthenticationChanges = new Listener() {
public void handleEvent(Event e) {
if (checkDataSourceConfigured(dataSourceForAuthentication.getText(), false)) {
projectInfo.setDataSourceForAuthentication(dataSourceForAuthentication.getText());
checkForMemoryDataSource(dataSourceForAuthentication.getText(), mockAuthenticationDataGenerateType);
}
else {
dataSourceForAuthentication.select(dataSourceForAuthentication.indexOf(projectInfo.getDataSourceForAuthentication()));
}
}
};
/**
* Listens on selection change of blob data source.
* <br>
* Modifies the mock data generator type if necessary.
*/
protected Listener dataSourceForBLOBChanges = new Listener() {
public void handleEvent(Event e) {
if (checkDataSourceConfigured(dataSourceForBLOB.getText(), false)) {
projectInfo.setDataSourceForBLOB(dataSourceForBLOB.getText());
checkForMemoryDataSource(dataSourceForBLOB.getText(), mockBlobDataGenerateType);
}
else {
dataSourceForBLOB.select(dataSourceForBLOB.indexOf(projectInfo.getDataSourceForBLOB()));
}
}
};
/**
* Listens on selection change of bpm engine data source.
* <br>
* Modifies the mock data generator type if necessary.
*/
protected Listener dataSourceForBPMChanges = new Listener() {
public void handleEvent(Event e) {
if (checkDataSourceConfigured(dataSourceForBPM.getText(), false)) {
projectInfo.setDataSourceForBPM(dataSourceForBPM.getText());
}
else {
dataSourceForBPM.select(dataSourceForBPM.indexOf(projectInfo.getDataSourceForBPM()));
}
}
};
/**
* Listens on selection change of business data source.
* <br>
* Modifies the mock data generator type if necessary.
*/
protected Listener dataSourceForBusinessDataChanges = new Listener() {
public void handleEvent(Event e) {
if (checkDataSourceConfigured(dataSourceForBusinessData.getText(), false)) {
projectInfo.setDataSourceForBusinessData(dataSourceForBusinessData.getText());
checkForMemoryDataSource(dataSourceForBusinessData.getText(), mockProductDataGenerateType);
}
else {
dataSourceForBusinessData.select(dataSourceForAuthentication.indexOf(dataSourceForBusinessData.getText()));
}
}
};
/**
* Listens on selection change of general data source.
* <br>
* Selects the corresponding data sources for authentication, blob, bpm engine and business data.
* <br>
* Modifies the mock data generator type if necessary.
*/
protected Listener dataSourceForGeneralChanges = new Listener() {
public void handleEvent(Event e) {
if (checkDataSourceConfigured(dataSourceForGeneral.getText(), false)) {
int selected = dataSourceForGeneral.getSelectionIndex();
dataSourceForAuthentication.select(selected);
dataSourceForBLOB.select(selected);
dataSourceForBPM.select(selected);
dataSourceForBusinessData.select(selected);
checkForMemoryDataSource(dataSourceForGeneral.getText(), mockGeneralGenerateType);
}
}
};
/**
* Minimal checks if data source configured.
* <br>
* The following relevant data source attributes should look fine:
* <ul>
* <li>name of the server</li>
* <li>name of the database</li>
* <li><i>user</i> of the database</li>
* <li><i>password</i> of the database</li>
* </ul>
* @param dataSource the data source
* @param justAsHint flag if just as hint has to be displayed, or a question is necessary
* @return true, if check or question was successful
*/
protected boolean checkDataSourceConfigured(String dataSource, boolean justAsHint) {
// do not re-check the last checked data source
boolean positive = dataSource.equals(lastDataSource);
if (!positive) {
lastDataSource = dataSource;
// get the data source configuration
DataSourceConfiguration dsf = ProductConfiguration.getDataSource(dataSource);
// check the minimal attributes
if (dsf != null) {
positive =
checkDataSourceParameter(dsf.getServerName()) &&
checkDataSourceParameter(dsf.getDatabaseName()) &&
checkDataSourceParameter(dsf.getDatabaseUser()) &&
checkDataSourceParameter(dsf.getDatabasePass());
}
if (!positive) {
int actions;
String question;
// either display a warning
if (justAsHint) {
actions = SWT.ICON_WARNING | SWT.OK;
question = "";
}
// or display a question
else {
actions = SWT.ICON_QUESTION | SWT.YES | SWT.NO;
question = translator.getDocumentation(this,"checkDataSourceConfigured.question").replace("%%DATASOURCE%%", dataSource);
// "\nDo you want to continue with the misconfigured JNDI Data Source '"+dataSource+"'?";
}
MessageBox messageBox = new MessageBox(
AllInOneDSLsNewProjectWizard.this.getShell(),
actions);
messageBox.setMessage(
translator.getDocumentation(this,"checkDataSourceConfigured.text").replace("%%DATASOURCE%%", dataSource)
+question);
messageBox.setText(
translator.getDocumentation(this,"checkDataSourceConfigured.title").replace("%%DATASOURCE%%", dataSource)
);
positive = (messageBox.open() != SWT.NO);
}
}
return positive;
}
/**
* @param value the attribute to be minimally checked
* @return if value contains neither &gt; nor &lt; the value seems fine
*/
protected boolean checkDataSourceParameter(String value) {
return !value.contains("<") && !value.contains(">");
}
/**
* Check the dataSource for reasonable mock generator types.
* @param dataSource the data source to be checked
* @param mockGenerateCombo the combobox containing reasonable mock generator types
*/
protected void checkForMemoryDataSource(final String dataSource, final Combo mockGenerateCombo) {
DataSourceConfiguration dsf = ProductConfiguration.getDataSource(dataSource);
// if the data source defines a in-memory data base, only "everytime" is reasonable
if ((dsf != null) && dsf.getDatabaseVendor().isInMemory()) {
setMockGenerateTypeOnlyEverytime(mockGenerateCombo);
}
// otherwise any other mock generator type than "everytime" is reasonable
else {
setMockGenerateTypeNeverEverytime(mockGenerateCombo);
}
}
/**
* Only <i>everytime</i> is reasonable for the mockGenerateCombo
* @param mockGenerateCombo
*/
protected void setMockGenerateTypeOnlyEverytime(Combo mockGenerateCombo) {
mockGenerateCombo.removeAll();
mockGenerateCombo.add(MockDataGenerateType.EVERYTIME.getDescription());
mockGenerateCombo.select(0);
}
/**
* Anything other than <i>everytime</i> is reasonable for the mockGenerateCombo
* @param mockGenerateCombo
*/
protected void setMockGenerateTypeNeverEverytime(Combo mockGenerateCombo) {
String selection = mockGenerateCombo.getItem(mockGenerateCombo.getSelectionIndex());
mockGenerateCombo.removeAll();
int selected = 0;
for (MockDataGenerateType type : MockDataGenerateType.values()) {
if (!MockDataGenerateType.EVERYTIME.equals(type)) {
mockGenerateCombo.add(type.getDescription());
if (type.getDescription().equals(selection)) {
selected = mockGenerateCombo.indexOf(type.getDescription());
}
}
}
mockGenerateCombo.select(selected);
}
/**
* Listens on selection change of mock generator type for general and delegates to projectInfo.
*/
protected Listener mockProductDataGenerateTypeChanges = new Listener() {
public void handleEvent(Event e) {
int selected = mockProductDataGenerateType.getSelectionIndex();
if (selected >= 0) {
projectInfo.setMockProductDataGenerateType(mockProductDataGenerateType.getItem(selected));
}
}
};
/**
* Listens on selection change of mock generator type for authentication and delegates to projectInfo.
*/
protected Listener mockAuthenticationDataGenerateTypeChanges = new Listener() {
public void handleEvent(Event e) {
int selected = mockAuthenticationDataGenerateType.getSelectionIndex();
if (selected >= 0) {
projectInfo.setMockAuthenticationDataGenerateType(mockAuthenticationDataGenerateType.getItem(selected));
}
}
};
/**
* Listens on selection change of mock generator type for blob and delegates to projectInfo.
*/
protected Listener mockBlobDataGenerateTypeChanges = new Listener() {
public void handleEvent(Event e) {
int selected = mockBlobDataGenerateType.getSelectionIndex();
if (selected >= 0) {
projectInfo.setMockBlobDataGenerateType(mockBlobDataGenerateType.getItem(selected));
}
}
};
/**
* Listens on selection change of vaaclipse theme and delegates to projectInfo.
*/
protected Listener vaaclipseThemeChanges = new Listener() {
public void handleEvent(Event e) {
projectInfo.setVaaclipseTheme(vaaclipseTheme.getItem(vaaclipseTheme.getSelectionIndex()));
}
};
/**
* Listens on selection change of XMS size and delegates to projectInfo.
*/
protected Listener xmsSizeChanges = new Listener() {
public void handleEvent(Event e) {
try {
int size = Integer.parseInt(xmsSize.getText());
xmsSize.setText(projectInfo.setXmsSizeInMB(size));
}
catch (Exception ex) {
xmsSize.setText(projectInfo.getXmsSizeInMB());
}
}
};
/**
* Listens on selection change of XMX size and delegates to projectInfo.
*/
protected Listener xmxSizeChanges = new Listener() {
public void handleEvent(Event e) {
try {
int size = Integer.parseInt(xmxSize.getText());
xmxSize.setText(projectInfo.setXmxSizeInMB(size));
}
catch (Exception ex) {
xmxSize.setText(projectInfo.getXmxSizeInMB());
}
}
};
/**
* Listens on change of application port no and delegates to projectInfo.
*/
protected Listener productPortNoChanges = new Listener() {
public void handleEvent(Event e) {
projectInfo.setProductPortNo(productPortNo.getText());
productLocalDesktopLink.setText(projectInfo.getProductLocalDesktopLink());
productLocalMobileLink.setText(projectInfo.getProductLocalMobileLink());
}
};
/**
* Listens on change of desktop url path and delegates to projectInfo.
* <br>
* The mobile url path and the clickable links are updated too.
*/
protected Listener productDesktopUrlPathChanges = new Listener() {
public void handleEvent(Event e) {
projectInfo.setProductDesktopUrlPath(productDesktopUrlPath.getText());
productMobileUrlPath.setText(projectInfo.getProductMobileUrlPath());
productLocalDesktopLink.setText(projectInfo.getProductLocalDesktopLink());
productLocalMobileLink.setText(projectInfo.getProductLocalMobileLink());
}
};
/**
* Add specific application wizard handlers.
*/
@Override
protected void addListenerToComponents() {
super.addListenerToComponents();
companyDomain.addListener(SWT.Modify, companyDomainChanges);
businessBundle.addListener(SWT.Modify, businessBundleChanges);
for (Listener projectNameChange : projectNameChanges) {
businessBundle.addListener(SWT.Modify, projectNameChange);
}
dataSourceForAuthentication.addListener(SWT.Modify, dataSourceForAuthenticationChanges);
dataSourceForBLOB.addListener(SWT.Modify, dataSourceForBLOBChanges);
dataSourceForBPM.addListener(SWT.Modify, dataSourceForBPMChanges);
dataSourceForBusinessData.addListener(SWT.Modify, dataSourceForBusinessDataChanges);
dataSourceForGeneral.addListener(SWT.Modify, dataSourceForGeneralChanges);
mockProductDataGenerateType.addListener(SWT.Modify, mockProductDataGenerateTypeChanges);
mockAuthenticationDataGenerateType.addListener(SWT.Modify, mockAuthenticationDataGenerateTypeChanges);
mockBlobDataGenerateType.addListener(SWT.Modify, mockBlobDataGenerateTypeChanges);
vaaclipseTheme.addListener(SWT.Selection, vaaclipseThemeChanges);
xmsSize.addListener(SWT.FocusOut, xmsSizeChanges);
xmxSize.addListener(SWT.FocusOut, xmxSizeChanges);
productPortNo.addListener(SWT.Modify, productPortNoChanges);
productDesktopUrlPath.addListener(SWT.Modify, productDesktopUrlPathChanges);
companyDomainChanges.handleEvent(null);
businessBundleChanges.handleEvent(null);
Set<String> dataSources = new TreeSet<String>();
dataSources.add(dataSourceForAuthentication.getText());
dataSources.add(dataSourceForBLOB.getText());
dataSources.add(dataSourceForBPM.getText());
dataSources.add(dataSourceForBusinessData.getText());
for (String dataSource : dataSources) {
checkDataSourceConfigured(dataSource, true);
}
checkForMemoryDataSource(dataSourceForAuthentication.getText(), mockAuthenticationDataGenerateType);
checkForMemoryDataSource(dataSourceForBLOB.getText(), mockBlobDataGenerateType);
checkForMemoryDataSource(dataSourceForBusinessData.getText(), mockProductDataGenerateType);
}
}