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);
}
}
Aggregations