Skip to content

Commit eb94655

Browse files
gian-benitoBAlgarraKN0987
committed
Added Filter Textfield support
Co-authored-by: Brandon Algarra <[email protected]> Co-authored-by: Khang Nguyen <[email protected]>
1 parent d9ad053 commit eb94655

File tree

7 files changed

+129
-0
lines changed

7 files changed

+129
-0
lines changed

ui/org.eclipse.pde.core/src/org/eclipse/pde/core/plugin/IPluginImport.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public interface IPluginImport extends IPluginObject, IPluginReference {
3434
*/
3535
String P_OPTIONAL = "optional"; //$NON-NLS-1$
3636

37+
/**
38+
* @since 3.21
39+
*/
40+
String P_FILTER = "filter"; //$NON-NLS-1$
41+
3742
/**
3843
* Tests whether the imported plug-in is reexported for
3944
* plug-ins that will use this plug-in.
@@ -70,4 +75,17 @@ public interface IPluginImport extends IPluginObject, IPluginReference {
7075
*/
7176
void setOptional(boolean value) throws CoreException;
7277

78+
/**
79+
* @since 3.21
80+
*/
81+
void setFilter(String filter) throws CoreException;
82+
83+
/**
84+
* Returns the filter string for this plugin reference.
85+
*
86+
* @return the filter string, or null if not set
87+
* @since 3.21
88+
*/
89+
String getFilter();
90+
7391
}

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/plugin/PluginImport.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public class PluginImport extends IdentifiablePluginObject implements IPluginImp
4646
private boolean reexported = false;
4747
private boolean optional = false;
4848
private String version;
49+
private String filter;
4950

5051
public PluginImport() {
5152
}
@@ -74,6 +75,11 @@ public String getVersion() {
7475
return version;
7576
}
7677

78+
@Override
79+
public String getFilter() {
80+
return filter;
81+
}
82+
7783
@Override
7884
public boolean isReexported() {
7985
return reexported;
@@ -203,6 +209,15 @@ public void setVersion(String version) throws CoreException {
203209
firePropertyChanged(P_VERSION, oldValue, version);
204210
}
205211

212+
@Override
213+
public void setFilter(String filter) throws CoreException {
214+
ensureModelEditable();
215+
String oldValue = this.filter;
216+
this.filter = filter;
217+
firePropertyChanged(P_FILTER, oldValue, filter);
218+
219+
}
220+
206221
@Override
207222
public void restoreProperty(String name, Object oldValue, Object newValue) throws CoreException {
208223
if (name.equals(P_MATCH)) {
@@ -312,4 +327,6 @@ public void writeDelimeter(PrintWriter writer) {
312327
writer.print(' ');
313328
}
314329

330+
331+
315332
}

ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginImportNode.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ public class PluginImportNode extends PluginObjectNode implements IPluginImport
2121

2222
private static final long serialVersionUID = 1L;
2323

24+
@Override
25+
public void setFilter(String filter) {
26+
setXMLAttribute(P_FILTER, filter);
27+
28+
}
29+
30+
@Override
31+
public String getFilter() {
32+
return getXMLAttributeValue(P_FILTER);
33+
}
34+
2435
public PluginImportNode(String id) {
2536
super();
2637
String name = "plugin"; //$NON-NLS-1$

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public class PDEUIMessages extends NLS {
247247
public static String ContainerRenameParticipant_renameBundleId;
248248

249249
public static String ControlValidationUtility_errorMsgFilterInvalidSyntax;
250+
public static String ControlValidationUtility_errorMsgFeatureFilterInvalidSyntax;
250251
public static String ControlValidationUtility_errorMsgKeyNotFound;
251252
public static String ControlValidationUtility_errorMsgNotOnClasspath;
252253
public static String ControlValidationUtility_errorMsgPluginUnresolved;
@@ -977,6 +978,7 @@ public class PDEUIMessages extends NLS {
977978
public static String ManifestEditor_MatchSection_equivalent;
978979
public static String ManifestEditor_MatchSection_compatible;
979980
public static String ManifestEditor_MatchSection_greater;
981+
public static String ManifestEditor_MatchSection_filter;
980982

981983
public static String ManifestEditor_PluginSpecSection_title;
982984
public static String ManifestEditor_PluginSpecSection_desc;

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/plugin/MatchSection.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
import org.eclipse.pde.core.plugin.IMatchRules;
2626
import org.eclipse.pde.core.plugin.IPluginImport;
2727
import org.eclipse.pde.core.plugin.IPluginReference;
28+
import org.eclipse.pde.internal.core.ifeature.IFeatureImport;
2829
import org.eclipse.pde.internal.core.plugin.ImportObject;
2930
import org.eclipse.pde.internal.ui.PDEPlugin;
3031
import org.eclipse.pde.internal.ui.PDEUIMessages;
3132
import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
3233
import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
3334
import org.eclipse.pde.internal.ui.editor.PDEFormPage;
3435
import org.eclipse.pde.internal.ui.editor.PDESection;
36+
import org.eclipse.pde.internal.ui.editor.validation.ControlValidationUtility;
37+
import org.eclipse.pde.internal.ui.editor.validation.TextValidator;
3538
import org.eclipse.pde.internal.ui.parts.ComboPart;
3639
import org.eclipse.pde.internal.ui.parts.FormEntry;
3740
import org.eclipse.swt.SWT;
@@ -44,13 +47,18 @@
4447
import org.eclipse.ui.forms.IPartSelectionListener;
4548
import org.eclipse.ui.forms.widgets.FormToolkit;
4649
import org.eclipse.ui.forms.widgets.Section;
50+
import org.osgi.framework.FrameworkUtil;
51+
import org.osgi.framework.InvalidSyntaxException;
4752

4853
public class MatchSection extends PDESection implements IPartSelectionListener {
4954

55+
5056
private Button fReexportButton;
5157
private Button fOptionalButton;
5258

5359
private FormEntry fVersionText;
60+
private FormEntry fFilterText;
61+
private TextValidator fFilterEntryValidator;
5462

5563
private ComboPart fMatchCombo;
5664
protected IPluginReference fCurrentImport;
@@ -134,6 +142,32 @@ public void textDirty(FormEntry text) {
134142
}));
135143
toolkit.paintBordersFor(container);
136144
initialize();
145+
146+
fFilterText = new FormEntry(container, toolkit, PDEUIMessages.ManifestEditor_MatchSection_filter, null, false);
147+
fFilterText.setFormEntryListener(
148+
new FormEntryAdapter(this, getPage().getEditor().getEditorSite().getActionBars()) {
149+
@Override
150+
public void textValueChanged(FormEntry text) {
151+
applyFilter(text.getValue());
152+
}
153+
154+
@Override
155+
public void textDirty(FormEntry text) {
156+
if (fBlockChanges) {
157+
return;
158+
}
159+
markDirty();
160+
fBlockChanges = true;
161+
resetMatchCombo(fCurrentImport);
162+
fBlockChanges = false;
163+
}
164+
});
165+
fFilterEntryValidator = new TextValidator(getManagedForm(), fFilterText.getText(), getProject(), true) {
166+
@Override
167+
protected boolean validateControl() {
168+
return validateFilter();
169+
}
170+
};
137171
update((IPluginReference) null);
138172

139173
section.setClient(container);
@@ -143,6 +177,16 @@ public void textDirty(FormEntry text) {
143177
section.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING));
144178
}
145179

180+
private boolean validateFilter() {
181+
// No validation required for an optional field
182+
if (fFilterText.getText().getText().length() == 0) {
183+
return true;
184+
}
185+
// Value must match the current environment and contain valid syntax
186+
return ControlValidationUtility.validateFilterField(fFilterText.getText().getText(),
187+
fFilterEntryValidator);
188+
}
189+
146190
private void createReexportButton(FormToolkit toolkit, Composite container) {
147191
fReexportButton = toolkit.createButton(container, PDEUIMessages.ManifestEditor_MatchSection_reexport, SWT.CHECK);
148192
fReexportButton.addSelectionListener(widgetSelectedAdapter(e -> {
@@ -200,6 +244,22 @@ private void applyMatch(int match) {
200244
}
201245
}
202246

247+
private void applyFilter(String filter) {
248+
try {
249+
if (fCurrentImport == null)
250+
return;
251+
if (filter == null || filter.isEmpty())
252+
((IFeatureImport) fCurrentImport).setFilter(null);
253+
else {
254+
FrameworkUtil.createFilter(filter);
255+
((IFeatureImport) fCurrentImport).setFilter(filter);
256+
}
257+
} catch (InvalidSyntaxException e) {
258+
} catch (CoreException e) {
259+
PDEPlugin.logException(e);
260+
}
261+
}
262+
203263
private int getMatch() {
204264
return fMatchCombo.getSelectionIndex();
205265
}
@@ -272,8 +332,11 @@ protected void update(IPluginReference iimport) {
272332
}
273333
fVersionText.setValue(null, true);
274334
fVersionText.setEditable(false);
335+
275336
fMatchCombo.getControl().setEnabled(false);
276337
fMatchCombo.setText(""); //$NON-NLS-1$
338+
fFilterText.setValue(null, false);
339+
fFilterText.setEditable(false);
277340
fCurrentImport = null;
278341
fBlockChanges = false;
279342
return;
@@ -292,7 +355,10 @@ protected void update(IPluginReference iimport) {
292355
}
293356
fVersionText.setEditable(isEditable());
294357
fVersionText.setValue(fCurrentImport.getVersion());
358+
295359
resetMatchCombo(fCurrentImport);
360+
fFilterText.setEditable(isEditable());
361+
fFilterText.setValue(((IFeatureImport) fCurrentImport).getFilter());
296362
fBlockChanges = false;
297363
}
298364
}

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/validation/ControlValidationUtility.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,19 @@ public static boolean validatePlatformFilterField(String value, IValidatorMessag
9595
return true;
9696
}
9797

98+
public static boolean validateFilterField(String value, IValidatorMessageHandler validator) {
99+
// Check to see if the platform filter syntax is valid
100+
try {
101+
PDECore.getDefault().getBundleContext().createFilter(value);
102+
} catch (InvalidSyntaxException ise) {
103+
validator.addMessage(PDEUIMessages.ControlValidationUtility_errorMsgFeatureFilterInvalidSyntax,
104+
IMessageProvider.ERROR);
105+
return false;
106+
}
107+
108+
return true;
109+
}
110+
98111
public static boolean validateActivatorField(String value, IValidatorMessageHandler validator, IProject project) {
99112

100113
// Check the compiler flag and translate it into a message type

ui/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ ManifestEditor_MatchSection_perfect = Perfect
388388
ManifestEditor_MatchSection_equivalent = Equivalent
389389
ManifestEditor_MatchSection_compatible = Compatible
390390
ManifestEditor_MatchSection_greater = Greater or Equal
391+
ManifestEditor_MatchSection_filter = Filter:
391392

392393
ManifestEditor_PluginSpecSection_title = General Information
393394
ManifestEditor_PluginSpecSection_desc = This section describes general information about this plug-in.
@@ -2523,6 +2524,7 @@ ControlValidationUtility_errorMsgValueMustBeSpecified=A value must be specified
25232524
ControlValidationUtility_errorMsgValueNotExternalized=The specified value is not externalized
25242525
ControlValidationUtility_errorMsgKeyNotFound=The specified key is not present in the plug-in's properties file
25252526
ControlValidationUtility_errorMsgFilterInvalidSyntax=The specified platform filter contains invalid syntax
2527+
ControlValidationUtility_errorMsgFeatureFilterInvalidSyntax=The specified feature filter contains invalid syntax
25262528
PackageFinder_taskName=Searching class files for package references
25272529

25282530
UpdateSingleton_dir_label=Update ''{0}'' to 'singleton' directive true

0 commit comments

Comments
 (0)