use of net.sourceforge.sqlexplorer.ExplorerException in project tdq-studio-se by Talend.
the class AliasManager method saveAliases.
/**
* Saves all the Aliases to the users preferences
*/
public void saveAliases() throws ExplorerException {
DefaultElement root = new DefaultElement(Alias.ALIASES);
for (Alias alias : aliases.values()) {
root.add(alias.describeAsXml());
}
try {
FileWriter writer = new FileWriter(new File(ApplicationFiles.USER_ALIAS_FILE_NAME));
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(root);
writer.flush();
writer.close();
} catch (IOException e) {
throw new ExplorerException(e);
}
}
use of net.sourceforge.sqlexplorer.ExplorerException in project tdq-studio-se by Talend.
the class DriverManager method restoreDrivers.
/**
* Restores drivers to their default location
* @throws ExplorerException
*/
public void restoreDrivers() throws ExplorerException {
try {
drivers.clear();
highestId = 0;
URL url = URLUtil.getResourceURL("default_drivers.xml");
loadDrivers(url.openStream());
} catch (IOException e) {
throw new ExplorerException(e);
}
}
use of net.sourceforge.sqlexplorer.ExplorerException in project tdq-studio-se by Talend.
the class DriverManager method saveDrivers.
/**
* Saves the drivers back to disk
* @throws ExplorerException
*/
public void saveDrivers() throws ExplorerException {
Element root = new DefaultElement(DRIVERS);
for (ManagedDriver driver : drivers.values()) root.add(driver.describeAsXml());
try {
FileWriter writer = new FileWriter(new File(ApplicationFiles.USER_DRIVER_FILE_NAME));
OutputFormat format = OutputFormat.createPrettyPrint();
XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.write(root);
writer.flush();
writer.close();
} catch (IOException e) {
throw new ExplorerException(e);
}
}
use of net.sourceforge.sqlexplorer.ExplorerException in project tdq-studio-se by Talend.
the class RowCountTab method getDataSet.
public DataSet getDataSet() throws ExplorerException {
String nodeName = getNode().toString();
if (getNode() instanceof TableNode) {
TableNode tableNode = (TableNode) getNode();
nodeName = tableNode.getQualifiedName();
}
try {
// $NON-NLS-1$
return new DataSet(null, "select count(*) from " + nodeName, null, getNode().getSession());
} catch (SQLException e) {
throw new ExplorerException(e);
}
}
use of net.sourceforge.sqlexplorer.ExplorerException in project tdq-studio-se by Talend.
the class DriverLabelProvider method createContents.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) The UI is
* defined in the DriverContainerGroup class. Note: The [Restore Default] and [Apply] buttons have been removed
* using the noDefaultandApplyButton method as these don't apply since all updates are made in the corresponding
* dialogs.
*/
@Override
protected Control createContents(Composite parent) {
noDefaultAndApplyButton();
_driverModel = SQLExplorerPlugin.getDefault().getDriverModel();
PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, SQLExplorerPlugin.PLUGIN_ID + ".DriverContainerGroup");
_prefs = SQLExplorerPlugin.getDefault().getPreferenceStore();
GridLayout parentLayout = new GridLayout(1, false);
parentLayout.marginTop = parentLayout.marginBottom = 0;
parentLayout.marginHeight = 0;
parentLayout.verticalSpacing = 10;
parent.setLayout(parentLayout);
GridLayout layout;
Composite myComposite = new Composite(parent, SWT.NONE);
// Define layout.
layout = new GridLayout();
layout.numColumns = 2;
layout.marginWidth = layout.marginHeight = 0;
layout.horizontalSpacing = 20;
layout.verticalSpacing = 10;
myComposite.setLayout(layout);
myComposite.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true));
GridData gid = new GridData(GridData.FILL_BOTH);
gid.grabExcessHorizontalSpace = gid.grabExcessVerticalSpace = true;
gid.horizontalAlignment = gid.verticalAlignment = GridData.FILL;
gid.verticalSpan = 6;
_tableViewer = new TableViewer(myComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
_tableViewer.getControl().setLayoutData(gid);
_tableViewer.setContentProvider(new DriverContentProvider());
final DriverLabelProvider dlp = new DriverLabelProvider();
_tableViewer.setLabelProvider(dlp);
_tableViewer.getTable().addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
dlp.dispose();
if (_boldfont != null) {
_boldfont.dispose();
}
}
});
_tableViewer.getTable().addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent e) {
changeDriver();
}
});
_tableViewer.setInput(_driverModel);
selectFirst();
final Table table = _tableViewer.getTable();
myComposite.layout();
parent.layout();
// Add Buttons
gid = new GridData(GridData.FILL);
gid.widthHint = 75;
Button add = new Button(myComposite, SWT.PUSH);
add.setText(Messages.getString("Preferences.Drivers.Button.Add"));
add.setLayoutData(gid);
add.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
CreateDriverDlg dlg = new CreateDriverDlg(getShell(), CreateDriverDlg.Type.CREATE, null);
dlg.open();
_tableViewer.refresh();
selectFirst();
}
});
gid = new GridData(GridData.FILL);
gid.widthHint = 75;
Button edit = new Button(myComposite, SWT.PUSH);
edit.setText(Messages.getString("Preferences.Drivers.Button.Edit"));
edit.setLayoutData(gid);
edit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
changeDriver();
_tableViewer.refresh();
}
});
gid = new GridData(GridData.FILL);
gid.widthHint = 75;
Button copy = new Button(myComposite, SWT.PUSH);
copy.setText(Messages.getString("Preferences.Drivers.Button.Copy"));
copy.setLayoutData(gid);
copy.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
StructuredSelection sel = (StructuredSelection) _tableViewer.getSelection();
ManagedDriver dv = (ManagedDriver) sel.getFirstElement();
if (dv != null) {
CreateDriverDlg dlg = new CreateDriverDlg(getShell(), CreateDriverDlg.Type.COPY, dv);
dlg.open();
_tableViewer.refresh();
}
}
});
gid = new GridData(GridData.FILL);
gid.widthHint = 75;
Button remove = new Button(myComposite, SWT.PUSH);
remove.setText(Messages.getString("Preferences.Drivers.Button.Remove"));
remove.setLayoutData(gid);
remove.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
StructuredSelection sel = (StructuredSelection) _tableViewer.getSelection();
ManagedDriver managedDriver = (ManagedDriver) sel.getFirstElement();
if (managedDriver != null) {
// when the driver is used by other Aliases, give a warning to user
if (managedDriver.isUsedByAliases()) {
MessageDialog.openWarning(getShell(), Messages.getString("Preferences.Drivers.ConfirmDelete.Title"), Messages.getString("Preferences.Drivers.ConfirmDelete.Warning"));
} else {
boolean okToDelete = MessageDialog.openConfirm(getShell(), Messages.getString("Preferences.Drivers.ConfirmDelete.Title"), Messages.getString("Preferences.Drivers.ConfirmDelete.Prefix") + _tableViewer.getTable().getSelection()[0].getText() + Messages.getString("Preferences.Drivers.ConfirmDelete.Postfix"));
if (okToDelete) {
_driverModel.removeDriver(managedDriver);
_tableViewer.refresh();
selectFirst();
}
}
}
}
});
gid = new GridData(GridData.FILL);
gid.widthHint = 73;
Button bdefault = new Button(myComposite, SWT.PUSH);
bdefault.setText(Messages.getString("Preferences.Drivers.Button.Default"));
bdefault.setLayoutData(gid);
// Remove bold font on all elements, and make selected element bold
bdefault.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
for (int i = 0; i < _tableViewer.getTable().getItemCount(); i++) {
_tableViewer.getTable().getItem(i).setFont(0, table.getFont());
}
_boldfont = new Font(_tableViewer.getTable().getDisplay(), table.getFont().toString(), table.getFont().getFontData()[0].getHeight(), SWT.BOLD);
_tableViewer.getTable().getSelection()[0].setFont(0, _boldfont);
_prefs.setValue(IConstants.DEFAULT_DRIVER, _tableViewer.getTable().getSelection()[0].getText());
}
});
// add button to restore default drivers
Button bRestore = new Button(parent, SWT.PUSH);
bRestore.setText(Messages.getString("Preferences.Drivers.Button.RestoreDefault"));
bRestore.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
try {
_driverModel.restoreDrivers();
_tableViewer.refresh();
selectFirst();
} catch (ExplorerException ex) {
SQLExplorerPlugin.error("Cannot restore default driver configuration", ex);
}
}
});
bRestore.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, false, false));
selectDefault(table);
return parent;
}
Aggregations