ITPub博客

首页 > Linux操作系统 > Linux操作系统 > swt

swt

原创 Linux操作系统 作者:seventhreecn 时间:2013-08-01 14:43:26 0 删除 编辑
代码增加一个combo,由于swt的全部读取功能,只能选择非隐藏作为第一选择,所以第一选项为hana,这里需要加一个flag,作为隐藏的标志,但是在java中flag的初始值是false,而对应的combo里面会设定成ture,但对于第一次选择并不会选择,所以采用默认,so,一开始将flag设值为true,这样就可以了。
下面是option的代码(swt的自动生成代码功能,使我有直视的方案,这样便于我的修改)当然对于逻辑判断,我觉得在UI里面也是可以改的,但是学习时间比较短,所以就直接在代码里面改了。



package com.bobj.ui;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.GridData;

import com.bobj.util.SWTResourceManager;
import com.businessobjects.emm.install.db.JDBCEnvironmentData;
import com.businessobjects.emm.install.db.NewDBEnvironmentData;
import org.eclipse.swt.widgets.Combo;

public class DSInstallOptionView extends Composite {

private Button nextButton;
private Button backButton;
private DetailView detail;
private Properties prop;

private Text text_cms_passFir;
private Text text_sqla_passFir;
private Label lblHostname;
private Label lblPort;
private Label lblUsername;
private Label lblPassword;
private Label lblClient;
private boolean flagDb = true;
private Text text_hostname;
private Text text_port;
private Text text_username;
private Text text_hana_passFir;
private Text text_client;
private Composite composite;
private Button btnOpenFile;
private Label lblConfirm;
private Text text_cms_passSec;
private Text text_sqla_passSec;
private Composite composite_1;
private Composite composite_2;
private Label lblNewLabel;
private Label lblNewLabel_2;
private Label lblNewLabel_3;
// private Text text_hana_passSec;
private Label label_1;
private Label label_2;

private String HANAmessage = "HANA connect fail";

public DSInstallOptionView(Composite parent, int style, DetailView detail) {
super(parent, style);
setBackground(SWTResourceManager.getColor(51, 51, 51));
this.detail = detail;
this.prop = detail.getProp();
initGUI();

}

private void initGUI() {
GridLayout gridLayout = new GridLayout(3, false);
gridLayout.marginWidth = 10;
gridLayout.marginHeight = 10;
gridLayout.horizontalSpacing = 10;
setLayout(gridLayout);

composite = new Composite(this, SWT.NONE);
GridData gd_composite = new GridData(SWT.FILL, SWT.FILL, true, false,
3, 1);
gd_composite.heightHint = 397;
composite.setLayoutData(gd_composite);
composite.setBackground(SWTResourceManager.getColor(51, 51, 51));
composite.setLayout(new GridLayout(5, false));

composite_1 = new Composite(composite, SWT.NONE);
composite_1.setBackground(SWTResourceManager.getColor(51, 51, 51));
composite_1.setLayout(new GridLayout(4, false));
GridData gd_composite_1 = new GridData(SWT.FILL, SWT.CENTER, true,
false, 5, 2);
gd_composite_1.heightHint = 214;
gd_composite_1.widthHint = 613;
composite_1.setLayoutData(gd_composite_1);

lblNewLabel = new Label(composite_1, SWT.NONE);
lblNewLabel.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
lblNewLabel.setBackground(SWTResourceManager.getColor(51, 51, 51));
lblNewLabel.setFont(SWTResourceManager.getFont("Segoe UI", 12,
SWT.NORMAL));
GridData gd_lblNewLabel = new GridData(SWT.FILL, SWT.CENTER, false,
false, 3, 1);
gd_lblNewLabel.heightHint = 25;
lblNewLabel.setLayoutData(gd_lblNewLabel);
lblNewLabel.setText("[ Configure CMS Administrator Account ]");
new Label(composite_1, SWT.NONE);

label_1 = new Label(composite_1, SWT.NONE);
label_1.setBackground(SWTResourceManager.getColor(51, 51, 51));
label_1.setVisible(false);
label_1.setText("New Label");

// prop = new Properties();
// try {
// FileInputStream fis = new FileInputStream("install_config.config");
// prop.load(fis);
// fis.close();
// } catch (Exception ex) {
// }

Label passwordLbl = new Label(composite_1, SWT.RIGHT);
passwordLbl.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
passwordLbl.setBackground(SWTResourceManager.getColor(51, 51, 51));
passwordLbl.setAlignment(SWT.LEFT);
GridData gd_passwordLbl = new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1);
gd_passwordLbl.widthHint = 131;
passwordLbl.setLayoutData(gd_passwordLbl);
passwordLbl.setText("Password  ");
text_cms_passFir = new Text(composite_1, SWT.PASSWORD | SWT.BORDER);
text_cms_passFir.setBackground(SWTResourceManager.getColor(170, 170,
170));
GridData gd_text_cms_passFir = new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1);
gd_text_cms_passFir.widthHint = 319;
text_cms_passFir.setLayoutData(gd_text_cms_passFir);
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);

lblConfirm = new Label(composite_1, SWT.RIGHT);
lblConfirm.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
lblConfirm.setBackground(SWTResourceManager.getColor(51, 51, 51));
lblConfirm.setAlignment(SWT.LEFT);
lblConfirm.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
lblConfirm.setText("Confirm Password  ");

text_cms_passSec = new Text(composite_1, SWT.BORDER | SWT.PASSWORD);
text_cms_passSec.setBackground(SWTResourceManager.getColor(170, 170,
170));
GridData gd_text_cms_passSec = new GridData(SWT.FILL, SWT.CENTER,
false, false, 1, 1);
gd_text_cms_passSec.widthHint = 325;
text_cms_passSec.setLayoutData(gd_text_cms_passSec);

lblNewLabel_2 = new Label(composite_1, SWT.NONE);
lblNewLabel_2.setText("New Label");
lblNewLabel_2.setVisible(false);

label_3 = new Label(composite_1, SWT.NONE);
label_3.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false,
3, 1));
label_3.setText("[ Configure BOE Repository Account ]");
label_3.setForeground(SWTResourceManager.getColor(
255, 255, 255));
label_3.setFont(SWTResourceManager.getFont(
"Segoe UI", 12, SWT.NORMAL));
label_3.setBackground(SWTResourceManager.getColor(
51, 51, 51));
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);

label_4 = new Label(composite_1, SWT.RIGHT);
label_4.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false,
1, 1));
label_4.setText("Password  ");
label_4.setForeground(SWTResourceManager.getColor(
255, 255, 255));
label_4.setBackground(SWTResourceManager.getColor(
51, 51, 51));
label_4.setAlignment(SWT.LEFT);

text_sqla_passFir = new Text(composite_1, SWT.PASSWORD | SWT.BORDER);
text_sqla_passFir.setBackground(SWTResourceManager.getColor(170, 170,
170));
GridData gd_text_sqla_passFir = new GridData(SWT.FILL, SWT.CENTER,
true, false, 1, 1);
gd_text_sqla_passFir.widthHint = 319;
text_sqla_passFir.setLayoutData(gd_text_sqla_passFir);
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);

label_5 = new Label(composite_1, SWT.RIGHT);
label_5.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false,
1, 1));
label_5.setText("Confirm Password  ");
label_5.setForeground(SWTResourceManager.getColor(
255, 255, 255));
label_5.setBackground(SWTResourceManager.getColor(
51, 51, 51));
label_5.setAlignment(SWT.LEFT);

text_sqla_passSec = new Text(composite_1, SWT.BORDER | SWT.PASSWORD);
text_sqla_passSec.setBackground(SWTResourceManager.getColor(170, 170,
170));
GridData gd_text_sqla_passSec = new GridData(SWT.FILL, SWT.CENTER,
false, false, 1, 1);
gd_text_sqla_passSec.widthHint = 325;
text_sqla_passSec.setLayoutData(gd_text_sqla_passSec);
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);
new Label(composite_1, SWT.NONE);

lblDataservicesRepository = new Label(composite_1, SWT.NONE);
lblDataservicesRepository.setLayoutData(new GridData(SWT.LEFT,
SWT.CENTER, false, false, 2, 1));
lblDataservicesRepository.setText("[ DataServices Repository ]");
lblDataservicesRepository
.setForeground(SWTResourceManager.getColor(
255, 255, 255));
lblDataservicesRepository.setFont(SWTResourceManager
.getFont("Segoe UI", 12, SWT.NORMAL));
lblDataservicesRepository
.setBackground(SWTResourceManager.getColor(
51, 51, 51));

combo = new Combo(composite_1, SWT.READ_ONLY);
combo.setItems(new String[] { "HANA", "SQL Anywhere" });
combo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1,
1));
combo.select(0);
combo.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub
               
boolean flag = combo.getSelectionIndex() == 0;
setCompositeVisible(composite_2, flag);
flagDb = flag ;
}

@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
// TODO Auto-generated method stub

}

});

new Label(composite_1, SWT.NONE);

composite_2 = new Composite(composite, SWT.NONE);
GridData gd_composite_2 = new GridData(SWT.FILL, SWT.FILL, false,
false, 5, 1);
gd_composite_2.widthHint = 592;
composite_2.setLayoutData(gd_composite_2);
composite_2.setBackground(SWTResourceManager.getColor(51, 51, 51));
composite_2.setLayout(new GridLayout(4, false));

label_2 = new Label(composite_2, SWT.NONE);
label_2.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
label_2.setBackground(SWTResourceManager.getColor(51, 51, 51));
label_2.setVisible(false);
label_2.setText("New Label");

lblHostname = new Label(composite_2, SWT.RIGHT);
lblHostname.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
lblHostname.setBackground(SWTResourceManager.getColor(51, 51, 51));
lblHostname.setAlignment(SWT.LEFT);
GridData gd_lblHostname = new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1);
gd_lblHostname.widthHint = 133;
lblHostname.setLayoutData(gd_lblHostname);
lblHostname.setText("HANA Hostname  ");

text_hostname = new Text(composite_2, SWT.BORDER);
text_hostname.setBackground(SWTResourceManager.getColor(170, 170, 170));
text_hostname.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
false, 1, 1));

label = new Label(composite_2, SWT.NONE);
label.setVisible(false);
label.setText("New Label");
new Label(composite_2, SWT.NONE);

lblPort = new Label(composite_2, SWT.RIGHT);
lblPort.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
lblPort.setBackground(SWTResourceManager.getColor(51, 51, 51));
lblPort.setAlignment(SWT.LEFT);
GridData gd_lblPort = new GridData(SWT.FILL, SWT.CENTER, false, false,
1, 1);
gd_lblPort.widthHint = 116;
lblPort.setLayoutData(gd_lblPort);
lblPort.setText("HANA Instance Number  ");

text_port = new Text(composite_2, SWT.BORDER);
text_port.setBackground(SWTResourceManager.getColor(170, 170, 170));
text_port.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
new Label(composite_2, SWT.NONE);
new Label(composite_2, SWT.NONE);

lblUsername = new Label(composite_2, SWT.RIGHT);
lblUsername.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
lblUsername.setBackground(SWTResourceManager.getColor(51, 51, 51));
lblUsername.setAlignment(SWT.LEFT);
lblUsername.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
lblUsername.setText("User Name for HANA  ");

text_username = new Text(composite_2, SWT.BORDER);
text_username.setBackground(SWTResourceManager.getColor(170, 170, 170));
text_username.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
new Label(composite_2, SWT.NONE);
new Label(composite_2, SWT.NONE);

lblPassword = new Label(composite_2, SWT.RIGHT);
lblPassword.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
lblPassword.setBackground(SWTResourceManager.getColor(51, 51, 51));
lblPassword.setAlignment(SWT.LEFT);
lblPassword.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
lblPassword.setText("Password for HANA  ");

text_hana_passFir = new Text(composite_2, SWT.BORDER | SWT.PASSWORD);
text_hana_passFir.setBackground(SWTResourceManager.getColor(170, 170,
170));
text_hana_passFir.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
false, false, 1, 1));
new Label(composite_2, SWT.NONE);
new Label(composite_2, SWT.NONE);

lblClient = new Label(composite_2, SWT.RIGHT);
lblClient.setForeground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
lblClient.setBackground(SWTResourceManager.getColor(51, 51, 51));
lblClient.setAlignment(SWT.LEFT);
lblClient.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
lblClient.setText("HANA ODBC driver  ");

text_client = new Text(composite_2, SWT.BORDER);
text_client.setBackground(SWTResourceManager.getColor(170, 170, 170));
text_client.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false,
false, 1, 1));
text_client.setText(setDefaultHANAClient());

// text_client.setEnabled(false);

btnOpenFile = new Button(composite_2, SWT.NONE);
btnOpenFile.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String tmpFileDir = openFile();
if (tmpFileDir != null)
text_client.setText(tmpFileDir);
}
});
btnOpenFile.setText("...");

lblNewLabel_4 = new Label(this, SWT.NONE);
lblNewLabel_4.setBackground(SWTResourceManager.getColor(93, 93, 93));
GridData gd_lblNewLabel_4 = new GridData(SWT.FILL, SWT.CENTER, false,
false, 3, 1);
gd_lblNewLabel_4.heightHint = 1;
lblNewLabel_4.setLayoutData(gd_lblNewLabel_4);

backButton = new Button(this, SWT.PUSH);
GridData gd_backButton = new GridData(SWT.RIGHT, SWT.CENTER, true,
false, 1, 1);
gd_backButton.widthHint = 70;
backButton.setLayoutData(gd_backButton);
backButton.setText("

nextButton = new Button(this, SWT.PUSH);
GridData gd_nextButton = new GridData(SWT.LEFT, SWT.CENTER, false,
false, 1, 1);
gd_nextButton.widthHint = 70;
nextButton.setLayoutData(gd_nextButton);
nextButton.setText("Install");

btnNewButton = new Button(this, SWT.NONE);
btnNewButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
MessageBox mb = new MessageBox(detail.getShell(),
SWT.ICON_QUESTION | SWT.YES | SWT.NO);
mb.setText("Exit?");
mb.setMessage("Do you really want to leave the Installation?");
int rt = mb.open();
if (rt == SWT.YES) {
System.exit(0);
}
}
});
GridData gd_btnNewButton = new GridData(SWT.LEFT, SWT.CENTER, false,
false, 1, 1);
gd_btnNewButton.widthHint = 70;
btnNewButton.setLayoutData(gd_btnNewButton);
btnNewButton.setText("Cancel");
nextButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
if (checkText()) {
MessageBox mb = new MessageBox(detail.getShell(),
SWT.ICON_QUESTION | SWT.YES | SWT.NO);
mb.setText("Installing");
mb.setMessage("Do you really want to install Infomation Platform. Services and Data Services ?");
int rc = mb.open();
if (rc == SWT.YES) {
SetProperties();
detail.goToNextStep();
detail.getInstallInfoView().executeInstallShell();
}
}

}
});

if (prop.getProperty("BOE_ADMIN_PASS") != null) {
text_cms_passFir.setText(prop.getProperty("BOE_ADMIN_PASS"));
text_cms_passSec.setText(prop.getProperty("BOE_ADMIN_PASS"));
}
if (prop.getProperty("BOE_DBKEY") != null) {
text_sqla_passFir.setText(prop.getProperty("BOE_DBKEY"));
text_sqla_passSec.setText(prop.getProperty("BOE_DBKEY"));
}
if (flagDb) {
if (prop.getProperty("DS_HANA_HOST") != null)
text_hostname.setText(prop.getProperty("DS_HANA_HOST"));
if (prop.getProperty("DS_HANA_PORT") != null)
text_port.setText(prop.getProperty("DS_HANA_PORT"));
if (prop.getProperty("DS_HANA_USER") != null)
text_username.setText(prop.getProperty("DS_HANA_USER"));
if (prop.getProperty("DS_HANA_PWD") != null) {
text_hana_passFir.setText(prop.getProperty("DS_HANA_PWD"));
// text_hana_passSec.setText(prop.getProperty("DS_HANA_PWD"));
}
if (prop.getProperty("DS_HANA_ODBC_PATH") != null)
text_client.setText(prop.getProperty("DS_HANA_ODBC_PATH"));
// btnOpenFile.setEnabled(false);
}

backButton.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
detail.goToPreviousStep();
}
});

}

private void SetProperties() {

try {

prop.setProperty("BOE_ADMIN_PASS", text_cms_passFir.getText());
prop.setProperty("BOE_DBKEY", text_sqla_passFir.getText());
if (flagDb) {
   prop.setProperty("DS_REPO_TYPE", "HANA");
}else{
prop.setProperty("DS_REPO_TYPE", "SQL_Anywhere");
}
// prop.setProperty("DS_LICENSE_KEY", text_key.getText());
prop.setProperty("DS_REPO_HOST", text_hostname.getText());
prop.setProperty("DS_REPO_PORT", text_port.getText());
prop.setProperty("DS_REPO_USER", text_username.getText());
prop.setProperty("DS_REPO_PWD", text_hana_passFir.getText());
prop.setProperty("DS_REPO_ODBC_PATH", text_client.getText());

// String filePATH = detail.getBasePATH()
// + detail.getPropConfig().getString("FILE_OUTPUT_CONFIG");
// String filePATH = detail.getPropConfig().getString(
// "FILE_OUTPUT_CONFIG");
File configFile = File.createTempFile(".__install_ds", ".config");
configFile.deleteOnExit();
FileOutputStream fos = new FileOutputStream(configFile);
prop.store(fos, "");
fos.close();
detail.getPropEnv().setProperty("SCRIPTNAME_DEFAULTS",
configFile.getAbsolutePath());

} catch (Exception ex) {

}

}

public void setCompositeVisible(Control compositeObject, boolean flag) {
((GridData) compositeObject.getLayoutData()).exclude = !flag;
compositeObject.setVisible(flag);
compositeObject.getParent().layout();
}

private String openFile() {
FileDialog fileDialog = new FileDialog(detail.getShell(), SWT.OPEN);
fileDialog.setFilterExtensions(new String[] { "*.so", "*.*" });
String name = fileDialog.open();

return name;
}

public void setTextFocus() {
text_cms_passFir.setFocus();

}

public boolean checkText() {
MessageBox mb = new MessageBox(detail.getShell(), SWT.ERROR | SWT.OK);
mb.setText("Warning");

if (checkNull(text_cms_passFir.getText())) {
mb.setMessage("CMS password can not be empty!");
mb.open();
return false;
}
if (!checkCMSPwd(text_cms_passFir.getText())) {
mb.setMessage("CMS password must be of length 8 or higher!");
mb.open();
return false;
}
if (!text_cms_passFir.getText().equals(text_cms_passSec.getText())) {
mb.setMessage("CMS Password and Confirm hava to be the same!");
mb.open();
return false;
}
if (checkNull(text_sqla_passFir.getText())) {
mb.setMessage("BOE repository Password can not be empty!");
mb.open();
return false;
}
if (!checkSQLAPwd(text_sqla_passFir.getText())) {
mb.setMessage("BOE repository Password must be of length 6 or higher!");
mb.open();
return false;
}
if (!text_sqla_passFir.getText().equals(text_sqla_passSec.getText())) {
mb.setMessage("BOE repository Password and Confirm hava to be the same!");
mb.open();
return false;
}
if (flagDb) {
checkHanaText();
}
return true;
}

public boolean checkHanaText() {
MessageBox mb = new MessageBox(detail.getShell(), SWT.ERROR | SWT.OK);
mb.setText("Warning");
if (checkNull(text_hostname.getText())) {
mb.setMessage("Hostname can not be empty!");
mb.open();
return false;
}
if (!checkHost(text_hostname.getText())) {
mb.setMessage("Hostname formatting errors!");
mb.open();
return false;
}
if (checkNull(text_port.getText())) {
mb.setMessage("Instance number can not be empty!");
mb.open();
return false;
}
if (!checkPort(text_port.getText())) {
mb.setMessage("Instance number must in the range of {0,99}!");
mb.open();
return false;
}
if (checkNull(text_username.getText())) {
mb.setMessage("HANA username can not be empty!");
mb.open();
return false;
}
if (checkNull(text_hana_passFir.getText())) {
mb.setMessage("HANA password can not be empty!");
mb.open();
return false;
}
// if (!text_hana_passFir.getText().equals(text_hana_passSec.getText()))
// {
// mb.setMessage("HANA Password and Confirm hava to be the same!");
// mb.open();
// return false;
// }
if (checkNull(text_client.getText())) {
mb.setMessage("HANA ODBC driver path can not be empty!");
mb.open();
return false;
}
if (!checkHANAPath(text_client.getText())) {
mb.setMessage("HANA ODBC driver does not exist!");
mb.open();
return false;
}
if (checkHANAConnect(text_hostname.getText(),
getInstanceNum(text_port.getText()), text_username.getText(),
text_hana_passFir.getText())) {
mb.setMessage(HANAmessage);
mb.open();
return false;
}

int rt = checkRepo(text_hostname.getText(), text_port.getText(),
text_username.getText(), text_hana_passFir.getText(),
text_client.getText());
if (rt == 1) {
mb.setMessage("Already exist a DataServices HANA repo, continue will overwrite it!");
mb.open();
return true;
}
if (rt != 2) {
mb.setMessage("Connect to HANA DB failed! Please input again.");
mb.open();
return false;
}
return true;
}

public String setDefaultHANAClient() {
String filePath = "/usr/sap/hdbclient/libodbcHDB.so";
File file = new File(filePath);
if (file.exists()) {
return filePath;
}
return "";
}

public boolean checkHost(String value) {
return value
.matches("^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])|(\\d+\\.\\d+\\.\\d+\\.\\d+)$");
}

public boolean checkPort(String value) {
return value.matches("^[0-9]{1,2}$");
}

public boolean checkNull(String value) {
return value == null || "".equals(value.trim());
}

public boolean checkCMSPwd(String value) {
return value.length() >= 8;
}

public boolean checkSQLAPwd(String value) {
return value.length() >= 6;
}

public boolean checkHANAPath(String filePath) {
File file = new File(filePath);
if (file.exists()) {
return true;
}
return false;
}

private int checkRepo(String host, String port, String user, String pwd,
String driver) {
try {
String str = detail.getBasePATH() + "/scripts/connRepo.sh " + host
+ " " + port + " " + user + " " + pwd + " " + driver;
ProcessBuilder builder = new ProcessBuilder(new String[] {
"/bin/sh", "-c", str });
Process process = builder.start();
int rt = process.waitFor();
return rt;
} catch (Exception ex) {
}
return -1;
}

private String getInstanceNum(String portNum) {
if (portNum.length() == 1)
return "30" + portNum + "15";
if (portNum.length() == 2)
return "3" + portNum + "15";
return "30015";
}

// ------------------------------------------------------------------------------

private static final String UNKNOWN = "Unknown";
private Label lblNewLabel_4;
private Button btnNewButton;
private Label label_3;
private Label label_4;
private Label label_5;
private Text text;
private Text text_1;
private Label lblDataservicesRepository;
private Combo combo;
private Label label;

public boolean checkHANAConnect(String host, String port, String user,
String pwd) {
String[] args = new String[] { "testDB", "NewDB", host, port, user,
user, pwd, "test" };
return !execute(args);
}

private boolean execute(String[] args) {
JDBCEnvironmentData jdbcData = null;

// If we have args, they must be files for database install
int funcIndex = 7;

if (args[1].equalsIgnoreCase("NewDB")) {
NewDBEnvironmentData data = new NewDBEnvironmentData();
data.setHost(args[2]);
data.setPort(args[3]);
data.setDatabaseName(args[4]);
data.setUser(args[5]);
data.setPassword(args[6]);
jdbcData = data;
}

try {
String dbTestFunc = "write";
if (args.length > funcIndex) {
dbTestFunc = args[funcIndex];
}

boolean k = testDBConnection(jdbcData);

if (ok) {
if ("getversion".equalsIgnoreCase(dbTestFunc)) {
String[] repoInfo = getRepoVersion(jdbcData);
if (repoInfo != null) {
if (!UNKNOWN.equals(repoInfo[0])) {
saveMessage("repo.version",
"Metadata Manager version/" + repoInfo[0]);
}
if (!UNKNOWN.equals(repoInfo[1])) {
saveMessage("repo.serialnumber", repoInfo[1]);
}
} else {
return false;// No repository found
}

}
return true;
} else {
return false;
}
} catch (Exception e) {
logException("MMInstall", e);
return false;
}
}

private boolean testDBConnection(JDBCEnvironmentData jdbcData)
throws Exception {

String url = jdbcData.getUrl();
String user = jdbcData.getUser();
String password = jdbcData.getPassword();
try {
Class clazz = Class.forName(jdbcData.getDriver());
DriverManager.registerDriver((Driver) clazz.newInstance());
Connection conn = DriverManager.getConnection(url, user, password);
if (conn == null) {
return false;
}
// check whether fist time connectHANA or not
if (jdbcData.getDriver().equals("com.sap.db.jdbc.Driver"))
return !isFisttimeConnectHANA(conn);
//
conn.close();
} catch (Exception e) {
logException("MMInstall", e);
return false;
}

return true;
}

private boolean isFisttimeConnectHANA(Connection conn) {
String sqlStr = "select now() from dummy";
try {
conn.prepareCall(sqlStr);
} catch (SQLException e) {
logException("MMInstall", e);
return true;
}
return false;
}

private String[] getRepoVersion(JDBCEnvironmentData jdbcData) {

// read the parameter table
String BOE_VERSION = "SELECT technical_name, parameter_value from MMD_Parameter where technical_name in ('BOE_VERSION','MM_REPO_CUID') ";
String version = UNKNOWN;
String repoCUID = UNKNOWN;
String url = jdbcData.getUrl();
String user = jdbcData.getUser();
String password = jdbcData.getPassword();
try {
Class clazz = Class.forName(jdbcData.getDriver());
DriverManager.registerDriver((Driver) clazz.newInstance());
Connection conn = DriverManager.getConnection(url, user, password);
if (conn == null) {
return null;
}
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery(BOE_VERSION);
while (rs.next()) {
String parameter = rs.getString(1);
if (parameter.equals("BOE_VERSION")) {
version = rs.getString(2);
} else if (parameter.equals("MM_REPO_CUID")) {
repoCUID = rs.getString(2);
}
}
conn.close();
} catch (Exception e) {
logException("MMInstall", e);
return null;
}

return new String[] { version, repoCUID };
}

private void logException(String prefix, Throwable t) {
HANAmessage = t.getMessage();
}

private void saveMessage(String filename, String msg) {
// System.out.println(msg);
}

}

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27633196/viewspace-767629/,如需转载,请注明出处,否则将追究法律责任。

上一篇: mysql 1
下一篇: linux访问windows
请登录后发表评论 登录
全部评论

注册时间:2012-08-15

  • 博文量
    28
  • 访问量
    20698