use of org.eclipse.wst.sse.ui.views.properties.IPropertySourceExtension in project webtools.sourceediting by eclipse.
the class ConfigurablePropertySheetPage method remove.
void remove() {
if (fSelectedEntries != null) {
Object[] entries = fSelectedEntries;
ISelection selection = fInput;
boolean needsRefresh = false;
if (selection != null && !selection.isEmpty() && selection instanceof IStructuredSelection) {
IPropertySource source = getConfiguration().getPropertySourceProvider(this).getPropertySource(((IStructuredSelection) selection).getFirstElement());
if (source != null && source instanceof IPropertySourceExtension) {
for (int i = 0; i < entries.length; i++) {
if (entries[i] instanceof IPropertySheetEntry) {
IPropertySheetEntry entry = (IPropertySheetEntry) entries[i];
needsRefresh = true;
((IPropertySourceExtension) source).removeProperty(entry.getDisplayName());
}
}
}
}
if (needsRefresh) {
refresh();
}
}
}
use of org.eclipse.wst.sse.ui.views.properties.IPropertySourceExtension in project webtools.sourceediting by eclipse.
the class TestPropertySheetConfiguration method testPropertySourceRemoval.
public void testPropertySourceRemoval() throws BadLocationException {
IDocument document = (IDocument) fEditor.getAdapter(IDocument.class);
// set up the editor document
document.replace(0, 0, "<test><myproperty props=\"yes\" /></test>");
// set current selection in editor
ISelection setSelection = new TextSelection(9, 0);
fEditor.getSelectionProvider().setSelection(setSelection);
// get current selection in editor
Object item = null;
ISelection selection = fEditor.getSelectionProvider().getSelection();
if (selection instanceof IStructuredSelection) {
item = ((IStructuredSelection) selection).getFirstElement();
IPropertySheetPage propertySheet = (IPropertySheetPage) fEditor.getAdapter(IPropertySheetPage.class);
assertTrue("No ConfigurablePropertySheetPage found", propertySheet instanceof ConfigurablePropertySheetPage);
if (propertySheet instanceof ConfigurablePropertySheetPage) {
ConfigurablePropertySheetPage cps = (ConfigurablePropertySheetPage) propertySheet;
PropertySheetConfiguration config = cps.getConfiguration();
assertNotNull("No property sheet configuration found", config);
IPropertySourceProvider provider = config.getPropertySourceProvider(cps);
assertNotNull("No property sheet provider found", provider);
IPropertySource source = provider.getPropertySource(item);
if (source instanceof IPropertySourceExtension) {
boolean canRemove = ((IPropertySourceExtension) source).isPropertyRemovable("props");
assertTrue("Current property cannot be removed", canRemove);
if (canRemove) {
((IPropertySourceExtension) source).removeProperty("props");
assertTrue("Current property cannot be removed", true);
// failing assert
return;
}
}
}
}
// if we get to here, always fail, since something went wrong.
assertTrue("testPropertySourceRemoval test did not take expected path", false);
}
Aggregations