Search in sources :

Example 61 with Preferences

use of org.eclipse.core.runtime.Preferences in project tdi-studio-se by Talend.

the class OpenFileAction method loadFiles.

/**
     * Load one or more files into the editor.
     * 
     * @param files string[] of relative file paths
     * @param filePath path where all files are found
     */
public void loadFiles(String[] files, String filePath) {
    BufferedReader reader = null;
    try {
        StringBuffer all = new StringBuffer();
        String str = null;
        Preferences prefs = SqlBuilderPlugin.getDefault().getPluginPreferences();
        char delimiter = prefs.getString(IConstants.LINE_DELIMITER).charAt(0);
        for (int i = 0; i < files.length; i++) {
            //$NON-NLS-1$
            String path = "";
            if (filePath != null) {
                path += filePath + File.separator;
            }
            path += files[i];
            reader = new BufferedReader(new FileReader(path));
            while ((str = reader.readLine()) != null) {
                all.append(str);
                all.append(delimiter);
            }
            if (files.length > 1) {
                all.append(delimiter);
            }
        }
        editor.setEditorContent(all.toString());
    } catch (Throwable e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("OpenFileAction.logTextErrorLoadingDoc"), e);
    } finally {
        try {
            reader.close();
        } catch (java.io.IOException e) {
        // noop
        }
    }
}
Also used : BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) Preferences(org.eclipse.core.runtime.Preferences)

Example 62 with Preferences

use of org.eclipse.core.runtime.Preferences in project tdi-studio-se by Talend.

the class DB2ExplainPlanAction method run.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.sqlbuilder.actions.AbstractEditorAction#run()
     */
//$NON-NLS-1$
@SuppressWarnings("unchecked")
@Override
public void run() {
    RepositoryNode node = editor.getRepositoryNode();
    SessionTreeNodeManager nodeManager = new SessionTreeNodeManager();
    SessionTreeNode runNode = null;
    try {
        runNode = nodeManager.getSessionTreeNode(node, editor.getDialog().getSelectedContext());
    } catch (Exception e) {
        //$NON-NLS-1$
        MessageDialog.openError(null, Messages.getString("AbstractSQLExecution.Executing.Error"), e.getMessage());
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage1"), e);
        return;
    }
    Preferences prefs = SqlBuilderPlugin.getDefault().getPluginPreferences();
    String queryDelimiter = prefs.getString(IConstants.QUERY_DELIMITER);
    String alternateDelimiter = prefs.getString(IConstants.ALTERNATE_DELIMITER);
    String commentDelimiter = prefs.getString(IConstants.COMMENT_DELIMITER);
    QueryTokenizer qt = new QueryTokenizer(getSQLToBeExecuted(), queryDelimiter, alternateDelimiter, commentDelimiter);
    final List queryStrings = new ArrayList();
    while (qt.hasQuery()) {
        final String querySql = qt.nextQuery();
        // ignore commented lines.
        if (!querySql.startsWith("--")) {
            //$NON-NLS-1$
            queryStrings.add(querySql);
        }
    }
    // check if we can run explain plans
    try {
        Statement st = runNode.getInteractiveConnection().createStatement();
        boolean createPlanTable = false;
        boolean notFoundTable = true;
        try {
            //$NON-NLS-1$
            ResultSet rs = st.executeQuery("select queryno from SYSTOOLS.EXPLAIN_STATEMENT");
            notFoundTable = false;
            rs.close();
        } catch (Throwable e) {
            createPlanTable = MessageDialog.openQuestion(null, //$NON-NLS-1$
            Messages.getString("db2.editor.actions.explain.notFound.Title"), //$NON-NLS-1$
            Messages.getString("db2.editor.actions.explain.notFound"));
        } finally {
            try {
                st.close();
            } catch (Throwable e) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage2"), e);
            }
        }
        if (notFoundTable && !createPlanTable) {
            return;
        }
        if (notFoundTable && createPlanTable) {
            SQLConnection conn = runNode.getInteractiveConnection();
            st = conn.createStatement();
            try {
                st.execute(createPlanScript1);
                st.execute(createPlanScript2);
                st.execute(createPlanScript3);
                st.execute(createPlanScript4);
                st.execute(createPlanScript5);
                st.execute(createPlanScript6);
                st.execute(createPlanScript7);
                if (!conn.getAutoCommit()) {
                    conn.commit();
                }
            } catch (Throwable e) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage3"), e);
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                null, //$NON-NLS-1$
                Messages.getString("db2.editor.actions.explain.createError.Title"), //$NON-NLS-1$
                Messages.getString("db2.editor.actions.explain.createError"));
                try {
                    st.close();
                } catch (Throwable e1) {
                    //$NON-NLS-1$
                    SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage2"), e1);
                }
                return;
            }
            try {
                st.close();
            } catch (Throwable e) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage2"), e);
            }
        }
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage4"), e);
    }
    try {
        while (!queryStrings.isEmpty()) {
            String querySql = (String) queryStrings.remove(0);
            if (querySql != null) {
                resultDisplayer.addSQLExecution(new DB2ExplainPlanExecution(querySql, runNode));
            }
        }
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("DB2ExplainPlanAction.logMessage5"), e);
    }
}
Also used : Statement(java.sql.Statement) SessionTreeNode(org.talend.sqlbuilder.sessiontree.model.SessionTreeNode) SQLConnection(net.sourceforge.squirrel_sql.fw.sql.SQLConnection) ArrayList(java.util.ArrayList) RepositoryNode(org.talend.repository.model.RepositoryNode) QueryTokenizer(org.talend.sqlbuilder.util.QueryTokenizer) SessionTreeNodeManager(org.talend.sqlbuilder.dbstructure.SessionTreeNodeManager) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) List(java.util.List) Preferences(org.eclipse.core.runtime.Preferences)

Example 63 with Preferences

use of org.eclipse.core.runtime.Preferences in project tdi-studio-se by Talend.

the class SQLEditorProposalUtil method getAllSqlQuery.

/**
     * dev Comment method "getAllQqlQuery". s
     * 
     * @param content editor has input all String
     * @return list of all SQL Query.
     */
private List<String> getAllSqlQuery(String content) {
    Preferences prefs = SqlBuilderPlugin.getDefault().getPluginPreferences();
    String queryDelimiter = prefs.getString(IConstants.QUERY_DELIMITER);
    String alternateDelimiter = prefs.getString(IConstants.ALTERNATE_DELIMITER);
    String commentDelimiter = prefs.getString(IConstants.COMMENT_DELIMITER);
    QueryTokenizer qt = new QueryTokenizer(content, queryDelimiter, alternateDelimiter, commentDelimiter);
    List<String> queryStringsTmp = new ArrayList<String>();
    while (qt.hasQuery()) {
        String querySql = qt.nextQuery();
        // ignore commented lines.
        if (!querySql.startsWith("--")) {
            //$NON-NLS-1$
            queryStringsTmp.add(querySql);
        }
    }
    List<String> queryStrings = new ArrayList<String>();
    while (!queryStringsTmp.isEmpty()) {
        String temp = (String) queryStringsTmp.remove(0);
        //$NON-NLS-1$ //$NON-NLS-2$
        String querySql = temp.replaceAll("\n", "");
        queryStrings.add(querySql);
    }
    return queryStrings;
}
Also used : QueryTokenizer(org.talend.sqlbuilder.util.QueryTokenizer) ArrayList(java.util.ArrayList) Preferences(org.eclipse.core.runtime.Preferences)

Example 64 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class NewXMLGenerator method getUserPreferredCharset.

private String getUserPreferredCharset() {
    Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences();
    String charSet = preference.getString(CommonEncodingPreferenceNames.OUTPUT_CODESET);
    return charSet;
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 65 with Preferences

use of org.eclipse.core.runtime.Preferences in project webtools.sourceediting by eclipse.

the class NewXMLWizard method addPages.

public void addPages() {
    String grammarURI = generator.getGrammarURI();
    // new file page
    newFilePage = new NewFilePage(fSelection);
    newFilePage.setTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_FILE_HEADING);
    newFilePage.setDescription(XMLWizardsMessages._UI_WIZARD_CREATE_XML_FILE_EXPL);
    // $NON-NLS-1$
    newFilePage.defaultName = (grammarURI != null) ? URIHelper.removeFileExtension(URIHelper.getLastSegment(grammarURI)) : "NewFile";
    Preferences preference = XMLCorePlugin.getDefault().getPluginPreferences();
    String ext = preference.getString(XMLCorePreferenceNames.DEFAULT_EXTENSION);
    // $NON-NLS-1$
    newFilePage.defaultFileExtension = "." + ext;
    newFilePage.filterExtensions = filePageFilterExtensions;
    addPage(newFilePage);
    if (grammarURI == null) {
        // create xml from page
        fCreateXMLFromWizardPage = new // $NON-NLS-1$
        StartPage(// $NON-NLS-1$
        "StartPage", // $NON-NLS-1$
        createFromRadioButtonLabel) {

            public void createControl(Composite parent) {
                super.createControl(parent);
            }

            public void setVisible(boolean visible) {
                super.setVisible(visible);
                getRadioButtonAtIndex(getCreateMode()).setSelection(true);
                getRadioButtonAtIndex(getCreateMode()).setFocus();
                // Set the help context for each button
                PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(0), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML1_HELPID);
                PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(1), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML2_HELPID);
                PlatformUI.getWorkbench().getHelpSystem().setHelp(fCreateXMLFromWizardPage.getRadioButtonAtIndex(2), IXMLWizardHelpContextIds.XML_NEWWIZARD_CREATEXML3_HELPID);
            }
        };
        fCreateXMLFromWizardPage.setTitle(XMLWizardsMessages._UI_WIZARD_CREATE_XML_HEADING);
        fCreateXMLFromWizardPage.setDescription(XMLWizardsMessages._UI_WIZARD_CREATE_XML_EXPL);
        addPage(fCreateXMLFromWizardPage);
    }
    // selectGrammarFilePage
    selectGrammarFilePage = new SelectGrammarFilePage();
    addPage(selectGrammarFilePage);
    // select root element page
    selectRootElementPage = new SelectRootElementPage();
    selectRootElementPage.setTitle(XMLWizardsMessages._UI_WIZARD_SELECT_ROOT_HEADING);
    selectRootElementPage.setDescription(XMLWizardsMessages._UI_WIZARD_SELECT_ROOT_EXPL);
    addPage(selectRootElementPage);
    // from "scratch"
    fNewXMLTemplatesWizardPage = new NewXMLTemplatesWizardPage();
    addPage(fNewXMLTemplatesWizardPage);
}
Also used : Composite(org.eclipse.swt.widgets.Composite) Preferences(org.eclipse.core.runtime.Preferences)

Aggregations

Preferences (org.eclipse.core.runtime.Preferences)113 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)7 IFile (org.eclipse.core.resources.IFile)6 PartInitException (org.eclipse.ui.PartInitException)6 CSSCleanupStrategy (org.eclipse.wst.css.core.internal.cleanup.CSSCleanupStrategy)6 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStreamWriter (java.io.OutputStreamWriter)5 IStructuredFormatPreferences (org.eclipse.wst.sse.core.internal.format.IStructuredFormatPreferences)5 ArrayList (java.util.ArrayList)4 CoreException (org.eclipse.core.runtime.CoreException)4 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)4 IStructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupPreferences)4 StructuredCleanupPreferences (org.eclipse.wst.sse.core.internal.cleanup.StructuredCleanupPreferences)4 List (java.util.List)3 Vector (java.util.Vector)3 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)3 ResultSet (java.sql.ResultSet)2 Statement (java.sql.Statement)2