generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bld project panel with commands display
- Loading branch information
Showing
24 changed files
with
849 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com) | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
*/ | ||
package rife.bld.idea.config; | ||
|
||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.util.NlsSafe; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public interface BldBuildCommand { | ||
@Nullable | ||
@NlsSafe | ||
String getName(); | ||
|
||
@Nullable | ||
@NlsSafe | ||
String getDisplayName(); | ||
|
||
@Nullable | ||
@Nls(capitalization = Nls.Capitalization.Sentence) String getNotEmptyDescription(); | ||
|
||
void run(DataContext dataContext, List<?> additionalProperties, BldBuildListener buildListener); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com) | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
*/ | ||
package rife.bld.idea.config; | ||
|
||
public interface BldBuildListener { | ||
int FINISHED_SUCCESSFULLY = 0; | ||
int ABORTED = 1; | ||
int FAILED_TO_RUN = 2; | ||
|
||
BldBuildListener NULL = new BldBuildListener() { | ||
@Override | ||
public void buildFinished(int state, int errorCount) { | ||
} | ||
}; | ||
|
||
void buildFinished(int state, int errorCount); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com) | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
*/ | ||
package rife.bld.idea.config; | ||
|
||
import com.intellij.openapi.Disposable; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.application.ApplicationManager; | ||
import com.intellij.openapi.application.ModalityState; | ||
import com.intellij.openapi.components.PersistentStateComponent; | ||
import com.intellij.openapi.components.Service; | ||
import com.intellij.openapi.components.State; | ||
import com.intellij.openapi.components.Storage; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.SimpleModificationTracker; | ||
import com.intellij.util.EventDispatcher; | ||
import org.jdom.Element; | ||
import org.jetbrains.annotations.Nls; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CopyOnWriteArrayList; | ||
|
||
@Service(Service.Level.PROJECT) | ||
public final class BldConfiguration implements Disposable { | ||
private final Project project_; | ||
private final List<BldBuildCommand> buildCommands_ = new CopyOnWriteArrayList<>(); | ||
private final EventDispatcher<BldConfigurationListener> myEventDispatcher = EventDispatcher.create(BldConfigurationListener.class); | ||
|
||
private volatile boolean initialized_ = false; | ||
|
||
public BldConfiguration(final Project project) { | ||
project_ = project; | ||
|
||
ApplicationManager.getApplication().invokeLater( | ||
() -> myEventDispatcher.getMulticaster().configurationLoaded(), | ||
ModalityState.any() | ||
); | ||
} | ||
|
||
public static BldConfiguration getInstance(final @NotNull Project project) { | ||
return project.getService(BldConfiguration.class); | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
// no-op | ||
} | ||
|
||
public boolean isInitialized() { | ||
return initialized_; | ||
} | ||
|
||
public List<BldBuildCommand> getBuildCommandList() { | ||
return buildCommands_; | ||
} | ||
|
||
public void setBuildCommandList(ArrayList<BldBuildCommand> commands) { | ||
initialized_ = true; | ||
|
||
buildCommands_.clear(); | ||
buildCommands_.addAll(commands); | ||
ApplicationManager.getApplication().invokeLater( | ||
() -> myEventDispatcher.getMulticaster().configurationChanged(), | ||
ModalityState.any() | ||
); | ||
} | ||
|
||
public void addBldConfigurationListener(final BldConfigurationListener listener) { | ||
myEventDispatcher.addListener(listener); | ||
} | ||
|
||
public void removeBldConfigurationListener(final BldConfigurationListener listener) { | ||
myEventDispatcher.removeListener(listener); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/rife/bld/idea/config/BldConfigurationListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com) | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
*/ | ||
package rife.bld.idea.config; | ||
|
||
import java.util.EventListener; | ||
|
||
public interface BldConfigurationListener extends EventListener { | ||
default void configurationLoaded() { | ||
} | ||
|
||
default void configurationChanged() { | ||
} | ||
} |
144 changes: 144 additions & 0 deletions
144
src/main/java/rife/bld/idea/config/explorer/BldExplorerTreeStructure.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/* | ||
* Copyright 2024 Geert Bevin (gbevin[remove] at uwyn dot com) | ||
* Licensed under the Apache License, Version 2.0 (the "License") | ||
*/ | ||
package rife.bld.idea.config.explorer; | ||
|
||
import com.intellij.ide.util.treeView.AbstractTreeStructure; | ||
import com.intellij.ide.util.treeView.NodeDescriptor; | ||
import com.intellij.openapi.diagnostic.Logger; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.util.ActionCallback; | ||
import com.intellij.psi.PsiDocumentManager; | ||
import com.intellij.util.ArrayUtilRt; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import rife.bld.idea.config.BldBuildCommand; | ||
import rife.bld.idea.config.BldConfiguration; | ||
import rife.bld.idea.config.explorer.nodeDescriptors.*; | ||
import rife.bld.idea.utils.BldBundle; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
|
||
public final class BldExplorerTreeStructure extends AbstractTreeStructure { | ||
private static final Logger LOG = Logger.getInstance(BldExplorerTreeStructure.class); | ||
|
||
private final Project project_; | ||
|
||
private final Object root_ = new Object(); | ||
private final Object commandsFolder_ = new Object(); | ||
private final Object dependenciesFolder_ = new Object(); | ||
|
||
private static final Comparator<BldBuildCommand> commandComparator = (command1, command2) -> { | ||
final String name1 = command1.getDisplayName(); | ||
if (name1 == null) return -1; | ||
final String name2 = command2.getDisplayName(); | ||
if (name2 == null) return 1; | ||
return name1.compareToIgnoreCase(name2); | ||
}; | ||
|
||
public BldExplorerTreeStructure(final Project project) { | ||
project_ = project; | ||
} | ||
|
||
@Override | ||
public boolean isToBuildChildrenInBackground(@NotNull final Object element) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isAlwaysLeaf(@NotNull Object element) { | ||
return element != root_ && element != commandsFolder_ && element != dependenciesFolder_; | ||
} | ||
|
||
@Override | ||
@NotNull | ||
public BldNodeDescriptor createDescriptor(@NotNull Object element, NodeDescriptor parentDescriptor) { | ||
if (element == root_) { | ||
return new BldRootNodeDescriptor(project_, parentDescriptor, root_); | ||
} | ||
if (element == commandsFolder_) { | ||
return new BldFolderNodeDescriptor(project_, parentDescriptor, commandsFolder_, BldBundle.message("bld.project.commands")); | ||
} | ||
if (element == dependenciesFolder_) { | ||
return new BldFolderNodeDescriptor(project_, parentDescriptor, dependenciesFolder_, BldBundle.message("bld.project.dependencies")); | ||
} | ||
|
||
if (element instanceof BldBuildCommand) { | ||
return new BldCommandNodeDescriptor(project_, parentDescriptor, (BldBuildCommand)element); | ||
} | ||
|
||
if (element instanceof String) { | ||
return new BldTextNodeDescriptor(project_, parentDescriptor, (String) element); | ||
} | ||
|
||
LOG.error("Unknown element for this tree structure " + element); | ||
return new BldTextNodeDescriptor(project_, parentDescriptor, String.valueOf(element)); | ||
} | ||
|
||
@Override | ||
public Object @NotNull [] getChildElements(@NotNull Object element) { | ||
final var configuration = BldConfiguration.getInstance(project_); | ||
if (element == root_) { | ||
if (!configuration.isInitialized()) { | ||
return new Object[]{BldBundle.message("progress.text.loading.bld.config")}; | ||
} | ||
return new Object[]{commandsFolder_, dependenciesFolder_}; | ||
} | ||
|
||
if (element == commandsFolder_) { | ||
final var commands = new ArrayList<>(configuration.getBuildCommandList()); | ||
commands.sort(commandComparator); | ||
return commands.toArray(new BldBuildCommand[0]); | ||
} | ||
|
||
if (element == dependenciesFolder_) { | ||
// todo | ||
return ArrayUtilRt.EMPTY_OBJECT_ARRAY; | ||
} | ||
|
||
return ArrayUtilRt.EMPTY_OBJECT_ARRAY; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public Object getParentElement(@NotNull Object element) { | ||
if (element instanceof BldBuildCommand) { | ||
return commandsFolder_; | ||
} | ||
|
||
if (element == commandsFolder_) { | ||
return root_; | ||
} | ||
|
||
if (element == dependenciesFolder_) { | ||
return root_; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void commit() { | ||
PsiDocumentManager.getInstance(project_).commitAllDocuments(); | ||
} | ||
|
||
@Override | ||
public boolean hasSomethingToCommit() { | ||
return PsiDocumentManager.getInstance(project_).hasUncommitedDocuments(); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public ActionCallback asyncCommit() { | ||
return asyncCommitDocuments(project_); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Object getRootElement() { | ||
return root_; | ||
} | ||
|
||
} |
Oops, something went wrong.