TypeSafeDataProvider Replacement?

Wondering what the recommended replacement is for the deprecated class TypeSafeDataProvider? For example, we have this class:

class PropertiesTable extends JBTable implements TypeSafeDataProvider, CopyProvider{

Within it we implement the calcData function:

@SuppressWarnings("rawtypes")
@Override
public void calcData(DataKey key, DataSink sink) {
if (key.equals(PlatformDataKeys.COPY_PROVIDER)) {
sink.put(PlatformDataKeys.COPY_PROVIDER, this);
}
}

Without the TypeSafeDataProvider implementation our context menus don't work. I see on the comments for TypeSafeDataProvider that the DataProvider class is recommended as a replacement: https://github.com/JetBrains/intellij-community/blob/master/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataProvider.java. But I'm not sure how?

0
2 comments
@Nullable
@Override
public Object getData(@NonNls String dataId) {
if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
return this;
}
return null;
}
1
Avatar
Permanently deleted user

Thanks Aleksey, that seems to have done it! General pattern for anyone in future:

Old code within calcData:

if (key.equals(FOO)) {

    sink.put(FOO, BAR);

  }

Replacement code within getData:

if (FOO.is(dataId)) {

    return BAR;

  }

& put a default return value of null at the end of getData.

0

Please sign in to leave a comment.