Author: scabanovich
Date: 2009-11-11 09:01:42 -0500 (Wed, 11 Nov 2009)
New Revision: 18614
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/IValueFilter.java
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultValueAdapter.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/JavaClassContentAssistProvider.java
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/JavaEclipseChoicerEditor.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-2023
Added:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/IValueFilter.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/IValueFilter.java
(rev 0)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/IValueFilter.java 2009-11-11
14:01:42 UTC (rev 18614)
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.model.ui.attribute;
+
+import org.jboss.tools.common.meta.XAttribute;
+import org.jboss.tools.common.model.XModelObject;
+
+/**
+ *
+ * @author Viacheslav Kabanovich
+ *
+ */
+public interface IValueFilter {
+ public boolean init(XModelObject context, XAttribute attribute);
+ public boolean accept(String value);
+}
Property changes on:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/IValueFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultValueAdapter.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultValueAdapter.java 2009-11-11
13:37:31 UTC (rev 18613)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/DefaultValueAdapter.java 2009-11-11
14:01:42 UTC (rev 18614)
@@ -18,7 +18,10 @@
import org.jboss.tools.common.model.ui.IAttributeErrorProvider;
import org.jboss.tools.common.model.ui.IValueChangeListener;
import org.jboss.tools.common.model.ui.IValueProvider;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.attribute.IValueFilter;
import org.jboss.tools.common.model.ui.attribute.editor.IPropertyEditor;
+import org.jboss.tools.common.model.util.ModelFeatureFactory;
import org.jboss.tools.common.meta.XAttribute;
import org.jboss.tools.common.meta.action.XAttributeData;
@@ -51,6 +54,9 @@
protected String lastCorrectValue = null;
protected String currentError = null;
+ boolean valueFilterChecked = false;
+ IValueFilter valueFilter = null;
+
public DefaultValueAdapter() {}
public void store() {
@@ -158,6 +164,27 @@
if(adapter == IAttributeErrorProvider.class) {
return this;
}
+ if(adapter == IValueFilter.class) {
+ if(valueFilterChecked) return valueFilter;
+ valueFilterChecked = true;
+ if(valueFilter == null) {
+ XAttribute a = (attribute != null) ? attribute : attributeData != null ?
attributeData.getAttribute() : null;
+ if(a == null) return null;
+ String cls = a.getProperty("valueFilter");
+ if(cls == null || cls.length() == 0) return null;
+ try {
+ valueFilter =
(IValueFilter)ModelFeatureFactory.getInstance().createFeatureInstance(cls);
+ } catch (ClassCastException exc) {
+ ModelUIPlugin.getPluginLog().logError(exc);
+ }
+ if(valueFilter != null) {
+ if(!valueFilter.init(getModelObject(), a)) {
+ valueFilter = null;
+ }
+ }
+ return valueFilter;
+ }
+ }
return null;
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/JavaClassContentAssistProvider.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/JavaClassContentAssistProvider.java 2009-11-11
13:37:31 UTC (rev 18613)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/adapter/JavaClassContentAssistProvider.java 2009-11-11
14:01:42 UTC (rev 18614)
@@ -28,17 +28,21 @@
import org.jboss.tools.common.meta.XAttribute;
import org.jboss.tools.common.meta.action.XEntityData;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
import org.jboss.tools.common.model.ui.attribute.IAttributeContentProposalProvider;
+import org.jboss.tools.common.model.ui.attribute.IValueFilter;
import org.jboss.tools.common.model.ui.attribute.editor.JavaHyperlinkCueLabelProvider;
+import org.jboss.tools.common.model.util.ModelFeatureFactory;
public class JavaClassContentAssistProvider implements
IAttributeContentProposalProvider {
XModelObject object;
XAttribute attribute;
+ IValueFilter valueFilter = null;
public IContentProposalProvider getContentProposalProvider() {
IProject project =
(IProject)object.getModel().getProperties().get("project"); //$NON-NLS-1$
- return (project == null) ? null : new TypeContentProposalProvider(project,
IJavaSearchConstants.TYPE);
+ return (project == null) ? null : new TypeContentProposalProvider(project,
IJavaSearchConstants.TYPE, valueFilter);
}
public int getProposalAcceptanceStyle() {
@@ -48,8 +52,25 @@
public void init(XModelObject object, XEntityData data, XAttribute attribute) {
this.object = object;
this.attribute = attribute;
+ createValueFilter();
}
+ void createValueFilter() {
+ if(attribute == null) return;
+ String cls = attribute.getProperty("valueFilter");
+ if(cls == null || cls.length() == 0) return;
+ try {
+ valueFilter =
(IValueFilter)ModelFeatureFactory.getInstance().createFeatureInstance(cls);
+ } catch (ClassCastException exc) {
+ ModelUIPlugin.getPluginLog().logError(exc);
+ }
+ if(valueFilter != null) {
+ if(!valueFilter.init(object, attribute)) {
+ valueFilter = null;
+ }
+ }
+ }
+
public boolean isRelevant(XModelObject object, XAttribute attribute) {
if(object == null || attribute == null) return false;
String editorName = attribute.getEditor().getName();
@@ -77,13 +98,17 @@
private String fInitialContent;
private Comparator fComparator;
+ IValueFilter valueFilter;
+
/**
*
*/
- public TypeContentProposalProvider(IProject project, int scope) {
+ public TypeContentProposalProvider(IProject project, int scope, IValueFilter
valueFilter) {
fProject = project;
fTypeScope = scope;
fComparator = new TypeComparator();
+
+ this.valueFilter = valueFilter;
reset();
}
@@ -139,8 +164,11 @@
// characters in the field causing new characters to be appended to
// the initial field contents
currentContentProposals = filterContentProposals(contents);
+
}
+ currentContentProposals =
filterContentProposalsByValueFilter(currentContentProposals);
+
return convertResultsToSortedProposals(currentContentProposals);
}
@@ -211,6 +239,7 @@
*/
private ArrayList filterContentProposals(String currentContent) {
String lowerCaseCurrentContent = currentContent.toLowerCase();
+
ListIterator iterator = fInitialContentProposals.listIterator();
// Maintain a list of filtered search results
ArrayList filteredContentProposals = new ArrayList();
@@ -233,7 +262,25 @@
filteredContentProposals.add(proposal);
}
}
+
return filteredContentProposals;
}
+ private ArrayList filterContentProposalsByValueFilter(ArrayList
filteredContentProposals) {
+ if(valueFilter != null && filteredContentProposals != null &&
filteredContentProposals.size() < 200) {
+ ArrayList filteredContentProposals2 = new ArrayList();
+ ListIterator iterator = filteredContentProposals.listIterator();
+ while (iterator.hasNext()) {
+ Object object = iterator.next();
+ IContentProposal proposal = (IContentProposal) object;
+ String value = proposal.getContent();
+ if(valueFilter.accept(value)) {
+ filteredContentProposals2.add(proposal);
+ }
+ }
+ filteredContentProposals = filteredContentProposals2;
+ }
+ return filteredContentProposals;
+ }
+
}
Modified:
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/JavaEclipseChoicerEditor.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/JavaEclipseChoicerEditor.java 2009-11-11
13:37:31 UTC (rev 18613)
+++
trunk/common/plugins/org.jboss.tools.common.model.ui/src/org/jboss/tools/common/model/ui/attribute/editor/JavaEclipseChoicerEditor.java 2009-11-11
14:01:42 UTC (rev 18614)
@@ -12,12 +12,16 @@
import java.text.MessageFormat;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.internal.ui.dialogs.FilteredTypesSelectionDialog;
+import org.eclipse.jdt.ui.dialogs.ITypeInfoFilterExtension;
+import org.eclipse.jdt.ui.dialogs.ITypeInfoRequestor;
+import org.eclipse.jdt.ui.dialogs.TypeSelectionExtension;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.SWT;
@@ -29,6 +33,7 @@
import org.jboss.tools.common.model.XModelObject;
import org.jboss.tools.common.model.ui.IValueProvider;
import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.common.model.ui.attribute.IValueFilter;
import org.jboss.tools.common.model.ui.attribute.adapter.DefaultValueAdapter;
import org.jboss.tools.common.model.ui.widgets.IWidgetSettings;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
@@ -38,7 +43,7 @@
protected JavaHyperlinkCellEditor cellEditor;
//protected JavaChoicerFieldEditor fieldEditor;
protected JavaHyperlinkLineFieldEditor fieldEditor;
-
+
public JavaEclipseChoicerEditor() {}
public JavaEclipseChoicerEditor(IWidgetSettings settings) {
@@ -105,7 +110,7 @@
ModelUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow(),
jp == null ? SearchEngine.createWorkspaceScope()
: SearchEngine.createJavaSearchScope(new IJavaElement[]{jp}),
- IJavaSearchConstants.TYPE);
+ IJavaSearchConstants.TYPE, createTypeSelectionExtension());
dialog.setTitle(title);
IValueProvider valueProvider =
(IValueProvider)adapter.getAdapter(IValueProvider.class);
String v = valueProvider.getStringValue(true);
@@ -120,4 +125,36 @@
return null;
}
+ TypeSelectionExtension createTypeSelectionExtension() {
+ final ITypeInfoFilterExtension filter = createFilterExtension();
+ if(filter == null) return null;
+ return new TypeSelectionExtension() {
+ public ITypeInfoFilterExtension getFilterExtension() {
+ return filter;
+ }
+ };
+ }
+
+ ITypeInfoFilterExtension createFilterExtension() {
+ if(getInput() instanceof IAdaptable) {
+ IValueFilter filter =
(IValueFilter)((IAdaptable)getInput()).getAdapter(IValueFilter.class);
+ if(filter != null) {
+ return new FilterExtension(filter);
+ }
+ }
+ return null;
+ }
+
+ class FilterExtension implements ITypeInfoFilterExtension {
+ IValueFilter filter;
+ public FilterExtension(IValueFilter filter) {
+ this.filter = filter;
+ }
+ public boolean select(ITypeInfoRequestor typeInfoRequestor) {
+ String pkg = typeInfoRequestor.getPackageName();
+ String cls = typeInfoRequestor.getTypeName();
+ String q = pkg == null || pkg.length() == 0 ? cls : pkg + "." + cls;
+ return filter.accept(q);
+ }
+ }
}