Search in sources :

Example 1 with Preferences

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

the class OracleExplainPlanAction 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("OracleExplainPlanAction.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);
    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 statement_id from plan_table");
            notFoundTable = false;
            rs.close();
        } catch (Throwable e) {
            createPlanTable = MessageDialog.openQuestion(null, //$NON-NLS-1$
            Messages.getString("oracle.editor.actions.explain.notFound.Title"), //$NON-NLS-1$
            Messages.getString("oracle.editor.actions.explain.notFound"));
        } finally {
            try {
                st.close();
            } catch (Throwable e) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage2"), e);
            }
        }
        if (notFoundTable && !createPlanTable) {
            return;
        }
        if (notFoundTable && createPlanTable) {
            SQLConnection conn = runNode.getInteractiveConnection();
            st = conn.createStatement();
            try {
                st.execute(createPlanTableScript);
                if (!conn.getAutoCommit()) {
                    conn.commit();
                }
            } catch (Throwable e) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage2"), e);
                //$NON-NLS-1$
                MessageDialog.openError(//$NON-NLS-1$
                null, //$NON-NLS-1$
                Messages.getString("oracle.editor.actions.explain.createError.Title"), //$NON-NLS-1$
                Messages.getString("oracle.editor.actions.explain.createError"));
                try {
                    st.close();
                } catch (Throwable e1) {
                    //$NON-NLS-1$
                    SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage3"), e1);
                }
                return;
            }
            try {
                st.close();
            } catch (Throwable e) {
                //$NON-NLS-1$
                SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage3"), e);
            }
        }
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.logMessage4"), e);
    }
    try {
        while (!queryStrings.isEmpty()) {
            String querySql = (String) queryStrings.remove(0);
            if (querySql != null) {
                resultDisplayer.addSQLExecution(new OracleExplainPlanExecution(querySql, runNode));
            }
        }
    } catch (Exception e) {
        //$NON-NLS-1$
        SqlBuilderPlugin.log(Messages.getString("OracleExplainPlanAction.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 2 with Preferences

use of org.eclipse.core.runtime.Preferences in project liferay-ide by liferay.

the class Plugin method initializeDefaultPluginPreferences.

/**
 * Initializes the plugin preferences with default preference values for
 * this plug-in.
 */
protected void initializeDefaultPluginPreferences() {
    Preferences prefs = getPluginPreferences();
    prefs.setDefault(Constants.HIGHLIGHT_RELATED_ITEMS, true);
    // $NON-NLS-1$
    prefs.setDefault(Constants.COLOR_COMMENT, "170,0,0");
    // $NON-NLS-1$
    prefs.setDefault(Constants.COLOR_TEXT, "0,0,0");
    // $NON-NLS-1$
    prefs.setDefault(Constants.COLOR_INTERPOLATION, "255,0,128");
    // $NON-NLS-1$
    prefs.setDefault(Constants.COLOR_DIRECTIVE, "0,0,255");
    // $NON-NLS-1$
    prefs.setDefault(Constants.COLOR_STRING, "0,128,128");
    // $NON-NLS-1$
    prefs.setDefault(Constants.COLOR_XML_COMMENT, "128,128,128");
    // $NON-NLS-1$
    prefs.setDefault(Constants.COLOR_XML_TAG, "0,0,128");
    // $NON-NLS-1$
    prefs.setDefault(Constants.COLOR_RELATED_ITEM, "255,255,128");
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 3 with Preferences

use of org.eclipse.core.runtime.Preferences in project jbosstools-hibernate by jbosstools.

the class ToggleLayoutAction method valueChanged.

private void valueChanged(boolean value, boolean doStore) {
    setChecked(!value);
    view.setManualLayout(value);
    setToolTipText(value ? HibernateConsoleMessages.ToggleLayoutAction_manual_layout_active : HibernateConsoleMessages.ToggleLayoutAction_auto_layout_active);
    setDescription(value ? HibernateConsoleMessages.ToggleLayoutAction_enable_auto_layout : HibernateConsoleMessages.ToggleLayoutAction_enable_manual_layout);
    if (doStore) {
        Preferences prefs = HibernateConsolePlugin.getDefault().getPluginPreferences();
        prefs.setValue(pluginKey, value);
        HibernateConsolePlugin.getDefault().savePluginPreferences();
    }
}
Also used : Preferences(org.eclipse.core.runtime.Preferences)

Example 4 with Preferences

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

the class BasicQueryParser method parse.

/* (non-JavaDoc)
	 * @see net.sourceforge.sqlexplorer.parsers.QueryParser#parse()
	 */
public void parse() throws ParserException {
    if (sql == null)
        return;
    Preferences prefs = SQLExplorerPlugin.getDefault().getPluginPreferences();
    if (prefs.getBoolean(IConstants.ENABLE_STRUCTURED_COMMENTS)) {
        StringBuffer buffer = new StringBuffer(sql.toString());
        Tokenizer tokenizer = new Tokenizer(buffer);
        StructuredCommentParser structuredComments = new StructuredCommentParser(this, buffer);
        // Otherwise just use a standard tokenizer
        try {
            Token token;
            while ((token = tokenizer.nextToken()) != null) {
                if (token.getTokenType() == Tokenizer.TokenType.EOL_COMMENT || token.getTokenType() == Tokenizer.TokenType.ML_COMMENT) {
                    structuredComments.addComment(token);
                }
            }
        } catch (StructuredCommentException e) {
        }
        // Do the structured comments and then reset the tokenizer
        structuredComments.process();
        tokenizer.reset();
        tokenizer = null;
        sql = buffer;
    }
    _sQuerys = prepareSQL(sql.toString());
    _sNextQuery = doParse();
    sql = null;
}
Also used : StructuredCommentParser(net.sourceforge.sqlexplorer.parsers.scp.StructuredCommentParser) StructuredCommentException(net.sourceforge.sqlexplorer.parsers.scp.StructuredCommentException) Token(net.sourceforge.sqlexplorer.parsers.Tokenizer.Token) Preferences(org.eclipse.core.runtime.Preferences) StringTokenizer(java.util.StringTokenizer)

Example 5 with Preferences

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

the class MonitorManager method loadMonitors.

protected synchronized void loadMonitors() {
    if (Trace.FINEST) {
        Trace.trace(Trace.STRING_FINEST, "Loading monitors");
    }
    monitors = new ArrayList<IMonitor>();
    Preferences prefs = MonitorPlugin.getInstance().getPluginPreferences();
    String xmlString = prefs.getString("monitors");
    if (xmlString != null && xmlString.length() > 0) {
        try {
            ByteArrayInputStream in = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
            IMemento memento = XMLMemento.loadMemento(in);
            IMemento[] children = memento.getChildren("monitor");
            if (children != null) {
                int size = children.length;
                for (int i = 0; i < size; i++) {
                    Monitor monitor = new Monitor();
                    monitor.load(children[i]);
                    monitors.add(monitor);
                }
            }
        } catch (Exception e) {
            if (Trace.WARNING) {
                Trace.trace(Trace.STRING_WARNING, "Could not load monitors", e);
            }
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Preferences(org.eclipse.core.runtime.Preferences) CoreException(org.eclipse.core.runtime.CoreException)

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