Search in sources :

Example 21 with ConnectionBean

use of org.talend.core.model.general.ConnectionBean in project tdi-studio-se by Talend.

the class ConnectionsListButtonsToolBar method createAddPushButton.

@Override
protected AddPushButton createAddPushButton() {
    return new AddPushButtonForExtendedTable(this.toolbar, getExtendedTableViewer()) {

        @Override
        protected Object getObjectToAdd() {
            ConnectionBean newConnection = new ConnectionBean();
            newConnection.setName(NEW_CONNECTION_LABEL);
            return newConnection;
        }
    };
}
Also used : AddPushButtonForExtendedTable(org.talend.commons.ui.swt.advanced.dataeditor.button.AddPushButtonForExtendedTable) ConnectionBean(org.talend.core.model.general.ConnectionBean)

Example 22 with ConnectionBean

use of org.talend.core.model.general.ConnectionBean in project tdi-studio-se by Talend.

the class ConnectionsListComposite method setConnectionsFormComposite.

public void setConnectionsFormComposite(ConnectionFormComposite connectionsFormComposite) {
    this.connectionsFormComposite = connectionsFormComposite;
    table.getTableViewerCreator().getSelectionHelper().addAfterSelectionListener(new ILineSelectionListener() {

        @Override
        public void handle(LineSelectionEvent e) {
            ISelection sel = e.source.getTableViewer().getSelection();
            IStructuredSelection sel2 = (IStructuredSelection) sel;
            ConnectionBean selected = (ConnectionBean) sel2.getFirstElement();
            setSelectedConnection(selected);
        }
    });
    if (!list.isEmpty()) {
        for (int i = 0; i < list.size(); i++) {
            setSelectedConnection(list.get(i));
        }
        setSelectedConnection(list.get(0));
    }
}
Also used : LineSelectionEvent(org.talend.commons.ui.runtime.swt.tableviewer.selection.LineSelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) ConnectionBean(org.talend.core.model.general.ConnectionBean) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ILineSelectionListener(org.talend.commons.ui.runtime.swt.tableviewer.selection.ILineSelectionListener)

Example 23 with ConnectionBean

use of org.talend.core.model.general.ConnectionBean in project tdi-studio-se by Talend.

the class TOSLoginComposite method addListener.

private void addListener() {
    createButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Project project = null;
            ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
            NewProjectWizard newPrjWiz = new NewProjectWizard(null);
            WizardDialog newProjectDialog = new WizardDialog(getShell(), newPrjWiz);
            //$NON-NLS-1$
            newProjectDialog.setTitle(Messages.getString("LoginDialog.newProjectTitle"));
            if (newProjectDialog.open() == Window.OK) {
                project = newPrjWiz.getProject();
                refresh();
                ArrayList<String> allProjects = (ArrayList<String>) projectListViewer.getInput();
                int index = 0;
                Collections.sort(allProjects);
                for (int i = 0; i < allProjects.size(); i++) {
                    String projectName = allProjects.get(i);
                    if (project.getLabel().equals(projectName)) {
                        index = i;
                        break;
                    }
                }
                projectListViewer.getList().select(index);
                projectListViewer.refresh();
            }
        }
    });
    deleteButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Shell activeShell = Display.getCurrent().getActiveShell();
            SelectDeleteProjectDialog dialog = new SelectDeleteProjectDialog(activeShell, true);
            if (dialog.open() == Dialog.OK) {
                CorePlugin.getDefault().getRepositoryLocalProviderService().resetXmiResourceSet();
                java.util.List<Object> delList = dialog.getDelList();
                if (delList.size() != 0) {
                    for (Object obj : delList) {
                        if (obj instanceof IProject) {
                            IProject p = (IProject) obj;
                            if (projectsMap.containsKey(p.getName())) {
                                projectsMap.remove(p.getName());
                                String name = convertorMapper.get(p.getName());
                                if (name != null) {
                                    convertorMapper.remove(p.getName());
                                    TOSLoginComposite.this.projectListViewer.getList().remove(name);
                                }
                                if (TOSLoginComposite.this.projectListViewer.getList().getItemCount() == 0) {
                                    enableOpenAndDelete(false);
                                } else if (TOSLoginComposite.this.projectListViewer.getSelection().isEmpty()) {
                                    TOSLoginComposite.this.projectListViewer.getList().select(0);
                                }
                                try {
                                    setStatusArea();
                                } catch (PersistenceException e1) {
                                    ExceptionHandler.process(e1);
                                }
                            }
                        }
                    }
                }
            }
            refresh();
        }
    });
    importButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ImportDemoProjectAction.getInstance().setShell(getShell());
            ImportProjectAsAction.getInstance().run();
            String newProject = ImportProjectAsAction.getInstance().getProjectName();
            if (newProject != null) {
                ProxyRepositoryFactory repositoryFactory = ProxyRepositoryFactory.getInstance();
                Project[] projects = null;
                try {
                    projects = repositoryFactory.readProject();
                } catch (PersistenceException e1) {
                    e1.printStackTrace();
                } catch (BusinessException e1) {
                    e1.printStackTrace();
                }
                if (!projectsMap.containsKey(newProject.toUpperCase())) {
                    for (Project project : projects) {
                        if (project.getLabel().toUpperCase().equals(newProject.toUpperCase())) {
                            projectsMap.put(newProject.toUpperCase(), project);
                            convertorMapper.put(newProject.toUpperCase(), newProject);
                            enableOpenAndDelete(true);
                            try {
                                setStatusArea();
                            } catch (PersistenceException e1) {
                                ExceptionHandler.process(e1);
                            }
                        }
                    }
                    TOSLoginComposite.this.projectListViewer.setInput(new ArrayList(convertorMapper.values()));
                }
            }
            try {
                IRunnableWithProgress op = new IRunnableWithProgress() {

                    @Override
                    public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                        try {
                            ProxyRepositoryFactory.getInstance().initialize();
                        } catch (PersistenceException e) {
                            throw new InvocationTargetException(e);
                        }
                    }
                };
                new ProgressMonitorDialog(getShell()).run(true, false, op);
                refresh();
            } catch (InvocationTargetException e1) {
                e1.getTargetException();
            } catch (InterruptedException e1) {
                e1.printStackTrace();
            }
        }
    });
    changeButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dirDialog = new DirectoryDialog(dialog.getShell());
            String path = dirDialog.open();
            if (path == null || "".equals(path)) {
                //$NON-NLS-1$
                workspaceText.setText(getRecentWorkSpace());
                loginComposite.getConnection().setWorkSpace(getRecentWorkSpace());
            } else {
                workspaceText.setText(path);
                loginComposite.getConnection().setWorkSpace(path);
                if (!path.equals(oldPath)) {
                    oldPath = path;
                    restartBut.setVisible(true);
                    openButton.setEnabled(false);
                    deleteButton.setEnabled(false);
                    createButton.setEnabled(false);
                    importButton.setEnabled(false);
                    demoProjectButton.setEnabled(false);
                    changeButton.setEnabled(false);
                }
            }
            java.util.List<ConnectionBean> list = new ArrayList<ConnectionBean>();
            list.add(loginComposite.getConnection());
            loginComposite.storedConnections = list;
            perReader.saveConnections(loginComposite.storedConnections);
            if (!loginComposite.isWorkSpaceSame()) {
                try {
                    setStatusArea();
                } catch (PersistenceException e1) {
                    ExceptionHandler.process(e1);
                }
            }
        }
    });
    restartBut.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            LoginComposite.isRestart = true;
            ConnectionBean connection = loginComposite.getConnection();
            perReader.saveLastConnectionBean(connection);
            // update the restart command line to specify the workspace to launch
            // if relaunch, should delete the "disableLoginDialog" argument in eclipse data for bug TDI-19214
            //$NON-NLS-1$
            EclipseCommandLine.updateOrCreateExitDataPropertyWithCommand("-data", connection.getWorkSpace(), false);
            // store the workspace in the eclipse history so that it is rememebered on next studio launch
            //$NON-NLS-1$
            ChooseWorkspaceData workspaceData = new ChooseWorkspaceData("");
            workspaceData.workspaceSelected(connection.getWorkSpace());
            workspaceData.writePersistedData();
            dialog.okPressed();
        }
    });
    openButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            loginComposite.setRepositoryContextInContext();
            if (!TOSLoginComposite.this.projectListViewer.getSelection().isEmpty()) {
                String selection = TOSLoginComposite.this.projectListViewer.getList().getSelection()[0];
                if (selection != null && !selection.equals("")) {
                    Project project = (Project) projectsMap.get(selection.toUpperCase());
                    boolean flag = dialog.logIn(project);
                    if (flag) {
                        dialog.okPressed();
                    }
                }
            }
        }
    });
    demoProjectButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            ImportDemoProjectAction action = ImportDemoProjectAction.getInstance();
            action.setShell(getShell());
            action.run();
            refresh();
        }
    });
}
Also used : ImportDemoProjectAction(org.talend.repository.ui.actions.importproject.ImportDemoProjectAction) ArrayList(java.util.ArrayList) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Shell(org.eclipse.swt.widgets.Shell) BusinessException(org.talend.commons.exception.BusinessException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) NewProjectWizard(org.talend.repository.ui.wizards.newproject.NewProjectWizard) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog) ChooseWorkspaceData(org.talend.core.ui.workspace.ChooseWorkspaceData) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IProject(org.eclipse.core.resources.IProject) InvocationTargetException(java.lang.reflect.InvocationTargetException) SelectDeleteProjectDialog(org.talend.repository.ui.actions.importproject.SelectDeleteProjectDialog) Project(org.talend.core.model.general.Project) IProject(org.eclipse.core.resources.IProject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) PersistenceException(org.talend.commons.exception.PersistenceException) ConnectionBean(org.talend.core.model.general.ConnectionBean) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Aggregations

ConnectionBean (org.talend.core.model.general.ConnectionBean)23 PersistenceException (org.talend.commons.exception.PersistenceException)8 ArrayList (java.util.ArrayList)7 Project (org.talend.core.model.general.Project)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)5 JSONException (org.talend.utils.json.JSONException)5 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)4 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Shell (org.eclipse.swt.widgets.Shell)4 SystemException (org.talend.commons.exception.SystemException)4 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)4 IBrandingService (org.talend.core.ui.branding.IBrandingService)4 List (java.util.List)3 User (org.talend.core.model.properties.User)3 JSONObject (org.talend.utils.json.JSONObject)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IProject (org.eclipse.core.resources.IProject)2 Job (org.eclipse.core.runtime.jobs.Job)2