Skip to content

Commit

Permalink
modernized implementation of combobox text fields with builtin button…
Browse files Browse the repository at this point in the history
…s as well as added allow/deny lists with autocompletion (#56)

Also upgraded DependencyTable to its autocompletion gets icons

Signed-off-by: Noam Dori <TheNODO55@gmail.com>
  • Loading branch information
Noam-Dori committed May 31, 2021
1 parent 0a95432 commit ba06146
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 220 deletions.
5 changes: 5 additions & 0 deletions .idea/libraries/ROS.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/main/java/ros/integrate/buildtool/ROSProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ROSProfile {
private String makeArgs = "", cmakeArgs = "", buildtoolArgs = "";
@NotNull
private String sourceDir = "", buildDir = "", develDir = "", installDir = "";
private String allowList = "", denyList = "";

@NotNull
public String getName() {
Expand Down Expand Up @@ -133,4 +134,20 @@ public void setDevelDir(@NotNull String develDir) {
public void setInstallDir(@NotNull String installDir) {
this.installDir = installDir;
}

public String getAllowList() {
return allowList;
}

public String getDenyList() {
return denyList;
}

public void setDenyList(String denyList) {
this.denyList = denyList;
}

public void setAllowList(String allowList) {
this.allowList = allowList;
}
}
85 changes: 58 additions & 27 deletions src/main/java/ros/integrate/buildtool/ui/ROSProfileForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,29 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.ui.DocumentAdapter;
import com.intellij.ui.TextFieldWithAutoCompletionListProvider;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBTextField;
import com.intellij.ui.components.fields.ExpandableTextField;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import ros.integrate.buildtool.ROSBuildTool;
import ros.integrate.buildtool.ROSProfile;
import ros.integrate.ui.BrowserOptions;
import ros.integrate.ui.BrowserOptions.HistoryKey;
import ros.integrate.pkg.ROSDepKeyCache;
import ros.integrate.pkg.ROSPackageManager;
import ros.integrate.pkg.psi.ROSPackage;
import ros.integrate.ui.HistoryKey;
import ros.integrate.ui.PathListTextField;
import ros.integrate.ui.PathTextFieldWithHistory;
import ros.integrate.ui.SectionedFormBuilder;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.awt.*;
import java.util.stream.Stream;
import java.util.Collection;
import java.util.HashSet;
import java.util.stream.Collectors;

/**
* the GUI component that allows editing details about a specific profile while remaining
Expand All @@ -28,16 +35,7 @@
public class ROSProfileForm {
@NotNull
private final JPanel panel;

private final JBLabel buildtoolArgsLabel = new JBLabel("<html><code>Buildtool</code> args:</html>");

private static int getMaxBuildtoolSize() {
int explicitSize = Stream.of(ROSBuildTool.values()).map(Enum::name)
.map(String::length)
.max(Integer::compare).orElse(0);
return Math.max(explicitSize, 9);
}

private final JBLabel buildtoolArgsLabel = new JBLabel();
private final JBTextField name = new FocusTextField();
private final ComboBox<ROSBuildTool> buildtool = new ComboBox<>(ROSBuildTool.values());
private final JBCheckBox doInstall = new JBCheckBox("Run install step");
Expand All @@ -50,6 +48,9 @@ private static int getMaxBuildtoolSize() {
develDir = new PathTextFieldWithHistory(),
installDir = new PathTextFieldWithHistory();

private final PathListTextField allowList = new PathListTextField(), denyList = new PathListTextField();
private final Collection<ROSPackage> packages = new HashSet<>();

public ROSProfileForm(@NotNull Project project) {
JBLabel nameLabel = new JBLabel("Name:");
JBLabel buildtoolLabel = new JBLabel("Build tool:");
Expand All @@ -60,19 +61,45 @@ public ROSProfileForm(@NotNull Project project) {
JBLabel buildDirLabel = new JBLabel("Build directory:");
JBLabel develDirLabel = new JBLabel("Devel directory:");
JBLabel installDirLabel = new JBLabel("Install directory:");

sourceDir.installFeatures(new BrowserOptions(project, HistoryKey.PROFILE_SOURCE)
.withTitle("Choose source directory")
.withDescription("The directory containing all sources"));
buildDir.installFeatures(new BrowserOptions(project, HistoryKey.PROFILE_BUILD)
.withTitle("Choose build directory")
.withDescription("The directory containing all files generated by CMake, the compiler, and linker"));
develDir.installFeatures(new BrowserOptions(project, HistoryKey.PROFILE_DEVEL)
.withTitle("Choose devel directory")
.withDescription("The directory containing the result files created by the build process"));
installDir.installFeatures(new BrowserOptions(project, HistoryKey.PROFILE_INSTALL)
.withTitle("Choose build directory")
.withDescription("The directory containing the final output exposed to the client"));
JBLabel allowListLabel = new JBLabel("Allowed packages");
JBLabel denyListLabel = new JBLabel("Denied packages");
buildtoolArgsLabel.setText("<html><code>Buildtool</code> args:</html>");

packages.addAll(project.getService(ROSPackageManager.class).getAllPackages());
packages.addAll(project.getService(ROSDepKeyCache.class).getAllKeys());
TextFieldWithAutoCompletionListProvider<String> provider =
new TextFieldWithAutoCompletionListProvider<String>(
packages.stream().map(ROSPackage::getName).collect(Collectors.toList())){
@NotNull
@Override
protected String getLookupString(@NotNull String item) {
return item;
}

@Override
protected @Nullable Icon getIcon(@NotNull String item) {
return packages.stream().filter(pkg -> item.equals(pkg.getName()))
.findFirst().orElse(ROSPackage.ORPHAN).getIcon(0);
}
};

sourceDir.installHistory(project, HistoryKey.PROFILE_SOURCE);
sourceDir.installBrowser("Choose source directory", "The directory containing all sources");
buildDir.installHistory(project, HistoryKey.PROFILE_BUILD);
buildDir.installBrowser("Choose build directory",
"The directory containing all files generated by CMake, the compiler, and linker");
develDir.installHistory(project, HistoryKey.PROFILE_DEVEL);
buildDir.installBrowser("Choose devel directory",
"The directory containing the result files created by the build process");
installDir.installHistory(project, HistoryKey.PROFILE_INSTALL);
installDir.installBrowser("Choose build directory",
"The directory containing the final output exposed to the client");
allowList.installHistory(project, HistoryKey.PACKAGE_LISTS);
allowList.installListExpansion("Change allowed packages", ',');
allowList.installAutoCompletion(provider);
denyList.installHistory(project, HistoryKey.PACKAGE_LISTS);
denyList.installListExpansion("Change denied packages ", ',');
denyList.installAutoCompletion(provider);

buildtool.setEditable(false);
buildtool.setRenderer(new DefaultListCellRenderer() {
Expand Down Expand Up @@ -123,7 +150,9 @@ public Component getListCellRendererComponent(JList<?> list, Object value, int i
.addLabeledComponent(buildDirLabel, buildDir)
.addLabeledComponent(develDirLabel, develDir)
.addLabeledComponent(installDirLabel, installDir)
.closeSection()
.closeSection().addSection("Specific packages")
.addLabeledComponent(allowListLabel, allowList)
.addLabeledComponent(denyListLabel, denyList)
.getPanel();
}

Expand All @@ -144,6 +173,8 @@ public void loadData(@NotNull ROSProfile profile, Runnable update) {
buildDir.setText(profile.getBuildDirectory());
develDir.setText(profile.getDevelDirectory());
installDir.setText(profile.getInstallDirectory());
allowList.setText(profile.getAllowList());
denyList.setText(profile.getDenyList());

name.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ros/integrate/pkg/ROSDepKeyCacheImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import ros.integrate.pkg.psi.impl.ROSDepKey;
import ros.integrate.ui.BrowserOptions;
import ros.integrate.settings.ROSSettings;
import ros.integrate.ui.HistoryKey;

import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -52,7 +52,7 @@ private void init() {
internetAttempted = false;
offlineMode = true;
};
settings.addListener(doOfflineCaching, BrowserOptions.HistoryKey.KNOWN_ROSDEP_KEYS.get());
settings.addListener(doOfflineCaching, HistoryKey.KNOWN_ROSDEP_KEYS.get());
doOfflineCaching.accept(settings);
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ros/integrate/pkg/ROSLibraryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupActivity;
import org.jetbrains.annotations.NotNull;
import ros.integrate.ui.BrowserOptions;
import ros.integrate.settings.ROSSettings;
import ros.integrate.ui.HistoryKey;

import java.util.Arrays;

Expand All @@ -27,7 +27,7 @@ public void runActivity(@NotNull Project project) {
if (ROSPackageFinder.FINDERS.stream().map(finder -> finder.updateLibraries(project))
.reduce((sum, val) -> sum || val).orElse(false))
project.getService(ROSPackageManager.class).reloadIndex();
}), new String[]{BrowserOptions.HistoryKey.EXTRA_SOURCES.get(),
BrowserOptions.HistoryKey.WORKSPACE.get()});
}), new String[]{HistoryKey.EXTRA_SOURCES.get(),
HistoryKey.WORKSPACE.get()});
}
}
4 changes: 2 additions & 2 deletions src/main/java/ros/integrate/pkg/ROSPackageManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import ros.integrate.pkg.psi.ROSPackage;
import ros.integrate.ui.BrowserOptions;
import ros.integrate.settings.ROSSettings;
import ros.integrate.ui.HistoryKey;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
Expand All @@ -41,7 +41,7 @@ public ROSPackageManagerImpl(@NotNull Project project) {
this.project = project;
loaded = false;
ROSSettings.getInstance(project).addListener(settings -> reloadIndex(),
BrowserOptions.HistoryKey.EXCLUDED_XMLS.get());
HistoryKey.EXCLUDED_XMLS.get());
}

private void loadIndex() {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ros/integrate/pkg/xml/ui/DependencyTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.intellij.util.ui.ListTableModel;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import ros.integrate.pkg.ROSDepKeyCache;
import ros.integrate.pkg.ROSPackageManager;
import ros.integrate.pkg.psi.ROSPackage;
Expand Down Expand Up @@ -166,6 +167,11 @@ public TableCellEditor getEditor(Entry entry) {
protected String getLookupString(@NotNull ROSPackage item) {
return item.getName();
}

@Override
protected @Nullable Icon getIcon(@NotNull ROSPackage item) {
return item.getIcon(0);
}
};
TextFieldWithAutoCompletion<ROSPackage> field = new TextFieldWithAutoCompletion<>(project,
provider, true, null);
Expand Down
40 changes: 16 additions & 24 deletions src/main/java/ros/integrate/settings/ROSSettingsPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import ros.integrate.pkg.ROSDepKeyCache;
import ros.integrate.pkg.xml.ROSLicenses;
import ros.integrate.ui.*;
import ros.integrate.ui.BrowserOptions.HistoryKey;

import javax.swing.*;
import javax.swing.event.DocumentEvent;
import java.util.Optional;
Expand Down Expand Up @@ -102,28 +100,22 @@ public JComponent createComponent() {
knownRosdepKeysLabel.setText("Known ROSDep Keys:");
fetchSourceListsButton.setText("Fetch ROSDep Source Lists");

rosRoot.installFeatures(new BrowserOptions(project)
.withTitle("Choose Target Directory")
.withDescription("This Directory is the Root ROS Library."));
workspace.installFeatures(new BrowserOptions(project, HistoryKey.WORKSPACE)
.withTitle("Choose Target Workspace")
.withDialogTitle("Configure Path to Workspace")
.withDescription("This is the root directory of this project's workspace"));
additionalSources.installFeatures(new BrowserOptions(project, HistoryKey.EXTRA_SOURCES)
.withTitle("Modify source path")
.withDialogTitle("Configure Paths to Source")
.withDescription("This is the a root directory to additional sources outside of the workspace."));
excludedXmls.installFeatures(new BrowserOptions(project, HistoryKey.EXCLUDED_XMLS)
.withTitle("Modify Excluded XMLs")
.withDialogTitle("Configure excluded XMLs")
.withDescription("These XML files will not be processed by the ROS plugin, and will not get extra context."));
rosdepSources.installFeatures(new BrowserOptions(project, HistoryKey.ROSDEP_SOURCES)
.withDialogTitle("Configure ROSDep Lists")
.withDelimiter('"')
.noFilePaths());
knownRosdepKeys.installFeatures(new BrowserOptions(project, HistoryKey.KNOWN_ROSDEP_KEYS)
.withDialogTitle("Configure Saved ROSDep Keys")
.noFilePaths());
rosRoot.installHistory(project, HistoryKey.ROS_ROOT);
rosRoot.installBrowser("Choose Target Directory", "This Directory is the Root ROS Library.");
workspace.installHistory(project, HistoryKey.WORKSPACE);
workspace.installBrowser("Choose Target Workspace", "This is the root directory of this project's workspace");
additionalSources.installHistory(project, HistoryKey.EXTRA_SOURCES);
additionalSources.installBrowser("Modify source path",
"This is the a root directory to additional sources outside of the workspace.");
additionalSources.installListExpansion("Configure Paths to Source");
excludedXmls.installHistory(project, HistoryKey.EXCLUDED_XMLS);
excludedXmls.installBrowser("Modify Excluded XMLs",
"These XML files will not be processed by the ROS plugin, and will not get extra context.");
excludedXmls.installListExpansion("Configure excluded XMLs");
rosdepSources.installHistory(project, HistoryKey.ROSDEP_SOURCES);
rosdepSources.installListExpansion("Configure ROSDep Lists", '"');
knownRosdepKeys.installHistory(project, HistoryKey.KNOWN_ROSDEP_KEYS);
knownRosdepKeys.installListExpansion("Configure Saved ROSDep Keys");
additionalSources.getTextEditor().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(@NotNull DocumentEvent e) {
Expand Down
Loading

0 comments on commit ba06146

Please sign in to comment.