Search in sources :

Example 46 with PropertyChangeCommand

use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.

the class DbTableController method openDbTableSelectorJob.

/**
     * qzhang Comment method "openDbTableSelectorJob".
     * 
     * @param openListTable
     */
private void openDbTableSelectorJob(final Button openListTable) {
    Job job = new //$NON-NLS-1$
    Job(//$NON-NLS-1$
    Messages.getString("DbTableController.openSelectionDialog")) {

        @Override
        protected IStatus run(final IProgressMonitor monitor) {
            //$NON-NLS-1$
            monitor.beginTask(Messages.getString("DbTableController.waitingForOpen"), IProgressMonitor.UNKNOWN);
            DatabaseConnection existConnection = getExistConnection();
            if (existConnection == null) {
                if (connParameters == null) {
                    initConnectionParameters();
                }
                existConnection = TracesConnectionUtils.createConnection(connParameters);
            }
            final DatabaseConnection con = existConnection;
            IMetadataConnection iMetadataConnection = null;
            final IMetadataConnection[] iMetadata = new IMetadataConnection[1];
            boolean isStatus = false;
            if (existConnection != null) {
                Display.getDefault().syncExec(new Runnable() {

                    @Override
                    public void run() {
                        IMetadataConnection convert = ConvertionHelper.convert(con);
                        iMetadata[0] = convert;
                    }
                });
                iMetadataConnection = iMetadata[0];
                // Added by Marvin Wang for bug TDI-24288.
                if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
                    if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
                        try {
                            HiveConnectionManager.getInstance().checkConnection(iMetadataConnection);
                            isStatus = true;
                        } catch (ClassNotFoundException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (InstantiationException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (IllegalAccessException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        } catch (SQLException e) {
                            isStatus = false;
                            ExceptionHandler.process(e);
                        }
                    }
                } else {
                    isStatus = checkConnection(iMetadataConnection);
                }
            }
            String type = null;
            if (iMetadataConnection != null) {
                type = iMetadataConnection.getDbType();
            }
            final String dbType = type;
            if (!monitor.isCanceled()) {
                try {
                    if (isStatus) {
                        // Added by Marvin Wang for bug TDI-24288.
                        if (EDatabaseTypeName.HIVE.getProduct().equalsIgnoreCase(con.getDatabaseType())) {
                            if (EDatabaseVersion4Drivers.HIVE_EMBEDDED.getVersionValue().equalsIgnoreCase(con.getDbVersionString())) {
                                JavaSqlFactory.doHivePreSetup((DatabaseConnection) iMetadataConnection.getCurrentConnection());
                                returnTablesFormConnection = ExtractMetaDataFromDataBase.fetchAllTablesForHiveEmbeddedModel(iMetadataConnection);
                                JavaSqlFactory.doHiveConfigurationClear();
                            }
                        } else {
                            returnTablesFormConnection = ExtractMetaDataFromDataBase.returnTablesFormConnection(iMetadataConnection);
                        }
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                final DbTableSelectorObject object = new DbTableSelectorObject();
                                DbTableSelectorObject connO = new DbTableSelectorObject();
                                if (dbType != null && dbType.equals(EDatabaseTypeName.ORACLE_OCI.getDisplayName())) {
                                    connO.setLabel(connParameters.getLocalServiceName());
                                } else if ("".equals(connParameters.getDbName())) {
                                    //$NON-NLS-1$
                                    connO.setLabel(connParameters.getDatasource());
                                } else {
                                    connO.setLabel(connParameters.getDbName());
                                }
                                // ...
                                if (connO.getLabel() == null || connO.getLabel().equals("")) {
                                    //$NON-NLS-1$
                                    if (elem instanceof INode) {
                                        connO.setLabel(elem.getElementName());
                                    } else {
                                        connO.setLabel("tJDBCConnection");
                                    }
                                }
                                connO.setType(ObjectType.DB);
                                if (monitor.isCanceled()) {
                                    monitor.done();
                                    return;
                                }
                                for (String string : returnTablesFormConnection) {
                                    DbTableSelectorObject tableO = new DbTableSelectorObject();
                                    tableO.setLabel(string);
                                    tableO.setType(ObjectType.TABLE);
                                    connO.addChildren(tableO);
                                }
                                object.addChildren(connO);
                                String propertyName = (String) openListTable.getData(PARAMETER_NAME);
                                DbTableSelectorDialog selectorDialog = new DbTableSelectorDialog(composite.getShell(), object);
                                if (selectorDialog.open() == DbTableSelectorDialog.OK) {
                                    String name = selectorDialog.getSelectName();
                                    if (name != null) {
                                        Command dbSelectorCommand = new PropertyChangeCommand(elem, propertyName, TalendTextUtils.addQuotes(name));
                                        executeCommand(dbSelectorCommand);
                                        Text labelText = (Text) hashCurControls.get(propertyName);
                                        labelText.setText(TalendTextUtils.addQuotes(name));
                                    }
                                }
                            }
                        });
                    } 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(openListTable, part.getProcess().getContextManager());
                                }
                            }
                        });
                    }
                } catch (SQLException e) {
                    // Added by Marvin Wang for bug TDI-24288.
                    JavaSqlFactory.doHiveConfigurationClear();
                    ExceptionHandler.process(e);
                    Display.getDefault().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            MessageDialog.openError(openListTable.getShell(), //$NON-NLS-1$
                            Messages.getString("DbTableController.dialog.title"), //$NON-NLS-1$
                            Messages.getString("DbTableController.dialog.contents.fetchTableFailed"));
                        }
                    });
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            monitor.done();
            return Status.OK_STATUS;
        }
    };
    if (part != null) {
        IWorkbenchSiteProgressService siteps = (IWorkbenchSiteProgressService) part.getSite().getAdapter(IWorkbenchSiteProgressService.class);
        siteps.showInDialog(composite.getShell(), job);
    } else {
        PlatformUI.getWorkbench().getProgressService().showInDialog(composite.getShell(), job);
    }
    job.setUser(true);
    job.schedule();
}
Also used : ErrorDialogWithDetailAreaAndContinueButton(org.talend.commons.ui.swt.dialogs.ErrorDialogWithDetailAreaAndContinueButton) INode(org.talend.core.model.process.INode) SQLException(java.sql.SQLException) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Text(org.eclipse.swt.widgets.Text) DbTableSelectorDialog(org.talend.core.ui.metadata.dialog.DbTableSelectorDialog) DbTableSelectorObject(org.talend.core.ui.metadata.dialog.DbTableSelectorObject) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IWorkbenchSiteProgressService(org.eclipse.ui.progress.IWorkbenchSiteProgressService) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Job(org.eclipse.core.runtime.jobs.Job)

Example 47 with PropertyChangeCommand

use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.

the class DbTypeListController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
public Command createCommand(SelectionEvent selectionEvent) {
    Set<String> elementsName;
    Control ctrl;
    IMetadataTable repositoryMetadata = new MetadataTable();
    Connection repositoryConnection = null;
    elementsName = hashCurControls.keySet();
    for (String name : elementsName) {
        Object o = hashCurControls.get(name);
        if (o instanceof Control) {
            ctrl = (Control) o;
            if (ctrl == null) {
                hashCurControls.remove(name);
                return null;
            }
            if (ctrl.equals(selectionEvent.getSource()) && ctrl instanceof CCombo) {
                boolean isDisposed = ((CCombo) ctrl).isDisposed();
                if (!isDisposed && (!elem.getPropertyValue(name).equals(((CCombo) ctrl).getText()))) {
                    //$NON-NLS-1$
                    String value = new String("");
                    for (int i = 0; i < elem.getElementParameters().size(); i++) {
                        IElementParameter param = elem.getElementParameters().get(i);
                        if (param.getName().equals(name)) {
                            for (int j = 0; j < param.getListItemsValue().length; j++) {
                                if (((CCombo) ctrl).getText().equals(param.getListItemsDisplayName()[j])) {
                                    value = (String) param.getListItemsValue()[j];
                                }
                            }
                        }
                    }
                    if (value.equals(elem.getPropertyValue(name))) {
                        // same value so no need to do anything
                        return null;
                    }
                    return new PropertyChangeCommand(elem, name, value);
                }
            }
        }
    }
    return null;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Control(org.eclipse.swt.widgets.Control) CCombo(org.eclipse.swt.custom.CCombo) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IElementParameter(org.talend.core.model.process.IElementParameter) Point(org.eclipse.swt.graphics.Point)

Example 48 with PropertyChangeCommand

use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.

the class DateController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
public Command createCommand(Button button) {
    DateDialog dateDial = new DateDialog(composite.getShell());
    int returnValue = dateDial.open();
    if (returnValue == DateDialog.OK) {
        String propertyName = (String) button.getData(PARAMETER_NAME);
        String date = dateDial.getTalendDateString();
        if (date != null && !date.equals(elem.getPropertyValue(propertyName))) {
            elem.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
            return new PropertyChangeCommand(elem, propertyName, TalendTextUtils.addQuotes(date));
        }
    }
    return null;
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) DateDialog(org.talend.commons.ui.runtime.swt.tableviewer.celleditor.DateDialog) Point(org.eclipse.swt.graphics.Point)

Example 49 with PropertyChangeCommand

use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.

the class ConnectionListController method createCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties2.editors.AbstractElementPropertySectionController#createCommand()
     */
public Command createCommand(SelectionEvent selectionEvent) {
    Assert.isTrue(selectionEvent.getSource() instanceof CCombo);
    CCombo combo = (CCombo) selectionEvent.getSource();
    String paramName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter param = elem.getElementParameter(paramName);
    //$NON-NLS-1$
    String comboValue = new String("");
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            comboValue = (String) param.getListItemsValue()[j];
        }
    }
    if (comboValue.equals(param.getValue())) {
        // same value so no need to do anything
        return null;
    }
    return new PropertyChangeCommand(elem, paramName, comboValue);
}
Also used : CCombo(org.eclipse.swt.custom.CCombo) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IElementParameter(org.talend.core.model.process.IElementParameter) Point(org.eclipse.swt.graphics.Point)

Example 50 with PropertyChangeCommand

use of org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand in project tdi-studio-se by Talend.

the class SqlMemoController method createCommand.

// built-in open query
private Command createCommand() {
    initConnectionParameters();
    IElementParameter basePropertyParameter = null;
    for (IElementParameter param : elem.getElementParameters()) {
        if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
            if (param.getRepositoryValue().startsWith("DATABASE")) {
                basePropertyParameter = param;
                break;
            }
        }
    }
    String repositoryType = null;
    if (basePropertyParameter != null) {
        repositoryType = (String) basePropertyParameter.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getValue();
    } else {
        repositoryType = (String) elem.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
    }
    String propertyName = (String) openSQLEditorButton.getData(PARAMETER_NAME);
    String query = (String) elem.getPropertyValue(propertyName);
    ECodeLanguage lang = LanguageManager.getCurrentLanguage();
    if ((!TalendTextUtils.isCommonString(query) || QueryUtil.checkIfHasSpecialEscapeValue(query) || QueryUtil.checkIfIsNoQuotesAtAll(query)) && (lang == ECodeLanguage.JAVA)) {
        // if
        // the input query is in context mode in java
        // String pid = SqlBuilderPlugin.PLUGIN_ID;
        // String mainMsg = Messages.getString("SqlMemoController.QueryError.mainMsg");
        // String infoMsg = Messages.getString("SqlMemoController.QueryError.infoMsg",
        // TalendTextUtils.getQuoteChar());
        // new ErrorDialogWidthDetailArea(composite.getShell(), pid, mainMsg, infoMsg);
        // return null;
        // pass the value to Initializing the contextmode button
        connParameters.setIfContextButtonCheckedFromBuiltIn(true);
    // String contextSql = openSQLBuilder(repositoryType, propertyName, query);
    // if (contextSql != null) {
    // queryText.setText(contextSql);
    // return new PropertyChangeCommand(elem, propertyName, contextSql);
    // }
    // return null;
    } else {
        // if the input query isn't contextmode or it's a standard query in perl
        query = this.removeStrInQuery(query);
    }
    initConnectionParametersWithContext(elem, part == null ? new EmptyContextManager().getDefaultContext() : part.getProcess().getContextManager().getDefaultContext());
    String sql = openSQLBuilder(repositoryType, propertyName, query);
    if (sql != null) {
        queryText.setText(sql);
        return new PropertyChangeCommand(elem, propertyName, sql);
    }
    return null;
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IElementParameter(org.talend.core.model.process.IElementParameter) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Aggregations

PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)68 IElementParameter (org.talend.core.model.process.IElementParameter)34 Command (org.eclipse.gef.commands.Command)24 Point (org.eclipse.swt.graphics.Point)18 INode (org.talend.core.model.process.INode)18 Node (org.talend.designer.core.ui.editor.nodes.Node)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 Control (org.eclipse.swt.widgets.Control)14 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)13 RepositoryNode (org.talend.repository.model.RepositoryNode)12 CCombo (org.eclipse.swt.custom.CCombo)11 IConnection (org.talend.core.model.process.IConnection)11 ConnectionItem (org.talend.core.model.properties.ConnectionItem)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)10 Item (org.talend.core.model.properties.Item)10 Button (org.eclipse.swt.widgets.Button)8 MetadataTable (org.talend.core.model.metadata.MetadataTable)8 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)8