Search in sources :

Example 1 with FTPWizard

use of org.talend.repository.ftp.ui.wizards.FTPWizard in project tdi-studio-se by Talend.

the class CreateFTPConnectionAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.actions.AContextualAction#doRun()
     */
@Override
protected void doRun() {
    RepositoryNode dbConnectionNode = getCurrentRepositoryNode();
    if (isToolbar()) {
        if (dbConnectionNode != null && dbConnectionNode.getContentType() != ERepositoryObjectType.METADATA_FILE_FTP) {
            dbConnectionNode = null;
        }
        if (dbConnectionNode == null) {
            dbConnectionNode = getRepositoryNodeForDefault(ERepositoryObjectType.METADATA_FILE_FTP);
        }
    }
    RepositoryNode metadataNode = dbConnectionNode.getParent();
    if (metadataNode != null) {
        // Force focus to the repositoryView and open Metadata and DbConnection nodes
        IRepositoryView viewPart = getViewPart();
        if (viewPart != null) {
            viewPart.setFocus();
            viewPart.expand(metadataNode, true);
            viewPart.expand(dbConnectionNode, true);
        }
    }
    FTPConnection connection = null;
    IPath pathToSave = null;
    // Define the RepositoryNode, by default Metadata/DbConnection
    RepositoryNode node = dbConnectionNode;
    ISelection selection = null;
    // When the userSelection is an element of metadataNode, use it !
    if (!isToolbar()) {
        Object userSelection = ((IStructuredSelection) getSelection()).getFirstElement();
        if (userSelection instanceof RepositoryNode) {
            switch(((RepositoryNode) userSelection).getType()) {
                case REPOSITORY_ELEMENT:
                case SIMPLE_FOLDER:
                case SYSTEM_FOLDER:
                    node = (RepositoryNode) userSelection;
                    break;
            }
        }
        selection = getSelection();
    }
    boolean creation = false;
    // Define the repositoryObject DatabaseConnection and his pathToSave
    switch(node.getType()) {
        case REPOSITORY_ELEMENT:
            // pathToSave = null;
            connection = (FTPConnection) ((ConnectionItem) node.getObject().getProperty().getItem()).getConnection();
            creation = false;
            break;
        case SIMPLE_FOLDER:
            pathToSave = RepositoryNodeUtilities.getPath(node);
            connection = ConnectionFactory.eINSTANCE.createFTPConnection();
            creation = true;
            break;
        case SYSTEM_FOLDER:
            //$NON-NLS-1$
            pathToSave = new Path("");
            connection = ConnectionFactory.eINSTANCE.createFTPConnection();
            creation = true;
            break;
    }
    // Init the content of the Wizard
    init(node);
    FTPWizard ftpWizard;
    if (isToolbar()) {
        ftpWizard = new FTPWizard(PlatformUI.getWorkbench(), creation, node, getExistingNames());
        ftpWizard.setToolBar(true);
    } else {
        ftpWizard = new FTPWizard(PlatformUI.getWorkbench(), creation, selection, getExistingNames());
    }
    // Open the Wizard
    WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(), ftpWizard);
    wizardDialog.setPageSize(700, 550);
    wizardDialog.create();
    wizardDialog.open();
    IRepositoryView view = getViewPart();
    if (view != null) {
        view.expand(dbConnectionNode, true);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) FTPConnectionItem(org.talend.core.model.properties.FTPConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) FTPConnection(org.talend.core.model.metadata.builder.connection.FTPConnection) FTPWizard(org.talend.repository.ftp.ui.wizards.FTPWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 FTPConnection (org.talend.core.model.metadata.builder.connection.FTPConnection)1 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 FTPConnectionItem (org.talend.core.model.properties.FTPConnectionItem)1 FTPWizard (org.talend.repository.ftp.ui.wizards.FTPWizard)1 RepositoryNode (org.talend.repository.model.RepositoryNode)1 IRepositoryView (org.talend.repository.ui.views.IRepositoryView)1