提交 30981462 编写于 作者: J jurgen

Duplicate proposals filtering

上级 5b4ae832
......@@ -102,6 +102,7 @@ public class DBeaverPreferencesInitializer extends AbstractPreferenceInitializer
RuntimeUtils.setDefaultPreferenceValue(store, SQLPreferenceConstants.AUTO_ACTIVATION_DELAY, 500);
RuntimeUtils.setDefaultPreferenceValue(store, SQLPreferenceConstants.INSERT_SINGLE_PROPOSALS_AUTO, true);
RuntimeUtils.setDefaultPreferenceValue(store, SQLPreferenceConstants.PROPOSAL_INSERT_CASE, SQLPreferenceConstants.PROPOSAL_CASE_DEFAULT);
RuntimeUtils.setDefaultPreferenceValue(store, SQLPreferenceConstants.HIDE_DUPLICATE_PROPOSALS, true);
RuntimeUtils.setDefaultPreferenceValue(store, SQLPreferenceConstants.SQLEDITOR_CLOSE_SINGLE_QUOTES, true);
RuntimeUtils.setDefaultPreferenceValue(store, SQLPreferenceConstants.SQLEDITOR_CLOSE_DOUBLE_QUOTES, true);
......
......@@ -25,6 +25,7 @@ public class SQLPreferenceConstants
public static final String ENABLE_AUTO_ACTIVATION = "enable.auto.activation";
public static final String AUTO_ACTIVATION_DELAY = "auto.activation.delay";
public static final String PROPOSAL_INSERT_CASE = "proposal.insert.case";
public static final String HIDE_DUPLICATE_PROPOSALS = "hide.duplicate.proposals";
// Syntax Validation
public static final String SYNTAX_VALIDATION = "syntax.validation";
......
......@@ -97,7 +97,7 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
this.activeQuery = null;
this.wordDetector = new SQLWordPartDetector(viewer.getDocument(), editor.getSyntaxManager(), documentOffset);
final List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
final List<SQLCompletionProposal> proposals = new ArrayList<SQLCompletionProposal>();
final String wordPart = wordDetector.getWordPart();
QueryType queryType = null;
......@@ -148,15 +148,16 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
keyWord,
keyWord + " (" + keywordType.name() + ")",
null,
false));
false,
null));
}
}
// Remove duplications
for (int i = 0; i < proposals.size(); i++) {
ICompletionProposal proposal = proposals.get(i);
SQLCompletionProposal proposal = proposals.get(i);
for (int j = i + 1; j < proposals.size(); ) {
ICompletionProposal proposal2 = proposals.get(j);
SQLCompletionProposal proposal2 = proposals.get(j);
if (proposal.getDisplayString().equals(proposal2.getDisplayString())) {
proposals.remove(j);
} else {
......@@ -164,12 +165,38 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
}
}
}
DBSObject selectedObject = getSelectedObject(editor.getDataSource());
boolean hideDups = getPreferences().getBoolean(SQLPreferenceConstants.HIDE_DUPLICATE_PROPOSALS) && selectedObject != null;
if (hideDups) {
for (int i = 0; i < proposals.size(); i++) {
SQLCompletionProposal proposal = proposals.get(i);
for (int j = 0; j < proposals.size(); ) {
SQLCompletionProposal proposal2 = proposals.get(j);
if (i != j && proposal.hasStructObject() && proposal2.hasStructObject() &&
CommonUtils.equalObjects(proposal.getObject().getName(), proposal2.getObject().getName()) &&
proposal.getObjectContainer() == selectedObject) {
proposals.remove(j);
} else {
j++;
}
}
}
}
if (hideDups) {
// Remove duplicates from non-active schema
if (selectedObject instanceof DBSObjectContainer) {
//List<ICompletionProposal>
}
}
return proposals.toArray(new ICompletionProposal[proposals.size()]);
}
private void makeStructureProposals(
final DBRProgressMonitor monitor,
final List<ICompletionProposal> proposals,
final List<SQLCompletionProposal> proposals,
final String wordPart,
final QueryType queryType)
{
......@@ -227,7 +254,7 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
private void makeStructureProposals(
DBRProgressMonitor monitor,
DBPDataSource dataSource,
List<ICompletionProposal> proposals)
List<SQLCompletionProposal> proposals)
{
final DBSObjectContainer rootContainer = DBUtils.getAdapter(DBSObjectContainer.class, dataSource);
if (rootContainer == null) {
......@@ -441,7 +468,7 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
DBRProgressMonitor monitor,
DBSObject parent,
@Nullable String startPart,
List<ICompletionProposal> proposals)
List<SQLCompletionProposal> proposals)
{
if (startPart != null) {
startPart = wordDetector.removeQuotes(startPart).toUpperCase();
......@@ -475,7 +502,7 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
DBSStructureAssistant assistant,
@Nullable DBSObjectContainer rootSC,
String objectName,
List<ICompletionProposal> proposals)
List<SQLCompletionProposal> proposals)
{
try {
Collection<DBSObjectReference> references = assistant.findObjectsByMask(
......@@ -493,13 +520,13 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
}
}
private ICompletionProposal makeProposalsFromObject(DBRProgressMonitor monitor, DBSObject object)
private SQLCompletionProposal makeProposalsFromObject(DBRProgressMonitor monitor, DBSObject object)
{
DBNNode node = DBeaverCore.getInstance().getNavigatorModel().getNodeByObject(monitor, object, false);
return makeProposalsFromObject(object, node == null ? null : node.getNodeIconDefault());
}
private ICompletionProposal makeProposalsFromObject(DBPNamedObject object, @Nullable Image objectIcon)
private SQLCompletionProposal makeProposalsFromObject(DBPNamedObject object, @Nullable Image objectIcon)
{
String objectFullName = DBUtils.getObjectFullName(object);
......@@ -550,23 +577,36 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
objectFullName,
info.toString(),
objectIcon,
isSingleObject);
isSingleObject,
object);
}
private IPreferenceStore getPreferences() {
IPreferenceStore store = null;
SQLDataSource dataSource = editor.getDataSource();
if (dataSource != null) {
store = dataSource.getContainer().getPreferenceStore();
}
if (store == null) {
store = DBeaverCore.getGlobalPreferenceStore();
}
return store;
}
/*
* Turns the vector into an Array of ICompletionProposal objects
*/
protected ICompletionProposal createCompletionProposal(
protected SQLCompletionProposal createCompletionProposal(
String replaceString,
String displayString,
String description,
@Nullable Image image,
boolean isObject)
boolean isObject,
@Nullable DBPNamedObject object)
{
IPreferenceStore store = DBeaverCore.getGlobalPreferenceStore();
IPreferenceStore store = getPreferences();
SQLDataSource dataSource = editor.getDataSource();
if (dataSource != null) {
store = dataSource.getContainer().getPreferenceStore();
if (isObject) {
// Escape replace string if required
replaceString = DBUtils.getQuotedIdentifier(dataSource, replaceString);
......@@ -600,7 +640,8 @@ public class SQLCompletionProcessor implements IContentAssistProcessor
// relative to replacementOffset
image, //image to display
new ContextInformation(image, displayString, displayString), //the context information associated with this proposal
description);
description,
object);
}
/**
......
......@@ -30,6 +30,9 @@ import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.jkiss.code.Nullable;
import org.jkiss.dbeaver.model.DBPNamedObject;
import org.jkiss.dbeaver.model.struct.DBSObject;
import org.jkiss.dbeaver.model.struct.DBSObjectReference;
import org.jkiss.utils.CommonUtils;
/**
......@@ -60,6 +63,8 @@ public class SQLCompletionProposal implements ICompletionProposal, ICompletionPr
/** The additional info of this proposal. */
private String additionalProposalInfo;
private DBPNamedObject object;
public SQLCompletionProposal(
SQLSyntaxManager syntaxManager,
String displayString,
......@@ -68,7 +73,8 @@ public class SQLCompletionProposal implements ICompletionProposal, ICompletionPr
int cursorPosition,
@Nullable Image image,
IContextInformation contextInformation,
String additionalProposalInfo)
String additionalProposalInfo,
DBPNamedObject object)
{
this.syntaxManager = syntaxManager;
this.displayString = displayString;
......@@ -86,6 +92,12 @@ public class SQLCompletionProposal implements ICompletionProposal, ICompletionPr
this.additionalProposalInfo = additionalProposalInfo;
setPosition(wordDetector);
this.object = object;
}
public DBPNamedObject getObject() {
return object;
}
private void setPosition(SQLWordPartDetector wordDetector)
......@@ -191,4 +203,19 @@ public class SQLCompletionProposal implements ICompletionProposal, ICompletionPr
return false;
}
}
public boolean hasStructObject() {
return object instanceof DBSObject || object instanceof DBSObjectReference;
}
public DBSObject getObjectContainer() {
if (object instanceof DBSObject) {
return ((DBSObject) object).getParentObject();
} else if (object instanceof DBSObjectReference) {
return ((DBSObjectReference) object).getContainer();
} else {
return null;
}
}
}
......@@ -60,6 +60,7 @@ public class PrefPageSQLEditor extends TargetPrefPage
private Spinner csAutoActivationDelaySpinner;
private Button csAutoInsertCheck;
private Combo csInsertCase;
private Button csHideDuplicates;
private Map<RulerColumnDescriptor, Button> rulerChecks = new HashMap<RulerColumnDescriptor, Button>();
private Button acSingleQuotesCheck;
private Button acDoubleQuotesCheck;
......@@ -177,6 +178,8 @@ public class PrefPageSQLEditor extends TargetPrefPage
csInsertCase.add("Default");
csInsertCase.add("Upper case");
csInsertCase.add("Lower case");
csHideDuplicates = UIUtils.createLabelCheckbox(assistGroup, "Hide duplicate names\nfrom non-active schemas", false);
}
// Autoclose
......@@ -227,6 +230,7 @@ public class PrefPageSQLEditor extends TargetPrefPage
csAutoActivationDelaySpinner.setSelection(store.getInt(SQLPreferenceConstants.AUTO_ACTIVATION_DELAY));
csAutoInsertCheck.setSelection(store.getBoolean(SQLPreferenceConstants.INSERT_SINGLE_PROPOSALS_AUTO));
csInsertCase.select(store.getInt(SQLPreferenceConstants.PROPOSAL_INSERT_CASE));
csHideDuplicates.setSelection(store.getBoolean(SQLPreferenceConstants.HIDE_DUPLICATE_PROPOSALS));
acSingleQuotesCheck.setSelection(store.getBoolean(SQLPreferenceConstants.SQLEDITOR_CLOSE_SINGLE_QUOTES));
acDoubleQuotesCheck.setSelection(store.getBoolean(SQLPreferenceConstants.SQLEDITOR_CLOSE_DOUBLE_QUOTES));
acBracketsCheck.setSelection(store.getBoolean(SQLPreferenceConstants.SQLEDITOR_CLOSE_BRACKETS));
......@@ -254,6 +258,7 @@ public class PrefPageSQLEditor extends TargetPrefPage
store.setValue(SQLPreferenceConstants.AUTO_ACTIVATION_DELAY, csAutoActivationDelaySpinner.getSelection());
store.setValue(SQLPreferenceConstants.INSERT_SINGLE_PROPOSALS_AUTO, csAutoInsertCheck.getSelection());
store.setValue(SQLPreferenceConstants.PROPOSAL_INSERT_CASE, csInsertCase.getSelectionIndex());
store.setValue(SQLPreferenceConstants.HIDE_DUPLICATE_PROPOSALS, csHideDuplicates.getSelection());
store.setValue(DBeaverPreferences.SCRIPT_COMMIT_TYPE, CommonUtils.fromOrdinal(SQLScriptCommitType.class, commitTypeCombo.getSelectionIndex()).name());
store.setValue(DBeaverPreferences.SCRIPT_COMMIT_LINES, commitLinesText.getSelection());
......@@ -287,6 +292,7 @@ public class PrefPageSQLEditor extends TargetPrefPage
store.setToDefault(SQLPreferenceConstants.AUTO_ACTIVATION_DELAY);
store.setToDefault(SQLPreferenceConstants.INSERT_SINGLE_PROPOSALS_AUTO);
store.setToDefault(SQLPreferenceConstants.PROPOSAL_INSERT_CASE);
store.setToDefault(SQLPreferenceConstants.HIDE_DUPLICATE_PROPOSALS);
store.setToDefault(DBeaverPreferences.SCRIPT_COMMIT_TYPE);
store.setToDefault(DBeaverPreferences.SCRIPT_COMMIT_LINES);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册