Skip to content

Commit

Permalink
Updated constant name from LIBERTY_BUILD_FILE to LIBERTY_BUILD_FILE_D…
Browse files Browse the repository at this point in the history
…ATAKEY and added comments
  • Loading branch information
staicy123 committed Nov 29, 2024
1 parent 831f833 commit e7fcbdd
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public void invokePopup(Component comp, int x, int y) {

menu.setDataContext(() -> SimpleDataContext.builder()
.add(CommonDataKeys.PROJECT, libertyNode.getProject())
.add(Constants.LIBERTY_BUILD_FILE, libertyNode.getFilePath()).build());
.add(Constants.LIBERTY_BUILD_FILE_DATAKEY, libertyNode.getFilePath()).build());

menu.getComponent().show(comp, x, y);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ public void actionPerformed(@NotNull AnActionEvent e) {

// Obtain the liberty module associated to the current action.
LibertyModule libertyModule = null;
VirtualFile buildFile = e.getDataContext().getData(Constants.LIBERTY_BUILD_FILE);
//Using DataKey instead of a string because the getData(String) method is deprecated
// and does not work as expected in IntelliJ 2024.2 and later versions.
// This ensures compatibility and proper retrieval of the build file across all supported versions.
VirtualFile buildFile = e.getDataContext().getData(Constants.LIBERTY_BUILD_FILE_DATAKEY);
if (buildFile != null) {
// The action is being driven from the project drop-down tree menu or from the project context menu.
libertyModule = LibertyModules.getInstance().getLibertyModule(buildFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEn
if (CommonDataKeys.PROJECT.is(dataId)) {
return libertyModule.getProject();
}
if (Constants.LIBERTY_BUILD_FILE.getName().equals(dataId)) {
if (Constants.LIBERTY_BUILD_FILE_DATAKEY.getName().equals(dataId)) {
return libertyModule.getBuildFile();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public final class Constants {
/**
* Constants for Data Context, passing information between the tree nodes and the Actions
*/
public static final DataKey<VirtualFile> LIBERTY_BUILD_FILE = DataKey.create("LIBERTY_BUILD_FILE");
// Using DataKey instead of a string because the getData(String) method is deprecated starting with intellij 2024.2
public static final DataKey<VirtualFile> LIBERTY_BUILD_FILE_DATAKEY = DataKey.create("LIBERTY_BUILD_FILE");
public static final String LIBERTY_PROJECT_NAME = "LIBERTY_PROJECT_NAME";
public static final String LIBERTY_PROJECT_TYPE = "LIBERTY_PROJECT_TYPE";
public static final String LIBERTY_PROJECT_MAP = "LIBERTY_PROJECT_MAP";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class TreeDataProvider implements DataProvider {
@Nullable
@Override
public Object getData(@NotNull String dataId) {
if (dataId.equals(Constants.LIBERTY_BUILD_FILE.getName())) {
if (dataId.equals(Constants.LIBERTY_BUILD_FILE_DATAKEY.getName())) {
return this.currentFile;
} else if (dataId.equals(Constants.LIBERTY_PROJECT_NAME)) {
return this.projectName;
Expand Down

0 comments on commit e7fcbdd

Please sign in to comment.