Search in sources :

Example 1 with IPropertySourceExtension

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();
        }
    }
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IPropertySourceExtension(org.eclipse.wst.sse.ui.views.properties.IPropertySourceExtension) IPropertySource(org.eclipse.ui.views.properties.IPropertySource) IPropertySheetEntry(org.eclipse.ui.views.properties.IPropertySheetEntry) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 2 with IPropertySourceExtension

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);
}
Also used : ConfigurablePropertySheetPage(org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage) IPropertySourceProvider(org.eclipse.ui.views.properties.IPropertySourceProvider) IPropertySheetPage(org.eclipse.ui.views.properties.IPropertySheetPage) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) IPropertySourceExtension(org.eclipse.wst.sse.ui.views.properties.IPropertySourceExtension) IPropertySource(org.eclipse.ui.views.properties.IPropertySource) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) PropertySheetConfiguration(org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration) IDocument(org.eclipse.jface.text.IDocument)

Aggregations

ISelection (org.eclipse.jface.viewers.ISelection)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 IPropertySource (org.eclipse.ui.views.properties.IPropertySource)2 IPropertySourceExtension (org.eclipse.wst.sse.ui.views.properties.IPropertySourceExtension)2 IDocument (org.eclipse.jface.text.IDocument)1 TextSelection (org.eclipse.jface.text.TextSelection)1 IPropertySheetEntry (org.eclipse.ui.views.properties.IPropertySheetEntry)1 IPropertySheetPage (org.eclipse.ui.views.properties.IPropertySheetPage)1 IPropertySourceProvider (org.eclipse.ui.views.properties.IPropertySourceProvider)1 ConfigurablePropertySheetPage (org.eclipse.wst.sse.ui.internal.properties.ConfigurablePropertySheetPage)1 PropertySheetConfiguration (org.eclipse.wst.sse.ui.views.properties.PropertySheetConfiguration)1