0

I develop extension of PDT plugin. I need dialog with interfaces only (not classes). Basic code looks like it:

OpenTypeSelectionDialog2 dialog = new OpenTypeSelectionDialog2(
    DLTKUIPlugin.getActiveWorkbenchShell(), 
    multi, 
    PlatformUI.getWorkbench().getProgressService(), 
    null, 
    type, 
    PHPUILanguageToolkit.getInstance());

It's works fine but I get classes and interfaces together (type variables). Is any method to filter it? I can't find this kind of mechanism in PDT but classes and interfaces are recognize correctly (icons next to names).

1 Answers1

0

I don't know if its the best solution but it works.

int falseFlags = 0;
int trueFlags = 0;

IDLTKSearchScope scope = SearchEngine.createSearchScope(getScriptFolder().getScriptProject());

trueFlags = PHPFlags.AccInterface;

OpenTypeSelectionDialog2 dialog = new OpenTypeSelectionDialog2(
    DLTKUIPlugin.getActiveWorkbenchShell(), 
    multi,
    PlatformUI.getWorkbench().getProgressService(), 
    scope, 
    IDLTKSearchConstants.TYPE,
    new PHPTypeSelectionExtension(trueFlags, falseFlags), 
    PHPUILanguageToolkit.getInstance());

And PHPTypeSelectionExtension looks like this:

public class PHPTypeSelectionExtension extends TypeSelectionExtension {

/**
 * @see PHPFlags
 */
private int trueFlags = 0;
private int falseFlags = 0;

public PHPTypeSelectionExtension() {
}

public PHPTypeSelectionExtension(int trueFlags, int falseFlags) {
    super();
    this.trueFlags = trueFlags;
    this.falseFlags = falseFlags;
}

@Override
public ITypeInfoFilterExtension getFilterExtension() {
    return new ITypeInfoFilterExtension() {
        @Override
        public boolean select(ITypeInfoRequestor typeInfoRequestor) {
            if (falseFlags != 0 && (falseFlags & typeInfoRequestor.getModifiers()) != 0) {

                // Try to filter by black list.
                return false;
            } else if (trueFlags == 0 || (trueFlags & typeInfoRequestor.getModifiers()) != 0) {

                // Try to filter by white list, if trueFlags == 0 this is fine 'couse we pass black list.
                return true;
            } else {

                // Rest is filter out.
                return false;
            }
        }
    };
}

@SuppressWarnings("restriction")
@Override
public ISelectionStatusValidator getSelectionValidator() {
    return new TypedElementSelectionValidator(new Class[] {IType.class, INamespace.class}, false);
}

}