use of net.sourceforge.sqlexplorer.util.MyURLClassLoader in project tdq-studio-se by Talend.
the class FileLabelProvider method createExtraClassPathPanel.
private void createExtraClassPathPanel(final TabFolder tabFolder, TabItem tabItem) {
Composite parent = new Composite(tabFolder, SWT.NULL);
parent.setLayout(new FillLayout());
tabItem.setControl(parent);
Composite cmp = new Composite(parent, SWT.NULL);
GridLayout grid = new GridLayout();
grid.numColumns = 2;
cmp.setLayout(grid);
extraClassPathList = new ListViewer(cmp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData data = new GridData();
data.grabExcessVerticalSpace = true;
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
extraClassPathList.getControl().setLayoutData(data);
extraClassPathList.setContentProvider(new FileContentProvider());
extraClassPathList.setLabelProvider(new FileLabelProvider());
extraClassPathList.setInput(defaultModel);
Composite left = new Composite(cmp, SWT.NULL);
data = new GridData();
data.horizontalSpan = 1;
data.grabExcessVerticalSpace = true;
data.widthHint = 100;
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
left.setLayoutData(data);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
left.setLayout(gridLayout);
_extraClasspathListDriversBtn = new Button(left, SWT.NULL);
_extraClasspathListDriversBtn.setText(Messages.getString("List_Drivers_21"));
_extraClasspathListDriversBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
combo.removeAll();
File file = (File) ((IStructuredSelection) extraClassPathList.getSelection()).getFirstElement();
if (file != null) {
try {
MyURLClassLoader cl = new MyURLClassLoader(file.toURL());
Class[] classes = cl.getAssignableClasses(Driver.class);
for (int i = 0; i < classes.length; ++i) {
combo.add(classes[i].getName());
}
} catch (Exception ex) {
SQLExplorerPlugin.error(ex);
}
}
if (combo.getItemCount() > 0) {
combo.setText(combo.getItem(0));
}
validate();
}
});
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = GridData.FILL;
_extraClasspathListDriversBtn.setLayoutData(data);
_extraClasspathUpBtn = new Button(left, SWT.NULL);
_extraClasspathUpBtn.setText(Messages.getString("Up_22"));
_extraClasspathUpBtn.setEnabled(false);
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = GridData.FILL;
_extraClasspathUpBtn.setLayoutData(data);
_extraClasspathDownBtn = new Button(left, SWT.NULL);
_extraClasspathDownBtn.setText(Messages.getString("Down_23"));
_extraClasspathDownBtn.setEnabled(false);
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = GridData.FILL;
_extraClasspathDownBtn.setLayoutData(data);
newBtn = new Button(left, SWT.NULL);
newBtn.setText(Messages.getString("New_24"));
newBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
FileDialog dlg = new FileDialog(tabFolder.getShell(), SWT.OPEN);
dlg.setFilterExtensions(new String[] { "*.jar;*.zip" });
String str = dlg.open();
if (str != null) {
Object obj = new File(str);
defaultModel.add(obj);
extraClassPathList.refresh();
StructuredSelection sel = new StructuredSelection(obj);
extraClassPathList.setSelection(sel);
}
}
});
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = GridData.FILL;
newBtn.setLayoutData(data);
_extraClasspathDeleteBtn = new Button(left, SWT.NULL);
_extraClasspathDeleteBtn.setText(Messages.getString("Delete_26"));
_extraClasspathDeleteBtn.setEnabled(false);
_extraClasspathDeleteBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
File f = (File) ((IStructuredSelection) extraClassPathList.getSelection()).getFirstElement();
if (f != null) {
defaultModel.remove(f);
extraClassPathList.refresh();
if (defaultModel.size() > 0) {
Object obj = (defaultModel.toArray())[0];
StructuredSelection sel = new StructuredSelection(obj);
extraClassPathList.setSelection(sel);
}
}
}
});
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = GridData.FILL;
_extraClasspathDeleteBtn.setLayoutData(data);
extraClassPathList.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
File f = (File) selection.getFirstElement();
if (f != null) {
_extraClasspathDeleteBtn.setEnabled(true);
_extraClasspathListDriversBtn.setEnabled(true);
} else {
_extraClasspathListDriversBtn.setEnabled(false);
_extraClasspathDeleteBtn.setEnabled(false);
}
}
});
}
use of net.sourceforge.sqlexplorer.util.MyURLClassLoader in project tdq-studio-se by Talend.
the class SqlexplorerService method getDriver.
/*
* (non-Javadoc)
*
* @see org.talend.dataprofiler.service.ISqlexplorerService#getDriver(java.lang.String, java.lang.String)
*/
@Override
public Driver getDriver(String driverClassName, String jarsPath) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
Driver driver = null;
if (StringUtils.isNotEmpty(jarsPath)) {
try {
driver = this.createGenericJDBC(jarsPath, driverClassName);
} catch (Exception e) {
log.error(e, e);
}
return driver;
}
SQLExplorerPlugin sqlExplorerPlugin = SQLExplorerPlugin.getDefault();
if (sqlExplorerPlugin != null) {
net.sourceforge.sqlexplorer.dbproduct.DriverManager driverModel = sqlExplorerPlugin.getDriverModel();
try {
Collection<ManagedDriver> drivers = driverModel.getDrivers();
for (ManagedDriver managedDriver : drivers) {
LinkedList<String> jars = managedDriver.getJars();
List<URL> urls = new ArrayList<URL>();
for (int i = 0; i < jars.size(); i++) {
File file = new File(jars.get(i));
if (file.exists()) {
urls.add(file.toURI().toURL());
}
}
if (!urls.isEmpty()) {
try {
MyURLClassLoader cl;
cl = new MyURLClassLoader(urls.toArray(new URL[0]));
Class<?> clazz = cl.findClass(driverClassName);
if (clazz != null) {
driver = (Driver) clazz.newInstance();
if (driver != null) {
return driver;
}
}
} catch (ClassNotFoundException e) {
// do nothings
}
}
}
} catch (MalformedURLException e) {
// do nothings
}
}
if (driver == null) {
driver = (Driver) Class.forName(driverClassName).newInstance();
}
return driver;
}
use of net.sourceforge.sqlexplorer.util.MyURLClassLoader in project tdq-studio-se by Talend.
the class FileLabelProvider method createJavaClassPathPanel.
private void createJavaClassPathPanel(TabFolder tabFolder, TabItem tabItem) {
Composite parent = new Composite(tabFolder, SWT.NULL);
parent.setLayout(new FillLayout());
tabItem.setControl(parent);
Composite cmp = new Composite(parent, SWT.NULL);
GridLayout grid = new GridLayout();
grid.numColumns = 2;
cmp.setLayout(grid);
javaClassPathList = new ListViewer(cmp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
GridData data = new GridData();
data.grabExcessVerticalSpace = true;
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
data.grabExcessHorizontalSpace = true;
javaClassPathList.getControl().setLayoutData(data);
javaClassPathList.setContentProvider(new FileContentProvider());
javaClassPathList.setLabelProvider(new FileLabelProvider());
ClassPathListModel model = new ClassPathListModel();
javaClassPathList.setInput(model);
Composite left = new Composite(cmp, SWT.NULL);
data = new GridData();
data.horizontalSpan = 1;
data.grabExcessVerticalSpace = true;
data.widthHint = 100;
data.horizontalAlignment = GridData.FILL;
data.verticalAlignment = GridData.FILL;
left.setLayoutData(data);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 1;
left.setLayout(gridLayout);
_javaClasspathListDriversBtn = new Button(left, SWT.NULL);
_javaClasspathListDriversBtn.setText(Messages.getString("List_Drivers_20"));
_javaClasspathListDriversBtn.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
combo.removeAll();
File file = (File) ((IStructuredSelection) javaClassPathList.getSelection()).getFirstElement();
if (file != null) {
try {
MyURLClassLoader cl = new MyURLClassLoader(file.toURL());
Class[] classes = cl.getAssignableClasses(Driver.class);
for (int i = 0; i < classes.length; ++i) {
combo.add(classes[i].getName());
}
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
if (combo.getItemCount() > 0) {
combo.setText(combo.getItem(0));
}
}
});
data = new GridData();
data.grabExcessHorizontalSpace = true;
data.horizontalAlignment = GridData.FILL;
_javaClasspathListDriversBtn.setLayoutData(data);
javaClassPathList.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection) event.getSelection();
File f = (File) selection.getFirstElement();
if (f != null) {
if (f.isFile())
_javaClasspathListDriversBtn.setEnabled(true);
else
_javaClasspathListDriversBtn.setEnabled(false);
} else
_javaClasspathListDriversBtn.setEnabled(false);
}
});
if (model.size() > 0) {
Object obj = (model.toArray())[0];
StructuredSelection sel = new StructuredSelection(obj);
javaClassPathList.setSelection(sel);
}
}
Aggregations