# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/matthias/NetBeansProjects/core-main
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: db.sql.editor/nbproject/project.xml
--- db.sql.editor/nbproject/project.xml
+++ db.sql.editor/nbproject/project.xml
@@ -267,6 +267,14 @@
8.0
+
+ org.openide.windows
+
+
+
+ 6.72
+
+
Index: db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLCompletionProvider.java
--- db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLCompletionProvider.java
+++ db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLCompletionProvider.java
@@ -51,6 +51,8 @@
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.modules.db.api.sql.execute.SQLExecution;
import org.netbeans.modules.db.sql.editor.ui.actions.SQLExecutionBaseAction;
+import org.netbeans.modules.db.sql.editor.ui.actions.SQLHistoryAction;
+import org.netbeans.modules.db.sql.editor.ui.actions.SQLInplaceHistoryAction;
import org.netbeans.modules.db.sql.lexer.SQLTokenId;
import org.netbeans.spi.editor.completion.CompletionProvider;
import org.netbeans.spi.editor.completion.CompletionTask;
@@ -66,7 +68,15 @@
public class SQLCompletionProvider implements CompletionProvider {
public CompletionTask createTask(int queryType, JTextComponent component) {
- if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE || queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
+ if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE
+ || queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
+ Document doc = component.getDocument();
+ Boolean historyCompletion = (Boolean) doc.getProperty(
+ SQLInplaceHistoryAction.completionProperty);
+ if (historyCompletion != null && historyCompletion) {
+ doc.putProperty(SQLInplaceHistoryAction.completionProperty, Boolean.FALSE);
+ return new AsyncCompletionTask(new SQLHistoryCompletionQuery(), component);
+ } else {
DatabaseConnection dbconn = findDBConn(component);
if (dbconn == null) {
// XXX perhaps should have an item in the completion instead?
@@ -76,6 +86,7 @@
}
return new AsyncCompletionTask(new SQLCompletionQuery(dbconn), component);
}
+ }
return null;
}
Index: db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLHistoryCompletionItem.java
--- db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLHistoryCompletionItem.java
+++ db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLHistoryCompletionItem.java
@@ -0,0 +1,152 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2014 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.db.sql.editor.completion;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.event.KeyEvent;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.ImageIcon;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.completion.Completion;
+import org.netbeans.modules.db.api.sql.history.SQLHistoryEntry;
+import org.netbeans.spi.editor.completion.CompletionItem;
+import org.netbeans.spi.editor.completion.CompletionTask;
+import org.netbeans.spi.editor.completion.support.CompletionUtilities;
+
+public class SQLHistoryCompletionItem implements CompletionItem {
+ private static final Logger LOG = Logger.getLogger(SQLHistoryCompletionItem.class.getName());
+
+ private final SQLHistoryEntry she;
+ private final int startOffset;
+
+ public SQLHistoryCompletionItem(SQLHistoryEntry she, int startOffset) {
+ this.she = she;
+ this.startOffset = startOffset;
+ }
+
+ @Override
+ public void defaultAction(JTextComponent component) {
+ Completion.get().hideDocumentation();
+ Completion.get().hideCompletion();
+ try {
+ int insertPos = startOffset;
+ while (insertPos < component.getCaretPosition()) {
+ if (Character.isWhitespace(component.getDocument().getText(insertPos, 1).charAt(0))) {
+ insertPos++;
+ } else {
+ break;
+ }
+ }
+
+ component.getDocument().remove(insertPos, component.getCaretPosition()
+ - insertPos);
+ component.getDocument().insertString(insertPos, she.getSql(), null);
+ } catch (BadLocationException ex) {
+ LOG.log(Level.WARNING, "Position error", ex);
+ }
+ }
+
+ @Override
+ public void processKeyEvent(KeyEvent evt) {
+ }
+
+ public int getPreferredWidth(Graphics g, Font defaultFont) {
+ return CompletionUtilities.getPreferredWidth(
+ getLeftHtmlText(),
+ getRightHtmlText(),
+ g,
+ defaultFont);
+ }
+
+ public void render(Graphics g, Font defaultFont, Color defaultColor, Color backgroundColor, int width, int height, boolean selected) {
+ CompletionUtilities.renderHtml(
+ getImageIcon(),
+ getLeftHtmlText(),
+ getRightHtmlText(),
+ g,
+ defaultFont,
+ defaultColor,
+ width,
+ height,
+ selected);
+ }
+
+ public CompletionTask createDocumentationTask() {
+ return null;
+ }
+
+ public CompletionTask createToolTipTask() {
+ return null;
+ }
+
+ public boolean instantSubstitution(JTextComponent component) {
+ return false;
+ }
+
+ public int getSortPriority() {
+ return 0;
+ }
+
+ public CharSequence getSortText() {
+ return null;
+ }
+
+ public CharSequence getInsertPrefix() {
+ return "";
+ }
+
+ protected ImageIcon getImageIcon() {
+ return null;
+ }
+
+ protected String getLeftHtmlText() {
+ return she.getSql();
+ }
+
+ protected String getRightHtmlText() {
+ return null;
+ }
+}
Index: db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLHistoryCompletionQuery.java
--- db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLHistoryCompletionQuery.java
+++ db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLHistoryCompletionQuery.java
@@ -0,0 +1,90 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2014 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2014 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.db.sql.editor.completion;
+
+import java.util.logging.Logger;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+import org.netbeans.modules.db.api.sql.history.SQLHistory;
+import org.netbeans.modules.db.api.sql.history.SQLHistoryEntry;
+import org.netbeans.modules.db.api.sql.history.SQLHistoryManager;
+import org.netbeans.spi.editor.completion.CompletionResultSet;
+import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery;
+import org.openide.util.Exceptions;
+
+public class SQLHistoryCompletionQuery extends AsyncCompletionQuery {
+ private static final Logger LOG = Logger.getLogger(SQLHistoryCompletionQuery.class.getName());
+
+ private final SQLHistory history;
+
+ public SQLHistoryCompletionQuery() {
+ this.history = SQLHistoryManager.getInstance().getHistory();
+ }
+
+ @Override
+ protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
+ try {
+ SQLCompletionEnv env = SQLCompletionEnv.forDocument(doc, caretOffset);
+ int startOffset = env.getStatementOffset();
+ int endOffset = caretOffset;
+ if (endOffset >= startOffset) {
+ String prefix = doc
+ .getText(startOffset, endOffset - startOffset)
+ .trim()
+ .toUpperCase();
+ for (SQLHistoryEntry she : history) {
+ String sql = she.getSql();
+ // Optimization assumption: SQL History is trimmed, so no whitespace at start...
+ if (sql.length() >= prefix.length()) {
+ String sqlPrefix = sql.substring(0, prefix.length());
+ if (sqlPrefix.equalsIgnoreCase(prefix)) {
+ resultSet.addItem(new SQLHistoryCompletionItem(she, startOffset));
+ }
+ }
+ }
+ }
+ resultSet.finish();
+ } catch (BadLocationException ex) {
+ Exceptions.printStackTrace(ex);
+ }
+ }
+}
Index: db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml
--- db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml
+++ db.sql.editor/src/org/netbeans/modules/db/sql/editor/resources/layer.xml
@@ -59,6 +59,7 @@
+
@@ -69,6 +70,9 @@
+
+
+
Index: db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/Bundle.properties
--- db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/Bundle.properties
+++ db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/Bundle.properties
@@ -52,6 +52,7 @@
# SQLHistoryAction
LBL_SQLHistoryAction=SQL History
+LBL_SQLInplaceHistoryAction=SQL History (Inplace)
LBL_NoSQLExecuted=To show SQL History, execute an SQL statement.
# RunSQLSelectionAction
Index: db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/SQLInplaceHistoryAction.java
--- db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/SQLInplaceHistoryAction.java
+++ db.sql.editor/src/org/netbeans/modules/db/sql/editor/ui/actions/SQLInplaceHistoryAction.java
@@ -0,0 +1,83 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2008 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.db.sql.editor.ui.actions;
+
+import java.awt.event.ActionEvent;
+import javax.swing.AbstractAction;
+import javax.swing.Action;
+import javax.swing.text.Document;
+import org.netbeans.api.editor.completion.Completion;
+import org.netbeans.modules.db.api.sql.execute.SQLExecution;
+import org.openide.text.CloneableEditor;
+import org.openide.util.ContextAwareAction;
+import org.openide.util.Lookup;
+import org.openide.util.NbBundle;
+
+public class SQLInplaceHistoryAction extends AbstractAction implements ContextAwareAction {
+ public static final String completionProperty = SQLInplaceHistoryAction.class.getName();
+ private Lookup ctx;
+
+ public SQLInplaceHistoryAction() {
+ this(null);
+ }
+
+ public SQLInplaceHistoryAction(Lookup ctx) {
+ super(NbBundle.getMessage(SQLInplaceHistoryAction.class, "LBL_SQLInplaceHistoryAction"));
+ this.ctx = ctx;
+ }
+
+ @Override
+ public Action createContextAwareInstance(Lookup actionContext) {
+ return new SQLInplaceHistoryAction(actionContext);
+ }
+
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ if(ctx != null && ctx.lookup(SQLExecution.class) != null && ctx.lookup(CloneableEditor.class) != null) {
+ CloneableEditor ce = ctx.lookup(CloneableEditor.class);
+ Document d = ce.getEditorPane().getDocument();
+ d.putProperty(completionProperty, Boolean.TRUE);
+ Completion.get().showCompletion();
+ }
+ }
+}
\ No newline at end of file