This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 192020
Collapse All | Expand All

(-)db.sql.editor/nbproject/project.xml (+8 lines)
Lines 267-272 Link Here
267
                        <specification-version>8.0</specification-version>
267
                        <specification-version>8.0</specification-version>
268
                    </run-dependency>
268
                    </run-dependency>
269
                </dependency>
269
                </dependency>
270
                <dependency>
271
                    <code-name-base>org.openide.windows</code-name-base>
272
                    <build-prerequisite/>
273
                    <compile-dependency/>
274
                    <run-dependency>
275
                        <specification-version>6.72</specification-version>
276
                    </run-dependency>
277
                </dependency>
270
            </module-dependencies>
278
            </module-dependencies>
271
            <test-dependencies>
279
            <test-dependencies>
272
                <test-type>
280
                <test-type>
(-)db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLCompletionProvider.java (-1 / +12 lines)
Lines 51-56 Link Here
51
import org.netbeans.api.lexer.TokenSequence;
51
import org.netbeans.api.lexer.TokenSequence;
52
import org.netbeans.modules.db.api.sql.execute.SQLExecution;
52
import org.netbeans.modules.db.api.sql.execute.SQLExecution;
53
import org.netbeans.modules.db.sql.editor.ui.actions.SQLExecutionBaseAction;
53
import org.netbeans.modules.db.sql.editor.ui.actions.SQLExecutionBaseAction;
54
import org.netbeans.modules.db.sql.editor.ui.actions.SQLHistoryAction;
55
import org.netbeans.modules.db.sql.editor.ui.actions.SQLInplaceHistoryAction;
54
import org.netbeans.modules.db.sql.lexer.SQLTokenId;
56
import org.netbeans.modules.db.sql.lexer.SQLTokenId;
55
import org.netbeans.spi.editor.completion.CompletionProvider;
57
import org.netbeans.spi.editor.completion.CompletionProvider;
56
import org.netbeans.spi.editor.completion.CompletionTask;
58
import org.netbeans.spi.editor.completion.CompletionTask;
Lines 66-72 Link Here
66
public class SQLCompletionProvider implements CompletionProvider {
68
public class SQLCompletionProvider implements CompletionProvider {
67
69
68
    public CompletionTask createTask(int queryType, JTextComponent component) {
70
    public CompletionTask createTask(int queryType, JTextComponent component) {
69
        if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE || queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
71
        if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE 
72
                || queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
73
            Document doc = component.getDocument();
74
            Boolean historyCompletion = (Boolean) doc.getProperty(
75
                    SQLInplaceHistoryAction.completionProperty);
76
            if (historyCompletion != null && historyCompletion) {
77
                doc.putProperty(SQLInplaceHistoryAction.completionProperty, Boolean.FALSE);
78
                return new AsyncCompletionTask(new SQLHistoryCompletionQuery(), component);
79
            } else {
70
            DatabaseConnection dbconn = findDBConn(component);
80
            DatabaseConnection dbconn = findDBConn(component);
71
            if (dbconn == null) {
81
            if (dbconn == null) {
72
                // XXX perhaps should have an item in the completion instead?
82
                // XXX perhaps should have an item in the completion instead?
Lines 76-81 Link Here
76
            }
86
            }
77
            return new AsyncCompletionTask(new SQLCompletionQuery(dbconn), component);
87
            return new AsyncCompletionTask(new SQLCompletionQuery(dbconn), component);
78
        }
88
        }
89
        }
79
        return null;
90
        return null;
80
    }
91
    }
81
92
(-)db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLHistoryCompletionItem.java (+152 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.db.sql.editor.completion;
43
44
import java.awt.Color;
45
import java.awt.Font;
46
import java.awt.Graphics;
47
import java.awt.event.KeyEvent;
48
import java.util.logging.Level;
49
import java.util.logging.Logger;
50
import javax.swing.ImageIcon;
51
import javax.swing.text.BadLocationException;
52
import javax.swing.text.JTextComponent;
53
import org.netbeans.api.editor.completion.Completion;
54
import org.netbeans.modules.db.api.sql.history.SQLHistoryEntry;
55
import org.netbeans.spi.editor.completion.CompletionItem;
56
import org.netbeans.spi.editor.completion.CompletionTask;
57
import org.netbeans.spi.editor.completion.support.CompletionUtilities;
58
59
public class SQLHistoryCompletionItem implements CompletionItem {
60
    private static final Logger LOG = Logger.getLogger(SQLHistoryCompletionItem.class.getName());
61
62
    private final SQLHistoryEntry she;
63
    private final int startOffset;
64
65
    public SQLHistoryCompletionItem(SQLHistoryEntry she, int startOffset) {
66
        this.she = she;
67
        this.startOffset = startOffset;
68
    }
69
70
    @Override
71
    public void defaultAction(JTextComponent component) {
72
        Completion.get().hideDocumentation();
73
        Completion.get().hideCompletion();
74
        try {
75
            int insertPos = startOffset;
76
            while (insertPos < component.getCaretPosition()) {
77
                if (Character.isWhitespace(component.getDocument().getText(insertPos, 1).charAt(0))) {
78
                    insertPos++;
79
                } else {
80
                    break;
81
                }
82
            }
83
            
84
            component.getDocument().remove(insertPos, component.getCaretPosition()
85
                    - insertPos);
86
            component.getDocument().insertString(insertPos, she.getSql(), null);
87
        } catch (BadLocationException ex) {
88
            LOG.log(Level.WARNING, "Position error", ex);
89
        }
90
    }
91
92
    @Override
93
    public void processKeyEvent(KeyEvent evt) {
94
    }
95
96
    public int getPreferredWidth(Graphics g, Font defaultFont) {
97
        return CompletionUtilities.getPreferredWidth(
98
                getLeftHtmlText(),
99
                getRightHtmlText(),
100
                g,
101
                defaultFont);
102
    }
103
104
    public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) {
105
        CompletionUtilities.renderHtml(
106
                getImageIcon(),
107
                getLeftHtmlText(),
108
                getRightHtmlText(),
109
                g,
110
                defaultFont,
111
                defaultColor,
112
                width,
113
                height,
114
                selected);
115
    }
116
117
    public CompletionTask createDocumentationTask() {
118
        return null;
119
    }
120
121
    public CompletionTask createToolTipTask() {
122
        return null;
123
    }
124
125
    public boolean instantSubstitution(JTextComponent component) {
126
        return false;
127
    }
128
129
    public int getSortPriority() {
130
        return 0;
131
    }
132
133
    public CharSequence getSortText() {
134
        return null;
135
    }
136
137
    public CharSequence getInsertPrefix() {
138
        return "";
139
    }
140
141
    protected ImageIcon getImageIcon() {
142
        return null;
143
    }
144
145
    protected String getLeftHtmlText() {
146
        return she.getSql();
147
    }
148
149
    protected String getRightHtmlText() {
150
        return null;
151
    }
152
}
(-)db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLHistoryCompletionQuery.java (+90 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 *
40
 * Portions Copyrighted 2014 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.db.sql.editor.completion;
43
44
import java.util.logging.Logger;
45
import javax.swing.text.BadLocationException;
46
import javax.swing.text.Document;
47
import org.netbeans.modules.db.api.sql.history.SQLHistory;
48
import org.netbeans.modules.db.api.sql.history.SQLHistoryEntry;
49
import org.netbeans.modules.db.api.sql.history.SQLHistoryManager;
50
import org.netbeans.spi.editor.completion.CompletionResultSet;
51
import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery;
52
import org.openide.util.Exceptions;
53
54
public class SQLHistoryCompletionQuery extends AsyncCompletionQuery {
55
    private static final Logger LOG = Logger.getLogger(SQLHistoryCompletionQuery.class.getName());
56
57
    private final SQLHistory history;
58
59
    public SQLHistoryCompletionQuery() {
60
        this.history = SQLHistoryManager.getInstance().getHistory();
61
    }
62
63
    @Override
64
    protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
65
        try {
66
            SQLCompletionEnv env = SQLCompletionEnv.forDocument(doc, caretOffset);
67
            int startOffset = env.getStatementOffset();
68
            int endOffset = caretOffset;
69
            if (endOffset >= startOffset) {
70
                String prefix = doc
71
                        .getText(startOffset, endOffset - startOffset)
72
                        .trim()
73
                        .toUpperCase();
74
                for (SQLHistoryEntry she : history) {
75
                    String sql = she.getSql();
76
                    // Optimization assumption: SQL History is trimmed, so no whitespace at start...
77
                    if (sql.length() >= prefix.length()) {
78
                        String sqlPrefix = sql.substring(0, prefix.length());
79
                        if (sqlPrefix.equalsIgnoreCase(prefix)) {
80
                            resultSet.addItem(new SQLHistoryCompletionItem(she, startOffset));
81
                        }
82
                    }
83
                }
84
            }
85
            resultSet.finish();
86
        } catch (BadLocationException ex) {
87
            Exceptions.printStackTrace(ex);
88
        }
89
    }
90
}
(-)db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml (+4 lines)
Lines 59-64 Link Here
59
                <attr name="iconBase" stringvalue="org/netbeans/modules/db/sql/editor/resources/sql_history_16.png"/>
59
                <attr name="iconBase" stringvalue="org/netbeans/modules/db/sql/editor/resources/sql_history_16.png"/>
60
            </file>
60
            </file>
61
            <file name="org-netbeans-modules-db-sql-editor-ui-actions-ToggleKeepOldResultTabsAction.instance"/>
61
            <file name="org-netbeans-modules-db-sql-editor-ui-actions-ToggleKeepOldResultTabsAction.instance"/>
62
            <file name="org-netbeans-modules-db-sql-editor-ui-actions-SQLInplaceHistoryAction.instance"/>
62
        </folder>
63
        </folder>
63
    </folder>
64
    </folder>
64
65
Lines 69-74 Link Here
69
        <file name="DAS-H.shadow">
70
        <file name="DAS-H.shadow">
70
            <attr name="originalFile" stringvalue="Actions/System/org-netbeans-modules-db-sql-editor-ui-actions-SQLHistoryAction.instance"/>
71
            <attr name="originalFile" stringvalue="Actions/System/org-netbeans-modules-db-sql-editor-ui-actions-SQLHistoryAction.instance"/>
71
        </file>
72
        </file>
73
        <file name="AS-R.shadow">
74
            <attr name="originalFile" stringvalue="Actions/System/org-netbeans-modules-db-sql-editor-ui-actions-SQLInplaceHistoryAction.instance"/>
75
        </file>
72
    </folder>
76
    </folder>
73
77
74
    <folder name="Editors">
78
    <folder name="Editors">
(-)db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/Bundle.properties (+1 lines)
Lines 52-57 Link Here
52
52
53
# SQLHistoryAction
53
# SQLHistoryAction
54
LBL_SQLHistoryAction=SQL History
54
LBL_SQLHistoryAction=SQL History
55
LBL_SQLInplaceHistoryAction=SQL History (Inplace)
55
LBL_NoSQLExecuted=To show SQL History, execute an SQL statement.
56
LBL_NoSQLExecuted=To show SQL History, execute an SQL statement.
56
57
57
# RunSQLSelectionAction
58
# RunSQLSelectionAction
(-)db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/SQLInplaceHistoryAction.java (+83 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 * 
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 * 
38
 * Contributor(s):
39
 * 
40
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
41
 */
42
43
package org.netbeans.modules.db.sql.editor.ui.actions;
44
45
import java.awt.event.ActionEvent;
46
import javax.swing.AbstractAction;
47
import javax.swing.Action;
48
import javax.swing.text.Document;
49
import org.netbeans.api.editor.completion.Completion;
50
import org.netbeans.modules.db.api.sql.execute.SQLExecution;
51
import org.openide.text.CloneableEditor;
52
import org.openide.util.ContextAwareAction;
53
import org.openide.util.Lookup;
54
import org.openide.util.NbBundle;
55
56
public class SQLInplaceHistoryAction extends AbstractAction implements ContextAwareAction {
57
    public static final String completionProperty = SQLInplaceHistoryAction.class.getName();
58
    private Lookup ctx;
59
    
60
    public SQLInplaceHistoryAction() {
61
        this(null);
62
    }
63
64
    public SQLInplaceHistoryAction(Lookup ctx) {
65
        super(NbBundle.getMessage(SQLInplaceHistoryAction.class, "LBL_SQLInplaceHistoryAction"));
66
        this.ctx = ctx;
67
    }
68
    
69
    @Override
70
    public Action createContextAwareInstance(Lookup actionContext) {
71
        return new SQLInplaceHistoryAction(actionContext);
72
    }
73
74
    @Override
75
    public void actionPerformed(ActionEvent e) {
76
        if(ctx != null && ctx.lookup(SQLExecution.class) != null && ctx.lookup(CloneableEditor.class) != null) {
77
            CloneableEditor ce = ctx.lookup(CloneableEditor.class);
78
            Document d = ce.getEditorPane().getDocument();
79
            d.putProperty(completionProperty, Boolean.TRUE);
80
            Completion.get().showCompletion();
81
        }
82
    }
83
}

Return to bug 192020