Skip to content

Commit

Permalink
tmf: Add parent ID and creation configuration to IDataProviderDescriptor
Browse files Browse the repository at this point in the history
This will allow to show configuration parameters that were used to
create a data provider to the user, as well as, group data providers
using the parent ID.

[Added] parent ID and creation configuration to IDataProviderDescriptor

Signed-off-by: Bernd Hufmann <[email protected]>
  • Loading branch information
bhufmann committed Oct 15, 2024
1 parent 9fb2174 commit 55144e8
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import static org.junit.Assert.assertTrue;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
import org.eclipse.tracecompass.tmf.core.config.TmfConfiguration;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor.ProviderType;
import org.eclipse.tracecompass.tmf.core.model.DataProviderDescriptor;
Expand All @@ -31,6 +33,9 @@ public class DataProviderDescriptorTest {
private static final String ID = "my.data.provider.id";
private static final String NAME = "Data Provider Name";
private static final ProviderType TYPE = ProviderType.TIME_GRAPH;
private static final String PARENT_ID = "a.parent.id";
private static final String CONFIG_ID = "a.config.id";
private static final String CONFIG_TYPE_ID = "a.type.id";

/**
* Test the equality methods
Expand Down Expand Up @@ -59,6 +64,22 @@ public void testEquality() {
assertFalse(baseDescriptor.equals(builder.build()));
builder.setDescription(DESCRIPTION).setId(ID).setName(NAME).setProviderType(ProviderType.TABLE);
assertFalse(baseDescriptor.equals(builder.build()));
builder.setDescription(DESCRIPTION).setId(ID).setName(NAME).setProviderType(ProviderType.TABLE).setParentId(PARENT_ID);
assertFalse(baseDescriptor.equals(builder.build()));

baseDescriptor = builder.build();
ITmfConfiguration config = new TmfConfiguration.Builder().setId(CONFIG_ID).setSourceTypeId(CONFIG_TYPE_ID).build();
builder.setDescription(DESCRIPTION)
.setId(ID)
.setName(NAME)
.setProviderType(ProviderType.TABLE)
.setParentId(PARENT_ID)
.setCreationConfiguration(config);
assertFalse(baseDescriptor.equals(builder.build()));

// Make sure it is equal to itself (with parent id and config)
baseDescriptor = builder.build();
assertTrue(baseDescriptor.equals(builder.build()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package org.eclipse.tracecompass.tmf.core.dataprovider;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;

/**
* Data Provider description, used to list the available providers for a trace
Expand Down Expand Up @@ -87,4 +89,25 @@ public enum ProviderType {
* @return a short description of this data provider.
*/
String getDescription();

/**
* Gets the parent data provider ID for grouping purposes.
*
* @return parent ID or null if not grouped or derived data provider
* @since 9.5
*/
default @Nullable String getParentId() {
return null;
}

/**
* Gets the input configuration used to create this data provider.
*
* @return the {@link ITmfConfiguration} configuration use to create this
* data provider, or null if not applicable
* @since 9.5
*/
default @Nullable ITmfConfiguration getConfiguration() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.Objects;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.tracecompass.tmf.core.config.ITmfConfiguration;
import org.eclipse.tracecompass.tmf.core.dataprovider.IDataProviderDescriptor;

/**
Expand All @@ -31,18 +32,22 @@ public class DataProviderDescriptor implements IDataProviderDescriptor {
private final String fName;
private final String fDescription;
private final ProviderType fType;
private final @Nullable String fParentId;
private final @Nullable ITmfConfiguration fCreationConfiguration;

/**
* Constructor
*
* @param bulider
* @param buidder
* the builder object to create the descriptor
*/
private DataProviderDescriptor(Builder builder) {
fId = builder.fId;
fName = builder.fName;
fDescription = builder.fDescription;
fType = Objects.requireNonNull(builder.fType);
fParentId = builder.fParentId;
fCreationConfiguration = builder.fCreationConfiguration;
}

@Override
Expand All @@ -65,12 +70,24 @@ public String getDescription() {
return fDescription;
}

@Override
public @Nullable String getParentId() {
return fParentId;
}

@Override
public @Nullable ITmfConfiguration getConfiguration() {
return fCreationConfiguration;
}

@Override
@SuppressWarnings("nls")
public String toString() {
return getClass().getSimpleName() + " [fName=" + getName()
+ ", fDescription=" + getDescription() + ", fType=" + getType()
+ ", fId=" + getId()
+ ", fParentId=" + fParentId
+ ", fCreationConfiguration" + fCreationConfiguration
+ "]";
}

Expand All @@ -81,7 +98,8 @@ public boolean equals(@Nullable Object arg0) {
}
DataProviderDescriptor other = (DataProviderDescriptor) arg0;
return Objects.equals(fName, other.fName) && Objects.equals(fId, other.fId)
&& Objects.equals(fType, other.fType) && Objects.equals(fDescription, other.fDescription);
&& Objects.equals(fType, other.fType) && Objects.equals(fDescription, other.fDescription)
&& Objects.equals(fParentId, other.fParentId) && Objects.equals(fCreationConfiguration, other.fCreationConfiguration);
}

@Override
Expand All @@ -97,6 +115,8 @@ public static class Builder {
private String fName = ""; //$NON-NLS-1$
private String fDescription = ""; //$NON-NLS-1$
private @Nullable ProviderType fType = null;
private @Nullable String fParentId = null;
private @Nullable ITmfConfiguration fCreationConfiguration = null;

/**
* Constructor
Expand Down Expand Up @@ -153,6 +173,34 @@ public Builder setProviderType(ProviderType type) {
return this;
}


/**
* Sets the parent ID of the descriptor
*
* @param parentId
* the parent ID to set
* @return the builder instance.
* @since 9.5
*/
public Builder setParentId(@Nullable String parentId) {
fParentId = parentId;
return this;
}

/**
* Sets the {@link ITmfConfiguration} used to create this data provider
*
* @param configuration
* the {@link ITmfConfiguration} to set
* @return the builder instance.
* @since 9.5
*/
public Builder setCreationConfiguration(@Nullable ITmfConfiguration configuration) {
fCreationConfiguration = configuration;
return this;
}


/**
* The method to construct an instance of
* {@link IDataProviderDescriptor}
Expand Down

0 comments on commit 55144e8

Please sign in to comment.