datasourcetablesection.java
来自「一个eclipse插件源代码。用于web开发」· Java 代码 · 共 315 行
JAVA
315 行
/*
* $Header: /home/cvs/WEBPUMP2.0/WebPumpIDE_Src/WebPumpIDE/src/com/webpump/ui/datasource/editor/DataSourceTableSection.java,v 1.1.1.1 2004/07/01 09:07:43 wang_j Exp $
* $Revision: 1.1.1.1 $
* $Date: 2004/07/01 09:07:43 $
*
* ====================================================================
*
* The NanJing HopeRun(IT-FOREST) Software License, Version 2.0.0
*
* Copyright 2003-2004 by NanJing HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and
* IT Forest Corporation
* All rights reserved.
*
* This software is the confidential and proprietary information of
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
* You shall not disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into with
* HopeRun(IT-FOREST) Information System Co., Ltd, CHINA and IT Forest Corporation.
*/
package com.webpump.ui.datasource.editor;
import java.sql.DriverManager;
import java.util.Vector;
import java.sql.*;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.swt.widgets.TableItem;
import com.webpump.ui.base.data.BaseModel;
import com.webpump.ui.base.gui.BasePage;
import com.webpump.ui.base.gui.BaseTableSection;
import com.webpump.ui.datasource.data.DataSource;
import com.webpump.ui.datasource.data.DataSourceModel;
import com.webpump.ui.datasource.data.PropertyInfo;
import com.webpump.ui.datasource.data.SourceList;
import com.webpump.ui.datasource.dialog.CreateLogicBeanDialog;
import com.webpump.ui.dialog.AddDialog;
import com.webpump.ui.perspective.MacroResource;
import com.webpump.ui.perspective.WebpumpIDEPlugin;
/**
* Class for the table part of the datasource editor.
*
* @author zhang_tx
* @version 2.0.0 2004-2-24
*/
public class DataSourceTableSection extends BaseTableSection{
private Object recentmodel;
private DataSourceEditor m_objEditor;
// private int insert = 0;
String PropertyName[] = {"factory","driverClassName","url","username","password","maxActive","maxIdle","maxWait" };
public static Vector m_objtablename = new Vector();
private String m_strPrefix = "";
private String []m_strPriKeyList;
/**
* the constructor which define the content of this part
* @param page the page in which the part lies
*/
public DataSourceTableSection(BasePage page) {
//Define the layout of the part using the super class's constructor
super(page, new String[] {(WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_EDITOR_TABLESECTION_BUTTONA)),null,
(WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_EDITOR_TABLESECTION_BUTTONB)),null,
(WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_EDITOR_TABLESECTION_BUTTONC)),null,
(WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_EDITOR_TABLESECTION_BUTTOND))});
//Set the head text of this part
this.setHeaderText((WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_EDITOR_TABLESECTION_NAME)));
handleDefaultButton = false;
m_objEditor = (DataSourceEditor)((DataSourcePage)page).getEditor();
m_strPrefix = ((DataSourceEditor)((DataSourcePage)page).getEditor()).getProjectPath();
}
/**
* Initialize the layout of this part
* @param input the input in "datasource.xml"
*/
public void initialize(Object input) {
BaseModel model = (BaseModel) input;
//Initialize this part by inputting the model's AllException in it
tableViewer.setInput((SourceList)(model.getDataObject()));
if(tableViewer.getTable().getItemCount() == 0||((IStructuredSelection)tableViewer.getSelection()).getFirstElement() == null){
getTablePart().setButtonEnabled(2, false);
getTablePart().setButtonEnabled(4, false);
getTablePart().setButtonEnabled(6, false);
}
model.addModelChangedListener(this);
}
/**
* Define the action to the tableViewer after the selection is changed
* @param selection the selected item
*/
protected void selectionChanged(IStructuredSelection selection) {
DataSourceInfoSection objDataSourceInfoSection1 = ((DataSourceForm)(getFormPage().getForm())).getDataSourceInfoSection();
objDataSourceInfoSection1.setSel(selection);
//Get the selected element
Object item = selection.getFirstElement();
if(tableViewer.getTable().getItemCount() == 0||item == null){
getTablePart().setButtonEnabled(2, false);
getTablePart().setButtonEnabled(4, false);
getTablePart().setButtonEnabled(6, false);
}else{
getTablePart().setButtonEnabled(2, true);
getTablePart().setButtonEnabled(4, true);
getTablePart().setButtonEnabled(6, true);
}
DataSource SelectedDataSource = (DataSource) item;
if (item == null){
m_strSelectName = null;
DataSourceInfoSection objDataSourceInfoSection = ((DataSourceForm)(getFormPage().getForm())).getDataSourceInfoSection();
//refresh the content of the infosection Texts
objDataSourceInfoSection.setAuthor("");
objDataSourceInfoSection.setType("");
objDataSourceInfoSection.setFactory("");
objDataSourceInfoSection.setDriverClass("");
objDataSourceInfoSection.setURL("");
objDataSourceInfoSection.setUser("");
objDataSourceInfoSection.setPassWord("");
objDataSourceInfoSection.setMaxActive("");
objDataSourceInfoSection.setMaxIdle("");
objDataSourceInfoSection.setMaxWait("");
}
if(item!=null) {
//Get the object of ExceptionDetailSection
DataSourceInfoSection objDataSourceInfoSection = ((DataSourceForm)(getFormPage().getForm())).getDataSourceInfoSection();
//Set the button style on the ExceptionDetailSection
Vector SelectionPropertyInfo = SelectedDataSource.getvPropertyInfo();
String []infovalue = new String[8];
String []sourceProp = new String[2];
sourceProp[0] = SelectedDataSource.getSourceProp().getAuthor();
sourceProp[1] = SelectedDataSource.getSourceProp().getSourceType();
for(int j=0;j<8;j++){
PropertyInfo info = (PropertyInfo)SelectionPropertyInfo.get(j);
String propname = info.toString();
for(int i = 0;i<8;i++){
if(propname.compareTo(PropertyName[i]) == 0){
infovalue[i] = info.getValue();
break;
}
}
}
//update the content of the infosection Texts
objDataSourceInfoSection.setSeltag();
objDataSourceInfoSection.setAuthor(sourceProp[0]);
objDataSourceInfoSection.setType(sourceProp[1]);
objDataSourceInfoSection.setFactory(infovalue[0]);
objDataSourceInfoSection.setDriverClass(infovalue[1]);
objDataSourceInfoSection.setURL(infovalue[2]);
objDataSourceInfoSection.setUser(infovalue[3]);
objDataSourceInfoSection.setPassWord(infovalue[4]);
objDataSourceInfoSection.setMaxActive(infovalue[5]);
objDataSourceInfoSection.setMaxIdle(infovalue[6]);
objDataSourceInfoSection.setMaxWait(infovalue[7]);
objDataSourceInfoSection.resetSeltag();
}
}
/**
* Define what to do when selecting one of the botton
* @param index a param which indicates the botton which has been selected
*/
protected void buttonSelected(int index) {
if (index == 0)
handleAdd();
if (index == 4)
handleReMove();
if (index == 2)
handleConnect();
if (index == 6)
handleCreateLB();
}
public TableViewer getTableViewer(){
return tableViewer;
}
/**
* Set the button style
* @param item the selected item
*/
public void setButtonStyle(Object item){
if (isReadOnly())
return;
boolean addEnabled = false;
boolean removeEnabled = false;
boolean editEnabled = false;
if (item != null){
if (item instanceof DataSource){
addEnabled = true;
removeEnabled = true;
editEnabled = true;
} else{
addEnabled = false;
removeEnabled = false;
}
}
getTablePart().setButtonEnabled(0, addEnabled);
getTablePart().setButtonEnabled(2, removeEnabled);
getTablePart().setButtonEnabled(4, editEnabled);
}
/**
* Set the button style
*/
public void setButtonStyle(){
//Get the selected item from the table viewer
IStructuredSelection sel =
(IStructuredSelection) tableViewer.getSelection();
Object item = sel.getFirstElement();
//Set the botton style on the selection
setButtonStyle(item);
}
/**
* add new database
*/
public void handleAdd(){
// insert = 1;
DataSourceModel currentModel = (DataSourceModel)getFormPage().getEditor().getModel();
SourceList currentsources = (SourceList)currentModel.getDataObject();
String strValue = "";
AddDialog objWizard = new AddDialog(WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_LISTTITLE),
WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_LISTTITLE),
WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_DESCRIPTION),
WebpumpIDEPlugin.getResourceString(MacroResource.DATASOURCE_LABLE_TEXT),
strValue,
currentsources);
objWizard.init(WebpumpIDEPlugin.getDefault().getWorkbench(), null);
WizardDialog objDialog = new WizardDialog(WebpumpIDEPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(),objWizard);
String value = "";
DataSource add ;
IStructuredSelection sel;
if (objDialog.open() == WizardDialog.OK )
{
add = new DataSource();
add.init();
value = objWizard.getValue();
add.setName(value);
currentsources.addDataSource(add);
this.update();
sel = new StructuredSelection(add);
DataSourceInfoSection objDataSourceInfoSection = ((DataSourceForm)(getFormPage().getForm())).getDataSourceInfoSection();
objDataSourceInfoSection.setSel(sel);
tableViewer.setSelection(sel);
}
}
/**
* remove a selected database
*/
public void handleReMove(){
IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
DataSource object = (DataSource) sel.getFirstElement();
SourceList parent = (SourceList)object.getParent();
parent.remove(object);
if(tableViewer.getTable().getItemCount() == 0||((IStructuredSelection)tableViewer.getSelection()).getFirstElement() == null){
getTablePart().setButtonEnabled(2, false);
getTablePart().setButtonEnabled(4, false);
getTablePart().setButtonEnabled(6, false);
}
Object first = tableViewer.getElementAt(0);
if(first!= null){
sel = new StructuredSelection(first);
tableViewer.setSelection(sel);
DataSourceInfoSection objDataSourceInfoSection = ((DataSourceForm)(getFormPage().getForm())).getDataSourceInfoSection();
objDataSourceInfoSection.setSel(sel);
}
}
/**
* test connection of the selected database
*/
public void handleConnect(){
Connection conn = null;
boolean bNeedClose = false;
boolean bNeedRollBack = false;
IStructuredSelection sel = (IStructuredSelection) tableViewer.getSelection();
DataSource object = (DataSource) sel.getFirstElement();
Vector SelectionPropertyInfo = object.getvPropertyInfo();
try
{
String strDBURL = ((PropertyInfo)SelectionPropertyInfo.get(2)).getValue();
String strDBUser = ((PropertyInfo)SelectionPropertyInfo.get(3)).getValue();
String strDBPassword = ((PropertyInfo)SelectionPropertyInfo.get(4)).getValue();
//1、联接
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?