package vciw.preferences;
|
|
import java.io.BufferedInputStream;
|
import java.io.BufferedReader;
|
import java.io.BufferedWriter;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileNotFoundException;
|
import java.io.FileOutputStream;
|
import java.io.FileReader;
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.InputStreamReader;
|
import java.io.OutputStream;
|
import java.io.OutputStreamWriter;
|
import java.io.UnsupportedEncodingException;
|
import java.sql.Connection;
|
import java.sql.DriverManager;
|
import java.sql.SQLException;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Collections;
|
import java.util.Comparator;
|
import java.util.Enumeration;
|
import java.util.LinkedHashSet;
|
import java.util.List;
|
import java.util.Properties;
|
import java.util.Set;
|
|
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.transform.OutputKeys;
|
import javax.xml.transform.Result;
|
import javax.xml.transform.Source;
|
import javax.xml.transform.Transformer;
|
import javax.xml.transform.TransformerFactory;
|
import javax.xml.transform.dom.DOMSource;
|
import javax.xml.transform.stream.StreamResult;
|
|
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.Path;
|
import org.eclipse.jdt.core.JavaCore;
|
import org.eclipse.jface.dialogs.IInputValidator;
|
import org.eclipse.jface.dialogs.InputDialog;
|
import org.eclipse.jface.dialogs.MessageDialog;
|
import org.eclipse.jface.preference.DirectoryFieldEditor;
|
import org.eclipse.jface.preference.FieldEditorPreferencePage;
|
import org.eclipse.jface.preference.StringFieldEditor;
|
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.events.ModifyEvent;
|
import org.eclipse.swt.events.ModifyListener;
|
import org.eclipse.swt.events.SelectionAdapter;
|
import org.eclipse.swt.events.SelectionEvent;
|
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.widgets.Button;
|
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Control;
|
import org.eclipse.swt.widgets.Group;
|
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Table;
|
import org.eclipse.swt.widgets.TableColumn;
|
import org.eclipse.swt.widgets.TableItem;
|
import org.eclipse.swt.widgets.Text;
|
import org.eclipse.ui.IWorkbench;
|
import org.eclipse.ui.IWorkbenchPreferencePage;
|
import org.w3c.dom.Document;
|
import org.w3c.dom.Element;
|
import org.w3c.dom.Node;
|
import org.w3c.dom.NodeList;
|
import org.xml.sax.EntityResolver;
|
import org.xml.sax.InputSource;
|
import org.xml.sax.SAXException;
|
|
import vciw.Activator;
|
|
/**
|
* This class represents a preference page that is contributed to the
|
* Preferences dialog. By subclassing <samp>FieldEditorPreferencePage</samp>, we
|
* can use the field support built into JFace that allows us to create a page
|
* that is small and knows how to save, restore and apply itself.
|
* <p>
|
* This page is used to modify preferences only. They are stored in the
|
* preference store that belongs to the main plug-in class. That way,
|
* preferences can be accessed directly via the preference store.
|
*/
|
|
public class SamplePreferencePage extends FieldEditorPreferencePage implements
|
IWorkbenchPreferencePage {
|
private DirectoryFieldEditor VCI_Home;
|
private DirectoryFieldEditor Corba_Home;
|
private DirectoryFieldEditor javaHome;
|
private static String VCI_Home_Path;
|
private static String VCI_Corba_Path;
|
private static String url = "";
|
private static String username = "";
|
private static String password = "";
|
private static String corboInfo = "";
|
private String[] columnTitles = { "index", "name", "class", "on" };
|
private SortedProperties properties = new SortedProperties();
|
Table table = null;
|
|
private boolean initTable = false;
|
|
private TableItem selectedRow = null;
|
|
// private boolean reverseSort = false;
|
// private String lastSelection = null;
|
|
public SamplePreferencePage() {
|
|
super(GRID);
|
setPreferenceStore(Activator.getDefault().getPreferenceStore());
|
setDescription(" DataSource and Corba Setting of VCI PlatFrom ");
|
|
}
|
|
/**
|
* Creates the field editors. Field editors are abstractions of the common
|
* GUI blocks needed to manipulate various types of preferences. Each field
|
* editor knows how to save and restore itself.
|
*/
|
public void createFieldEditors() {
|
Composite composite = new Composite(getFieldEditorParent(), SWT.NULL);
|
GridLayout layout = new GridLayout();
|
composite.setLayout(layout);
|
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
data.grabExcessHorizontalSpace = true;
|
composite.setLayoutData(data);
|
Group groupmain = new Group(composite, 1);
|
groupmain.setText("VCI Home ÉèÖÃ");
|
GridData gd = new GridData(GridData.FILL_BOTH);
|
groupmain.setLayoutData(gd);
|
VCI_Home = new DirectoryFieldEditor(PreferenceConstants.P_PATH_VCIHOME, "VCI_Home:", groupmain);
|
addSeparator(composite);
|
addFirstSection(composite);
|
//addSeparator(composite);
|
//addSecondSection(composite);
|
addSeparator(composite);
|
addCorbaServerInfoSection(composite);
|
}
|
|
class CorbaInput extends InputDialog {
|
CorbaInput(Shell paramShell, String paramString1, String paramString2,
|
String paramString3, IInputValidator paramIInputValidator) {
|
super(paramShell, paramString1, paramString2, paramString3,
|
paramIInputValidator);
|
}
|
|
private String clazzName = "";
|
|
protected void okPressed() {
|
clazzName = classtext.getText();
|
super.okPressed();
|
}
|
|
private Text classtext;
|
|
protected Control createDialogArea(Composite parent) {
|
Composite composite = (Composite) super.createDialogArea(parent);
|
|
this.classtext = new Text(composite, getInputTextStyle());
|
this.classtext.setLayoutData(new GridData(768));
|
this.classtext.setText("class");
|
this.classtext.addModifyListener(new ModifyListener() {
|
public void modifyText(ModifyEvent e) {
|
validateInput();
|
}
|
});
|
|
return classtext;
|
}
|
|
public String getClassText() {
|
return clazzName;
|
}
|
}
|
|
private void addCorbaServerInfoSection(Composite composite) {
|
/* GridLayout layout = new GridLayout();
|
composite.setLayout(layout);
|
GridData data = new GridData(GridData.FILL_HORIZONTAL);
|
data.grabExcessHorizontalSpace = true;
|
composite.setLayoutData(data);
|
Group groupmain = new Group(composite, 1);
|
groupmain.setText("VCI Home ÉèÖÃ");
|
GridData gd = new GridData(GridData.FILL_BOTH);
|
groupmain.setLayoutData(gd);
|
VCI_Home = new DirectoryFieldEditor(PreferenceConstants.P_PATH_VCIHOME, "VCI_Home:", groupmain);
|
*/
|
|
Group group = new Group(composite, 1);//32);
|
group.setText("Corba ·þÎñÅäÖÃ");
|
GridData data = new GridData(GridData.FILL_BOTH);//4, 16777216, true, false);
|
group.setLayoutData(data);
|
GridLayout layout = new GridLayout();
|
layout.numColumns = 3;
|
group.setLayout(layout);
|
|
// table
|
table = new Table(group, 68356);
|
GridData gridData = new GridData(GridData.FILL_BOTH);
|
gridData.heightHint = convertVerticalDLUsToPixels(150);
|
table.setLayoutData(gridData);
|
table.setHeaderVisible(true);
|
table.setLinesVisible(true);
|
table.setFont(group.getFont());
|
|
table.addSelectionListener(new SelectionAdapter() {
|
public void widgetSelected(SelectionEvent e) {
|
if (e.item != null)
|
selectedRow = (TableItem) e.item;
|
|
return;
|
}
|
});
|
|
Button buttoninit = new Button(group, SWT.PUSH);
|
buttoninit.setText("ÐÂÔö");
|
buttoninit.addSelectionListener(new SelectionAdapter() {
|
public void widgetSelected(SelectionEvent e) {
|
if (properties.get("servicecount") == null) {
|
MessageDialog.openInformation(getShell(), "Ìáʾ", "Çë³õʼ»¯");
|
return;
|
}
|
|
IInputValidator validator = new IInputValidator() {
|
public String isValid(String newText) {
|
return ((newText.length() == 0) ? "" : null);
|
}
|
};
|
CorbaInput dialog = new CorbaInput(getShell(), "corba service setting", "", "name", validator);
|
int result = dialog.open();
|
if (result != 0) {
|
return;
|
}
|
|
String name = dialog.getValue();
|
String clazz = dialog.getClassText();
|
int newrow = Integer.parseInt((String) properties.get("servicecount"));
|
String index = Integer.toString(newrow);
|
|
TableItem item = new TableItem(table, newrow);
|
item.setText(new String[] { index, name, clazz, "Y" });
|
// save
|
// properties.put("service" + newrow + ".name", name);
|
// properties.put("service" + newrow + ".class", clazz);
|
|
// /
|
File file = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_VCIHOME) + "\\src\\properties\\conf.properties");
|
InputStream inStream = null;
|
OutputStream out = null;
|
try {
|
inStream = new FileInputStream(file);
|
properties.load(inStream);
|
if (inStream != null) {
|
inStream.close();
|
}
|
|
out = new FileOutputStream(file);
|
properties.setProperty("service" + newrow + ".name", name);
|
|
properties.setProperty("service" + newrow + ".class", clazz);
|
properties.setProperty("servicecount", newrow + 1 + "");
|
properties.store(out, "conf.properties version by Eclipse");
|
if (out != null) {
|
out.close();
|
}
|
|
} catch (IOException ecx) {
|
MessageDialog.openInformation(getShell(), "Ìáʾ", ecx.getMessage());
|
}
|
|
}
|
|
});
|
|
Button buttondel = new Button(group, SWT.PUSH);
|
buttondel.setText("ɾ³ý");
|
buttondel.addSelectionListener(new SelectionAdapter() {
|
public void widgetSelected(SelectionEvent e) {
|
if (selectedRow != null) {
|
boolean istrue = MessageDialog.openConfirm(getShell(), "Ìáʾ", "ÊÇ·ñɾ³ý");
|
if (istrue) {
|
int row = 0;
|
// table.remove(table.get);
|
TableItem[] items = table.getItems();
|
for (int i = 0; i < items.length; i++) {
|
if (items[i].getText().equals(selectedRow.getText())) {
|
row = i;
|
break;
|
}
|
}
|
table.remove(row);
|
|
File file = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_VCIHOME) + "\\src\\properties\\conf.properties");
|
InputStream inStream = null;
|
OutputStream out = null;
|
try {
|
inStream = new FileInputStream(file);
|
properties.load(inStream);
|
if (inStream != null) {
|
inStream.close();
|
}
|
|
out = new FileOutputStream(file);
|
|
// properties.remove("service" + (row) + ".name");
|
// properties.remove("service" + (row) + ".class");
|
|
|
properties.setProperty("service" + row + ".class", "");
|
|
properties.setProperty("service" + row + ".name", "");
|
properties.setProperty("servicecount", Integer.parseInt((String) properties.get("servicecount")) - 1 + "");
|
properties.store(out, "conf.properties version by Eclipse");
|
if (out != null) {
|
out.close();
|
}
|
|
} catch (IOException ecx) {
|
MessageDialog.openInformation(getShell(), "Ìáʾ",
|
ecx.getMessage());
|
}
|
|
} else {
|
return;
|
}
|
|
}
|
}
|
|
});
|
|
int[] columnWidths = { convertHorizontalDLUsToPixels(35),
|
convertHorizontalDLUsToPixels(100),
|
convertHorizontalDLUsToPixels(140),
|
convertHorizontalDLUsToPixels(35),
|
convertHorizontalDLUsToPixels(130) };
|
|
for (int i = 0; i < columnTitles.length; ++i) {
|
TableColumn tableColumn = new TableColumn(table, 0);
|
tableColumn.setWidth(columnWidths[i]);
|
tableColumn.setText(this.columnTitles[i]);
|
final int columnIndex = i;
|
tableColumn.addSelectionListener(new SelectionAdapter() {
|
|
public void widgetSelected(SelectionEvent e) {
|
sort(columnIndex);
|
}
|
|
});
|
}
|
}
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
private void sort(int column) {
|
TableItem[] items = table.getItems();
|
Arrays.sort(items, new Comparator() {
|
public int compare(Object a, Object b) {
|
TableItem info1 = (TableItem) a;
|
TableItem info2 = (TableItem) b;
|
return info2.getText(0).compareTo(info1.getText(0));
|
}
|
});
|
System.out.println();
|
// table.removeAll();
|
// for (int i = 0; i < sorted.length; i++) {
|
// TableItem item = new TableItem(table, i);
|
// item.setText(sorted[i].getText());
|
// }
|
// for (int i = 0; i < items.length; ++i) {
|
// items[i].setText(createRow(this.bundleGroupInfos[i]));
|
// items[i].setData(this.bundleGroupInfos[i]);
|
// }
|
}
|
|
private void addFirstSection(Composite parent) {
|
|
//Composite composite = createDefaultComposite(parent);
|
Group groupDB = new Group(parent, 1);
|
groupDB.setText("²ÎÊýÉèÖÃ");
|
GridData gd = new GridData(GridData.FILL_BOTH);
|
groupDB.setLayoutData(gd);
|
|
|
final StringFieldEditor dbIP = new StringFieldEditor(PreferenceConstants.P_STRING_URL_IP, "Êý¾Ý¿âµØÖ· (&A):", groupDB);
|
addField(dbIP);
|
|
//addField(new StringFieldEditor(PreferenceConstants.P_STRING_URL_IP, "Êý¾Ý¿âµØÖ· &ip:", group));
|
|
final StringFieldEditor dbInstance = new StringFieldEditor(PreferenceConstants.P_STRING_URL_INSTANCE, "Êý¾Ý¿âʵÀý (&D):", groupDB);
|
addField(dbInstance);
|
|
final StringFieldEditor dbUser = new StringFieldEditor(PreferenceConstants.P_STRING_USER, "Óû§ (&U):", groupDB);
|
addField(dbUser);
|
|
final StringFieldEditor dbPws = new StringFieldEditor(PreferenceConstants.P_STRING_PWD, "ÃÜÂë (&P):", groupDB);
|
addField(dbPws);
|
|
javaHome = new DirectoryFieldEditor(PreferenceConstants.java_home, "Java home:", groupDB);
|
addField(javaHome);
|
|
addField(VCI_Home);
|
|
Group groupCorba = new Group(parent, 1);
|
groupCorba.setText("Corba ÉèÖÃ");
|
GridData gdCorba = new GridData(GridData.FILL_BOTH);
|
groupCorba.setLayoutData(gdCorba);
|
|
final StringFieldEditor dbCorbaIP = new StringFieldEditor(PreferenceConstants.P_PATH_COMBOIP, "Corba µØÖ·(&I):", groupCorba);
|
addField(dbCorbaIP);
|
|
|
final StringFieldEditor corbaCommand = new StringFieldEditor(PreferenceConstants.combo_command, "Corba ÃüÁî(&C):", groupCorba);
|
addField(corbaCommand);
|
|
Corba_Home = new DirectoryFieldEditor(PreferenceConstants.P_PATH_COMBOHOME, "Corba_&Home:", groupCorba);
|
addField(Corba_Home);
|
|
// Group groupOp = new Group(parent, 1);
|
// groupOp.setText("²Ù×÷");
|
// GridData opCorba = new GridData(GridData.FILL_BOTH);
|
// groupCorba.setLayoutData(opCorba);
|
Group groupOP = new Group(parent, 1);//32);
|
groupOP.setText("²Ù×÷");
|
GridData dataOP = new GridData(GridData.FILL_BOTH);//4, 16777216, true, false);
|
groupOP.setLayoutData(dataOP);
|
GridLayout layout = new GridLayout();
|
layout.numColumns = 3;
|
groupOP.setLayout(layout);
|
|
|
Button buttoninit = new Button(groupOP, SWT.PUSH);
|
buttoninit.setText("³õʼ»¯...");
|
buttoninit.addSelectionListener(new SelectionAdapter() {
|
public void widgetSelected(SelectionEvent e) {
|
int returnint = resetEclipseHomeVariable();
|
if (returnint == 1) {
|
return;
|
}
|
|
String psdefault_vcihome = VCI_Home.getStringValue();
|
if (psdefault_vcihome != null && !psdefault_vcihome.equals("")) {
|
// ²éѯxml
|
getXMlInfo(psdefault_vcihome);
|
getPreferenceStore().setValue(PreferenceConstants.P_PATH_VCIHOME, psdefault_vcihome);
|
|
if (Corba_Home.getStringValue().equals("")) {
|
Corba_Home.setStringValue(psdefault_vcihome + "\\JacORB");
|
getPreferenceStore().setValue(PreferenceConstants.P_PATH_COMBOHOME, psdefault_vcihome + "\\JacORB");
|
}
|
|
if (getPreferenceStore().getString(PreferenceConstants.combo_command).equals("")) {
|
getPreferenceStore().setValue(PreferenceConstants.combo_command, "ns -p 30000");
|
}
|
|
if (javaHome.getStringValue().equals("")) {
|
javaHome.setStringValue(psdefault_vcihome + "\\jre");
|
getPreferenceStore().setValue(PreferenceConstants.java_home, psdefault_vcihome + "\\jre");
|
}
|
|
getPreferenceStore().setValue(PreferenceConstants.P_STRING_URL_IP, getIP());
|
getPreferenceStore().setValue(PreferenceConstants.P_STRING_URL_INSTANCE, getInstance());
|
|
getPreferenceStore().setValue(PreferenceConstants.P_STRING_USER, username);
|
getPreferenceStore().setValue(PreferenceConstants.P_STRING_PWD, password);
|
corboInfo = getCombaInfo(psdefault_vcihome);
|
// ³õʼ»¯
|
initCorbaServer();
|
getPreferenceStore().setValue(PreferenceConstants.P_PATH_COMBOIP, getCombaip());
|
|
}
|
initialize();
|
MessageDialog.openInformation(getShell(), "Ìáʾ", "³õʼ»¯Íê³É" + "\n");
|
}
|
});
|
|
Button button = new Button(groupOP, SWT.PUSH);
|
button.setText("²âÊÔÊý¾Ý¿â ...");
|
button.addSelectionListener(new SelectionAdapter() {
|
public void widgetSelected(SelectionEvent e) {
|
try {
|
testDBConnect();
|
// ±£´æÊý¾Ý¿âÐÅÏ¢
|
saveXML();
|
// ±£´æCombaÐÅÏ¢
|
setCombaInfo();
|
} catch (SQLException e1) {
|
MessageDialog.openInformation(getShell(), "Ìáʾ", "Êý¾Ý¿âÁ¬½Óʧ°Ü" + "\n" + e1.getMessage());
|
}
|
}
|
});
|
|
Button buttonComba = new Button(groupOP, SWT.PUSH);
|
buttonComba.setText("Æô¶¯Corba·þÎñ...");
|
buttonComba.addSelectionListener(new SelectionAdapter() {
|
public void widgetSelected(SelectionEvent e) {
|
if (Corba_Home.getStringValue().equals("")) {
|
MessageDialog.openInformation(getShell(), "Ìáʾ", "ÇëÑ¡ÔñVCI_Corba·¾¶");
|
return;
|
|
}
|
getPreferenceStore().setValue(PreferenceConstants.P_PATH_COMBOHOME, Corba_Home.getStringValue());
|
getPreferenceStore().setValue(PreferenceConstants.java_home, javaHome.getStringValue());
|
getPreferenceStore().setValue(PreferenceConstants.combo_command, corbaCommand.getStringValue());
|
|
runCorba();
|
}
|
});
|
|
}
|
|
private void initCorbaServer() {
|
if (initTable == true) {
|
// return;
|
}
|
table.removeAll();
|
for (int i = 0; i < Integer.parseInt((String) properties.get("servicecount")); i++) {
|
String index = Integer.toString(i);
|
String name = (String) properties.get("service" + i + ".name");
|
String clazz = (String) properties.get("service" + i + ".class");
|
TableItem item = new TableItem(table, i);
|
item.setText(new String[] { index, name, clazz, "Y" });
|
}
|
initTable = true;
|
}
|
|
// private void addSecondSection(Composite parent) {
|
// //Composite composite = createDefaultComposite(parent);
|
// //Group groupHome = new Group(composite, 1);
|
// Group groupCorba = new Group(parent, 1);
|
// groupCorba.setText("Corba ÉèÖÃ");
|
// GridData gd = new GridData(GridData.FILL_BOTH);
|
// groupCorba.setLayoutData(gd);
|
// Corba_Home = new DirectoryFieldEditor(PreferenceConstants.P_PATH_COMBOHOME, "&Corba_Home:", groupCorba);
|
// addField(Corba_Home);
|
//
|
// // addSeparator(composite);
|
// //Composite compositeCommand = createDefaultComposite(parent);
|
// //Group groupCommand = new Group(compositeCommand, 1);
|
//// Group groupCommand = new Group(parent, 1);
|
//// groupCommand.setText("Corba CommandÉèÖÃ");
|
//// GridData gdCommand = new GridData(GridData.FILL_BOTH);
|
//// groupCommand.setLayoutData(gdCommand);
|
// final StringFieldEditor corbaCommand = new StringFieldEditor(PreferenceConstants.combo_command, "Corba ÃüÁî:", groupCorba);
|
// addField(corbaCommand);
|
//
|
// //final DirectoryFieldEditor
|
// javaHome = new DirectoryFieldEditor(PreferenceConstants.java_home, "Java home:", groupCorba);
|
// addField(javaHome);
|
//
|
// Button buttonComba = new Button(groupCorba, SWT.PUSH);
|
// buttonComba.setText("Æô¶¯Corba·þÎñ...");
|
// buttonComba.addSelectionListener(new SelectionAdapter() {
|
// public void widgetSelected(SelectionEvent e) {
|
// if (Corba_Home.getStringValue().equals("")) {
|
// MessageDialog.openInformation(getShell(), "Ìáʾ", "ÇëÑ¡ÔñVCI_Corba·¾¶");
|
// return;
|
//
|
// }
|
// getPreferenceStore().setValue(PreferenceConstants.P_PATH_COMBOHOME, Corba_Home.getStringValue());
|
// getPreferenceStore().setValue(PreferenceConstants.java_home, javaHome.getStringValue());
|
// getPreferenceStore().setValue(PreferenceConstants.combo_command, corbaCommand.getStringValue());
|
//
|
// runComba();
|
// }
|
// });
|
//
|
// }
|
|
// private Composite createDefaultComposite(Composite parent) {
|
// Composite composite = new Composite(parent, SWT.NULL);
|
// GridLayout layout = new GridLayout();
|
// layout.numColumns = 2;
|
// composite.setLayout(layout);
|
//
|
// GridData data = new GridData();
|
// data.verticalAlignment = GridData.FILL_BOTH;
|
// data.horizontalAlignment = GridData.FILL_BOTH;
|
// composite.setLayoutData(data);
|
//
|
// return composite;
|
// }
|
|
private void addSeparator(Composite parent) {
|
|
Label separator = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
|
GridData gridData = new GridData();
|
gridData.horizontalAlignment = GridData.FILL;
|
gridData.grabExcessHorizontalSpace = true;
|
separator.setLayoutData(gridData);
|
}
|
|
private void runCorba() {
|
try {
|
setCombaRun();
|
Runtime.getRuntime().exec("cmd /c start " + getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME) + "\\run.bat /k");
|
// p.waitFor();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
private String getInstance() {
|
String Instance = "";
|
if (url != null) {
|
String[] urls = url.split(":");
|
Instance = urls[urls.length - 1];
|
}
|
return Instance;
|
}
|
|
private void testDBConnect() throws SQLException {
|
Connection conn = null;
|
try {
|
Class.forName("oracle.jdbc.driver.OracleDriver");
|
String url = "jdbc:oracle:thin:@"
|
+ getPreferenceStore().getString(PreferenceConstants.P_STRING_URL_IP)
|
+ ":1521:"
|
+ getPreferenceStore().getString(PreferenceConstants.P_STRING_URL_INSTANCE);
|
String user = getPreferenceStore().getString(PreferenceConstants.P_STRING_USER);
|
String pwd = getPreferenceStore().getString(PreferenceConstants.P_STRING_PWD);
|
conn = DriverManager.getConnection(url, user, pwd);
|
conn.createStatement();
|
if (conn != null) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ", "Êý¾Ý¿âÁ¬½Ó³É¹¦");
|
}
|
} catch (ClassNotFoundException e) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ", "Êý¾Ý¿âÁ¬½Óʧ°Ü" + "\n" + e.getMessage());
|
} catch (SQLException e) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ", "Êý¾Ý¿âÁ¬½Óʧ°Ü" + "\n" + e.getMessage());
|
} finally {
|
if (conn != null) {
|
conn.close();
|
}
|
}
|
}
|
|
class SortedProperties extends Properties {
|
private static final long serialVersionUID = 1L;
|
private final LinkedHashSet<Object> keys = new LinkedHashSet<Object>();
|
|
public Enumeration<Object> keys() {
|
return Collections.enumeration(keys);
|
}
|
|
public Object put(Object key, Object value) {
|
keys.add(key);
|
return super.put(key, value);
|
}
|
|
public Set<Object> keySet() {
|
return keys;
|
}
|
|
public Set<String> stringPropertyNames() {
|
Set<String> set = new LinkedHashSet<String>();
|
for (Object key : this.keys) {
|
set.add((String) key);
|
}
|
return set;
|
}
|
}
|
|
private void setCombaRun() {
|
String encode = "UTF8";
|
File file = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME) + "\\run.bat");
|
Path path = new Path(getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME));
|
|
OutputStream out = null;
|
InputStream inStream = null;
|
try {
|
inStream = new FileInputStream(file);
|
InputStreamReader iread = new InputStreamReader(inStream, encode);
|
BufferedReader reader = new BufferedReader(iread);
|
reader.readLine();
|
reader.close();
|
out = new FileOutputStream(file);
|
OutputStreamWriter twriter = new OutputStreamWriter(out, encode);
|
BufferedWriter writer = new BufferedWriter(twriter);
|
|
// ±éÀú lib
|
File targetfile = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME) + "\\lib");
|
File[] jarFiles = targetfile.listFiles();
|
if (jarFiles == null) {
|
return;
|
}
|
|
List<String> platformpaths = new ArrayList<String>();
|
for (int i = 0; i < jarFiles.length; i++) {
|
String filename = jarFiles[i].getName();
|
if (isJarFile(filename)) {
|
String jarPath = jarFiles[i].getAbsolutePath();
|
platformpaths.add(jarPath);
|
}
|
}
|
StringBuffer s = new StringBuffer();
|
s.append("set path=");
|
s.append(getPreferenceStore().getString(PreferenceConstants.java_home));
|
s.append("\\bin;%PATH% \n");
|
s.append("SET CLASSPATH=%CLASSPATH%;");
|
for (int i = 0; i < platformpaths.size(); i++) {
|
s.append(platformpaths.get(i));
|
s.append(";");
|
}
|
String title = s.toString().substring(0, s.lastIndexOf(";"));
|
s.delete(0, s.length());
|
s.append(title);
|
s.append("\n");
|
|
s.append(" cd \\ \n");
|
s.append(" cd /d " + path.getDevice() + "\\ \n");
|
s.append(" cd "
|
+ getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOHOME) + " \n");
|
s.append(" cd bin \n");
|
s.append(getPreferenceStore().getString(PreferenceConstants.combo_command));
|
// s.append("ns -DOAPort=30000 \n");
|
writer.append(s.toString());
|
writer.flush();
|
writer.close();
|
|
} catch (FileNotFoundException e) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ", e.getMessage());
|
} catch (UnsupportedEncodingException e) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ", e.getMessage());
|
} catch (IOException e) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ", e.getMessage());
|
}
|
}
|
|
private boolean isJarFile(String fileName) {
|
if (fileName == null)
|
return false;
|
int last = fileName.lastIndexOf(".");
|
if (last == -1) {
|
return false;
|
}
|
String suffix = fileName.substring(fileName.lastIndexOf("."));
|
if (suffix.equals(".jar"))
|
return true;
|
else
|
return false;
|
}
|
|
private void setCombaInfo() {
|
|
File file = new File(getPreferenceStore().getString(PreferenceConstants.P_PATH_VCIHOME) + "\\src\\properties\\conf.properties");
|
InputStream inStream = null;
|
OutputStream out = null;
|
try {
|
inStream = new FileInputStream(file);
|
properties.load(inStream);
|
if (inStream != null) {
|
inStream.close();
|
}
|
|
out = new FileOutputStream(file);
|
properties.setProperty("NameService", "corbaloc::" + getPreferenceStore().getString(PreferenceConstants.P_PATH_COMBOIP) + "/NameService");
|
properties.store(out, "conf.properties version by Eclipse");
|
if (out != null) {
|
out.close();
|
}
|
|
} catch (IOException e) {
|
MessageDialog
|
.openInformation(this.getShell(), "Ìáʾ", e.getMessage());
|
}
|
|
}
|
|
private String getCombaInfo(String VCI_Home_Path) {
|
|
File file = new File(VCI_Home_Path + "\\src\\properties\\conf.properties");
|
InputStream inStream = null;
|
|
try {
|
inStream = new BufferedInputStream(new FileInputStream(file));
|
properties.load(inStream);
|
if (inStream != null) {
|
inStream.close();
|
}
|
} catch (IOException e) {
|
MessageDialog
|
.openInformation(this.getShell(), "Ìáʾ", e.getMessage());
|
}
|
return properties.getProperty("NameService");
|
}
|
|
private void saveXML() {
|
Element cpElement;
|
|
try {
|
DocumentBuilderFactory facrtory = DocumentBuilderFactory
|
.newInstance();
|
facrtory.setNamespaceAware(true);
|
DocumentBuilder parser = facrtory.newDocumentBuilder();
|
parser.setEntityResolver(new EntityResolver() {
|
|
public InputSource resolveEntity(String publicId,
|
String systemId) throws SAXException, IOException {
|
if (publicId
|
.equals("-//Hibernate/Hibernate Configuration DTD 3.0//EN")) {
|
String path = systemId
|
.substring("http://hibernate.sourceforge.net/"
|
.length());
|
return new InputSource(this.getClass()
|
.getResourceAsStream(path));
|
}
|
return null;
|
|
}
|
});
|
parser.getSchema();
|
facrtory.getSchema();
|
facrtory.isNamespaceAware();
|
Document document = parser.parse(getPreferenceStore().getString(
|
PreferenceConstants.P_PATH_VCIHOME)
|
+ "\\properties\\hibernate.cfg.xml");
|
cpElement = document.getDocumentElement();
|
cpElement.getElementsByTagName("property");
|
cpElement.getAttributeNode("name");
|
|
NodeList childs = cpElement.getChildNodes();
|
for (int i = 0; i < childs.getLength(); i++) {
|
Node childNode = childs.item(i);
|
if (childNode instanceof Element) {
|
childNode.getNodeName();
|
childNode.getFirstChild().getNodeValue();
|
Node propertychildnode = childNode.getFirstChild();
|
while (propertychildnode != null) {
|
Node node = propertychildnode.getNextSibling();
|
if (node != null && node instanceof Element) {
|
if (node.getAttributes().getNamedItem("name") == null) {
|
break;
|
}
|
Object o = node.getAttributes()
|
.getNamedItem("name").getNodeValue();
|
if (o != null
|
&& o.toString().equals("connection.url")) {
|
String url = "jdbc:oracle:thin:@"
|
+ getPreferenceStore()
|
.getString(
|
PreferenceConstants.P_STRING_URL_IP)
|
+ ":1521:"
|
+ getPreferenceStore()
|
.getString(
|
PreferenceConstants.P_STRING_URL_INSTANCE);
|
|
node.setTextContent(url);
|
} else if (o != null
|
&& o.toString().equals(
|
"connection.username")) {
|
String user = getPreferenceStore().getString(
|
PreferenceConstants.P_STRING_USER);
|
|
node.setTextContent(user);
|
} else if (o != null
|
&& o.toString().equals(
|
"connection.password")) {
|
String pwd = getPreferenceStore().getString(
|
PreferenceConstants.P_STRING_PWD);
|
node.setTextContent(pwd);
|
}
|
}
|
propertychildnode = node;
|
}
|
|
}
|
|
}
|
Source sourcexml = new DOMSource(document);
|
TransformerFactory transformFactory = TransformerFactory
|
.newInstance();
|
Transformer tansformer = transformFactory.newTransformer();
|
tansformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, document
|
.getDoctype().getPublicId());
|
tansformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, document
|
.getDoctype().getSystemId());
|
Result result = new StreamResult(getPreferenceStore().getString(
|
PreferenceConstants.P_PATH_VCIHOME)
|
+ "\\properties\\hibernate.cfg.xml");
|
tansformer.transform(sourcexml, result);
|
|
} catch (Exception localSAXException) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ",
|
localSAXException.getMessage());
|
}
|
|
}
|
|
private void getXMlInfo(String VCI_Home_Path) {
|
Element cpElement;
|
|
// Configuration config = new Configuration();
|
// config.setEntityResolver(new EJB3DTDEntityResolver());
|
// config.configure(new File(
|
// VCI_Home_Path + "\\properties\\hibernate.cfg.xml"));
|
|
try {
|
DocumentBuilderFactory facrtory = DocumentBuilderFactory
|
.newInstance();
|
DocumentBuilder parser = facrtory.newDocumentBuilder();
|
parser.setEntityResolver(new EntityResolver() {
|
|
public InputSource resolveEntity(String publicId,
|
String systemId) throws SAXException, IOException {
|
if (publicId
|
.equals("-//Hibernate/Hibernate Configuration DTD 3.0//EN")) {
|
String path = systemId
|
.substring("http://hibernate.sourceforge.net/"
|
.length());
|
return new InputSource(this.getClass()
|
.getResourceAsStream(path));
|
}
|
return null;
|
|
}
|
});
|
cpElement = parser.parse(
|
VCI_Home_Path + "\\properties\\hibernate.cfg.xml")
|
.getDocumentElement();
|
|
cpElement.getElementsByTagName("property");
|
cpElement.getAttributeNode("name");
|
NodeList childs = cpElement.getChildNodes();
|
for (int i = 0; i < childs.getLength(); i++) {
|
Node childNode = childs.item(i);
|
if (childNode instanceof Element) {
|
childNode.getNodeName();
|
childNode.getFirstChild().getNodeValue();
|
Node propertychildnode = childNode.getFirstChild();
|
while (propertychildnode != null) {
|
Node node = propertychildnode.getNextSibling();
|
if (node != null && node instanceof Element) {
|
if (node.getAttributes().getNamedItem("name") == null) {
|
break;
|
}
|
Object o = node.getAttributes().getNamedItem("name").getNodeValue();
|
if (o != null && o.toString().equals("connection.url")) {
|
url = node.getTextContent();
|
} else if (o != null && o.toString().equals("connection.username")) {
|
username = node.getTextContent();
|
} else if (o != null && o.toString().equals("connection.password")) {
|
password = node.getTextContent();
|
}
|
}
|
propertychildnode = node;
|
}
|
|
}
|
|
}
|
} catch (Exception localSAXException) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ",
|
localSAXException.getMessage());
|
}
|
}
|
|
private String getIP() {
|
String ip = "";
|
if (url != null) {
|
String[] urls = url.split(":");
|
for (int i = 0; i < urls.length; i++) {
|
if (urls[i].contains("@")) {
|
ip = urls[i].substring(urls[i].indexOf("@") + 1,
|
urls[i].length());
|
}
|
}
|
}
|
return ip;
|
}
|
|
private String getCombaip() {
|
return corboInfo.substring(corboInfo.indexOf("::") + 2,
|
corboInfo.indexOf("/"));
|
}
|
|
/*
|
* (non-Javadoc)
|
*
|
* @see
|
* org.eclipse.ui.IWorkbenchPreferencePage#init(org.eclipse.ui.IWorkbench)
|
*/
|
public void init(IWorkbench workbench) {
|
|
}
|
|
public void performApply() {
|
resetEclipseHomeVariable();
|
super.performApply();
|
|
}
|
|
public boolean performOk() {
|
resetEclipseHomeVariable();
|
super.performOk();
|
return true;
|
}
|
|
/*
|
* make ClassPathVariable
|
*/
|
public int resetEclipseHomeVariable() {
|
try {
|
// ÉèÖÃ
|
VCI_Home_Path = VCI_Home.getStringValue();
|
// getPreferenceStore().setValue(PreferenceConstants.P_PATH_VCIHOME,
|
// VCI_Home_Path);
|
JavaCore.setClasspathVariable("VCI_HOME", new Path(VCI_Home_Path), null);
|
VCI_Corba_Path = Corba_Home.getStringValue();
|
JavaCore.setClasspathVariable("Comba_HOME", new Path(VCI_Corba_Path), null);
|
} catch (CoreException localCoreException) {
|
localCoreException.printStackTrace();
|
}
|
if (VCI_Home_Path.equals("")) {
|
MessageDialog.openInformation(this.getShell(), "Ìáʾ", "ÇëÑ¡ÔñVCI_Home·¾¶");
|
return 1;
|
|
}
|
|
return 0;
|
}
|
|
public void applyData(Object data) {
|
|
super.applyData(data);
|
}
|
|
@SuppressWarnings("unused")
|
public boolean delItemOfProperties(String key, String value)
|
throws Exception {
|
boolean flag = false;
|
String replace = key + "=" + value + "\n";
|
StringBuffer text = new StringBuffer();
|
String templine;
|
File file = new File(VCI_Home_Path + "\\src\\properties\\conf.properties");
|
BufferedReader reader = new BufferedReader(new FileReader(file));
|
while ((templine = reader.readLine()) != null) {
|
// templine = templine;
|
}
|
return true;
|
}
|
}
|