Search in sources :

Example 1 with SessionEstablishedAdapter

use of net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter in project tdq-studio-se by Talend.

the class FileListEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    // Configure the editor
    setSite(site);
    setInput(input);
    // Create the text editor
    editor = new TextEditor();
    editor.init(site, input);
    // Make sure we get notification that our editor is closing because
    // we may need to stop running queries
    getSite().getPage().addPartListener(new PartAdapter2() {

        /* (non-JavaDoc)
			 * @see net.sourceforge.sqlexplorer.util.PartAdapter2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
			 */
        public void partClosed(IWorkbenchPartReference partRef) {
            if (partRef.getPart(false) == FileListEditor.this) {
                onCloseEditor();
            }
        }
    });
    // If we havn't got a view, then try for the current session in the ConnectionsView
    if (getSession() == null) {
        ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
        if (view != null) {
            User user = view.getDefaultUser();
            if (user != null)
                user.queueForNewSession(new SessionEstablishedAdapter() {

                    @Override
                    public void sessionEstablished(Session session) {
                        setSession(session);
                    }
                });
        }
    }
}
Also used : PartAdapter2(net.sourceforge.sqlexplorer.util.PartAdapter2) TextEditor(org.eclipse.ui.editors.text.TextEditor) User(net.sourceforge.sqlexplorer.dbproduct.User) ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 2 with SessionEstablishedAdapter

use of net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter in project tdq-studio-se by Talend.

the class OpenPasswordConnectDialogAction method run.

public void run() {
    SessionEstablishedListener listener = null;
    if (!user.hasAuthenticated())
        listener = new SessionEstablishedAdapter() {

            @Override
            public void sessionEstablished(Session session) {
                Display.getDefault().asyncExec(new Runnable() {

                    public void run() {
                        DatabaseStructureView dsView = SQLExplorerPlugin.getDefault().getDatabaseStructureView();
                        if (dsView != null)
                            try {
                                dsView.addUser(user);
                            } catch (SQLCannotConnectException e) {
                                MessageDialog.openError(Display.getDefault().getActiveShell(), "Cannot connect", e.getMessage());
                            }
                    }
                });
            }
        };
    ConnectionJob.createSession(alias, user, listener, alwaysPrompt);
}
Also used : SessionEstablishedListener(net.sourceforge.sqlexplorer.connections.SessionEstablishedListener) DatabaseStructureView(net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session) SQLCannotConnectException(net.sourceforge.sqlexplorer.SQLCannotConnectException)

Example 3 with SessionEstablishedAdapter

use of net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter in project tdq-studio-se by Talend.

the class SQLEditor method setInput.

/*
     * (non-JavaDoc)
     * 
     * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
     */
@Override
protected void setInput(IEditorInput input) {
    super.setInput(input);
    if (textEditor != null) {
        textEditor.setInput(input);
    }
    // Handle our own form of input
    if (input instanceof SQLEditorInput) {
        SQLEditorInput sqlInput = (SQLEditorInput) input;
        if (input != null) {
            User user = sqlInput.getUser();
            if (user != null) {
                user.queueForNewSession(new SessionEstablishedAdapter() {

                    @Override
                    public void sessionEstablished(Session session) {
                        setSession(session);
                    }
                });
            }
            isDirty = true;
            isUntitled = true;
        }
    }
    // set part name as displayName + " " + version
    String partName = input.getName();
    if (input instanceof FileEditorInput) {
        FileEditorInput fileEditorInput = (FileEditorInput) input;
        // $NON-NLS-1$
        IPath fileName = fileEditorInput.getPath().removeFileExtension().addFileExtension("properties");
        Property property = null;
        URI propURI = URI.createFileURI(fileName.toOSString());
        Resource resource = new ResourceSetImpl().getResource(propURI, true);
        if (resource.getContents() != null) {
            Object object = EcoreUtil.getObjectByType(resource.getContents(), PropertiesPackage.eINSTANCE.getProperty());
            if (object != null) {
                property = (Property) object;
            }
        }
        if (property != null) {
            // $NON-NLS-1$
            partName = property.getDisplayName() + " " + property.getVersion();
        }
    }
    setPartName(partName);
}
Also used : User(net.sourceforge.sqlexplorer.dbproduct.User) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) IPath(org.eclipse.core.runtime.IPath) Resource(org.eclipse.emf.ecore.resource.Resource) IResource(org.eclipse.core.resources.IResource) URI(org.eclipse.emf.common.util.URI) FileEditorInput(org.eclipse.ui.part.FileEditorInput) Property(org.talend.core.model.properties.Property) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Example 4 with SessionEstablishedAdapter

use of net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter in project tdq-studio-se by Talend.

the class SQLEditor method init.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
     */
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    // Configure the editor
    setSite(site);
    // PTODO qzhang fixed bug 3904: syschronize the resource.
    if (input instanceof FileEditorInput) {
        try {
            ((FileEditorInput) input).getFile().getParent().refreshLocal(IResource.DEPTH_ONE, null);
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
    setInput(input);
    // Create the text editor
    textEditor = new SQLTextEditor(this);
    textEditor.init(site, input);
    // setPartName(getSite().getPage().getLabel());
    // Make sure we get notification that our editor is closing because
    // we may need to stop running queries
    getSite().getPage().addPartListener(new PartAdapter2() {

        /*
             * (non-JavaDoc)
             * 
             * @see net.sourceforge.sqlexplorer.util.PartAdapter2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
             */
        @Override
        public void partClosed(IWorkbenchPartReference partRef) {
            if (partRef.getPart(false) == SQLEditor.this) {
                onCloseEditor();
            }
        }
    });
    // If we havn't got a view, then try for the current session in the ConnectionsView
    if (getSession() == null) {
        ConnectionsView view = SQLExplorerPlugin.getDefault().getConnectionsView();
        if (view != null) {
            User user = view.getDefaultUser();
            if (user != null) {
                user.queueForNewSession(new SessionEstablishedAdapter() {

                    @Override
                    public void sessionEstablished(Session session) {
                        setSession(session);
                    }
                });
            }
        }
    }
}
Also used : PartAdapter2(net.sourceforge.sqlexplorer.util.PartAdapter2) User(net.sourceforge.sqlexplorer.dbproduct.User) CoreException(org.eclipse.core.runtime.CoreException) ConnectionsView(net.sourceforge.sqlexplorer.connections.ConnectionsView) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IWorkbenchPartReference(org.eclipse.ui.IWorkbenchPartReference) SessionEstablishedAdapter(net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter) Session(net.sourceforge.sqlexplorer.dbproduct.Session)

Aggregations

SessionEstablishedAdapter (net.sourceforge.sqlexplorer.connections.SessionEstablishedAdapter)4 Session (net.sourceforge.sqlexplorer.dbproduct.Session)4 User (net.sourceforge.sqlexplorer.dbproduct.User)3 ConnectionsView (net.sourceforge.sqlexplorer.connections.ConnectionsView)2 PartAdapter2 (net.sourceforge.sqlexplorer.util.PartAdapter2)2 IWorkbenchPartReference (org.eclipse.ui.IWorkbenchPartReference)2 FileEditorInput (org.eclipse.ui.part.FileEditorInput)2 SQLCannotConnectException (net.sourceforge.sqlexplorer.SQLCannotConnectException)1 SessionEstablishedListener (net.sourceforge.sqlexplorer.connections.SessionEstablishedListener)1 DatabaseStructureView (net.sourceforge.sqlexplorer.plugin.views.DatabaseStructureView)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)1 TextEditor (org.eclipse.ui.editors.text.TextEditor)1 Property (org.talend.core.model.properties.Property)1