Search in sources :

Example 1 with ISQLBuilderService

use of org.talend.core.ui.services.ISQLBuilderService in project tdi-studio-se by Talend.

the class NodeLabelEditPart method propertyChange.

/*
     * (non-Javadoc)
     * 
     * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
     */
public void propertyChange(final PropertyChangeEvent evt) {
    String request = evt.getPropertyName();
    if (request.equals(NodeLabel.OFFSET_CHANGE)) {
        //$NON-NLS-1$ //$NON-NLS-2$
        refreshVisuals();
        getParent().refresh();
    }
    if (request.equals(NodeLabel.TEXT_CHANGE)) {
        refreshVisuals();
        // set the new size to update the node container
        ((NodeLabel) getModel()).setLabelSize(((SimpleHtmlFigure) figure).getPreferredSize());
        NodeLabel label = (NodeLabel) getModel();
        if (GlobalServiceRegister.getDefault().isServiceRegistered(ISQLBuilderService.class)) {
            ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
            service.updateSqlBuilderDialogTitle(label.getLabelText(), label.getNode().getProcess().getName(), label.getNode().getUniqueName());
        }
        getParent().refresh();
        // refresh the title of component setting view.
        ComponentSettingsView viewer = (ComponentSettingsView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(ComponentSettingsView.ID);
        if (viewer != null) {
            viewer.updatePropertiesViewerTitle();
        }
    }
    if (request.equals(NodeLabel.LOCATION)) {
        //$NON-NLS-1$
        refreshVisuals();
        getParent().refresh();
    }
    if (request.equals(EParameterName.ACTIVATE.getName())) {
        if (((NodeLabel) getModel()).isActivate()) {
            ((SimpleHtmlFigure) figure).setAlpha(-1);
            ((SimpleHtmlFigure) figure).repaint();
            refreshVisuals();
        } else {
            ((SimpleHtmlFigure) figure).setAlpha(Node.ALPHA_VALUE);
            ((SimpleHtmlFigure) figure).repaint();
            refreshVisuals();
        }
    }
    EditPart editPart = getParent();
    if (editPart != null) {
        while ((!(editPart instanceof ProcessPart)) && (!(editPart instanceof SubjobContainerPart))) {
            editPart = editPart.getParent();
        }
        if (editPart instanceof SubjobContainerPart) {
            editPart.refresh();
        }
    }
}
Also used : AbstractGraphicalEditPart(org.eclipse.gef.editparts.AbstractGraphicalEditPart) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) ProcessPart(org.talend.designer.core.ui.editor.process.ProcessPart) ComponentSettingsView(org.talend.designer.core.ui.views.properties.ComponentSettingsView) SubjobContainerPart(org.talend.designer.core.ui.editor.subjobcontainer.SubjobContainerPart) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService) SimpleHtmlFigure(org.talend.commons.ui.utils.workbench.gef.SimpleHtmlFigure)

Example 2 with ISQLBuilderService

use of org.talend.core.ui.services.ISQLBuilderService in project tdi-studio-se by Talend.

the class DbTableController method createOpenSQLCommand.

/**
     * qzhang Comment method "createOpenSQLCommand".
     * 
     * @param button
     */
protected void createOpenSQLCommand(Button button, IContextManager contextManager) {
    final Button btn = button;
    initConnectionParameters();
    if (this.connParameters != null) {
        if (isUseExistingConnection()) {
            initConnectionParametersWithContext(connectionNode, contextManager.getDefaultContext());
        } else {
            initConnectionParametersWithContext(elem, contextManager.getDefaultContext());
        }
        DatabaseConnection connection = getExistConnection();
        if (connection == null) {
            ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
            connection = service.createConnection(connParameters);
        }
        boolean isStatus = false;
        if (connection != null) {
            String contextId = connection.getContextId();
            if (contextId == null || "".equals(contextId)) {
                IMetadataConnection metadataConnection = null;
                metadataConnection = ConvertionHelper.convert(connection);
                isStatus = checkConnection(metadataConnection);
            } else {
                isStatus = true;
            }
        }
        if (isStatus) {
            openSQLBuilderWithParamer(button);
        } else {
            Display.getDefault().asyncExec(new Runnable() {

                @Override
                public void run() {
                    //$NON-NLS-1$
                    String pid = "org.talend.sqlbuilder";
                    //$NON-NLS-1$
                    String mainMsg = "Database connection is failed. ";
                    ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
                    if (dialog.getCodeOfButton() == Window.OK) {
                        openParamemerDialog(btn, part.getProcess().getContextManager());
                    }
                }
            });
        }
    } else {
        Display.getDefault().asyncExec(new Runnable() {

            @Override
            public void run() {
                //$NON-NLS-1$
                String pid = "org.talend.sqlbuilder";
                //$NON-NLS-1$
                String mainMsg = "Database connection is failed. ";
                ErrorDialogWithDetailAreaAndContinueButton dialog = new ErrorDialogWithDetailAreaAndContinueButton(composite.getShell(), pid, mainMsg, connParameters.getConnectionComment());
                if (dialog.getCodeOfButton() == Window.OK) {
                    openParamemerDialog(btn, part.getProcess().getContextManager());
                }
            }
        });
    }
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) Button(org.eclipse.swt.widgets.Button) ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService)

Example 3 with ISQLBuilderService

use of org.talend.core.ui.services.ISQLBuilderService in project tdi-studio-se by Talend.

the class ActiveProcessTracker method partClosed.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
     */
@Override
public void partClosed(IWorkbenchPart part) {
    if (part instanceof AbstractMultiPageTalendEditor && currentProcess != null) {
        AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
        if (mpte.isKeepPropertyLocked()) {
            currentProcess = null;
            return;
        }
        IProcess process = getJobFromActivatedEditor(part);
        if (process != null) {
            Problems.removeProblemsByProcess(process);
            Problems.removeJob(process);
            IRunProcessService service = DesignerPlugin.getDefault().getRunProcessService();
            service.removeProcess(process);
            CodeView.refreshCodeView(null);
            if (currentProcess == process) {
                //$NON-NLS-1$
                Contexts.setTitle("");
                Contexts.clearAll();
                if (lastProcessOpened == currentProcess) {
                    lastProcessOpened = null;
                }
                currentProcess = null;
                for (IJobTrackerListener listener : jobTrackerListeners) {
                    listener.allJobClosed();
                }
            } else if (lastProcessOpened == process) {
                lastProcessOpened = currentProcess;
            }
            if (GlobalServiceRegister.getDefault().isServiceRegistered(ISQLBuilderService.class)) {
                ISQLBuilderService sqlBuilderService = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
                sqlBuilderService.closeSqlBuilderDialogs(process.getName());
            }
        }
    } else if (part instanceof IEditorPart) {
        if (GlobalServiceRegister.getDefault().isServiceRegistered(IDiagramModelService.class) && CorePlugin.getDefault().getDiagramModelService().isBusinessDiagramEditor((IEditorPart) part)) {
            //$NON-NLS-1$
            Contexts.setTitle("");
            Contexts.clearAll();
        }
    }
    if (part instanceof AbstractMultiPageTalendEditor) {
        AbstractMultiPageTalendEditor mpte = (AbstractMultiPageTalendEditor) part;
        mpte.beforeDispose();
        JobSettings.switchToCurJobSettingsView();
    }
}
Also used : IRunProcessService(org.talend.designer.runprocess.IRunProcessService) IEditorPart(org.eclipse.ui.IEditorPart) IProcess(org.talend.core.model.process.IProcess) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService)

Example 4 with ISQLBuilderService

use of org.talend.core.ui.services.ISQLBuilderService in project tdi-studio-se by Talend.

the class AbstractElementPropertySectionController method openSQLBuilder.

/**
     * DOC qzhang Comment method "openSQLBuilder".
     *
     * @param repositoryType
     * @param propertyName
     * @param query
     */
protected String openSQLBuilder(String repositoryType, String propertyName, String query) {
    if (repositoryType.equals(EmfComponent.BUILTIN)) {
        connParameters.setQuery(query);
        if (connParameters.isShowConfigParamDialog()) {
            if (!isUseExistingConnection()) {
                initConnectionParametersWithContext(elem, part.getProcess().getContextManager().getDefaultContext());
            } else {
                initConnectionParametersWithContext(connectionNode, part.getProcess().getContextManager().getDefaultContext());
            }
        }
        // add for bug TDI-20335
        if (part == null) {
            Shell parentShell = new Shell(composite.getShell().getDisplay());
            ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
            Dialog sqlBuilder = service.openSQLBuilderDialog(parentShell, "", connParameters);
            sqlBuilder.open();
        } else {
            openSqlBuilderBuildIn(connParameters, propertyName);
        }
    } else if (repositoryType.equals(EmfComponent.REPOSITORY)) {
        //$NON-NLS-1$
        String repositoryName2 = "";
        String repositoryId = null;
        IElementParameter memoParam = elem.getElementParameter(propertyName);
        IElementParameter repositoryParam = null;
        for (IElementParameter param : elem.getElementParameters()) {
            if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE && param.getRepositoryValue().startsWith("DATABASE")) {
                repositoryParam = param;
                break;
            }
        }
        // in case no database property found, take the first property (to keep compatibility with old code)
        if (repositoryParam == null) {
            for (IElementParameter param : elem.getElementParameters()) {
                if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
                    repositoryParam = param;
                    break;
                }
            }
        }
        if (repositoryParam != null) {
            IElementParameter itemFromRepository = repositoryParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            String value = (String) itemFromRepository.getValue();
            repositoryId = value;
            // for (String key : this.dynamicProperty.getRepositoryConnectionItemMap().keySet()) {
            // if (key.equals(value)) {
            // repositoryName2 =
            // this.dynamicProperty.getRepositoryConnectionItemMap().get(key).getProperty().getLabel();
            // }
            // }
            /* get connection item dynamictly,not from cache ,see 16969 */
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(value);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        repositoryName2 = property.getLabel();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
        // When no repository avaiable on "Repository" mode, open a MessageDialog.
        if (repositoryName2 == null || repositoryName2.length() == 0) {
            MessageDialog.openError(composite.getShell(), Messages.getString("NoRepositoryDialog.Title"), //$NON-NLS-1$
            Messages.getString(//$NON-NLS-1$
            "NoRepositoryDialog.Text"));
            return null;
        }
        // Part maybe not exist
        //$NON-NLS-1$
        String processName = "";
        //$NON-NLS-1$
        String key = "";
        if (elem instanceof Node) {
            processName = ((Node) elem).getProcess().getName();
            key = processName + ((Node) elem).getUniqueName();
        } else if (elem instanceof IProcess) {
            processName = ((IProcess) elem).getName();
            key = processName;
        }
        key += repositoryName2;
        final Dialog builderDialog = sqlbuilers.get(key);
        if (!composite.isDisposed() && builderDialog != null && builderDialog.getShell() != null && !builderDialog.getShell().isDisposed()) {
            builderDialog.getShell().setActive();
        } else {
            connParameters.setRepositoryName(repositoryName2);
            if (repositoryId != null) {
                connParameters.setRepositoryId(repositoryId);
            }
            Shell parentShell = new Shell(composite.getShell().getDisplay());
            String nodeLabel = null;
            if (elem instanceof Node) {
                nodeLabel = (String) ((Node) elem).getElementParameter(EParameterName.LABEL.getName()).getValue();
            }
            TextUtil.setDialogTitle(processName, nodeLabel, elem.getElementName());
            ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
            connParameters.setQuery(query);
            // first open Sql Builder,set true
            connParameters.setFirstOpenSqlBuilder(true);
            Dialog sqlBuilder = service.openSQLBuilderDialog(parentShell, processName, connParameters);
            sqlbuilers.put(key, sqlBuilder);
            if (Window.OK == sqlBuilder.open()) {
                if (!composite.isDisposed() && !connParameters.isNodeReadOnly()) {
                    String sql = connParameters.getQuery();
                    // modified by hyWang
                    if (!connParameters.getIfContextButtonCheckedFromBuiltIn()) {
                        sql = QueryUtil.checkAndAddQuotes(sql);
                    }
                    return sql;
                }
            }
        }
    }
    return null;
}
Also used : Shell(org.eclipse.swt.widgets.Shell) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) Dialog(org.eclipse.jface.dialogs.Dialog) ModelSelectionDialog(org.talend.commons.ui.swt.dialogs.ModelSelectionDialog) INode(org.talend.core.model.process.INode) IGraphicalNode(org.talend.core.ui.process.IGraphicalNode) Node(org.talend.designer.core.ui.editor.nodes.Node) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProcess(org.talend.core.model.process.IProcess) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 5 with ISQLBuilderService

use of org.talend.core.ui.services.ISQLBuilderService in project tdi-studio-se by Talend.

the class AbstractElementPropertySectionController method isConnectionExist.

protected boolean isConnectionExist() {
    ISQLBuilderService service = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(ISQLBuilderService.class)) {
        service = (ISQLBuilderService) GlobalServiceRegister.getDefault().getService(ISQLBuilderService.class);
    }
    if (service == null) {
        return false;
    }
    if (contextManager != null && contextManager.getDefaultContext().getContextParameterList().size() != 0) {
        initConnectionParametersWithContext(elem, contextManager.getDefaultContext());
    }
    DatabaseConnection connection = service.createConnection(connParameters);
    if (connection != null) {
        IMetadataConnection metadataConnection = null;
        metadataConnection = ConvertionHelper.convert(connection);
        return checkExistConnections(metadataConnection);
    }
    return false;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) ISQLBuilderService(org.talend.core.ui.services.ISQLBuilderService)

Aggregations

ISQLBuilderService (org.talend.core.ui.services.ISQLBuilderService)8 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 IProcess (org.talend.core.model.process.IProcess)3 Dialog (org.eclipse.jface.dialogs.Dialog)2 ErrorDialogWithDetailAreaAndContinueButton (org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton)2 ModelSelectionDialog (org.talend.commons.ui.swt.dialogs.ModelSelectionDialog)2 INode (org.talend.core.model.process.INode)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 EditPart (org.eclipse.gef.EditPart)1 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)1 AbstractGraphicalEditPart (org.eclipse.gef.editparts.AbstractGraphicalEditPart)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1