Search in sources :

Example 6 with ExplorerException

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);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) DefaultElement(org.dom4j.tree.DefaultElement) FileWriter(java.io.FileWriter) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 7 with ExplorerException

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);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) IOException(java.io.IOException) URL(java.net.URL)

Example 8 with ExplorerException

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);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) DefaultElement(org.dom4j.tree.DefaultElement) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) FileWriter(java.io.FileWriter) OutputFormat(org.dom4j.io.OutputFormat) IOException(java.io.IOException) File(java.io.File) XMLWriter(org.dom4j.io.XMLWriter)

Example 9 with ExplorerException

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);
    }
}
Also used : ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) DataSet(net.sourceforge.sqlexplorer.dataset.DataSet) SQLException(java.sql.SQLException) TableNode(net.sourceforge.sqlexplorer.dbstructure.nodes.TableNode)

Example 10 with ExplorerException

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;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) MouseEvent(org.eclipse.swt.events.MouseEvent) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ExplorerException(net.sourceforge.sqlexplorer.ExplorerException) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) CreateDriverDlg(net.sourceforge.sqlexplorer.dialogs.CreateDriverDlg) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ExplorerException (net.sourceforge.sqlexplorer.ExplorerException)12 IOException (java.io.IOException)5 File (java.io.File)4 DefaultElement (org.dom4j.tree.DefaultElement)4 Element (org.dom4j.Element)3 SAXReader (org.dom4j.io.SAXReader)3 FileWriter (java.io.FileWriter)2 SQLException (java.sql.SQLException)2 ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)2 DocumentException (org.dom4j.DocumentException)2 OutputFormat (org.dom4j.io.OutputFormat)2 XMLWriter (org.dom4j.io.XMLWriter)2 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 Connection (java.sql.Connection)1 Properties (java.util.Properties)1 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)1 DataSet (net.sourceforge.sqlexplorer.dataset.DataSet)1 XmlDataType (net.sourceforge.sqlexplorer.dataset.XmlDataType)1